From 89263918eadafdc8909912ba9d4b4da859c3071a Mon Sep 17 00:00:00 2001 From: Lisbet Alvarez <107949262+lisbet-alvarez@users.noreply.github.com> Date: Wed, 12 Mar 2025 10:09:16 -0700 Subject: [PATCH] Icu 16534 refactor usage of tracked using this args (#2711) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: 💡 remove tracked usage with this.args --- addons/api/addon/models/host-catalog.js | 14 ++++++----- addons/api/addon/models/storage-bucket.js | 15 +++++++----- addons/api/addon/serializers/host-catalog.js | 2 +- .../form/host-catalog/aws/index.hbs | 4 ++-- .../components/form/host-catalog/aws/index.js | 23 ++++-------------- .../form/storage-bucket/aws/index.hbs | 4 ++-- .../form/storage-bucket/aws/index.js | 24 ++++--------------- .../worker-filter-generator/index.js | 9 ++++++- .../scopes/scope/host-catalogs/index.js | 6 ++--- .../scopes/scope/storage-buckets/index.js | 5 ++++ 10 files changed, 48 insertions(+), 58 deletions(-) diff --git a/addons/api/addon/models/host-catalog.js b/addons/api/addon/models/host-catalog.js index f220fd56e..c7f6ae2e7 100644 --- a/addons/api/addon/models/host-catalog.js +++ b/addons/api/addon/models/host-catalog.js @@ -4,6 +4,7 @@ */ import GeneratedHostCatalogModel from '../generated/models/host-catalog'; +import { tracked } from '@glimmer/tracking'; export const TYPE_HOST_CATALOG_STATIC = 'static'; export const TYPE_HOST_CATALOG_DYNAMIC = 'plugin'; @@ -40,7 +41,8 @@ export const STATIC_CREDENTIAL_FIELDS = ['access_key_id, secret_access_key']; export default class HostCatalogModel extends GeneratedHostCatalogModel { // =attributes - #credentialType; + @tracked _credentialTypeValue; + /** * True if the host catalog is static. * @type {boolean} @@ -62,14 +64,14 @@ export default class HostCatalogModel extends GeneratedHostCatalogModel { * @type {string} */ get credentialType() { - if (!this.#credentialType) { + if (!this._credentialTypeValue) { if (DYNAMIC_CREDENTIAL_FIELDS.some((field) => this[field])) { - this.#credentialType = TYPE_CREDENTIAL_DYNAMIC; + return TYPE_CREDENTIAL_DYNAMIC; } else { - this.#credentialType = TYPE_CREDENTIAL_STATIC; + return TYPE_CREDENTIAL_STATIC; } } - return this.#credentialType; + return this._credentialTypeValue; } /** @@ -77,7 +79,7 @@ export default class HostCatalogModel extends GeneratedHostCatalogModel { * @type {string} */ set credentialType(type) { - this.#credentialType = type; + this._credentialTypeValue = type; } /** diff --git a/addons/api/addon/models/storage-bucket.js b/addons/api/addon/models/storage-bucket.js index 7cd6c9756..baa01a42a 100644 --- a/addons/api/addon/models/storage-bucket.js +++ b/addons/api/addon/models/storage-bucket.js @@ -4,6 +4,7 @@ */ import GeneratedStorageBucketModel from '../generated/models/storage-bucket'; +import { tracked } from '@glimmer/tracking'; export const TYPE_STORAGE_BUCKET_PLUGIN = 'plugin'; export const TYPES_STORAGE_BUCKET = Object.freeze([TYPE_STORAGE_BUCKET_PLUGIN]); @@ -26,7 +27,8 @@ export const TYPES_CREDENTIALS = Object.freeze([ export default class StorageBucketModel extends GeneratedStorageBucketModel { // attributes - #credentialType; + @tracked _credentialTypeValue; + /** * True if the storage bucket is a plugin. * @type {boolean} @@ -40,14 +42,14 @@ export default class StorageBucketModel extends GeneratedStorageBucketModel { * @type {string} */ get credentialType() { - if (!this.#credentialType) { + if (!this._credentialTypeValue) { if (this.role_arn) { - this.#credentialType = TYPE_CREDENTIAL_DYNAMIC; + return TYPE_CREDENTIAL_DYNAMIC; } else { - this.#credentialType = TYPE_CREDENTIAL_STATIC; + return TYPE_CREDENTIAL_STATIC; } } - return this.#credentialType; + return this._credentialTypeValue; } /** @@ -55,8 +57,9 @@ export default class StorageBucketModel extends GeneratedStorageBucketModel { * @type {string} */ set credentialType(type) { - this.#credentialType = type; + this._credentialTypeValue = type; } + /** * True if the storage bucket is an unknown type. * @type {boolean} diff --git a/addons/api/addon/serializers/host-catalog.js b/addons/api/addon/serializers/host-catalog.js index 373f5eee9..01fff404a 100644 --- a/addons/api/addon/serializers/host-catalog.js +++ b/addons/api/addon/serializers/host-catalog.js @@ -34,7 +34,7 @@ export default class HostCatalogSerializer extends ApplicationSerializer { ) { if (options.isNestedAttribute) { json.attributes[key] = null; - } else if (options.isNestedSecret && json.secrets[key]) { + } else if (options.isNestedSecret && json.secrets?.[key]) { delete json.secrets[key]; if (Object.keys(json.secrets).length === 0) { delete json.secrets; diff --git a/ui/admin/app/components/form/host-catalog/aws/index.hbs b/ui/admin/app/components/form/host-catalog/aws/index.hbs index 5f0601c68..0b9276e6a 100644 --- a/ui/admin/app/components/form/host-catalog/aws/index.hbs +++ b/ui/admin/app/components/form/host-catalog/aws/index.hbs @@ -165,9 +165,9 @@ diff --git a/ui/admin/app/components/form/host-catalog/aws/index.js b/ui/admin/app/components/form/host-catalog/aws/index.js index 1385ea0ee..e6c8bf5e6 100644 --- a/ui/admin/app/components/form/host-catalog/aws/index.js +++ b/ui/admin/app/components/form/host-catalog/aws/index.js @@ -4,22 +4,16 @@ */ import Component from '@glimmer/component'; -import { action } from '@ember/object'; import { TYPES_CREDENTIALS, TYPE_CREDENTIAL_DYNAMIC, } from 'api/models/host-catalog'; -import { tracked } from '@glimmer/tracking'; export default class FormHostCatalogAwsComponent extends Component { // =attributes - @tracked selectedCredentialType = this.args.model.credentialType; - - @tracked showDynamicCredentials = - this.args.model.credentialType === TYPE_CREDENTIAL_DYNAMIC; /** - * returns an array of available credential types + * Returns an array of available credential types. * @type {array} */ get credentials() { @@ -27,17 +21,10 @@ export default class FormHostCatalogAwsComponent extends Component { } /** - * Allows to update the credential type - * @param type {string} + * Returns true if credential type is dynamic. + * @type {boolean} */ - @action - updateCredentialTypeSelection(type) { - this.selectedCredentialType = type; - if (type === TYPE_CREDENTIAL_DYNAMIC) { - this.showDynamicCredentials = true; - } else { - this.showDynamicCredentials = false; - } - this.args.changeCredentialType(type); + get showDynamicCredentials() { + return this.args.model.credentialType === TYPE_CREDENTIAL_DYNAMIC; } } diff --git a/ui/admin/app/components/form/storage-bucket/aws/index.hbs b/ui/admin/app/components/form/storage-bucket/aws/index.hbs index b61932cee..a4f53c64a 100644 --- a/ui/admin/app/components/form/storage-bucket/aws/index.hbs +++ b/ui/admin/app/components/form/storage-bucket/aws/index.hbs @@ -221,9 +221,9 @@ {{#each this.credentials as |credentialType|}} {{t diff --git a/ui/admin/app/components/form/storage-bucket/aws/index.js b/ui/admin/app/components/form/storage-bucket/aws/index.js index 3d8d43bd3..da83c87e3 100644 --- a/ui/admin/app/components/form/storage-bucket/aws/index.js +++ b/ui/admin/app/components/form/storage-bucket/aws/index.js @@ -4,41 +4,27 @@ */ import Component from '@glimmer/component'; -import { action } from '@ember/object'; import { TYPES_CREDENTIALS, TYPE_CREDENTIAL_DYNAMIC, } from 'api/models/storage-bucket'; -import { tracked } from '@glimmer/tracking'; export default class FormStorageBucketAwsIndexComponent extends Component { // =attributes - @tracked selectedCredentialType = this.args.model.credentialType; - @tracked showDynamicCredentials = - this.args.model.credentialType === TYPE_CREDENTIAL_DYNAMIC; - /** - * returns an array of available credential types + * Returns an array of available credential types. * @type {array} */ get credentials() { return TYPES_CREDENTIALS; } - // =actions /** - * Allows to update the credential type - * @param {string} type + * Returns true if credential type is dynamic. + * @type {boolean} */ - @action - updateCredentialTypeSelection(type) { - this.selectedCredentialType = type; - if (type === TYPE_CREDENTIAL_DYNAMIC) { - this.showDynamicCredentials = true; - } else { - this.showDynamicCredentials = false; - } - this.args.changeCredentialType(type); + get showDynamicCredentials() { + return this.args.model.credentialType === TYPE_CREDENTIAL_DYNAMIC; } } diff --git a/ui/admin/app/components/worker-filter-generator/index.js b/ui/admin/app/components/worker-filter-generator/index.js index 035d1bd73..dd2e2bf73 100644 --- a/ui/admin/app/components/worker-filter-generator/index.js +++ b/ui/admin/app/components/worker-filter-generator/index.js @@ -13,12 +13,19 @@ export default class WorkerFilterGeneratorIndexComponent extends Component { generatorTagType = 'tag'; generatorNameType = 'name'; operatorOptions = ['==', 'matches', 'contains']; - @tracked showFilterGenerator = this.args.showFilterGenerator; + @tracked showFilterGenerator = this.defaultShowFilterGenerator; @tracked selectedGeneratorType = this.generatorTagType; @tracked key = ''; @tracked value = ''; @tracked operator = ''; + /** + * @type {string} + */ + get defaultShowFilterGenerator() { + return this.args.showFilterGenerator; + } + /** * @return {string} */ diff --git a/ui/admin/app/controllers/scopes/scope/host-catalogs/index.js b/ui/admin/app/controllers/scopes/scope/host-catalogs/index.js index 1ea5c138e..c28af507b 100644 --- a/ui/admin/app/controllers/scopes/scope/host-catalogs/index.js +++ b/ui/admin/app/controllers/scopes/scope/host-catalogs/index.js @@ -11,7 +11,7 @@ import { debounce } from 'core/decorators/debounce'; import { loading } from 'ember-loading'; import { confirm } from 'core/decorators/confirm'; import { notifySuccess, notifyError } from 'core/decorators/notify'; -import { TYPE_STATIC_CREDENTIAL } from 'api/models/host-catalog'; +import { TYPE_CREDENTIAL_STATIC } from 'api/models/host-catalog'; export default class ScopesScopeHostCatalogsIndexController extends Controller { // =services @@ -92,7 +92,7 @@ export default class ScopesScopeHostCatalogsIndexController extends Controller { async save(hostCatalog) { // If the role_arn is empty, then the credential type should be static if (!hostCatalog.role_arn) { - hostCatalog.credentialType = TYPE_STATIC_CREDENTIAL; + hostCatalog.credentialType = TYPE_CREDENTIAL_STATIC; } await hostCatalog.save(); if (this.can.can('read host-catalog', hostCatalog)) { @@ -133,7 +133,7 @@ export default class ScopesScopeHostCatalogsIndexController extends Controller { /** * Updates credential type - * @param {model} hostcatalog + * @param {model} hostCatalog * @param {string} credentialType */ @action diff --git a/ui/admin/app/controllers/scopes/scope/storage-buckets/index.js b/ui/admin/app/controllers/scopes/scope/storage-buckets/index.js index c917c25b8..1566e6380 100644 --- a/ui/admin/app/controllers/scopes/scope/storage-buckets/index.js +++ b/ui/admin/app/controllers/scopes/scope/storage-buckets/index.js @@ -9,6 +9,7 @@ import { action } from '@ember/object'; import { loading } from 'ember-loading'; import { confirm } from 'core/decorators/confirm'; import { notifySuccess, notifyError } from 'core/decorators/notify'; +import { TYPE_CREDENTIAL_STATIC } from 'api/models/storage-bucket'; export default class ScopesScopeStorageBucketsIndexController extends Controller { // =services @@ -55,6 +56,10 @@ export default class ScopesScopeStorageBucketsIndexController extends Controller @notifyError(({ message }) => message) @notifySuccess('notifications.save-success') async save(storageBucket) { + // If the role_arn is empty, then the credential type should be static + if (!storageBucket.role_arn) { + storageBucket.credentialType = TYPE_CREDENTIAL_STATIC; + } await storageBucket.save(); await this.router.transitionTo( 'scopes.scope.storage-buckets.storage-bucket',