Skip to content

Commit

Permalink
[frontend] fix most used / all filters (#6391)
Browse files Browse the repository at this point in the history
  • Loading branch information
Archidoit committed Mar 20, 2024
1 parent a8d75ff commit d8e17eb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ const ListFilters = ({
? availableFilterKeys
.map((key) => {
const subEntityTypes = filterKeysMap.get(key)?.subEntityTypes ?? [];
const isFilterKeyForAllTypes = subEntityTypes.some((subType) => entityTypes.includes(subType));
const isFilterKeyForAllTypes = (entityTypes.length === 1 && subEntityTypes.some((subType) => entityTypes.includes(subType)))
|| (entityTypes.length > 1 && entityTypes.every((subType) => subEntityTypes.includes(subType)));
return {
value: key,
label: t_i18n(filterKeysMap.get(key)?.label ?? key),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -627,14 +627,32 @@ export const getAvailableOperatorForFilter = (

export const useBuildFilterKeysMapFromEntityType = (entityTypes = ['Stix-Core-Object']): Map<string, FilterDefinition> => {
const { filterKeysSchema } = useAuth().schema;
// 1. case one entity type
if (entityTypes.length === 1) {
return filterKeysSchema.get(entityTypes[0]) ?? new Map();
}
// 2. case several entity types
const filterKeysMap = new Map();
entityTypes.forEach((entityType) => {
const currentMap = filterKeysSchema.get(entityType);
currentMap?.forEach((value, key) => filterKeysMap.set(key, value));
currentMap?.forEach((value, key) => {
if (filterKeysMap.has(key)) { // add entity type in subEntityTypes of the filter definition
filterKeysMap.set(key, { ...value, subEntityTypes: filterKeysMap.get(key).subEntityTypes.concat([entityType]) });
} else { // add the filter definition in the map
filterKeysMap.set(key, value);
}
});
});
if (entityTypes.length > 0) { // add entity_type filter if several types are given (entity_type filter already present for abstract types)
filterKeysMap.set('entity_type', {
filterKey: 'entity_type',
type: 'string',
label: 'Entity type',
multiple: true,
subEntityTypes: entityTypes,
elementsForFilterValuesSearch: [],
});
}
return filterKeysMap;
};

Expand Down

0 comments on commit d8e17eb

Please sign in to comment.