■ ■ ■ ■ ■ ■
opencti-platform/opencti-front/src/private/components/techniques/data_components/Root.tsx
| 1 | + | import React, { FunctionComponent } from 'react'; |
| 2 | + | import { Route, Switch, useParams } from 'react-router-dom'; |
| 3 | + | import { graphql } from 'react-relay'; |
| 4 | + | import { |
| 5 | + | QueryRenderer, |
| 6 | + | requestSubscription, |
| 7 | + | } from '../../../../relay/environment'; |
| 8 | + | import TopBar from '../../nav/TopBar'; |
| 9 | + | import Loader from '../../../../components/Loader'; |
| 10 | + | import ErrorNotFound from '../../../../components/ErrorNotFound'; |
| 11 | + | import DataComponent from './DataComponent'; |
| 12 | + | import DataComponentKnowledge from './DataComponentKnowledge'; |
| 13 | + | import DataComponentPopover from './DataComponentPopover'; |
| 14 | + | import FileManager from '../../common/files/FileManager'; |
| 15 | + | import StixDomainObjectHeader from '../../common/stix_domain_objects/StixDomainObjectHeader'; |
| 16 | + | import StixCoreObjectHistory from '../../common/stix_core_objects/StixCoreObjectHistory'; |
| 17 | + | import { RootPrivateQuery$data } from '../../../__generated__/RootPrivateQuery.graphql'; |
| 18 | + | import useAuth from '../../../../utils/hooks/useAuth'; |
| 19 | + | |
| 20 | + | const subscription = graphql` |
| 21 | + | subscription RootDataComponentSubscription($id: ID!) { |
| 22 | + | stixDomainObject(id: $id) { |
| 23 | + | ... on DataComponent { |
| 24 | + | ...DataComponent_dataComponent |
| 25 | + | ...DataComponentEditionContainer_dataComponent |
| 26 | + | } |
| 27 | + | ...FileImportViewer_entity |
| 28 | + | ...FileExportViewer_entity |
| 29 | + | ...FileExternalReferencesViewer_entity |
| 30 | + | ...WorkbenchFileViewer_entity |
| 31 | + | } |
| 32 | + | } |
| 33 | + | `; |
| 34 | + | |
| 35 | + | const dataComponentQuery = graphql` |
| 36 | + | query RootDataComponentQuery($id: String!) { |
| 37 | + | dataComponent(id: $id) { |
| 38 | + | id |
| 39 | + | name |
| 40 | + | ...DataComponent_dataComponent |
| 41 | + | ...FileImportViewer_entity |
| 42 | + | ...FileExportViewer_entity |
| 43 | + | ...FileExternalReferencesViewer_entity |
| 44 | + | ...WorkbenchFileViewer_entity |
| 45 | + | } |
| 46 | + | connectorsForExport { |
| 47 | + | ...FileManager_connectorsExport |
| 48 | + | } |
| 49 | + | settings { |
| 50 | + | platform_enable_reference |
| 51 | + | } |
| 52 | + | } |
| 53 | + | `; |
| 54 | + | |
| 55 | + | interface RootDataComponentProps { |
| 56 | + | me: RootPrivateQuery$data['me'] | undefined; |
| 57 | + | children: React.ReactNode |
| 58 | + | } |
| 59 | + | |
| 60 | + | const RootDataComponent: FunctionComponent<RootDataComponentProps> = () => { |
| 61 | + | const { dataComponentId } = useParams() as { dataComponentId: string }; |
| 62 | + | const { me } = useAuth(); |
| 63 | + | const sub = requestSubscription({ |
| 64 | + | subscription, |
| 65 | + | variables: { id: dataComponentId }, |
| 66 | + | }); |
| 67 | + | const componentWillUnmount = () => { |
| 68 | + | sub.dispose(); |
| 69 | + | }; |
| 70 | + | |
| 71 | + | return ( |
| 72 | + | <div> |
| 73 | + | <TopBar me={me || null} /> |
| 74 | + | <QueryRenderer |
| 75 | + | query={dataComponentQuery} |
| 76 | + | variables={{ id: dataComponentId }} |
| 77 | + | render={({ props }: any) => { |
| 78 | + | if (props) { |
| 79 | + | if (props.dataComponent) { |
| 80 | + | return ( |
| 81 | + | <Switch> |
| 82 | + | <Route |
| 83 | + | // @ts-ignore |
| 84 | + | // TODO: required migration to V6 |
| 85 | + | exact |
| 86 | + | path="/dashboard/techniques/data_component/:dataComponentId" |
| 87 | + | // @ts-ignore |
| 88 | + | // TODO: required migration to V6 |
| 89 | + | render={(routeProps) => ( |
| 90 | + | <DataComponent |
| 91 | + | {...routeProps} |
| 92 | + | dataComponent={props.dataComponent} |
| 93 | + | /> |
| 94 | + | )} |
| 95 | + | /> |
| 96 | + | <Route |
| 97 | + | path="/dashboard/techniques/data_component/:dataComponentId/knowledge" |
| 98 | + | // @ts-ignore |
| 99 | + | // TODO: required migration to V6 |
| 100 | + | render={(routeProps) => ( |
| 101 | + | <DataComponentKnowledge |
| 102 | + | {...routeProps} |
| 103 | + | dataComponent={props.dataComponent} |
| 104 | + | /> |
| 105 | + | )} |
| 106 | + | /> |
| 107 | + | <Route |
| 108 | + | // @ts-ignore |
| 109 | + | // TODO: required migration to V6 |
| 110 | + | exact |
| 111 | + | path="/dashboard/techniques/data_component/:dataComponentId/files" |
| 112 | + | // @ts-ignore |
| 113 | + | // TODO: required migration to V6 |
| 114 | + | render={(routeProps) => ( |
| 115 | + | <React.Fragment> |
| 116 | + | <StixDomainObjectHeader |
| 117 | + | stixDomainObject={props.dataComponent} |
| 118 | + | PopoverComponent={<DataComponentPopover |
| 119 | + | dataComponentId={dataComponentId} |
| 120 | + | enableReferences={props.settings.platform_enable_reference?.includes( |
| 121 | + | 'Data-Component', |
| 122 | + | )}/>} |
| 123 | + | /> |
| 124 | + | <FileManager |
| 125 | + | {...routeProps} |
| 126 | + | id={dataComponentId} |
| 127 | + | connectorsImport={[]} |
| 128 | + | connectorsExport={props.connectorsForExport} |
| 129 | + | entity={props.dataComponent} |
| 130 | + | /> |
| 131 | + | </React.Fragment> |
| 132 | + | )} |
| 133 | + | /> |
| 134 | + | <Route |
| 135 | + | // @ts-ignore |
| 136 | + | // TODO: required migration to V6 |
| 137 | + | exact |
| 138 | + | path="/dashboard/techniques/data_component/:dataComponentId/history" |
| 139 | + | // @ts-ignore |
| 140 | + | // TODO: required migration to V6 |
| 141 | + | render={(routeProps) => ( |
| 142 | + | <React.Fragment> |
| 143 | + | <StixDomainObjectHeader |
| 144 | + | stixDomainObject={props.dataComponent} |
| 145 | + | PopoverComponent={<DataComponentPopover |
| 146 | + | dataComponentId={dataComponentId} |
| 147 | + | enableReferences={props.settings.platform_enable_reference?.includes( |
| 148 | + | 'Data-Component', |
| 149 | + | )} |
| 150 | + | />} |
| 151 | + | /> |
| 152 | + | <StixCoreObjectHistory |
| 153 | + | {...routeProps} |
| 154 | + | stixCoreObjectId={dataComponentId} |
| 155 | + | /> |
| 156 | + | </React.Fragment> |
| 157 | + | )} |
| 158 | + | /> |
| 159 | + | </Switch> |
| 160 | + | ); |
| 161 | + | } |
| 162 | + | return <ErrorNotFound />; |
| 163 | + | } |
| 164 | + | return <Loader />; |
| 165 | + | }} |
| 166 | + | /> |
| 167 | + | </div> |
| 168 | + | ); |
| 169 | + | }; |
| 170 | + | |
| 171 | + | export default RootDataComponent; |
| 172 | + | |