diff --git a/packages/threat-composer/src/components/workspaces/WorkspaceSelector/index.tsx b/packages/threat-composer/src/components/workspaces/WorkspaceSelector/index.tsx index a52a5ae2..f449a021 100644 --- a/packages/threat-composer/src/components/workspaces/WorkspaceSelector/index.tsx +++ b/packages/threat-composer/src/components/workspaces/WorkspaceSelector/index.tsx @@ -25,7 +25,6 @@ import { DEFAULT_WORKSPACE_ID, DEFAULT_WORKSPACE_LABEL, EXAMPLES_SECTION_WORKSPACE_LABEL, - EXAMPLES_WORKSPACE_ID_PREFIX, } from '../../../configs/constants'; import { useGlobalSetupContext } from '../../../contexts/GlobalSetupContext'; import { useWorkspaceExamplesContext } from '../../../contexts/WorkspaceExamplesContext'; @@ -89,7 +88,7 @@ const WorkspaceSelector: FC> = ({ label: EXAMPLES_SECTION_WORKSPACE_LABEL, options: workspaceExamples.map(we => ({ label: we.name, - value: `${EXAMPLES_WORKSPACE_ID_PREFIX}${we.name}`, + value: we.id, })), }, ]; diff --git a/packages/threat-composer/src/contexts/ApplicationContext/index.tsx b/packages/threat-composer/src/contexts/ApplicationContext/index.tsx index 4595e55f..8c3f8d21 100644 --- a/packages/threat-composer/src/contexts/ApplicationContext/index.tsx +++ b/packages/threat-composer/src/contexts/ApplicationContext/index.tsx @@ -25,8 +25,11 @@ const ApplicationContextProvider: FC) : - (); + () : + (); }; export default ApplicationContextProvider; diff --git a/packages/threat-composer/src/contexts/ArchitectureContext/index.tsx b/packages/threat-composer/src/contexts/ArchitectureContext/index.tsx index 6e18b36e..380f6cd9 100644 --- a/packages/threat-composer/src/contexts/ArchitectureContext/index.tsx +++ b/packages/threat-composer/src/contexts/ArchitectureContext/index.tsx @@ -25,8 +25,11 @@ const ArchitectureContextProvider: FC) : - (); + () : + (); }; export default ArchitectureContextProvider; diff --git a/packages/threat-composer/src/contexts/AssumptionLinksContext/index.tsx b/packages/threat-composer/src/contexts/AssumptionLinksContext/index.tsx index 906d259b..7b00486e 100644 --- a/packages/threat-composer/src/contexts/AssumptionLinksContext/index.tsx +++ b/packages/threat-composer/src/contexts/AssumptionLinksContext/index.tsx @@ -25,8 +25,11 @@ const AssumptionLinksContextProvider: FC) - : (); + () + : (); }; export default AssumptionLinksContextProvider; diff --git a/packages/threat-composer/src/contexts/AssumptionsContext/index.tsx b/packages/threat-composer/src/contexts/AssumptionsContext/index.tsx index 8fafdedd..1b31ae40 100644 --- a/packages/threat-composer/src/contexts/AssumptionsContext/index.tsx +++ b/packages/threat-composer/src/contexts/AssumptionsContext/index.tsx @@ -25,8 +25,11 @@ const AssumptionsContextProvider: FC) : - (); + () : + (); }; export default AssumptionsContextProvider; diff --git a/packages/threat-composer/src/contexts/DataflowContext/index.tsx b/packages/threat-composer/src/contexts/DataflowContext/index.tsx index 293cd590..5a35f674 100644 --- a/packages/threat-composer/src/contexts/DataflowContext/index.tsx +++ b/packages/threat-composer/src/contexts/DataflowContext/index.tsx @@ -25,8 +25,11 @@ const DataflowContextProvider: FC) : - (); + () : + (); }; export default DataflowContextProvider; diff --git a/packages/threat-composer/src/contexts/MitigationLinksContext/index.tsx b/packages/threat-composer/src/contexts/MitigationLinksContext/index.tsx index 19077d43..412684f7 100644 --- a/packages/threat-composer/src/contexts/MitigationLinksContext/index.tsx +++ b/packages/threat-composer/src/contexts/MitigationLinksContext/index.tsx @@ -25,8 +25,11 @@ const MitigationLinksContextProvider: FC) : - (); + () : + (); }; export default MitigationLinksContextProvider; diff --git a/packages/threat-composer/src/contexts/MitigationsContext/index.tsx b/packages/threat-composer/src/contexts/MitigationsContext/index.tsx index e17161a3..7d30b787 100644 --- a/packages/threat-composer/src/contexts/MitigationsContext/index.tsx +++ b/packages/threat-composer/src/contexts/MitigationsContext/index.tsx @@ -25,8 +25,10 @@ const MitigationsContextProvider: FC) : - (); + () : + (); }; export default MitigationsContextProvider; diff --git a/packages/threat-composer/src/contexts/ThreatsContext/index.tsx b/packages/threat-composer/src/contexts/ThreatsContext/index.tsx index 3eb829da..1f817b7d 100644 --- a/packages/threat-composer/src/contexts/ThreatsContext/index.tsx +++ b/packages/threat-composer/src/contexts/ThreatsContext/index.tsx @@ -26,10 +26,13 @@ const ThreatsContextProvider: FC> const { getWorkspaceExample } = useWorkspaceExamplesContext(); return isWorkspaceExample(props.workspaceId) ? - ( + ( {children} ) : - ( + ( {children} diff --git a/packages/threat-composer/src/contexts/WorkspaceExamplesContext/context.ts b/packages/threat-composer/src/contexts/WorkspaceExamplesContext/context.ts index 630cc9b3..bc78fe49 100644 --- a/packages/threat-composer/src/contexts/WorkspaceExamplesContext/context.ts +++ b/packages/threat-composer/src/contexts/WorkspaceExamplesContext/context.ts @@ -14,11 +14,11 @@ limitations under the License. ******************************************************************************************************************** */ import { useContext, createContext } from 'react'; -import { WorkspaceExample } from '../../customTypes'; +import { WorkspaceExampleWithId } from '../../customTypes'; export interface WorkspaceExamplesContextApi { - workspaceExamples: WorkspaceExample[]; - getWorkspaceExample: (workspaceExampleId?: string | null) => WorkspaceExample | undefined; + workspaceExamples: WorkspaceExampleWithId[]; + getWorkspaceExample: (workspaceExampleId?: string | null) => WorkspaceExampleWithId | undefined; } const initialState: WorkspaceExamplesContextApi = { diff --git a/packages/threat-composer/src/contexts/WorkspaceExamplesContext/index.tsx b/packages/threat-composer/src/contexts/WorkspaceExamplesContext/index.tsx index 2810b511..7b4f5367 100644 --- a/packages/threat-composer/src/contexts/WorkspaceExamplesContext/index.tsx +++ b/packages/threat-composer/src/contexts/WorkspaceExamplesContext/index.tsx @@ -14,22 +14,28 @@ limitations under the License. ******************************************************************************************************************** */ /** @jsxImportSource @emotion/react */ -import { FC, PropsWithChildren, useCallback } from 'react'; +import { FC, PropsWithChildren, useCallback, useMemo } from 'react'; import { WorkspaceExamplesContext, useWorkspaceExamplesContext } from './context'; import { EXAMPLES_WORKSPACE_ID_PREFIX } from '../../configs'; -import workspaceExamples from '../../data/workspaceExamples/workspaceExamples'; +import workspaceExamplesData from '../../data/workspaceExamples/workspaceExamples'; const WorkspaceExamplesContextProvider: FC> = ({ children, }) => { + const workspaceExamples = useMemo(() => { + return workspaceExamplesData.map(x => ({ + ...x, + id: `${EXAMPLES_WORKSPACE_ID_PREFIX}${x.name.replace(/\s/g, '')}`, + })); + }, [workspaceExamplesData]); + const handleGetWorkspaceExample = useCallback((workspaceExampleId?: string | null) => { if (workspaceExampleId) { - const workspaceExampleName = workspaceExampleId.substring(EXAMPLES_WORKSPACE_ID_PREFIX.length); - return workspaceExamples.find(x => x.name === workspaceExampleName); + return workspaceExamples.find(x => x.id === workspaceExampleId); } return undefined; - }, []); + }, [workspaceExamples]); return (; +export type WorkspaceExampleWithId = z.infer; + export interface HasContentDetails { applicationName: boolean; applicationInfo: boolean;