Skip to content

Commit

Permalink
[frontend/backend] remove resolved_instance_filters logic + filter va…
Browse files Browse the repository at this point in the history
…lue in ToolBar (#2686)
  • Loading branch information
Archidoit committed Sep 19, 2023
1 parent 6fe936e commit 9ee6103
Show file tree
Hide file tree
Showing 22 changed files with 217 additions and 349 deletions.
25 changes: 11 additions & 14 deletions opencti-platform/opencti-front/src/components/FilterIconButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { FunctionComponent } from 'react';
import makeStyles from '@mui/styles/makeStyles';
import { DataColumns } from './list_lines';
import { Filter, FilterGroup } from '../utils/filters/filtersUtils';
import { TriggerLine_node$data } from '../private/components/profile/triggers/__generated__/TriggerLine_node.graphql';
import { filterIconButtonContentQuery } from './FilterIconButtonContent';
import useQueryLoading from '../utils/hooks/useQueryLoading';
import Loader from './Loader';
Expand Down Expand Up @@ -50,7 +49,6 @@ interface FilterIconButtonProps {
dataColumns?: DataColumns;
disabledPossible?: boolean;
redirection?: boolean;
resolvedInstanceFilters?: TriggerLine_node$data['resolved_instance_filters'];
}

const FilterIconButton: FunctionComponent<FilterIconButtonProps> = ({
Expand All @@ -64,7 +62,6 @@ const FilterIconButton: FunctionComponent<FilterIconButtonProps> = ({
dataColumns,
disabledPossible,
redirection,
resolvedInstanceFilters,
}) => {
const classes = useStyles();

Expand Down Expand Up @@ -97,17 +94,17 @@ const FilterIconButton: FunctionComponent<FilterIconButtonProps> = ({
>
{filtersRepresentativesQueryRef && (
<React.Suspense fallback={<Loader />}>
<FilterIconButtonContainer
displayedFilters={displayedFilters}
globalMode={filters.mode}
handleRemoveFilter={handleRemoveFilter}
handleSwitchGlobalMode={handleSwitchGlobalMode}
handleSwitchLocalMode={handleSwitchLocalMode}
styleNumber={styleNumber}
disabledPossible={disabledPossible}
redirection={redirection}
filtersRepresentativesQueryRef={filtersRepresentativesQueryRef}
></FilterIconButtonContainer>
<FilterIconButtonContainer
displayedFilters={displayedFilters}
globalMode={filters.mode}
handleRemoveFilter={handleRemoveFilter}
handleSwitchGlobalMode={handleSwitchGlobalMode}
handleSwitchLocalMode={handleSwitchLocalMode}
styleNumber={styleNumber}
disabledPossible={disabledPossible}
redirection={redirection}
filtersRepresentativesQueryRef={filtersRepresentativesQueryRef}
></FilterIconButtonContainer>
</React.Suspense>)
}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { truncate } from '../utils/String';
import { DataColumns } from './list_lines';
import { useFormatter } from './i18n';
import { Theme } from './Theme';
import { Filter, filterValue } from '../utils/filters/filtersUtils';
import { Filter } from '../utils/filters/filtersUtils';
import FilterIconButtonContent, { filterIconButtonContentQuery } from './FilterIconButtonContent';
import { FilterIconButtonContentQuery } from './__generated__/FilterIconButtonContentQuery.graphql';

Expand Down Expand Up @@ -122,23 +122,22 @@ const FilterIconButtonContainer: FunctionComponent<FilterIconButtonContainerProp
const values = (
<>
{filterValues.map((n) => {
const value = filterValue(n);
return (
<span key={value}>
<FilterIconButtonContent
redirection={redirection}
filterKey={filterKey}
id={n}
filtersRepresentatives={filtersRepresentatives}
></FilterIconButtonContent>
{last(filterValues) !== n && (
<Chip
className={classes.inlineOperator}
label={t(currentFilter.mode.toUpperCase())}
onClick={() => handleSwitchLocalMode?.(currentFilter)}
/>
)}{' '}
</span>
<span key={n}>
<FilterIconButtonContent
redirection={redirection}
filterKey={filterKey}
id={n}
filtersRepresentatives={filtersRepresentatives}
></FilterIconButtonContent>
{last(filterValues) !== n && (
<Chip
className={classes.inlineOperator}
label={t(currentFilter.mode.toUpperCase())}
onClick={() => handleSwitchLocalMode?.(currentFilter)}
/>
)}{' '}
</span>
);
})}
</>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import React, { FunctionComponent, useState } from 'react';
import React, { FunctionComponent } from 'react';
import { graphql } from 'react-relay';
import { Link } from 'react-router-dom';
import {
dateFilters,
entityFilters, entityTypesFilters,
filtersWithRepresentative,
vocabularyFiltersWithTranslation,
} from '../utils/filters/filtersUtils';
import { entityFilters, filterValue } from '../utils/filters/filtersUtils';
import { truncate } from '../utils/String';
import { useFormatter } from './i18n';
import {
FilterIconButtonContentQuery$data,
} from './__generated__/FilterIconButtonContentQuery.graphql';
import { FilterIconButtonContentQuery$data } from './__generated__/FilterIconButtonContentQuery.graphql';

export const filterIconButtonContentQuery = graphql`
query FilterIconButtonContentQuery(
Expand All @@ -36,59 +29,26 @@ const FilterIconButtonContent: FunctionComponent<FilterIconButtonContentProps> =
id,
filtersRepresentatives,
}) => {
const { t, nsdt } = useFormatter();
const [isDeleted, setDeleted] = useState(false);
const filterValue = () => {
if (filtersWithRepresentative.includes(filterKey)) {
const value = filtersRepresentatives?.filter((n) => n?.id === id)?.[0]?.value;
if (!value) {
setDeleted(true);
return 'deleted';
}
return value;
}
if (vocabularyFiltersWithTranslation.includes(filterKey)) {
return t(id);
}
if (filterKey === 'basedOn') {
return id === 'EXISTS' ? t('Yes') : t('No');
}
if (filterKey === 'x_opencti_negative') {
return t(id ? 'False positive' : 'Malicious');
}
if (entityTypesFilters.includes(filterKey)) {
return id === 'all'
? t('entity_All')
: t(
id.toString()[0] === id.toString()[0].toUpperCase()
? `entity_${id.toString()}`
: `relationship_${id.toString()}`,
);
}
if (dateFilters.includes(filterKey)) {
return nsdt(id);
}
return id;
};
const displayedValue = truncate(filterValue(), 15);
const renderWithRedirection = () => {
const { t } = useFormatter();

const displayedValue = truncate(filterValue(filterKey, id, filtersRepresentatives), 15);

if (displayedValue === null) {
return (
<>
{!isDeleted
? (<Link to={`/dashboard/id/${id}`}>
<span color="primary">{displayedValue}</span>
</Link>)
: (<del>{displayedValue}</del>)}
<del>{t('deleted')}</del>
</>
);
};
}
if (redirection && entityFilters.includes(filterKey)) {
return renderWithRedirection();
return (
<Link to={`/dashboard/id/${id}`}>
<span color="primary">{displayedValue}</span>
</Link>
);
}
return (
<span>
{displayedValue}{' '}
</span>
<span>{displayedValue}</span>
);
};

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ export const stixCoreObjectQuickSubscriptionContentQuery = graphql`
id
name
}
resolved_instance_filters {
id
valid
value
}
}
}
}
Expand All @@ -83,7 +78,6 @@ interface InstanceTriggerEditionFormValues {
event_types: readonly Option[];
notifiers: readonly Option[];
filters: string | null,
resolved_instance_filters?: TriggerLine_node$data['resolved_instance_filters'],
}

const useStyles = makeStyles<Theme>((theme) => ({
Expand Down Expand Up @@ -361,7 +355,6 @@ const StixCoreObjectQuickSubscriptionContent: FunctionComponent<StixCoreObjectQu
classNameNumber={3}
styleNumber={3}
redirection
resolvedInstanceFilters={instanceTrigger.resolved_instance_filters ?? []}
/>
</div>
}
Expand Down Expand Up @@ -399,7 +392,7 @@ const StixCoreObjectQuickSubscriptionContent: FunctionComponent<StixCoreObjectQu
const triggerValues = existingInstanceTriggersEdges
.filter((l) => l)
.map((n) => ({
...pick(['id', 'name', 'description', 'filters', 'resolved_instance_filters'], n?.node),
...pick(['id', 'name', 'description', 'filters'], n?.node),
notifiers: convertNotifiers(n?.node),
event_types: convertEventTypes(n?.node),
})) as InstanceTriggerEditionFormValues[];
Expand Down
Loading

0 comments on commit 9ee6103

Please sign in to comment.