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.
This commit is contained in:
Chelsea Shaw
2024-03-13 10:03:27 -05:00
committed by GitHub
parent 51f9cfe7c7
commit 6e7717a707
12 changed files with 20 additions and 22 deletions

View File

@@ -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);
}

View File

@@ -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 = [];

View File

@@ -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);
});

View File

@@ -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);

View File

@@ -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;
});

View File

@@ -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;
});

View File

@@ -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';

View File

@@ -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,

View File

@@ -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`

View File

@@ -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');

View File

@@ -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,

View File

@@ -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'
);