Skip to content

Commit

Permalink
Remove doubling up of code
Browse files Browse the repository at this point in the history
  • Loading branch information
Konrad-Simso committed Oct 7, 2024
1 parent 898fc5b commit 5aebb81
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ export const SchemaEditorWithToolbar = ({
const [selectedOption, setSelectedOption] = useState<MetadataOption | undefined>(undefined);
const [schemaGenerationErrorMessages, setSchemaGenerationErrorMessages] = useState<string[]>([]);
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) => {
Expand All @@ -40,7 +44,7 @@ export const SchemaEditorWithToolbar = ({
createNewOpen={createNewOpen}
createPathOption={createPathOption}
dataModels={dataModels}
selectedOption={selectedOption}
selectedOption={existingSelectedOption}
setCreateNewOpen={setCreateNewOpen}
setSelectedOption={setSelectedOption}
onSetSchemaGenerationErrorMessages={(errorMessages: string[]) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 5aebb81

Please sign in to comment.