Skip to content

Commit

Permalink
[frontend] Fix filtering for toolbar (#6411)
Browse files Browse the repository at this point in the history
Co-authored-by: Cathia Archidoit <cathia.archidoit@filigran.io>
Co-authored-by: Archidoit <75783086+Archidoit@users.noreply.github.com>
Co-authored-by: Laurent Bonnet <146674147+labo-flg@users.noreply.github.com>
  • Loading branch information
4 people committed Jun 3, 2024
1 parent 79eb2e9 commit 1edc257
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import TaskFilterValue from './TaskFilterValue';
import Loader from './Loader';
import { FilterValuesContentQuery } from './__generated__/FilterValuesContentQuery.graphql';

const TasksFilterValueContainer = ({ filters }: { filters: FilterGroup }) => {
const cleanUpFilters = useRemoveIdAndIncorrectKeysFromFilterGroupObject(filters) as FilterGroup;
const TasksFilterValueContainer = ({ filters, entityTypes }: { filters: FilterGroup, entityTypes?: string[] }) => {
const cleanUpFilters = useRemoveIdAndIncorrectKeysFromFilterGroupObject(filters, entityTypes) as FilterGroup;
const queryRef = useQueryLoading<FilterValuesContentQuery>(
filterValuesContentQuery,
{ filters: cleanUpFilters as unknown as GqlFilterGroup },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,16 +203,16 @@ const EntityStixCoreRelationshipsRelationshipsView: FunctionComponent<EntityStix
>
<QueryRenderer
query={
// eslint-disable-next-line no-nested-ternary
allDirections
? entityStixCoreRelationshipsLinesAllQuery
: isRelationReversed
? entityStixCoreRelationshipsLinesToQuery
: entityStixCoreRelationshipsLinesFromQuery
}
// eslint-disable-next-line no-nested-ternary
allDirections
? entityStixCoreRelationshipsLinesAllQuery
: isRelationReversed
? entityStixCoreRelationshipsLinesToQuery
: entityStixCoreRelationshipsLinesFromQuery
}
variables={{ count: 25, ...paginationOptions }}
render={({ props }: { props: unknown }) =>
/* eslint-disable-next-line no-nested-ternary,implicit-arrow-linebreak */
/* eslint-disable-next-line no-nested-ternary,implicit-arrow-linebreak */
(allDirections ? (
<EntityStixCoreRelationshipsLinesAll
data={props}
Expand Down Expand Up @@ -254,7 +254,7 @@ const EntityStixCoreRelationshipsRelationshipsView: FunctionComponent<EntityStix
selectAll={selectAll}
/>
))
}
}
/>
</ListLines>
<ToolBar
Expand All @@ -266,6 +266,7 @@ const EntityStixCoreRelationshipsRelationshipsView: FunctionComponent<EntityStix
search={searchTerm}
handleClearSelectedElements={handleClearSelectedElements}
variant="medium"
type={'stix-core-relationship'}
/>
<Security needs={[KNOWLEDGE_KNUPDATE]}>
<StixCoreRelationshipCreationFromEntity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ const Relationships = () => {
filters={contextFilters}
search={searchTerm}
handleClearSelectedElements={handleClearSelectedElements}
type={'stix-core-relationship'}
/>
</React.Suspense>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1331,8 +1331,9 @@ class ToolBar extends Component {
&& selectedTypes.length > 0
&& selectedTypes.every((type) => promotionTypes.includes(type));
const promoteEnabled = isManualPromoteSelect || promotionTypesFiltered;
const entityTypes = selectedTypes.length > 0 ? selectedTypes : [this.props.type ?? 'Stix-Core-Object'];
const filterKeysMap = new Map();
entityTypeFilterValues.forEach((entityType) => {
entityTypes.forEach((entityType) => {
const currentMap = schema.filterKeysSchema.get(entityType);
currentMap?.forEach((value, key) => filterKeysMap.set(key, value));
});
Expand Down Expand Up @@ -1645,9 +1646,7 @@ class ToolBar extends Component {
)}
</span>
)}
<TasksFilterValueContainer
filters={filters}
></TasksFilterValueContainer>
<TasksFilterValueContainer filters={filters} entityTypes={entityTypes} />
</div>
) : (
<span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ const TasksList = ({ data }) => {
&& (isFilterGroupNotEmpty(filters)
? <TasksFilterValueContainer
filters={filters}
entityTypes={['Stix-Core-Object', 'stix-core-relationship', 'Notification']}
/>
: (
<Chip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ const NotificationsToolBar: FunctionComponent<NotificationsToolBarProps> = ({
{selectAll ? (
<TasksFilterValueContainer
filters={filters}
entityTypes={['Notification']}
/>
) : (
<span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ export const useRemoveIdAndIncorrectKeysFromFilterGroupObject = (filters?: Filte
delete newFilter.id;
return newFilter;
}),
filterGroups: filters.filterGroups.map((group) => useRemoveIdAndIncorrectKeysFromFilterGroupObject(group)) as FilterGroup[],
filterGroups: filters.filterGroups.map((group) => useRemoveIdAndIncorrectKeysFromFilterGroupObject(group, entityTypes)) as FilterGroup[],
};
};

Expand Down

0 comments on commit 1edc257

Please sign in to comment.