■ ■ ■ ■ ■ ■
opencti-platform/opencti-front/src/private/components/techniques/data_components/DataComponentCreation.tsx
| skipped 13 lines |
14 | 14 | | import { commitMutation, handleErrorInForm, } from '../../../../relay/environment'; |
15 | 15 | | import TextField from '../../../../components/TextField'; |
16 | 16 | | import CreatedByField, { CreatedBy } from '../../common/form/CreatedByField'; |
17 | | - | import ObjectLabelField from '../../common/form/ObjectLabelField'; |
18 | | - | import ObjectMarkingField from '../../common/form/ObjectMarkingField'; |
| 17 | + | import ObjectLabelField, { ObjectLabel } from '../../common/form/ObjectLabelField'; |
| 18 | + | import ObjectMarkingField, { ObjectMarking } from '../../common/form/ObjectMarkingField'; |
19 | 19 | | import MarkDownField from '../../../../components/MarkDownField'; |
20 | 20 | | import makeStyles from '@mui/styles/makeStyles'; |
21 | 21 | | import { Theme } from '../../../../components/Theme'; |
22 | 22 | | import { PaginationOptions } from '../../../../components/list_lines'; |
23 | 23 | | import { FormikHelpers } from 'formik/dist/types'; |
| 24 | + | import ExternalReferencesField, { ExternalReference } from '../../common/form/ExternalReferencesField'; |
24 | 25 | | |
25 | 26 | | const styles = makeStyles<Theme>((theme) => ({ |
26 | 27 | | drawerPaper: { |
| skipped 50 lines |
77 | 78 | | const dataComponentMutation = graphql` |
78 | 79 | | mutation DataComponentCreationMutation($input: DataComponentAddInput!) { |
79 | 80 | | dataComponentAdd(input: $input) { |
80 | | - | id |
81 | | - | name |
82 | | - | description |
| 81 | + | ...DataComponentLine_node |
83 | 82 | | } |
84 | 83 | | } |
85 | 84 | | `; |
| skipped 26 lines |
112 | 111 | | paginationOptions: PaginationOptions |
113 | 112 | | } |
114 | 113 | | |
115 | | - | interface DataComponentForm { // TODO: handle this type |
| 114 | + | interface DataComponentFormProps { // TODO: handle this type |
116 | 115 | | name: string, |
117 | 116 | | description: string, |
118 | 117 | | createdBy: CreatedBy, |
119 | | - | objectMarking: Array<any>, |
120 | | - | objectLabel: Array<any>, |
| 118 | + | objectMarking: Array<ObjectMarking>, |
| 119 | + | objectLabel: Array<ObjectLabel>, |
| 120 | + | externalReferences: Array<ExternalReference> |
121 | 121 | | } |
122 | 122 | | |
123 | 123 | | const DataComponentCreation: FunctionComponent<DataComponentCreationProps> = ({ |
| skipped 3 lines |
127 | 127 | | const classes = styles(); |
128 | 128 | | |
129 | 129 | | const [open, setOpen] = useState(false); |
| 130 | + | const initialValues: DataComponentFormProps = { name: '', |
| 131 | + | description: '', |
| 132 | + | createdBy: {} as CreatedBy, |
| 133 | + | objectMarking: [], |
| 134 | + | objectLabel: [], |
| 135 | + | externalReferences: [] |
| 136 | + | }; |
130 | 137 | | |
131 | 138 | | const handleOpen = () => { |
132 | 139 | | setOpen(true); |
| skipped 3 lines |
136 | 143 | | setOpen(false); |
137 | 144 | | } |
138 | 145 | | |
139 | | - | const onSubmit = (values: DataComponentForm, { setSubmitting, setErrors, resetForm }: FormikHelpers<DataComponentForm>) => { |
140 | | - | const finalValues = R.pipe( |
141 | | - | R.assoc('createdBy', values.createdBy?.value), |
142 | | - | R.assoc('objectMarking', R.pluck('value', values.objectMarking)), |
143 | | - | R.assoc('objectLabel', R.pluck('value', values.objectLabel)), |
144 | | - | // TODO: externalReferences |
145 | | - | )(values); |
| 146 | + | const onSubmit = ( |
| 147 | + | values: DataComponentFormProps, |
| 148 | + | { setSubmitting, setErrors, resetForm }: FormikHelpers<DataComponentFormProps> |
| 149 | + | ) => { |
| 150 | + | const finalValues = { |
| 151 | + | name: values.name, |
| 152 | + | description: values.description, |
| 153 | + | createdBy: values.createdBy?.value, |
| 154 | + | objectMarking: values.objectMarking.map(v => v.value), |
| 155 | + | objectLabel: values.objectLabel.map(v => v.value), |
| 156 | + | externalReferences: values.objectLabel.map(v => v.value) |
| 157 | + | }; |
146 | 158 | | commitMutation({ |
147 | 159 | | mutation: dataComponentMutation, |
148 | 160 | | variables: { |
| skipped 2 lines |
151 | 163 | | updater: (store: RecordSourceSelectorProxy) => { |
152 | 164 | | const payload: RecordProxy | null = store.getRootField('dataComponentAdd'); |
153 | 165 | | if (payload) { |
154 | | - | const newEdge: RecordProxy = payload.setLinkedRecord(payload, 'node'); // Creation of the pagination container. |
| 166 | + | const newEdge: RecordProxy = payload.setLinkedRecord(payload, 'node'); |
155 | 167 | | const container: RecordProxy = store.getRoot(); |
156 | 168 | | sharedUpdater( |
157 | 169 | | store, |
| skipped 54 lines |
212 | 224 | | </div> |
213 | 225 | | <div className={classes.container}> |
214 | 226 | | <Formik |
215 | | - | initialValues={{ |
216 | | - | name: '', |
217 | | - | description: '', |
218 | | - | createdBy: {} as CreatedBy, |
219 | | - | objectMarking: [], |
220 | | - | objectLabel: [], |
221 | | - | }} |
| 227 | + | initialValues={initialValues} |
222 | 228 | | validationSchema={dataComponentValidation(t)} |
223 | 229 | | onSubmit={onSubmit} |
224 | 230 | | onReset={onReset} |
| skipped 46 lines |
271 | 277 | | marginTop: 20, |
272 | 278 | | width: '100%' |
273 | 279 | | }} |
| 280 | + | /> |
| 281 | + | <ExternalReferencesField |
| 282 | + | name="externalReferences" |
| 283 | + | style={{ |
| 284 | + | marginTop: 20, |
| 285 | + | width: '100%', |
| 286 | + | }} |
| 287 | + | setFieldValue={setFieldValue} |
| 288 | + | values={values.externalReferences} |
274 | 289 | | /> |
275 | 290 | | <div className={classes.buttons}> |
276 | 291 | | <Button |
| skipped 28 lines |