From 5aebb812f46317180ad86aff784531e3e94e27d0 Mon Sep 17 00:00:00 2001 From: Konrad-Simso Date: Mon, 7 Oct 2024 14:09:36 +0200 Subject: [PATCH] Remove doubling up of code --- .../SchemaEditorWithToolbar.tsx | 10 +++++++--- .../SchemaEditorWithToolbar/TopToolbar/TopToolbar.tsx | 4 +--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/frontend/app-development/features/dataModelling/SchemaEditorWithToolbar/SchemaEditorWithToolbar.tsx b/frontend/app-development/features/dataModelling/SchemaEditorWithToolbar/SchemaEditorWithToolbar.tsx index 16feb7e3f56..7c6cba15a82 100644 --- a/frontend/app-development/features/dataModelling/SchemaEditorWithToolbar/SchemaEditorWithToolbar.tsx +++ b/frontend/app-development/features/dataModelling/SchemaEditorWithToolbar/SchemaEditorWithToolbar.tsx @@ -22,9 +22,13 @@ export const SchemaEditorWithToolbar = ({ const [selectedOption, setSelectedOption] = useState(undefined); const [schemaGenerationErrorMessages, setSchemaGenerationErrorMessages] = useState([]); const { mutate: addXsdFromRepo } = useAddXsdMutation(); - const modelPath = dataModels.find( + + const existingSelectedOption = dataModels.some( (model) => model.fileName === selectedOption?.value.fileName, - )?.repositoryRelativeUrl; + ) + ? selectedOption + : undefined; + const modelPath = existingSelectedOption?.value?.repositoryRelativeUrl; useEffect(() => { dataModels.forEach((model) => { @@ -40,7 +44,7 @@ export const SchemaEditorWithToolbar = ({ createNewOpen={createNewOpen} createPathOption={createPathOption} dataModels={dataModels} - selectedOption={selectedOption} + selectedOption={existingSelectedOption} setCreateNewOpen={setCreateNewOpen} setSelectedOption={setSelectedOption} onSetSchemaGenerationErrorMessages={(errorMessages: string[]) => diff --git a/frontend/app-development/features/dataModelling/SchemaEditorWithToolbar/TopToolbar/TopToolbar.tsx b/frontend/app-development/features/dataModelling/SchemaEditorWithToolbar/TopToolbar/TopToolbar.tsx index 02e66cb9b9f..9139f7af038 100644 --- a/frontend/app-development/features/dataModelling/SchemaEditorWithToolbar/TopToolbar/TopToolbar.tsx +++ b/frontend/app-development/features/dataModelling/SchemaEditorWithToolbar/TopToolbar/TopToolbar.tsx @@ -32,9 +32,7 @@ export function TopToolbar({ setSelectedOption, onSetSchemaGenerationErrorMessages, }: TopToolbarProps) { - const modelPath = dataModels.find( - (model) => model.fileName === selectedOption?.value.fileName, - )?.repositoryRelativeUrl; + const modelPath = selectedOption?.value.repositoryRelativeUrl; const { t } = useTranslation(); const { mutate: createDataModel } = useCreateDataModelMutation();