Deprecations: Remove firstObject from RecordArray (#25583)

* wip

* focusing on js files

* rest of the js files

* round up the last bits focusing on hbs

* address test failures

* Update transit-key-test.js

* Update ui/app/services/csp-event.js

Co-authored-by: claire bontempo <68122737+hellobontempo@users.noreply.github.com>

* Update options.js

* build error push

---------

Co-authored-by: claire bontempo <68122737+hellobontempo@users.noreply.github.com>
This commit is contained in:
Angel Garbarino
2024-02-23 10:34:29 -07:00
committed by GitHub
parent e6d2caaa52
commit 156de6a3fd
23 changed files with 35 additions and 45 deletions

View File

@@ -47,7 +47,7 @@ export default AuthConfigComponent.extend({
// because we're not calling model.save the model never updates with
// the error. Forcing the error message by manually setting the errorMessage
try {
this.model.set('errorMessage', err.errors.firstObject);
this.model.set('errorMessage', err.errors?.join(','));
} catch {
// do nothing
}

View File

@@ -121,7 +121,7 @@ export default Component.extend(DEFAULTS, {
},
firstMethod() {
const firstMethod = this.methodsToShow.firstObject;
const firstMethod = this.methodsToShow[0];
if (!firstMethod) return;
// prefer backends with a path over those with a type
return firstMethod.path || firstMethod.type;
@@ -166,7 +166,7 @@ export default Component.extend(DEFAULTS, {
return templateName;
}),
hasCSPError: alias('csp.connectionViolations.firstObject'),
hasCSPError: alias('csp.connectionViolations'),
cspErrorText: `This is a standby Vault node but can't communicate with the active node via request forwarding. Sign in at the active node to use the Vault UI.`,

View File

@@ -27,7 +27,7 @@ export default Component.extend({
this._super(...arguments);
this.store.findAll('auth-method').then((methods) => {
this.set('authMethods', methods);
this.set('aliasMountAccessor', methods.get('firstObject.accessor'));
this.set('aliasMountAccessor', methods[0].accessor);
});
},

View File

@@ -45,7 +45,7 @@ export default class MountAccessorSelect extends Component {
@task *authMethods() {
const methods = yield this.store.findAll('auth-method');
if (!this.args.value && !this.args.noDefault) {
const getValue = methods.get('firstObject.accessor');
const getValue = methods[0].accessor;
this.args.onChange(getValue);
}
return methods;

View File

@@ -2,7 +2,6 @@
Copyright (c) HashiCorp, Inc.
SPDX-License-Identifier: BUSL-1.1
~}}
<div {{did-update this.updateProps @selectedAction}}>
<MessageError @errorMessage={{this.errors}} />
@@ -109,7 +108,7 @@
@submitIsRunning={{this.doSubmit.isRunning}}
data-test-transit-action={{@selectedAction}}
/>
{{else if (or (eq @selectedAction "export") (eq @key.supportedActions.firstObject "export"))}}
{{else if (or (eq @selectedAction "export") (eq (get @key.supportedActions 0) "export"))}}
<TransitKeyAction::Export
@key={{@key}}
@keys={{this.props.keys}}

View File

@@ -21,7 +21,7 @@ export default Route.extend({
})
.then((model) => {
if (model) {
return model.get('firstObject');
return model[0];
}
});
},

View File

@@ -30,6 +30,6 @@ export default EditBase.extend({
setupController(controller, model) {
this._super(...arguments);
const { selectedAction } = this.paramsFor(this.routeName);
controller.set('selectedAction', selectedAction || model.secret.get('supportedActions.firstObject'));
controller.set('selectedAction', selectedAction || model.secret.supportedActions[0]);
},
});

View File

@@ -12,7 +12,7 @@ export default class SettingsAuthConfigureRoute extends Route {
beforeModel() {
const model = this.modelFor('vault.cluster.settings.auth.configure');
const section = tabsForAuthSection([model]).firstObject.routeParams.lastObject;
const section = tabsForAuthSection([model])[0].routeParams.lastObject;
return this.router.transitionTo('vault.cluster.settings.auth.configure.section', section);
}
}

View File

@@ -15,7 +15,7 @@ export default Route.extend({
model() {
const { backend } = this.paramsFor(this.routeName);
return this.store.query('secret-engine', { path: backend }).then((modelList) => {
const model = modelList && modelList.get('firstObject');
const model = modelList && modelList[0];
if (!model || !CONFIGURABLE_BACKEND_TYPES.includes(model.get('type'))) {
const error = new AdapterError();
set(error, 'httpStatus', 404);

View File

@@ -14,7 +14,7 @@ export default Service.extend({
return [];
}),
connectionViolations: computed('events.@each.violatedDirective', function () {
return this.events.filter((e) => e.violatedDirective.startsWith('connect-src'));
return this.events.some((e) => e.violatedDirective.startsWith('connect-src'));
}),
attach() {

View File

@@ -131,7 +131,7 @@ export default class SearchSelectWithModal extends Component {
@action
handleChange() {
if (this.selectedOptions.length && typeof this.selectedOptions.firstObject === 'object') {
if (this.selectedOptions.length && typeof this.selectedOptions[0] === 'object') {
this.args.onChange(Array.from(this.selectedOptions, (option) => option.id));
} else {
this.args.onChange(this.selectedOptions);
@@ -139,7 +139,7 @@ export default class SearchSelectWithModal extends Component {
}
shouldShowCreate(id, searchResults) {
if (searchResults && searchResults.length && searchResults.firstObject.groupName) {
if (searchResults && searchResults.length && searchResults[0].groupName) {
return !searchResults.some((group) => group.options.find((opt) => opt.id === id));
}
const existingOption =

View File

@@ -196,7 +196,7 @@ export default class SearchSelect extends Component {
@action
handleChange() {
if (this.selectedOptions.length && typeof this.selectedOptions.firstObject === 'object') {
if (this.selectedOptions.length && typeof this.selectedOptions[0] === 'object') {
this.args.onChange(
Array.from(this.selectedOptions, (option) =>
this.args.passObject ? this.customizeObject(option) : option.id
@@ -208,7 +208,7 @@ export default class SearchSelect extends Component {
}
shouldShowCreate(id, searchResults) {
if (searchResults && searchResults.length && searchResults.firstObject.groupName) {
if (searchResults && searchResults.length && searchResults[0].groupName) {
return !searchResults.some((group) => group.options.find((opt) => opt.id === id));
}
const existingOption =

View File

@@ -37,7 +37,7 @@
<hr />
<div class="is-flex">
<div class="kmip-role-allowed-operations">
{{#each-in this.model.operationFormFields.firstObject as |groupName fieldsInGroup|}}
{{#each-in (get this.model.operationFormFields 0) as |groupName fieldsInGroup|}}
<h4 class="title is-7">{{groupName}}</h4>
{{#each fieldsInGroup as |attr|}}
<FormField

View File

@@ -56,7 +56,9 @@ export default class PkiKeyParameters extends Component<Args> {
if (name === 'keyType' && Object.keys(KEY_BITS_OPTIONS)?.includes(selection)) {
const bitOptions = KEY_BITS_OPTIONS[selection as keyof TypeOptions];
this.args.model.keyBits = bitOptions?.firstObject;
if (bitOptions) {
this.args.model.keyBits = bitOptions[0];
}
}
}

View File

@@ -16,7 +16,7 @@ export default class ConfigurationIndexRoute extends Route {
async fetchMountConfig(backend) {
const mountConfig = await this.store.query('secret-engine', { path: backend });
if (mountConfig) {
return mountConfig.get('firstObject');
return mountConfig[0];
}
}

View File

@@ -8,9 +8,9 @@
<Page::PkiKeyList
@keyModels={{this.model.keyModels}}
@mountPoint={{this.mountPoint}}
@canImportKey={{this.model.keyModels.firstObject.canImportKey}}
@canGenerateKey={{this.model.keyModels.firstObject.canGenerateKey}}
@canRead={{this.model.keyModels.firstObject.canRead}}
@canEdit={{this.model.keyModels.firstObject.canEdit}}
@canImportKey={{(get (get this.model.keyModels 0) "canImportKey")}}
@canGenerateKey={{(get (get this.model.keyModels 0) "canGenerateKey")}}
@canRead={{(get (get this.model.keyModels 0) "canRead")}}
@canEdit={{(get (get this.model.keyModels 0) "canEdit")}}
@hasConfig={{this.model.hasConfig}}
/>

View File

@@ -92,9 +92,7 @@ module('Integration | Component | kubernetes | Page::Roles', function (hooks) {
test('it should render roles list', async function (assert) {
await this.renderComponent();
assert.dom('[data-test-list-item-content] svg').hasClass('flight-icon-user', 'List item icon renders');
assert
.dom('[data-test-list-item-content]')
.hasText(this.roles.firstObject.name, 'List item name renders');
assert.dom('[data-test-list-item-content]').hasText(this.roles[0].name, 'List item name renders');
await click('[data-test-popup-menu-trigger]');
assert.dom('[data-test-details]').hasText('Details', 'Details link renders in menu');
assert.dom('[data-test-edit]').hasText('Edit', 'Edit link renders in menu');

View File

@@ -93,7 +93,7 @@ module('Integration | Component | ldap | Page::Libraries', function (hooks) {
await this.renderComponent();
assert.dom('[data-test-list-item-content] svg').hasClass('flight-icon-folder', 'List item icon renders');
assert.dom('[data-test-library]').hasText(this.libraries.firstObject.name, 'List item name renders');
assert.dom('[data-test-library]').hasText(this.libraries[0].name, 'List item name renders');
await click('[data-test-popup-menu-trigger]');
assert.dom('[data-test-edit]').hasText('Edit', 'Edit link renders in menu');

View File

@@ -95,12 +95,10 @@ module('Integration | Component | ldap | Page::Roles', function (hooks) {
await this.renderComponent();
assert.dom('[data-test-list-item-content] svg').hasClass('flight-icon-user', 'List item icon renders');
assert
.dom('[data-test-role="static-test"]')
.hasText(this.roles.firstObject.name, 'List item name renders');
assert.dom('[data-test-role="static-test"]').hasText(this.roles[0].name, 'List item name renders');
assert
.dom('[data-test-role-type-badge="static-test"]')
.hasText(this.roles.firstObject.type, 'List item type badge renders');
.hasText(this.roles[0].type, 'List item type badge renders');
await click('[data-test-popup-menu-trigger]');
assert.dom('[data-test-edit]').hasText('Edit', 'Edit link renders in menu');

View File

@@ -141,7 +141,8 @@ module('Integration | Component | mfa-login-enforcement-form', function (hooks)
await click('[data-test-mlef-save]');
assert.true(this.didSave, 'onSave callback triggered');
assert.strictEqual(this.model.name, 'bar', 'Name property set on model');
assert.strictEqual(this.model.mfa_methods.firstObject.id, '123456', 'Mfa method added to model');
const methods = await this.model.mfa_methods; //hasManyPromise
assert.strictEqual(methods[0].id, '123456', 'Mfa method added to model');
assert.deepEqual(
this.model.auth_method_accessors,
['auth_userpass_1234'],

View File

@@ -72,7 +72,7 @@ module('Integration | Component | pki-generate-csr', function (hooks) {
await fillIn('[data-test-input="commonName"]', 'foo');
await click('[data-test-save]');
const savedRecord = this.store.peekAll('pki/action').firstObject;
const savedRecord = this.store.peekAll('pki/action')[0];
assert.false(savedRecord.isNew, 'record is saved');
});

View File

@@ -33,7 +33,7 @@ module('Unit | Adapter | ldap/role', function (hooks) {
this.models = await this.store.query('ldap/role', { backend: 'ldap-test' });
const model = this.models.firstObject;
const model = this.models[0];
assert.strictEqual(this.models.length, 2, 'Returns responses from both endpoints');
assert.strictEqual(model.backend, 'ldap-test', 'Backend value is set on records returned from query');
// sorted alphabetically by name so dynamic should be first

View File

@@ -73,23 +73,15 @@ module('Unit | Serializer | transit-key', function (hooks) {
const aesExpected = AES.data.keys[1] * 1000;
const chachaExpected = CHACHA.data.keys[1] * 1000;
const aesData = serializer.normalizeSecrets({ ...AES });
assert.strictEqual(aesData.firstObject.keys[1], aesExpected, 'converts seconds to millis for aes keys');
assert.strictEqual(aesData[0].keys[1], aesExpected, 'converts seconds to millis for aes keys');
const chachaData = serializer.normalizeSecrets({ ...CHACHA });
assert.strictEqual(
chachaData.firstObject.keys[1],
chachaExpected,
'converts seconds to millis for chacha keys'
);
assert.strictEqual(chachaData[0].keys[1], chachaExpected, 'converts seconds to millis for chacha keys');
});
test('it includes backend from the payload on the normalized data', function (assert) {
const serializer = this.owner.lookup('serializer:transit-key');
const data = serializer.normalizeSecrets({ ...AES });
assert.strictEqual(
data.firstObject.backend,
'its-a-transit',
'pulls backend from the payload onto the data'
);
assert.strictEqual(data[0].backend, 'its-a-transit', 'pulls backend from the payload onto the data');
});
});