diff --git a/addons/core/translations/resources/en-us.yaml b/addons/core/translations/resources/en-us.yaml index a96c0e70f..b48cbc316 100644 --- a/addons/core/translations/resources/en-us.yaml +++ b/addons/core/translations/resources/en-us.yaml @@ -434,15 +434,12 @@ target: messages: add: title: Enable session recording for target - options: - 1: Storage Bucket 1 - 2: Storage Bucket 2 form: filter: label: Record sessions for this target select: label: AWS storage buckets - description: Description for storage buckets + description: Sessions will be recorded and stored in this location. Must use Amazon S3. brokered-credential-source: title: Brokered Credential title_plural: Brokered Credentials diff --git a/ui/admin/app/components/form/enable-session-recording/index.js b/ui/admin/app/components/form/enable-session-recording/index.js deleted file mode 100644 index 2ad3f2629..000000000 --- a/ui/admin/app/components/form/enable-session-recording/index.js +++ /dev/null @@ -1,7 +0,0 @@ -import Component from '@glimmer/component'; -import { tracked } from '@glimmer/tracking'; - -export default class FormEnableSessionRecordingIndexComponent extends Component { - // =attributes - @tracked toggleEnabled = true; -} diff --git a/ui/admin/app/components/form/enable-session-recording/index.hbs b/ui/admin/app/components/form/target/enable-session-recording/index.hbs similarity index 60% rename from ui/admin/app/components/form/enable-session-recording/index.hbs rename to ui/admin/app/components/form/target/enable-session-recording/index.hbs index 5b60064a4..b1234f746 100644 --- a/ui/admin/app/components/form/enable-session-recording/index.hbs +++ b/ui/admin/app/components/form/target/enable-session-recording/index.hbs @@ -1,50 +1,54 @@ - +
- {{t 'resources.target.enable-session-recording.form.filter.label' }} - {{#if this.toggleEnabled}} {{t 'resources.target.enable-session-recording.form.select.label' }} - - {{!TODO: add correct description for form-select}} {{t 'resources.target.enable-session-recording.form.select.description' }} - - {{!TODO: replace dummy data with storage-bucket name and remove uneeded translations}} - - + {{#each @storageBucketList as |bucket|}} + + {{/each}} - - {{#if @model.errors.name}} + {{#if @model.errors.storage_bucket_id}} - {{#each @model.errors.name as |error|}} + {{#each @model.errors.storage_bucket_id as |error|}} {{error.message}} {{/each}} @@ -55,14 +59,14 @@ - +
\ No newline at end of file diff --git a/ui/admin/app/components/form/target/enable-session-recording/index.js b/ui/admin/app/components/form/target/enable-session-recording/index.js new file mode 100644 index 000000000..f506eb89c --- /dev/null +++ b/ui/admin/app/components/form/target/enable-session-recording/index.js @@ -0,0 +1,22 @@ +import Component from '@glimmer/component'; +import { tracked } from '@glimmer/tracking'; +import { action } from '@ember/object'; + +export default class FormEnableSessionRecordingIndexComponent extends Component { + // =attributes + @tracked toggleEnabled = true; + + //actions + /** + * toggle to enable session recording for the target + */ + @action + toggleSessionRecording() { + this.toggleEnabled = !this.toggleEnabled; + } + + @action + selectStorageBucket({ target: { value: selectedStorageBucketID } }) { + this.args.model.storage_bucket_id = selectedStorageBucketID; + } +} diff --git a/ui/admin/app/routes/scopes/scope/targets/target/enable-session-recording.js b/ui/admin/app/routes/scopes/scope/targets/target/enable-session-recording.js index 5dd07dd22..3b2363fd0 100644 --- a/ui/admin/app/routes/scopes/scope/targets/target/enable-session-recording.js +++ b/ui/admin/app/routes/scopes/scope/targets/target/enable-session-recording.js @@ -1,9 +1,13 @@ import Route from '@ember/routing/route'; import { inject as service } from '@ember/service'; +import { action } from '@ember/object'; +import { loading } from 'ember-loading'; +import { notifySuccess, notifyError } from 'core/decorators/notify'; +import { set } from '@ember/object'; export default class ScopesScopeTargetsTargetEnableSessionRecordingRoute extends Route { // =services - + @service store; @service router; // =methods @@ -14,7 +18,64 @@ export default class ScopesScopeTargetsTargetEnableSessionRecordingRoute extends */ async model() { - // TODO: need model for storage_bucket as well - return this.modelFor('scopes.scope.targets.target'); + const target = this.modelFor('scopes.scope.targets.target'); + const { scopeID: scope_id } = this.modelFor('scopes.scope'); + + //fetch storage buckets from global scope + const globalScopeStorageBuckets = await this.store.query('storage-bucket', { + scope_id: 'global', + }); + + //fetch storage buckets from target's org scope + const orgScopeStorageBuckets = await this.store.query('storage-bucket', { + scope_id, + }); + + //merge results from both global and target's org scope + //into one list for the dropdown + const storageBucketList = [ + ...globalScopeStorageBuckets.toArray(), + ...orgScopeStorageBuckets.toArray(), + ]; + + return { + target, + storageBucketList, + }; + } + + // =actions + /** + * Add storage bucket to target if the toggle is enabled, else remove it + * @param {TargetModel} target + * @param {boolean} isToggleEnabled + */ + @action + @loading + @notifyError(({ message }) => message, { catch: true }) + @notifySuccess('notifications.add-success') + async save(target, isToggleEnabled) { + const { id } = target; + if (isToggleEnabled) { + await target.setStorageBucket(); + } else { + await target.removeStorageBucket(); + } + this.router.replaceWith('scopes.scope.targets.target', id); + } + + /** + * reset the selected storage bucket and redirect to target + * @param {TargetModel} target + */ + @action + cancel(target) { + const { id } = target; + const changedAttributes = target.changedAttributes(); + if (Object.keys(changedAttributes).length) { + const existingAttributes = changedAttributes?.['storage_bucket_id']?.[0]; + set(target, 'storage_bucket_id', existingAttributes); + } + this.router.replaceWith('scopes.scope.targets.target', id); } } diff --git a/ui/admin/app/templates/scopes/scope/targets/target/enable-session-recording.hbs b/ui/admin/app/templates/scopes/scope/targets/target/enable-session-recording.hbs index 81e7bad08..89818dfa6 100644 --- a/ui/admin/app/templates/scopes/scope/targets/target/enable-session-recording.hbs +++ b/ui/admin/app/templates/scopes/scope/targets/target/enable-session-recording.hbs @@ -9,21 +9,22 @@

{{t 'resources.target.enable-session-recording.messages.add.title'}}

- {{!TODO: add description for enabling session recording}} + - {{@model.id}} + {{@model.target.id}} -