Icu 6036 update filter dropdown for tags in list view (#1337)

✅ Closes: ICU-6036
This commit is contained in:
Zhihe Li authored and GitHub committed 2022-09-20 20:51:06 -04:00
1 parent 5224512da0
commit eb539b9c5b
3 files changed
+69 -21

No files matched your search

+14
View File
@@ -36,6 +36,20 @@ export default class WorkerModel extends GeneratedWorkerModel {
);
}
/**
* Returns the config tags as an array of key/value pair objects.
* @type {[object]}
*/
getConfigTagList() {
if (!this.config_tags) {
return null;
}
return Object.entries(this.config_tags).flatMap(([key, value]) =>
value.map((tag) => ({ key, value: tag }))
);
}
@attr({
description:
'The deduplicated union of the tags reported by the worker ' +
@@ -14,12 +14,23 @@ export default class ScopesScopeWorkersIndexRoute extends Route {
const configTags = route
.modelFor('scopes.scope.workers')
.toArray()
.flatMap((worker) => worker.config_tags?.type)
.flatMap((worker) => worker.getConfigTagList())
.filter(Boolean);
// Filter out duplicate tags
return [...new Set(configTags)];
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;
@@ -32,11 +43,19 @@ export default class ScopesScopeWorkersIndexRoute extends Route {
if (this.tags?.length) {
// Return workers that have config tags that have at
// least one intersection with the filter tags
return workers.filter(
(worker) =>
worker.config_tags.type.filter(Set.prototype.has, new Set(this.tags))
.length > 0
);
return workers.filter((worker) => {
if (!worker.config_tags) {
return null;
}
const workerTags = worker.getConfigTagList();
return this.tags.some((tag) =>
workerTags.some(
(workerTag) =>
tag.key === workerTag.key && tag.value === workerTag.value
)
);
});
}
return workers;
}
@@ -61,6 +80,11 @@ export default class ScopesScopeWorkersIndexRoute extends Route {
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);
@@ -37,20 +37,30 @@
@ignoreClickInside={{true}}
as |dropdown|
>
<form.checkboxGroup
@name={{filter.name}}
@items={{filter.allowedValues}}
@selectedItems={{filter.selectedValue}}
@onChange={{route-action 'filterBy' filter.name}}
as |group|
>
<dropdown.item>
<group.checkbox
@label={{group.item}}
value={{group.item}}
/>
</dropdown.item>
</form.checkboxGroup>
{{#each-in
(group-by 'key' filter.allowedValues)
as |key tags|
}}
<dropdown.section
@title={{key}}
@icon='flight-icons/svg/tag-16'
/>
<form.checkboxGroup
@name={{key}}
@items={{tags}}
@selectedItems={{filter.selectedValue}}
@onChange={{route-action 'filterBy' filter.name}}
@itemEqualityFunc={{route-action 'isEqual'}}
as |group|
>
<dropdown.item class='indent-label-1'>
<group.checkbox
@label={{group.item.value}}
value={{group.item}}
/>
</dropdown.item>
</form.checkboxGroup>
{{/each-in}}
</Rose::Dropdown>
{{/if}}
{{/let}}