From aa5d9f7b4992ceb46cce1d0602786b125e4448f0 Mon Sep 17 00:00:00 2001 From: Chelsea Shaw <82459713+hashishaw@users.noreply.github.com> Date: Wed, 21 Feb 2024 12:45:00 -0600 Subject: [PATCH] UI: Ember 5 deprecations: filterBy, mapBy, auto location (#25546) * Replace all mapBy * Replace findBys * Remove auto location https://deprecations.emberjs.com/v4.x/\#toc_deprecate-auto-location * fixes Co-authored-by: Kianna <30884335+kiannaquach@users.noreply.github.com> --- ui/app/adapters/secret-engine.js | 6 +++++- ui/app/components/auth-form.js | 4 ++-- ui/app/components/control-group.js | 2 +- ui/app/components/mfa/mfa-form.js | 8 ++++++-- ui/app/components/mfa/mfa-login-enforcement-form.js | 4 ++-- .../components/mfa/mfa-login-enforcement-header.js | 2 +- ui/app/components/oidc/provider-form.js | 2 +- ui/app/components/secret-create-or-update.js | 4 ++-- ui/app/components/wizard/features-selection.js | 4 ++-- ui/app/config/environment.d.ts | 2 +- ui/app/controllers/vault/cluster/policies/index.js | 2 +- .../vault/cluster/settings/mount-secret-backend.js | 2 +- ui/app/helpers/mountable-secret-engines.js | 2 +- ui/app/models/mfa-login-enforcement.js | 2 +- ui/app/models/secret-engine.js | 2 +- ui/app/routes/vault/cluster/access/method.js | 2 +- ui/app/routes/vault/cluster/secrets/backend/list.js | 2 +- ui/app/services/auth.js | 4 ++-- ui/app/utils/field-to-attrs.js | 2 +- ui/lib/core/addon/components/icon.js | 2 +- .../core/addon/components/info-table-item-array.js | 2 +- ui/lib/core/addon/components/kv-object-editor.js | 2 +- .../addon/components/search-select-with-modal.js | 7 +++---- ui/lib/core/addon/components/search-select.js | 9 ++++----- ui/lib/core/addon/components/string-list.js | 2 +- ui/lib/core/addon/helpers/options-for-backend.js | 3 +-- ui/lib/core/addon/mixins/list-controller.js | 2 +- ui/lib/core/addon/utils/search-select-has-many.js | 2 +- .../addon/components/page/role/create-and-edit.js | 6 +++--- ui/lib/kv/addon/components/page/secret/paths.js | 4 ++-- .../addon/components/path-filter-config-list.js | 4 ++-- ui/mirage/handlers/kubernetes.js | 2 +- ui/tests/acceptance/init-test.js | 12 ++++++++++-- ui/tests/acceptance/mfa-method-test.js | 2 +- .../integration/components/search-select-test.js | 4 ++-- ui/tests/unit/services/store-test.js | 12 ++++++++---- 36 files changed, 76 insertions(+), 59 deletions(-) diff --git a/ui/app/adapters/secret-engine.js b/ui/app/adapters/secret-engine.js index fef5d33183..5f294b2b33 100644 --- a/ui/app/adapters/secret-engine.js +++ b/ui/app/adapters/secret-engine.js @@ -132,7 +132,11 @@ export default ApplicationAdapter.extend({ saveZeroAddressConfig(store, type, snapshot) { const path = encodePath(snapshot.id); - const roles = store.peekAll('role-ssh').filterBy('zeroAddress').mapBy('id').join(','); + const roles = store + .peekAll('role-ssh') + .filter((role) => role.zeroAddress) + .map((role) => role.id) + .join(','); const url = `/v1/${path}/config/zeroaddress`; const data = { roles }; if (roles === '') { diff --git a/ui/app/components/auth-form.js b/ui/app/components/auth-form.js index e7774f3437..76748f7cc9 100644 --- a/ui/app/components/auth-form.js +++ b/ui/app/components/auth-form.js @@ -139,9 +139,9 @@ export default Component.extend(DEFAULTS, { } // if type is provided we can ignore path since we are attempting to lookup a specific backend by type if (keyIsPath && !type) { - return methods.findBy('path', selected); + return methods.find((m) => m.path === selected); } - return this.authMethods.findBy('type', selected); + return this.authMethods.find((m) => m.type === selected); }, selectedAuthIsPath: match('selectedAuth', /\/$/), diff --git a/ui/app/components/control-group.js b/ui/app/components/control-group.js index fa47ccaee1..c5ff165922 100644 --- a/ui/app/components/control-group.js +++ b/ui/app/components/control-group.js @@ -33,7 +33,7 @@ export default Component.extend({ currentUserHasAuthorized: computed('currentUserEntityId', 'model.authorizations.@each.id', function () { const authorizations = this.model.authorizations || []; - return Boolean(authorizations.findBy('id', this.currentUserEntityId)); + return Boolean(authorizations.find((authz) => authz.id === this.currentUserEntityId)); }), isSuccess: or('currentUserHasAuthorized', 'model.approved'), diff --git a/ui/app/components/mfa/mfa-form.js b/ui/app/components/mfa/mfa-form.js index e5d8f8b768..20b09ac4f6 100644 --- a/ui/app/components/mfa/mfa-form.js +++ b/ui/app/components/mfa/mfa-form.js @@ -37,7 +37,7 @@ export default class MfaForm extends Component { super(...arguments); // trigger validation immediately when passcode is not required const passcodeOrSelect = this.constraints.filter((constraint) => { - return constraint.methods.length > 1 || constraint.methods.findBy('uses_passcode'); + return constraint.methods.length > 1 || constraint.methods.find((m) => m.uses_passcode); }); if (!passcodeOrSelect.length) { this.validate.perform(); @@ -112,7 +112,11 @@ export default class MfaForm extends Component { @action onSelect(constraint, id) { set(constraint, 'selectedId', id); - set(constraint, 'selectedMethod', constraint.methods.findBy('id', id)); + set( + constraint, + 'selectedMethod', + constraint.methods.find((m) => m.id === id) + ); } @action submit(e) { e.preventDefault(); diff --git a/ui/app/components/mfa/mfa-login-enforcement-form.js b/ui/app/components/mfa/mfa-login-enforcement-form.js index 533b1d10c6..6d9109bda7 100644 --- a/ui/app/components/mfa/mfa-login-enforcement-form.js +++ b/ui/app/components/mfa/mfa-login-enforcement-form.js @@ -91,11 +91,11 @@ export default class MfaLoginEnforcementForm extends Component { } async fetchAuthMethods() { const mounts = (await this.store.findAll('auth-method')).toArray(); - this.authMethods = mounts.mapBy('type'); + this.authMethods = mounts.map((auth) => auth.type); } get selectedTarget() { - return this.targetTypes.findBy('type', this.selectedTargetType); + return this.targetTypes.find((tt) => tt.type === this.selectedTargetType); } get errors() { return this.args.modelErrors || this.modelErrors; diff --git a/ui/app/components/mfa/mfa-login-enforcement-header.js b/ui/app/components/mfa/mfa-login-enforcement-header.js index e0aa6ee562..04ab55106e 100644 --- a/ui/app/components/mfa/mfa-login-enforcement-header.js +++ b/ui/app/components/mfa/mfa-login-enforcement-header.js @@ -52,6 +52,6 @@ export default class MfaLoginEnforcementHeaderComponent extends Component { onEnforcementSelect([name]) { // search select returns array of strings, in this case enforcement name // lookup model and pass to callback - this.args.onEnforcementSelect(this._enforcements.findBy('name', name)); + this.args.onEnforcementSelect(this._enforcements.find((enf) => enf.name === name)); } } diff --git a/ui/app/components/oidc/provider-form.js b/ui/app/components/oidc/provider-form.js index 0291ebb7ca..96ef58abc5 100644 --- a/ui/app/components/oidc/provider-form.js +++ b/ui/app/components/oidc/provider-form.js @@ -39,7 +39,7 @@ export default class OidcProviderForm extends Component { // function passed to search select renderInfoTooltip(selection, dropdownOptions) { // if a client has been deleted it will not exist in dropdownOptions (response from search select's query) - const clientExists = !!dropdownOptions.findBy('clientId', selection); + const clientExists = !!dropdownOptions.find((opt) => opt.clientId === selection); return !clientExists ? 'The application associated with this client_id no longer exists' : false; } diff --git a/ui/app/components/secret-create-or-update.js b/ui/app/components/secret-create-or-update.js index 7b56cf76e1..298ab3ff1e 100644 --- a/ui/app/components/secret-create-or-update.js +++ b/ui/app/components/secret-create-or-update.js @@ -150,7 +150,7 @@ export default class SecretCreateOrUpdate extends Component { addRow() { const data = this.args.secretData; // fired off on init - if (isNone(data.findBy('name', ''))) { + if (isNone(data.find((d) => d.name === ''))) { data.pushObject({ name: '', value: '' }); this.handleChange(); } @@ -191,7 +191,7 @@ export default class SecretCreateOrUpdate extends Component { @action deleteRow(name) { const data = this.args.secretData; - const item = data.findBy('name', name); + const item = data.find((d) => d.name === name); if (isBlank(item.name)) { return; } diff --git a/ui/app/components/wizard/features-selection.js b/ui/app/components/wizard/features-selection.js index ced810afac..25f557f202 100644 --- a/ui/app/components/wizard/features-selection.js +++ b/ui/app/components/wizard/features-selection.js @@ -26,7 +26,7 @@ export default Component.extend({ }); if (this.showReplication === false) { - const feature = this.allFeatures.findBy('key', 'replication'); + const feature = this.allFeatures.find((f) => f.key === 'replication'); feature.show = false; } }, @@ -134,7 +134,7 @@ export default Component.extend({ showReplication: or('version.hasPerfReplication', 'version.hasDRReplication'), selectedFeatures: computed('allFeatures.@each.selected', function () { - return this.allFeatures.filterBy('selected').mapBy('key'); + return this.allFeatures.filter((feature) => feature.selected).map((feature) => feature.key); }), cannotStartWizard: not('selectedFeatures.length'), diff --git a/ui/app/config/environment.d.ts b/ui/app/config/environment.d.ts index ab9469e7e9..0c5887b003 100644 --- a/ui/app/config/environment.d.ts +++ b/ui/app/config/environment.d.ts @@ -11,7 +11,7 @@ declare const config: { environment: string; modulePrefix: string; podModulePrefix: string; - locationType: 'history' | 'hash' | 'none' | 'auto'; + locationType: 'history' | 'hash' | 'none'; rootURL: string; APP: Record; }; diff --git a/ui/app/controllers/vault/cluster/policies/index.js b/ui/app/controllers/vault/cluster/policies/index.js index 3695b9ba4e..34a54a5c1a 100644 --- a/ui/app/controllers/vault/cluster/policies/index.js +++ b/ui/app/controllers/vault/cluster/policies/index.js @@ -36,7 +36,7 @@ export default Controller.extend({ filterMatchesKey: computed('filter', 'model', 'model.[]', function () { var filter = this.filter; var content = this.model; - return !!(content && content.length && content.findBy('id', filter)); + return !!(content && content.length && content.find((c) => c.id === filter)); }), firstPartialMatch: computed('filter', 'model', 'model.[]', 'filterMatchesKey', function () { diff --git a/ui/app/controllers/vault/cluster/settings/mount-secret-backend.js b/ui/app/controllers/vault/cluster/settings/mount-secret-backend.js index 0afac3b039..8f0715b2a0 100644 --- a/ui/app/controllers/vault/cluster/settings/mount-secret-backend.js +++ b/ui/app/controllers/vault/cluster/settings/mount-secret-backend.js @@ -18,7 +18,7 @@ export default class MountSecretBackendController extends Controller { onMountSuccess(type, path, useEngineRoute = false) { let transition; if (SUPPORTED_BACKENDS.includes(type)) { - const engineInfo = allEngines().findBy('type', type); + const engineInfo = allEngines().find((engine) => engine.type === type); if (useEngineRoute) { transition = this.router.transitionTo( `vault.cluster.secrets.backend.${engineInfo.engineRoute}`, diff --git a/ui/app/helpers/mountable-secret-engines.js b/ui/app/helpers/mountable-secret-engines.js index e20f563254..398ed5e367 100644 --- a/ui/app/helpers/mountable-secret-engines.js +++ b/ui/app/helpers/mountable-secret-engines.js @@ -144,7 +144,7 @@ export function allEngines() { export function isAddonEngine(type, version) { if (type === 'kv' && version === 1) return false; - const engineRoute = allEngines().findBy('type', type)?.engineRoute; + const engineRoute = allEngines().find((engine) => engine.type === type)?.engineRoute; return !!engineRoute; } diff --git a/ui/app/models/mfa-login-enforcement.js b/ui/app/models/mfa-login-enforcement.js index 5f02195410..a78576cd52 100644 --- a/ui/app/models/mfa-login-enforcement.js +++ b/ui/app/models/mfa-login-enforcement.js @@ -108,7 +108,7 @@ export default class MfaLoginEnforcementModel extends Model { iconForMount(type) { const mountableMethods = methods(); - const mount = mountableMethods.findBy('type', type); + const mount = mountableMethods.find((method) => method.type === type); return mount ? mount.glyph || mount.type : 'token'; } } diff --git a/ui/app/models/secret-engine.js b/ui/app/models/secret-engine.js index b11b379af0..694beba449 100644 --- a/ui/app/models/secret-engine.js +++ b/ui/app/models/secret-engine.js @@ -145,7 +145,7 @@ export default class SecretEngineModel extends Model { return 'vault.cluster.secrets.backend.overview'; } if (isAddonEngine(this.engineType, this.version)) { - const { engineRoute } = allEngines().findBy('type', this.engineType); + const { engineRoute } = allEngines().find((engine) => engine.type === this.engineType); return `vault.cluster.secrets.backend.${engineRoute}`; } return `vault.cluster.secrets.backend.list-root`; diff --git a/ui/app/routes/vault/cluster/access/method.js b/ui/app/routes/vault/cluster/access/method.js index b0a65eaad0..5ed006bb45 100644 --- a/ui/app/routes/vault/cluster/access/method.js +++ b/ui/app/routes/vault/cluster/access/method.js @@ -16,7 +16,7 @@ export default Route.extend({ model(params) { const { path } = params; return this.store.findAll('auth-method').then((modelArray) => { - const model = modelArray.findBy('id', path); + const model = modelArray.find((m) => m.id === path); if (!model) { const error = new AdapterError(); set(error, 'httpStatus', 404); diff --git a/ui/app/routes/vault/cluster/secrets/backend/list.js b/ui/app/routes/vault/cluster/secrets/backend/list.js index d5abab471c..c66b862637 100644 --- a/ui/app/routes/vault/cluster/secrets/backend/list.js +++ b/ui/app/routes/vault/cluster/secrets/backend/list.js @@ -69,7 +69,7 @@ export default Route.extend({ const secretEngine = this.store.peekRecord('secret-engine', backend); const type = secretEngine?.engineType; assert('secretEngine.engineType is not defined', !!type); - const engineRoute = allEngines().findBy('type', type)?.engineRoute; + const engineRoute = allEngines().find((engine) => engine.type === type)?.engineRoute; if (!type || !SUPPORTED_BACKENDS.includes(type)) { return this.router.transitionTo('vault.cluster.secrets'); diff --git a/ui/app/services/auth.js b/ui/app/services/auth.js index f4b9efe501..136f34dc38 100644 --- a/ui/app/services/auth.js +++ b/ui/app/services/auth.js @@ -121,7 +121,7 @@ export default Service.extend({ backend: { // add mount path for password reset mountPath: stored.backend.mountPath, - ...BACKENDS.findBy('type', backend), + ...BACKENDS.find((b) => b.type === backend), }, }); }), @@ -267,7 +267,7 @@ export default Service.extend({ const currentBackend = { mountPath, - ...BACKENDS.findBy('type', backend), + ...BACKENDS.find((b) => b.type === backend), }; let displayName; if (isArray(currentBackend.displayNamePath)) { diff --git a/ui/app/utils/field-to-attrs.js b/ui/app/utils/field-to-attrs.js index 668fe1900c..cd32bf3a86 100644 --- a/ui/app/utils/field-to-attrs.js +++ b/ui/app/utils/field-to-attrs.js @@ -56,7 +56,7 @@ export const expandAttributeMeta = function (modelClass, attributeNames) { }); } // lookup attr and return meta - return modelAttrs[klass.modelName].findBy('name', attrKey); + return modelAttrs[klass.modelName].find((attr) => attr.name === attrKey); }; return fields.map((field) => { diff --git a/ui/lib/core/addon/components/icon.js b/ui/lib/core/addon/components/icon.js index aeb25045fd..3b86a40e75 100644 --- a/ui/lib/core/addon/components/icon.js +++ b/ui/lib/core/addon/components/icon.js @@ -6,7 +6,7 @@ import Component from '@glimmer/component'; import { assert } from '@ember/debug'; import flightIconMap from '@hashicorp/flight-icons/catalog.json'; -const flightIconNames = flightIconMap.assets.mapBy('iconName').uniq(); +const flightIconNames = flightIconMap.assets.map((asset) => asset.iconName).uniq(); /** * @module Icon diff --git a/ui/lib/core/addon/components/info-table-item-array.js b/ui/lib/core/addon/components/info-table-item-array.js index e11f91d087..b79afe102a 100644 --- a/ui/lib/core/addon/components/info-table-item-array.js +++ b/ui/lib/core/addon/components/info-table-item-array.js @@ -80,7 +80,7 @@ export default class InfoTableItemArray extends Component { } }); - this.allOptions = modelRecords ? modelRecords.mapBy('id') : null; + this.allOptions = modelRecords ? modelRecords.map((record) => record.id) : null; if (this.args.renderItemName && modelRecords) { modelRecords.forEach(({ id, name }) => { // create key/value pair { item-id: item-name } for each record diff --git a/ui/lib/core/addon/components/kv-object-editor.js b/ui/lib/core/addon/components/kv-object-editor.js index 2a1f47e8c4..084d3cc4b3 100644 --- a/ui/lib/core/addon/components/kv-object-editor.js +++ b/ui/lib/core/addon/components/kv-object-editor.js @@ -63,7 +63,7 @@ export default class KvObjectEditor extends Component { } @action addRow() { - if (!isNone(this.kvData.findBy('name', ''))) { + if (!isNone(this.kvData.find((datum) => datum.name === ''))) { return; } const newObj = { name: '', value: '' }; 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 fd96a17432..3ebcad12a0 100644 --- a/ui/lib/core/addon/components/search-select-with-modal.js +++ b/ui/lib/core/addon/components/search-select-with-modal.js @@ -79,7 +79,7 @@ export default class SearchSelectWithModal extends Component { // inputValues are initially an array of strings from @inputValue // map over so selectedOptions are objects return inputValues.map((option) => { - const matchingOption = this.dropdownOptions.findBy('id', option); + const matchingOption = this.dropdownOptions.find((opt) => opt.id === option); // remove any matches from dropdown list this.dropdownOptions.removeObject(matchingOption); return { @@ -140,11 +140,10 @@ export default class SearchSelectWithModal extends Component { shouldShowCreate(id, searchResults) { if (searchResults && searchResults.length && searchResults.firstObject.groupName) { - return !searchResults.some((group) => group.options.findBy('id', id)); + return !searchResults.some((group) => group.options.find((opt) => opt.id === id)); } const existingOption = - this.dropdownOptions && - (this.dropdownOptions.findBy('id', id) || this.dropdownOptions.findBy('name', id)); + this.dropdownOptions && this.dropdownOptions.find((opt) => opt.id === id || opt.name === id); return !existingOption; } diff --git a/ui/lib/core/addon/components/search-select.js b/ui/lib/core/addon/components/search-select.js index e31c8bde42..eb65bde171 100644 --- a/ui/lib/core/addon/components/search-select.js +++ b/ui/lib/core/addon/components/search-select.js @@ -111,7 +111,7 @@ export default class SearchSelect extends Component { // inputValues are initially an array of strings from @inputValue // map over so selectedOptions are objects return inputValues.map((option) => { - const matchingOption = this.dropdownOptions.findBy(this.idKey, option); + const matchingOption = this.dropdownOptions.find((opt) => opt[this.idKey] === option); // tooltip text comes from return of parent function const addTooltip = this.args.renderInfoTooltip ? this.args.renderInfoTooltip(option, this.dropdownOptions) @@ -170,7 +170,7 @@ export default class SearchSelect extends Component { const options = yield this.store.query(modelType, queryParams); // store both select + unselected options in tracked property used by wildcard filter - this.allOptions = [...this.allOptions, ...options.mapBy('id')]; + this.allOptions = [...this.allOptions, ...options.map((option) => option.id)]; // add to dropdown options this.dropdownOptions = [...this.dropdownOptions, ...this.addSearchText(options)]; @@ -209,11 +209,10 @@ export default class SearchSelect extends Component { shouldShowCreate(id, searchResults) { if (searchResults && searchResults.length && searchResults.firstObject.groupName) { - return !searchResults.some((group) => group.options.findBy('id', id)); + return !searchResults.some((group) => group.options.find((opt) => opt.id === id)); } const existingOption = - this.dropdownOptions && - (this.dropdownOptions.findBy('id', id) || this.dropdownOptions.findBy('name', id)); + this.dropdownOptions && this.dropdownOptions.find((opt) => opt.id === id || opt.name === id); if (this.args.disallowNewItems && !existingOption) { return false; } diff --git a/ui/lib/core/addon/components/string-list.js b/ui/lib/core/addon/components/string-list.js index 08adeab775..0a356dd30b 100644 --- a/ui/lib/core/addon/components/string-list.js +++ b/ui/lib/core/addon/components/string-list.js @@ -70,7 +70,7 @@ export default class StringList extends Component { } toVal() { - const inputs = this.inputList.filter((x) => x.value).mapBy('value'); + const inputs = this.inputList.filter((x) => x.value).map((x) => x.value); if (this.args.type === 'string') { return inputs.join(','); } diff --git a/ui/lib/core/addon/helpers/options-for-backend.js b/ui/lib/core/addon/helpers/options-for-backend.js index 09b6d47785..115aaeca36 100644 --- a/ui/lib/core/addon/helpers/options-for-backend.js +++ b/ui/lib/core/addon/helpers/options-for-backend.js @@ -152,8 +152,7 @@ export function optionsForBackend(backend, tab) { const selected = SECRET_BACKENDS[backend]; let backendOptions; if (selected && selected.tabs) { - const tabData = - selected.tabs.findBy('name', tab) || selected.tabs.findBy('modelPrefix', tab) || selected.tabs[0]; + const tabData = selected.tabs.find((t) => t.name === tab || t.modelPrefix === tab) || selected.tabs[0]; backendOptions = { ...selected, ...tabData }; } else if (selected) { backendOptions = selected; diff --git a/ui/lib/core/addon/mixins/list-controller.js b/ui/lib/core/addon/mixins/list-controller.js index a1c9c07764..024c5e8012 100644 --- a/ui/lib/core/addon/mixins/list-controller.js +++ b/ui/lib/core/addon/mixins/list-controller.js @@ -23,7 +23,7 @@ export default Mixin.create({ filterMatchesKey: computed('filter', 'model', 'model.[]', function () { const { filter, model: content } = this; - return !!(content.length && content.findBy('id', filter)); + return !!(content.length && content.find((c) => c.id === filter)); }), firstPartialMatch: computed('filter', 'model', 'model.[]', 'filterMatchesKey', function () { diff --git a/ui/lib/core/addon/utils/search-select-has-many.js b/ui/lib/core/addon/utils/search-select-has-many.js index 2f8e147eb6..e30ec358cd 100644 --- a/ui/lib/core/addon/utils/search-select-has-many.js +++ b/ui/lib/core/addon/utils/search-select-has-many.js @@ -28,7 +28,7 @@ export default function handleHasManySelection(selectedIds, modelCollection, sto } }); // now check for selected items that don't exist and add them to the model - const modelIds = modelCollection.mapBy('id'); + const modelIds = modelCollection.map((model) => model.id); selectedIds.forEach((id) => { if (!modelIds.includes(id)) { const model = store.peekRecord(modelRecord, id); diff --git a/ui/lib/kubernetes/addon/components/page/role/create-and-edit.js b/ui/lib/kubernetes/addon/components/page/role/create-and-edit.js index c45dba008f..d01d521e9c 100644 --- a/ui/lib/kubernetes/addon/components/page/role/create-and-edit.js +++ b/ui/lib/kubernetes/addon/components/page/role/create-and-edit.js @@ -99,11 +99,11 @@ export default class CreateAndEditRolePageComponent extends Component { this.selectedTemplateId = '1'; if (generatedRoleRules) { - const template = rulesTemplates.findBy('rules', generatedRoleRules); + const template = rulesTemplates.find((t) => t.rules === generatedRoleRules); if (template) { this.selectedTemplateId = template.id; } else { - rulesTemplates.findBy('id', '1').rules = generatedRoleRules; + rulesTemplates.find((t) => t.id === '1').rules = generatedRoleRules; } } this.roleRulesTemplates = rulesTemplates; @@ -134,7 +134,7 @@ export default class CreateAndEditRolePageComponent extends Component { *save() { try { // set generatedRoleRoles to value of selected template - const selectedTemplate = this.roleRulesTemplates?.findBy('id', this.selectedTemplateId); + const selectedTemplate = this.roleRulesTemplates?.find((t) => t.id === this.selectedTemplateId); if (selectedTemplate) { this.args.model.generatedRoleRules = selectedTemplate.rules; } diff --git a/ui/lib/kv/addon/components/page/secret/paths.js b/ui/lib/kv/addon/components/page/secret/paths.js index 1be89452d1..716c76c398 100644 --- a/ui/lib/kv/addon/components/page/secret/paths.js +++ b/ui/lib/kv/addon/components/page/secret/paths.js @@ -55,8 +55,8 @@ export default class KvSecretPaths extends Component { } get commands() { - const cliPath = this.paths.findBy('label', 'CLI path').snippet; - const apiPath = this.paths.findBy('label', 'API path').snippet; + const cliPath = this.paths.find((p) => p.label === 'CLI path').snippet; + const apiPath = this.paths.find((p) => p.label === 'API path').snippet; // as a future improvement, it might be nice to use window.location.protocol here: const url = `https://127.0.0.1:8200${apiPath}`; diff --git a/ui/lib/replication/addon/components/path-filter-config-list.js b/ui/lib/replication/addon/components/path-filter-config-list.js index 70c5791e3a..b227956e2b 100644 --- a/ui/lib/replication/addon/components/path-filter-config-list.js +++ b/ui/lib/replication/addon/components/path-filter-config-list.js @@ -93,8 +93,8 @@ export default Component.extend({ secretList = result.secret; authList = result.auth; } - var currentSecrets = lastOptions && lastOptions.findBy('groupName', 'Secret Engines'); - var currentAuths = lastOptions && lastOptions.findBy('groupName', 'Auth Methods'); + var currentSecrets = lastOptions && lastOptions.find((opt) => opt.groupName === 'Secret Engines'); + var currentAuths = lastOptions && lastOptions.find((opt) => opt.groupName === 'Auth Methods'); const formattedNamespaces = namespaces.map((val) => { return { id: val, diff --git a/ui/mirage/handlers/kubernetes.js b/ui/mirage/handlers/kubernetes.js index 2f4e8b2669..022d801bdf 100644 --- a/ui/mirage/handlers/kubernetes.js +++ b/ui/mirage/handlers/kubernetes.js @@ -56,7 +56,7 @@ export default function (server) { server.get('/:path/roles', (schema) => { return { data: { - keys: schema.db.kubernetesRoles.where({}).mapBy('name'), + keys: schema.db.kubernetesRoles.where({}).map((role) => role.name), }, }; }); diff --git a/ui/tests/acceptance/init-test.js b/ui/tests/acceptance/init-test.js index 367c56dfa0..d22b1607fd 100644 --- a/ui/tests/acceptance/init-test.js +++ b/ui/tests/acceptance/init-test.js @@ -126,7 +126,11 @@ module('Acceptance | init', function (hooks) { 'shows all of the recovery keys' ); assert.strictEqual(initPage.buttonText, 'Continue to Authenticate', 'links to authenticate'); - assertRequest(this.server.handledRequests.findBy('url', '/v1/sys/init'), assert, true); + assertRequest( + this.server.handledRequests.find((req) => req.url === '/v1/sys/init'), + assert, + true + ); }); test('shamir seal init', async function (assert) { @@ -139,6 +143,10 @@ module('Acceptance | init', function (hooks) { assert.strictEqual(initPage.keys.length, SEAL_RESPONSE.keys.length, 'shows all of the recovery keys'); assert.strictEqual(initPage.buttonText, 'Continue to Unseal', 'links to unseal'); - assertRequest(this.server.handledRequests.findBy('url', '/v1/sys/init'), assert, false); + assertRequest( + this.server.handledRequests.find((r) => r.url === '/v1/sys/init'), + assert, + false + ); }); }); diff --git a/ui/tests/acceptance/mfa-method-test.js b/ui/tests/acceptance/mfa-method-test.js index afc5616ff0..52a82dd578 100644 --- a/ui/tests/acceptance/mfa-method-test.js +++ b/ui/tests/acceptance/mfa-method-test.js @@ -90,7 +90,7 @@ module('Acceptance | mfa-method', function (hooks) { // ensure methods are tied to an enforcement this.server.get('/identity/mfa/login-enforcement', () => { const record = this.server.create('mfa-login-enforcement', { - mfa_method_ids: this.getMethods().mapBy('id'), + mfa_method_ids: this.getMethods().map((m) => m.id), }); return { data: { diff --git a/ui/tests/integration/components/search-select-test.js b/ui/tests/integration/components/search-select-test.js index 2557806703..4557e95159 100644 --- a/ui/tests/integration/components/search-select-test.js +++ b/ui/tests/integration/components/search-select-test.js @@ -81,8 +81,8 @@ module('Integration | Component | search select', function (hooks) { hooks.beforeEach(function () { const mockFunctionFromParent = (selection, dropdownOptions) => { const modelExists = - !!dropdownOptions.findBy('id', selection) || - !!dropdownOptions.findBy('uuid', selection) || + !!dropdownOptions.find((opt) => opt.id === selection) || + !!dropdownOptions.find((opt) => opt.uuid === selection) || isWildcardString([selection]); return !modelExists ? 'The model associated with this id no longer exists' : false; }; diff --git a/ui/tests/unit/services/store-test.js b/ui/tests/unit/services/store-test.js index 26ee183d4c..9510fac734 100644 --- a/ui/tests/unit/services/store-test.js +++ b/ui/tests/unit/services/store-test.js @@ -134,7 +134,11 @@ module('Unit | Service | store', function (hooks) { let result; result = await this.store.fetchPage('transit-key', query); assert.strictEqual(result.get('length'), pageSize, 'returns the correct number of items'); - assert.deepEqual(result.mapBy('id'), keys.slice(0, pageSize), 'returns the first page of items'); + assert.deepEqual( + result.map((r) => r.id), + keys.slice(0, pageSize), + 'returns the first page of items' + ); assert.deepEqual( result.get('meta'), { @@ -157,7 +161,7 @@ module('Unit | Service | store', function (hooks) { const pageThreeEnd = 3 * pageSize; const pageThreeStart = pageThreeEnd - pageSize; assert.deepEqual( - result.mapBy('id'), + result.map((r) => r.id), keys.slice(pageThreeStart, pageThreeEnd), 'returns the third page of items' ); @@ -169,7 +173,7 @@ module('Unit | Service | store', function (hooks) { }); assert.deepEqual( - result.mapBy('id'), + result.map((r) => r.id), keys.slice(keys.length - 1), 'returns the last page when the page value is beyond the of bounds' ); @@ -180,7 +184,7 @@ module('Unit | Service | store', function (hooks) { responsePath: 'data.keys', }); assert.deepEqual( - result.mapBy('id'), + result.map((r) => r.id), keys.slice(0, pageSize), 'returns the first page when page value is under the bounds' );