From 6e7717a7071fbf6fefdcc16e38892c8fa25fdd5b Mon Sep 17 00:00:00 2001 From: Chelsea Shaw <82459713+hashishaw@users.noreply.github.com> Date: Wed, 13 Mar 2024 10:03:27 -0500 Subject: [PATCH] UI: Ember deprecation - remove toArray (#25859) * replace all instances of toArray() with slice() * remove unnecessary array check * remove superfluous that used to be toArray * remove other superfluous slices * Revert "remove other superfluous slices" This reverts commit 51df83f44ebf0445a18c5cf17283ca7cde23fd53. --- ui/app/components/mfa/mfa-login-enforcement-form.js | 4 ++-- ui/app/components/mfa/mfa-login-enforcement-header.js | 2 +- ui/app/services/store.js | 2 +- ui/app/services/wizard.js | 4 ++-- ui/lib/core/addon/components/search-select-with-modal.js | 2 +- ui/lib/core/addon/components/search-select.js | 5 +---- ui/mirage/handlers/mfa-config.js | 2 +- ui/tests/helpers/sync/setup-models.js | 4 ++-- .../components/mfa-login-enforcement-form-test.js | 6 +++--- ui/tests/integration/components/pki-paginated-list-test.js | 4 ++-- .../components/sync/secrets/page/destinations-test.js | 3 ++- ui/tests/unit/unload-test.js | 4 ++-- 12 files changed, 20 insertions(+), 22 deletions(-) diff --git a/ui/app/components/mfa/mfa-login-enforcement-form.js b/ui/app/components/mfa/mfa-login-enforcement-form.js index 353ae32048..f12f9d279c 100644 --- a/ui/app/components/mfa/mfa-login-enforcement-form.js +++ b/ui/app/components/mfa/mfa-login-enforcement-form.js @@ -74,7 +74,7 @@ export default class MfaLoginEnforcementForm extends Component { const types = ['identity/group', 'identity/entity']; for (const type of types) { try { - options[type] = (await this.store.query(type, {})).toArray(); + options[type] = await this.store.query(type, {}); } catch (error) { options[type] = []; } @@ -89,7 +89,7 @@ export default class MfaLoginEnforcementForm extends Component { } } async fetchAuthMethods() { - const mounts = (await this.store.findAll('auth-method')).toArray(); + const mounts = await this.store.findAll('auth-method'); this.authMethods = mounts.map((auth) => auth.type); } diff --git a/ui/app/components/mfa/mfa-login-enforcement-header.js b/ui/app/components/mfa/mfa-login-enforcement-header.js index 04ab55106e..03c424213c 100644 --- a/ui/app/components/mfa/mfa-login-enforcement-header.js +++ b/ui/app/components/mfa/mfa-login-enforcement-header.js @@ -41,7 +41,7 @@ export default class MfaLoginEnforcementHeaderComponent extends Component { async fetchEnforcements() { try { // cache initial values for lookup in select handler - this._enforcements = (await this.store.query('mfa-login-enforcement', {})).toArray(); + this._enforcements = await this.store.query('mfa-login-enforcement', {}); this.enforcements = [...this._enforcements]; } catch (error) { this.enforcements = []; diff --git a/ui/app/services/store.js b/ui/app/services/store.js index 3662614e21..d0b3e39dce 100644 --- a/ui/app/services/store.js +++ b/ui/app/services/store.js @@ -187,7 +187,7 @@ export default class StoreService extends Store { ); // Hack to make sure all records get in model correctly. remove with update to ember-data@4.12 this.peekAll(modelName).length; - const model = this.peekAll(modelName).toArray(); + const model = this.peekAll(modelName).slice(); model.set('meta', response.meta); resolve(model); }); diff --git a/ui/app/services/wizard.js b/ui/app/services/wizard.js index 58d242372a..b38b3af713 100644 --- a/ui/app/services/wizard.js +++ b/ui/app/services/wizard.js @@ -324,7 +324,7 @@ export default Service.extend(DEFAULTS, { getCompletedFeatures() { if (this.storageHasKey(COMPLETED_FEATURES)) { - return this.getExtState(COMPLETED_FEATURES).toArray(); + return this.getExtState(COMPLETED_FEATURES); } return []; }, @@ -337,7 +337,7 @@ export default Service.extend(DEFAULTS, { completed.push(done); this.saveExtState(COMPLETED_FEATURES, completed); } else { - this.saveExtState(COMPLETED_FEATURES, this.getExtState(COMPLETED_FEATURES).toArray().addObject(done)); + this.saveExtState(COMPLETED_FEATURES, this.getExtState(COMPLETED_FEATURES).addObject(done)); } this.saveExtState(FEATURE_LIST, features.length ? features : null); diff --git a/ui/lib/core/addon/components/search-select-with-modal.js b/ui/lib/core/addon/components/search-select-with-modal.js index 313f148621..85e66a872a 100644 --- a/ui/lib/core/addon/components/search-select-with-modal.js +++ b/ui/lib/core/addon/components/search-select-with-modal.js @@ -69,7 +69,7 @@ export default class SearchSelectWithModal extends Component { addSearchText(optionsToFormat) { // maps over array models from query - return optionsToFormat.toArray().map((option) => { + return optionsToFormat.map((option) => { option.searchText = `${option.name} ${option.id}`; return option; }); diff --git a/ui/lib/core/addon/components/search-select.js b/ui/lib/core/addon/components/search-select.js index f42dd2f27e..555941ef8b 100644 --- a/ui/lib/core/addon/components/search-select.js +++ b/ui/lib/core/addon/components/search-select.js @@ -100,7 +100,7 @@ export default class SearchSelect extends Component { addSearchText(optionsToFormat) { // maps over array of objects or response from query - return optionsToFormat.toArray().map((option) => { + return optionsToFormat.map((option) => { const id = option[this.idKey] ? option[this.idKey] : option.id; option.searchText = `${option[this.nameKey]} ${id}`; return option; @@ -278,9 +278,6 @@ export default class SearchSelect extends Component { } if (this.args.search) { return resolve(this.args.search(term, select)).then((results) => { - if (results.toArray) { - results = results.toArray(); - } this.addCreateOption(term, results); return results; }); diff --git a/ui/mirage/handlers/mfa-config.js b/ui/mirage/handlers/mfa-config.js index f16caa5ecd..2563f9b5d8 100644 --- a/ui/mirage/handlers/mfa-config.js +++ b/ui/mirage/handlers/mfa-config.js @@ -50,7 +50,7 @@ export default function (server) { records.push(server.create(`mfa-${type}-method`)); }); } else { - records = server.createList('mfa-login-enforcement', 4).toArray(); + records = server.createList('mfa-login-enforcement', 4); } } const dataKey = isMethod ? 'id' : 'name'; diff --git a/ui/tests/helpers/sync/setup-models.js b/ui/tests/helpers/sync/setup-models.js index 00a3a851da..801861d5b1 100644 --- a/ui/tests/helpers/sync/setup-models.js +++ b/ui/tests/helpers/sync/setup-models.js @@ -17,7 +17,7 @@ export function setupModels(hooks) { id: destination.name, }); this.destination = this.store.peekRecord(destinationModelName, destination.name); - this.destinations = this.store.peekAll(destinationModelName).toArray(); + this.destinations = this.store.peekAll(destinationModelName); this.destinations.meta = { filteredTotal: this.destinations.length, currentPage: 1, @@ -43,7 +43,7 @@ export function setupModels(hooks) { }); this.association = this.store.peekRecord(associationModelName, associationId); - this.associations = this.store.peekAll(associationModelName).toArray(); + this.associations = this.store.peekAll(associationModelName); this.associations.meta = { filteredTotal: this.associations.length, currentPage: 1, diff --git a/ui/tests/integration/components/mfa-login-enforcement-form-test.js b/ui/tests/integration/components/mfa-login-enforcement-form-test.js index b605d6d523..e593f2d19e 100644 --- a/ui/tests/integration/components/mfa-login-enforcement-form-test.js +++ b/ui/tests/integration/components/mfa-login-enforcement-form-test.js @@ -152,7 +152,7 @@ module('Integration | Component | mfa-login-enforcement-form', function (hooks) test('it should populate fields with model data', async function (assert) { this.model.name = 'foo'; - const [method] = (await this.store.query('mfa-method', {})).toArray(); + const [method] = await this.store.query('mfa-method', {}); this.model.mfa_methods.addObject(method); this.model.auth_method_accessors.addObject('auth_userpass_1234'); @@ -209,9 +209,9 @@ module('Integration | Component | mfa-login-enforcement-form', function (hooks) })); this.model.auth_method_accessors.addObject('auth_userpass_1234'); this.model.auth_method_types.addObject('userpass'); - const [entity] = (await this.store.query('identity/entity', {})).toArray(); + const [entity] = await this.store.query('identity/entity', {}); this.model.identity_entities.addObject(entity); - const [group] = (await this.store.query('identity/group', {})).toArray(); + const [group] = await this.store.query('identity/group', {}); this.model.identity_groups.addObject(group); await render(hbs` diff --git a/ui/tests/integration/components/pki-paginated-list-test.js b/ui/tests/integration/components/pki-paginated-list-test.js index 8ad3d1f8a7..f6a7ff065e 100644 --- a/ui/tests/integration/components/pki-paginated-list-test.js +++ b/ui/tests/integration/components/pki-paginated-list-test.js @@ -34,8 +34,8 @@ module('Integration | Component | pki-paginated-list', function (hooks) { key_name: 'another-key', }, }); - // toArray to mimic what happens in lazyPaginatedQuery - const keyModels = this.store.peekAll('pki/key').toArray(); + // mimic what happens in lazyPaginatedQuery + const keyModels = this.store.peekAll('pki/key'); keyModels.meta = STANDARD_META; this.list = keyModels; const emptyList = this.store.peekAll('pki/foo'); diff --git a/ui/tests/integration/components/sync/secrets/page/destinations-test.js b/ui/tests/integration/components/sync/secrets/page/destinations-test.js index 3d6d6944bf..51b93bbf9d 100644 --- a/ui/tests/integration/components/sync/secrets/page/destinations-test.js +++ b/ui/tests/integration/components/sync/secrets/page/destinations-test.js @@ -45,7 +45,8 @@ module('Integration | Component | sync | Page::Destinations', function (hooks) { id: destination.name, }); - this.destinations = store.peekAll(modelName).toArray(); + // mimic what happens in lazyPaginatedQuery + this.destinations = store.peekAll(modelName); this.destinations.meta = { filteredTotal: this.destinations.length, currentPage: 1, diff --git a/ui/tests/unit/unload-test.js b/ui/tests/unit/unload-test.js index ae090affb1..5b486618d2 100644 --- a/ui/tests/unit/unload-test.js +++ b/ui/tests/unit/unload-test.js @@ -70,7 +70,7 @@ module('Unit | Model | unloadAll works as expected', function (hooks) { assert.strictEqual(this.store.peekAll('company').length, 0, 'peekAll 0 - companies unloaded'); assert.strictEqual( - this.store.peekAll('company').toArray().length, + this.store.peekAll('company').slice().length, 0, 'peekAll array 0 - companies unloaded' ); @@ -106,7 +106,7 @@ module('Unit | Model | unloadAll works as expected', function (hooks) { assert.strictEqual(this.store.peekAll('company').length, 0, 'peekAll 0 - companies unloaded'); assert.strictEqual( - this.store.peekAll('company').toArray().length, + this.store.peekAll('company').slice().length, 0, 'peekAll array 0 - companies unloaded' );