* refactor: 💡 update worker factory to include api_tags ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13889 * feat: 🎸 add tags flyout for workers table ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13889 * refactor: 💡 move test selector to const ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13889 * refactor: 💡 only show 'view more tags' if more than 10 tags ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13889 * test: 💍 update test name ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13889 * refactor: 💡 update how worker tags are shown in flyout ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13889 * refactor: 💡 add one more api tag for worker in mirage ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13889 * refactor: 💡 fix tagDisplayName signature ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13889 * refactor: 💡 update tag shortener styling ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13889
112 lines
2.8 KiB
JavaScript
112 lines
2.8 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import Route from '@ember/routing/route';
|
|
import { action } from '@ember/object';
|
|
import { resourceFilter } from 'core/decorators/resource-filter';
|
|
import sortBy from 'lodash/sortBy';
|
|
|
|
export default class ScopesScopeWorkersIndexRoute extends Route {
|
|
// =attributes
|
|
|
|
// This resource filter depends on the data from the list route so can't
|
|
// live in the same model where the list is loaded as it needs to get loaded
|
|
// first. If it's in the same file it might try to grab the model data before
|
|
// it's loaded.
|
|
@resourceFilter({
|
|
allowed: (route) => {
|
|
const configTags = route
|
|
.modelFor('scopes.scope.workers')
|
|
.flatMap((worker) => worker.configTagList)
|
|
.filter(Boolean);
|
|
|
|
// Filter out duplicate tags
|
|
return configTags.reduce((uniqueConfigTags, currentTag) => {
|
|
const isDuplicateTag = uniqueConfigTags.some(
|
|
(tag) => tag.key === currentTag.key && tag.value === currentTag.value,
|
|
);
|
|
|
|
if (!isDuplicateTag) {
|
|
uniqueConfigTags.push(currentTag);
|
|
}
|
|
return uniqueConfigTags;
|
|
}, []);
|
|
},
|
|
findBySerialized: ({ key: itemKey, value: itemValue }, { key, value }) =>
|
|
itemKey === key && itemValue === value,
|
|
refreshRouteOnChange: false,
|
|
})
|
|
tags;
|
|
|
|
// =methods
|
|
|
|
model() {
|
|
const workers = sortBy(
|
|
this.modelFor('scopes.scope.workers'),
|
|
'displayName',
|
|
);
|
|
|
|
if (this.tags?.length) {
|
|
// Return workers that have config tags that have at
|
|
// least one intersection with the filter tags
|
|
return workers.filter((worker) => {
|
|
if (!worker.config_tags) {
|
|
return null;
|
|
}
|
|
|
|
const workerTags = worker.configTagList;
|
|
return this.tags.some((tag) =>
|
|
workerTags.some(
|
|
(workerTag) =>
|
|
tag.key === workerTag.key && tag.value === workerTag.value,
|
|
),
|
|
);
|
|
});
|
|
}
|
|
return workers;
|
|
}
|
|
|
|
resetController(controller, isExiting) {
|
|
// Clear selected worker when exiting route to prevent
|
|
// the flyout from showing when returning to this route
|
|
if (isExiting) {
|
|
controller.setProperties({
|
|
selectedWorker: null,
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Clears filter selections.
|
|
*/
|
|
@action
|
|
clearAllFilters() {
|
|
this.tags = [];
|
|
this.refresh();
|
|
}
|
|
|
|
/**
|
|
* Sets the specified resource filter field to the specified value.
|
|
* @param {string} field
|
|
* @param value
|
|
*/
|
|
@action
|
|
filterBy(field, value) {
|
|
this[field] = value;
|
|
this.refresh();
|
|
}
|
|
|
|
@action
|
|
isEqual(firstTag, secondTag) {
|
|
return firstTag.key === secondTag.key && firstTag.value === secondTag.value;
|
|
}
|
|
|
|
setupController(controller) {
|
|
const scope = this.modelFor('scopes.scope');
|
|
super.setupController(...arguments);
|
|
controller.setProperties({ scope });
|
|
}
|
|
}
|