■ ■ ■ ■ ■ ■
opencti-platform/opencti-front/src/private/components/techniques/data_components/DataComponentCreation.tsx
1 | 1 | | import React, { FunctionComponent, useState } from 'react'; |
2 | | - | import { Field, Form, Formik } from 'formik'; |
| 2 | + | import { Field, Formik } from 'formik'; |
3 | 3 | | import Drawer from '@mui/material/Drawer'; |
4 | 4 | | import Typography from '@mui/material/Typography'; |
5 | 5 | | import Button from '@mui/material/Button'; |
| skipped 4 lines |
10 | 10 | | import * as Yup from 'yup'; |
11 | 11 | | import { graphql } from 'react-relay'; |
12 | 12 | | import { FormikHelpers } from 'formik/dist/types'; |
13 | | - | import { ConnectionHandler, RecordProxy, RecordSourceSelectorProxy } from 'relay-runtime'; |
| 13 | + | import { Store } from 'relay-runtime'; |
14 | 14 | | import { useFormatter } from '../../../../components/i18n'; |
15 | 15 | | import { commitMutation, handleErrorInForm } from '../../../../relay/environment'; |
16 | 16 | | import TextField from '../../../../components/TextField'; |
| skipped 4 lines |
21 | 21 | | import { Theme } from '../../../../components/Theme'; |
22 | 22 | | import { PaginationOptions } from '../../../../components/list_lines'; |
23 | 23 | | import ExternalReferencesField, { ExternalReference } from '../../common/form/ExternalReferencesField'; |
| 24 | + | import { insertNode } from '../../../../utils/Store'; |
24 | 25 | | |
25 | 26 | | const styles = makeStyles<Theme>((theme) => ({ |
26 | 27 | | drawerPaper: { |
| skipped 65 lines |
92 | 93 | | .required(t('This field is required')), |
93 | 94 | | }); |
94 | 95 | | |
95 | | - | const sharedUpdater = (store: RecordSourceSelectorProxy, userId: string, paginationOptions: PaginationOptions, newEdge: RecordProxy) => { |
96 | | - | const userProxy = store.get(userId); |
97 | | - | if (userProxy) { |
98 | | - | const conn: RecordProxy | null | undefined = ConnectionHandler.getConnection( |
99 | | - | userProxy, |
100 | | - | 'Pagination_dataComponents', |
101 | | - | paginationOptions, |
102 | | - | ); |
103 | | - | if (conn) { |
104 | | - | ConnectionHandler.insertEdgeBefore(conn, newEdge); |
105 | | - | } |
106 | | - | } |
107 | | - | }; |
108 | | - | |
109 | 96 | | interface DataComponentCreationProps { |
110 | 97 | | paginationOptions: PaginationOptions |
111 | 98 | | } |
| skipped 17 lines |
129 | 116 | | const initialValues: DataComponentFormProps = { |
130 | 117 | | name: '', |
131 | 118 | | description: '', |
132 | | - | createdBy: {} as CreatedBy, |
| 119 | + | createdBy: '' as unknown as CreatedBy, |
133 | 120 | | objectMarking: [], |
134 | 121 | | objectLabel: [], |
135 | 122 | | externalReferences: [], |
| skipped 24 lines |
160 | 147 | | variables: { |
161 | 148 | | input: finalValues, |
162 | 149 | | }, |
163 | | - | updater: (store: RecordSourceSelectorProxy) => { |
164 | | - | const payload: RecordProxy | null = store.getRootField('dataComponentAdd'); |
165 | | - | if (payload) { |
166 | | - | const newEdge: RecordProxy = payload.setLinkedRecord(payload, 'node'); |
167 | | - | const container: RecordProxy = store.getRoot(); |
168 | | - | sharedUpdater( |
169 | | - | store, |
170 | | - | container.getDataID(), |
171 | | - | paginationOptions, |
172 | | - | newEdge, |
173 | | - | ); |
174 | | - | } |
| 150 | + | updater: (store: Store) => { |
| 151 | + | insertNode( |
| 152 | + | store, |
| 153 | + | 'Pagination_dataComponents', |
| 154 | + | paginationOptions, |
| 155 | + | 'dataComponentAdd', |
| 156 | + | ); |
175 | 157 | | }, |
176 | 158 | | onError: (error: Error) => { |
177 | 159 | | handleErrorInForm(error, setErrors); |
| skipped 58 lines |
236 | 218 | | setFieldValue, |
237 | 219 | | values, |
238 | 220 | | }) => ( |
239 | | - | <Form style={{ margin: '20px 0 20px 0' }}> |
| 221 | + | <div style={{ margin: '20px 0 20px 0' }}> |
240 | 222 | | <Field |
241 | 223 | | component={TextField} |
242 | 224 | | variant="standard" |
243 | 225 | | name="name" |
244 | 226 | | label={t('Name')} |
245 | 227 | | fullWidth={true} |
246 | | - | detectDuplicate={['Data Component']} |
| 228 | + | detectduplicate={['Data Component']} |
247 | 229 | | /> |
248 | 230 | | <Field |
249 | 231 | | component={MarkDownField} |
| skipped 56 lines |
306 | 288 | | {t('Create')} |
307 | 289 | | </Button> |
308 | 290 | | </div> |
309 | | - | </Form> |
| 291 | + | </div> |
310 | 292 | | )} |
311 | 293 | | </Formik> |
312 | 294 | | </div> |
| skipped 7 lines |