Skip to content

Commit

Permalink
[frontend]duplicate feed sharing ok (#7400)
Browse files Browse the repository at this point in the history
  • Loading branch information
CelineSebe committed Sep 27, 2024
1 parent ebf0b38 commit 04d8432
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { stixCyberObservablesLinesAttributesQuery } from '../../observations/sti
import Filters from '../../common/lists/Filters';
import {
cleanFilters,
deserializeFilterGroupForFrontend,
emptyFilterGroup,
serializeFilterGroupForBackend,
useAvailableFilterKeysForEntityTypes,
Expand Down Expand Up @@ -162,7 +163,7 @@ const FeedCreation: FunctionComponent<FeedCreationFormProps> = (props) => {
const classes = useStyles();
const { t_i18n } = useFormatter();
const [selectedTypes, setSelectedTypes] = useState(feed?.feed_types ?? []);
const [filters, helpers] = useFiltersState(emptyFilterGroup);
const [filters, helpers] = useFiltersState(deserializeFilterGroupForFrontend(feed?.filters) ?? emptyFilterGroup);

const completeFilterKeysMap: Map<string, Map<string, FilterDefinition>> = useFetchFilterKeysSchema();
const availableFilterKeys = useAvailableFilterKeysForEntityTypes(selectedTypes).filter((k) => k !== 'entity_type');
Expand All @@ -172,17 +173,15 @@ const FeedCreation: FunctionComponent<FeedCreationFormProps> = (props) => {
...n,
mappings: R.indexBy(R.prop('type'), n.mappings),
}))
: [];
: { 0: {} };

// TODO: typing this state properly implies deep refactoring
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const [feedAttributes, setFeedAttributes] = useState<{ [key: string]: any }>({ 0: {} });
const [feedAttributes, setFeedAttributes] = useState<{ [key: string]: any }>(feedAttributesInitialState);
const { ignoredAttributesInFeeds } = useAttributes();

const handleClose = () => {
setSelectedTypes([]);
helpers.handleClearAllFilters();
setFeedAttributes(feedAttributesInitialState);
if (!isDuplicated) {
const onHandleClose = () => {
if (isDuplicated) {
onDrawerClose();
}
};
Expand Down Expand Up @@ -341,13 +340,12 @@ const FeedCreation: FunctionComponent<FeedCreationFormProps> = (props) => {
feed_date_attribute: 'created_at',
feed_public: false,
};

return (
<Drawer
title={isDuplicated ? (t_i18n('Duplicate a feed')) : (t_i18n('Create a feed'))}
variant={isDuplicated ? undefined : DrawerVariant.createWithPanel}
open={open}
onClose={handleClose}
onClose={onHandleClose}
>
{({ onClose }) => (
<QueryRenderer
Expand Down Expand Up @@ -580,12 +578,18 @@ const FeedCreation: FunctionComponent<FeedCreationFormProps> = (props) => {
),
);
}

return (
<Select
style={{ width: 150 }}
value={feedAttributes[i]?.mappings?.[selectedType]?.attribute || ''}
onChange={(event) => handleChangeAttributeMapping(i, selectedType, event.target.value) }
value={feedAttributes[i]?.mappings
&& feedAttributes[i]?.mappings?.[
selectedType
]?.attribute}
onChange={(event) => handleChangeAttributeMapping(
i,
selectedType,
event.target.value,
)}
>
{attributes.map(
(attribute) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ import { stixCyberObservablesLinesAttributesQuery } from '../../observations/sti
import Filters from '../../common/lists/Filters';
import { feedCreationAllTypesQuery } from './FeedCreation';
import {
useAvailableFilterKeysForEntityTypes,
cleanFilters,
deserializeFilterGroupForFrontend,
serializeFilterGroupForBackend,
useAvailableFilterKeysForEntityTypes,
useFetchFilterKeysSchema,
} from '../../../../utils/filters/filtersUtils';
import FilterIconButton from '../../../../components/FilterIconButton';
Expand Down

0 comments on commit 04d8432

Please sign in to comment.