Skip to content

Commit

Permalink
[frontend] Ability to duplicate a CSV feed data sharing, a CSV feed i…
Browse files Browse the repository at this point in the history
…ngestion, a CSV mapper (#7400)
  • Loading branch information
CelineSebe authored and Kedae committed Oct 4, 2024
1 parent 0b77655 commit c0b3de1
Show file tree
Hide file tree
Showing 27 changed files with 618 additions and 286 deletions.
3 changes: 3 additions & 0 deletions opencti-platform/opencti-front/lang/back/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@
"DST Payload": "DST Nutzlast",
"DST port": "DST-Anschluss",
"Due date": "Fälligkeitsdatum",
"Duplicate a CSV ingester": "Duplizieren Sie einen CSV-Ingester",
"Duplicate a CSV mapper": "Duplizieren eines CSV-Mappers",
"Duplicate a feed": "Einspeisung duplizieren",
"Element ID": "Element-ID",
"Email": "E-Mail",
"Email date": "E-Mail Datum",
Expand Down
3 changes: 3 additions & 0 deletions opencti-platform/opencti-front/lang/back/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@
"DST Payload": "DST Payload",
"DST port": "DST port",
"Due date": "Due date",
"Duplicate a CSV ingester": "Duplicate a CSV ingester",
"Duplicate a CSV mapper": "Duplicate a CSV mapper",
"Duplicate a feed": "Duplicate a feed",
"Element ID": "Element ID",
"Email": "Email",
"Email date": "Email date",
Expand Down
3 changes: 3 additions & 0 deletions opencti-platform/opencti-front/lang/back/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@
"DST Payload": "Carga útil DST",
"DST port": "Puerto DST",
"Due date": "Fecha de vencimiento",
"Duplicate a CSV ingester": "Duplicar una entrada CSV",
"Duplicate a CSV mapper": "Duplicar un mapeador CSV",
"Duplicate a feed": "Duplicar un feed",
"Element ID": "Elemento ID",
"Email": "Correo electrónico",
"Email date": "Fecha de correo electrónico",
Expand Down
3 changes: 3 additions & 0 deletions opencti-platform/opencti-front/lang/back/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@
"DST Payload": "DST Payload",
"DST port": "Port DST",
"Due date": "Date d'échéance",
"Duplicate a CSV ingester": "Dupliquer un injecteur CSV",
"Duplicate a CSV mapper": "Dupliquer un mappeur CSV",
"Duplicate a feed": "Dupliquer un flux",
"Element ID": "ID de l'élément",
"Email": "Email",
"Email date": "Date de l'email",
Expand Down
3 changes: 3 additions & 0 deletions opencti-platform/opencti-front/lang/back/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@
"DST Payload": "DSTペイロード",
"DST port": "DSTポート",
"Due date": "個人的な動機",
"Duplicate a CSV ingester": "CSVインジェスターの複製",
"Duplicate a CSV mapper": "CSVマッパーを複製する",
"Duplicate a feed": "フィードの複製",
"Element ID": "要素ID",
"Email": "電子メール",
"Email date": "メール送信日",
Expand Down
3 changes: 3 additions & 0 deletions opencti-platform/opencti-front/lang/back/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@
"DST Payload": "DST 페이로드",
"DST port": "DST 포트",
"Due date": "기한 날짜",
"Duplicate a CSV ingester": "CSV 수집기 복제",
"Duplicate a CSV mapper": "CSV 매퍼 복제",
"Duplicate a feed": "피드 복제하기",
"Element ID": "요소 ID",
"Email": "이메일",
"Email date": "이메일 날짜",
Expand Down
3 changes: 3 additions & 0 deletions opencti-platform/opencti-front/lang/back/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@
"DST Payload": "DST 有效载荷",
"DST port": "DST 端口",
"Due date": "到期日",
"Duplicate a CSV ingester": "复制 CSV 输入器",
"Duplicate a CSV mapper": "复制 CSV 映射器",
"Duplicate a feed": "复制一个饲料",
"Element ID": "元素 ID",
"Email": "电子邮件",
"Email date": "电子邮件日期",
Expand Down
3 changes: 3 additions & 0 deletions opencti-platform/opencti-front/lang/front/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,9 @@
"Download this support package": "Laden Sie dieses Support-Paket herunter",
"Due Date": "Fälligkeitsdatum",
"Duplicate": "Duplizieren",
"Duplicate a CSV ingester": "Duplizieren Sie einen CSV-Ingester",
"Duplicate a CSV mapper": "Duplizieren eines CSV-Mappers",
"Duplicate a feed": "Einspeisung duplizieren",
"Duplicate the dashboard": "Duplizieren Sie das Dashboard",
"Dynamic source filters": "Dynamische Quellfilter",
"Dynamic target filters": "Dynamische Zielfilter",
Expand Down
3 changes: 3 additions & 0 deletions opencti-platform/opencti-front/lang/front/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,9 @@
"Download this support package": "Download this support package",
"Due Date": "Due Date",
"Duplicate": "Duplicate",
"Duplicate a CSV ingester": "Duplicate a CSV ingester",
"Duplicate a CSV mapper": "Duplicate a CSV mapper",
"Duplicate a feed": "Duplicate a feed",
"Duplicate the dashboard": "Duplicate the dashboard",
"Dynamic source filters": "Dynamic source filters",
"Dynamic target filters": "Dynamic target filters",
Expand Down
3 changes: 3 additions & 0 deletions opencti-platform/opencti-front/lang/front/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,9 @@
"Download this support package": "Descargar este paquete de soporte",
"Due Date": "Fecha de vencimiento",
"Duplicate": "Duplicar",
"Duplicate a CSV ingester": "Duplicar una entrada CSV",
"Duplicate a CSV mapper": "Duplicar un mapeador CSV",
"Duplicate a feed": "Duplicar un feed",
"Duplicate the dashboard": "Duplicar el salpicadero",
"Dynamic source filters": "Filtros de fuente dinámicos",
"Dynamic target filters": "Filtros dinámicos de destino",
Expand Down
3 changes: 3 additions & 0 deletions opencti-platform/opencti-front/lang/front/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,9 @@
"Download this support package": "Télécharger ce paquet de support",
"Due Date": "Date d'échéance",
"Duplicate": "Dupliquer",
"Duplicate a CSV ingester": "Dupliquer un injecteur CSV",
"Duplicate a CSV mapper": "Dupliquer un mappeur CSV",
"Duplicate a feed": "Dupliquer un flux",
"Duplicate the dashboard": "Dupliquer le tableau de bord",
"Dynamic source filters": "Filtres de source dynamique",
"Dynamic target filters": "Filtres dynamiques cibles",
Expand Down
3 changes: 3 additions & 0 deletions opencti-platform/opencti-front/lang/front/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,9 @@
"Download this support package": "このサポートパッケージをダウンロードする",
"Due Date": "期日",
"Duplicate": "重複",
"Duplicate a CSV ingester": "CSVインジェスターの複製",
"Duplicate a CSV mapper": "CSVマッパーを複製する",
"Duplicate a feed": "フィードの複製",
"Duplicate the dashboard": "ダッシュボードの複製",
"Dynamic source filters": "ダイナミック・ソース・フィルタ",
"Dynamic target filters": "動的ターゲットフィルタ",
Expand Down
3 changes: 3 additions & 0 deletions opencti-platform/opencti-front/lang/front/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,9 @@
"Download this support package": "이 지원 패키지를 다운로드",
"Due Date": "마감일",
"Duplicate": "복제",
"Duplicate a CSV ingester": "CSV 수집기 복제",
"Duplicate a CSV mapper": "CSV 매퍼 복제",
"Duplicate a feed": "피드 복제하기",
"Duplicate the dashboard": "대시보드 복제",
"Dynamic source filters": "동적 소스 필터",
"Dynamic target filters": "동적 대상 필터",
Expand Down
3 changes: 3 additions & 0 deletions opencti-platform/opencti-front/lang/front/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,9 @@
"Download this support package": "下载此支持软件包",
"Due Date": "到期日",
"Duplicate": "复制",
"Duplicate a CSV ingester": "复制 CSV 输入器",
"Duplicate a CSV mapper": "复制 CSV 映射器",
"Duplicate a feed": "复制一个饲料",
"Duplicate the dashboard": "复制仪表板",
"Dynamic source filters": "动态源过滤器",
"Dynamic target filters": "动态目标过滤器",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ const CsvMappers = () => {
/>
</React.Suspense>
</ListLines>
<CsvMapperCreationContainer paginationOptions={paginationOptions}/>
<CsvMapperCreationContainer paginationOptions={paginationOptions} open={false} onClose={() => {
}}
/>
</div>
</CsvMappersProvider>
</Suspense>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import IngestionMenu from '@components/data/IngestionMenu';
import IngestionCsvLines, { ingestionCsvLinesQuery } from '@components/data/ingestionCsv/IngestionCsvLines';
import { IngestionCsvLinesPaginationQuery, IngestionCsvLinesPaginationQuery$variables } from '@components/data/ingestionCsv/__generated__/IngestionCsvLinesPaginationQuery.graphql';
import { IngestionCsvLineDummy } from '@components/data/ingestionCsv/IngestionCsvLine';
import IngestionCsvCreation from '@components/data/ingestionCsv/IngestionCsvCreation';
import { IngestionCsvCreationContainer } from '@components/data/ingestionCsv/IngestionCsvCreation';
import { useFormatter } from '../../../components/i18n';
import useAuth from '../../../utils/hooks/useAuth';
import { usePaginationLocalStorage } from '../../../utils/hooks/useLocalStorage';
Expand Down Expand Up @@ -127,8 +127,12 @@ const IngestionCsv = () => {
<IngestionMenu/>
{renderLines()}
<Security needs={[INGESTION_SETINGESTIONS]}>
<IngestionCsvCreation
<IngestionCsvCreationContainer
open={false}
handleClose={() => {
}}
paginationOptions={paginationOptions}
isDuplicated={false}
/>
</Security>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import React, { FunctionComponent } from 'react';
import { FormikConfig } from 'formik';
import { graphql } from 'react-relay';
import CsvMapperForm from '@components/data/csvMapper/CsvMapperForm';
import { graphql, useFragment } from 'react-relay';
import { CsvMapperFormData } from '@components/data/csvMapper/CsvMapper';
import { CsvMapperAddInput } from '@components/data/csvMapper/__generated__/CsvMapperCreationContainerMutation.graphql';
import { formDataToCsvMapper } from '@components/data/csvMapper/CsvMapperUtils';
import { csvMappers_MappersQuery$variables } from '@components/data/csvMapper/__generated__/csvMappers_MappersQuery.graphql';
import { CsvMapperEditionContainerFragment_csvMapper$key } from '@components/data/csvMapper/__generated__/CsvMapperEditionContainerFragment_csvMapper.graphql';
import { useCsvMappersData } from '@components/data/csvMapper/csvMappers.data';
import {
CsvMapperRepresentationAttributesForm_allSchemaAttributes$key,
} from '@components/data/csvMapper/representations/attributes/__generated__/CsvMapperRepresentationAttributesForm_allSchemaAttributes.graphql';
import { CsvMapperRepresentationAttributesFormFragment } from '@components/data/csvMapper/representations/attributes/CsvMapperRepresentationAttributesForm';
import { csvMapperToFormData, formDataToCsvMapper } from '@components/data/csvMapper/CsvMapperUtils';
import CsvMapperForm from '@components/data/csvMapper/CsvMapperForm';
import { csvMapperEditionContainerFragment } from '@components/data/csvMapper/CsvMapperEditionContainer';
import { insertNode } from '../../../../utils/store';
import useApiMutation from '../../../../utils/hooks/useApiMutation';
import { handleErrorInForm } from '../../../../relay/environment';
import { useComputeDefaultValues } from '../../../../utils/hooks/useDefaultValues';

const csvMapperCreation = graphql`
mutation CsvMapperCreationContainerMutation($input: CsvMapperAddInput!) {
Expand All @@ -24,16 +32,31 @@ const csvMapperCreation = graphql`
`;

interface CsvMapperCreationFormProps {
onClose?: () => void;
paginationOptions: csvMappers_MappersQuery$variables;
paginationOptions: csvMappers_MappersQuery$variables
isDuplicated?: boolean
onClose?: () => void
open: boolean
mappingCsv?: CsvMapperEditionContainerFragment_csvMapper$key | null,
}

const CsvMapperCreation: FunctionComponent<CsvMapperCreationFormProps> = ({
mappingCsv,
isDuplicated,
onClose,
paginationOptions,
}) => {
const [commit] = useApiMutation(csvMapperCreation);
const { schemaAttributes } = useCsvMappersData();
const data = useFragment<CsvMapperRepresentationAttributesForm_allSchemaAttributes$key>(
CsvMapperRepresentationAttributesFormFragment,
schemaAttributes,
) || { csvMapperSchemaAttributes: [] };

const computeDefaultValues = useComputeDefaultValues();
const csvMapper = useFragment(
csvMapperEditionContainerFragment,
mappingCsv,
);
const onSubmit: FormikConfig<CsvMapperFormData>['onSubmit'] = (
values,
{ resetForm, setSubmitting, setErrors },
Expand All @@ -57,6 +80,7 @@ const CsvMapperCreation: FunctionComponent<CsvMapperCreationFormProps> = ({
'csvMapperAdd',
),
onCompleted: () => {
setSubmitting(false);
resetForm();
if (onClose) {
onClose();
Expand All @@ -69,17 +93,22 @@ const CsvMapperCreation: FunctionComponent<CsvMapperCreationFormProps> = ({
});
};

const initialValues: CsvMapperFormData = {
id: '',
name: '',
has_header: false,
separator: ',',
skip_line_char: '',
entity_representations: [],
relationship_representations: [],
};
const initialValues: CsvMapperFormData = isDuplicated && csvMapper
? csvMapperToFormData(
csvMapper,
data.csvMapperSchemaAttributes,
computeDefaultValues,
) : {
id: '',
name: '',
has_header: false,
separator: ',',
skip_line_char: '',
entity_representations: [],
relationship_representations: [],
};

return <CsvMapperForm csvMapper={initialValues} onSubmit={onSubmit} />;
return <CsvMapperForm csvMapper={initialValues} onSubmit={onSubmit} isDuplicated={isDuplicated}/>;
};

export default CsvMapperCreation;
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,43 @@ import React, { FunctionComponent } from 'react';
import Drawer, { DrawerVariant } from '@components/common/drawer/Drawer';
import CsvMapperCreation from '@components/data/csvMapper/CsvMapperCreation';
import { csvMappers_MappersQuery$variables } from '@components/data/csvMapper/__generated__/csvMappers_MappersQuery.graphql';
import { PreloadedQuery, usePreloadedQuery } from 'react-relay';
import { CsvMapperEditionContainerQuery } from '@components/data/csvMapper/__generated__/CsvMapperEditionContainerQuery.graphql';
import { csvMapperEditionContainerQuery } from '@components/data/csvMapper/CsvMapperEditionContainer';
import { useFormatter } from '../../../../components/i18n';

interface CsvMapperCreationProps {
paginationOptions: csvMappers_MappersQuery$variables;
queryRef?: PreloadedQuery<CsvMapperEditionContainerQuery>,
isDuplicated?: boolean;
onClose?: () => void;
open: boolean;
}

const CsvMapperCreationContainer: FunctionComponent<CsvMapperCreationProps> = ({
queryRef,
onClose,
isDuplicated,
open,
paginationOptions,
}) => {
const { t_i18n } = useFormatter();
const mappingCsv = queryRef ? (usePreloadedQuery(csvMapperEditionContainerQuery, queryRef)).csvMapper : null;

return (
<Drawer
title={t_i18n('Create a CSV mapper')}
variant={DrawerVariant.createWithPanel}
title={isDuplicated ? t_i18n('Duplicate a CSV mapper') : t_i18n('Create a CSV mapper')}
open={open}
onClose={onClose}
variant={isDuplicated ? undefined : DrawerVariant.createWithPanel}
>
<CsvMapperCreation paginationOptions={paginationOptions} />
<CsvMapperCreation
mappingCsv={mappingCsv}
paginationOptions={paginationOptions}
onClose={onClose}
isDuplicated={isDuplicated}
open={open}
/>
</Drawer>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Drawer from '@components/common/drawer/Drawer';
import Loader, { LoaderVariant } from '../../../../components/Loader';
import { useFormatter } from '../../../../components/i18n';

const csvMapperEditionContainerFragment = graphql`
export const csvMapperEditionContainerFragment = graphql`
fragment CsvMapperEditionContainerFragment_csvMapper on CsvMapper {
id
name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ interface CsvMapperFormProps {
values: CsvMapperFormData,
formikHelpers: FormikHelpers<CsvMapperFormData>,
) => void;
isDuplicated?: boolean,
}

const CsvMapperForm: FunctionComponent<CsvMapperFormProps> = ({ csvMapper, onSubmit }) => {
const CsvMapperForm: FunctionComponent<CsvMapperFormProps> = ({ csvMapper, onSubmit, isDuplicated }) => {
const { t_i18n } = useFormatter();
const classes = useStyles();

Expand Down Expand Up @@ -142,6 +143,16 @@ const CsvMapperForm: FunctionComponent<CsvMapperFormProps> = ({ csvMapper, onSub
]);
};

const getButtonText = () => {
if (isDuplicated) {
return t_i18n('Duplicate');
}
if (csvMapper.id) {
return t_i18n('Update');
}
return t_i18n('Create');
};

// -- ERRORS --
// on edit mode, csvMapper.errors might be set; on create mode backend validation is not done yet so error is null
const [hasError, setHasError] = useState<boolean>(
Expand Down Expand Up @@ -334,7 +345,7 @@ const CsvMapperForm: FunctionComponent<CsvMapperFormProps> = ({ csvMapper, onSub
disabled={isSubmitting}
classes={{ root: classes.button }}
>
{csvMapper.id ? t_i18n('Update') : t_i18n('Create')}
{getButtonText()}
</Button>
</div>
<CsvMapperTestDialog
Expand Down
Loading

0 comments on commit c0b3de1

Please sign in to comment.