From 42101909093878ec03a9bebf19ba85d72be8d76e Mon Sep 17 00:00:00 2001 From: basseche Date: Fri, 13 Dec 2024 13:53:25 +0100 Subject: [PATCH] change the way we get case base name --- .../dialogs/commons/prefilled-name-input.tsx | 12 ++++++++---- src/utils/rest-api.ts | 8 ++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/components/dialogs/commons/prefilled-name-input.tsx b/src/components/dialogs/commons/prefilled-name-input.tsx index b3db4a33..3e0b2477 100644 --- a/src/components/dialogs/commons/prefilled-name-input.tsx +++ b/src/components/dialogs/commons/prefilled-name-input.tsx @@ -9,7 +9,7 @@ import { useEffect, useState } from 'react'; import { useFormContext } from 'react-hook-form'; import { ElementType, FieldConstants, UniqueNameInput } from '@gridsuite/commons-ui'; import { useSelector } from 'react-redux'; -import { elementExists } from '../../../utils/rest-api'; +import { elementExists, getBaseName } from '../../../utils/rest-api'; import { AppState } from '../../../redux/types'; export interface PrefilledNameInputProps { @@ -45,9 +45,13 @@ export default function PrefilledNameInput({ label, name, elementType }: Readonl if (caseName) { clearErrors(name); - setValue(name, caseName?.substring(0, caseName.indexOf('.')), { - shouldDirty: true, - }); + if (caseName.length > 0) { + getBaseName(caseName).then((response) => { + setValue(name, response, { + shouldDirty: true, + }); + }); + } } } }, [caseFile, modifiedByUser, apiCallErrorMessage, caseFileErrorMessage, setValue, clearErrors, name]); diff --git a/src/utils/rest-api.ts b/src/utils/rest-api.ts index ec4237cb..95321884 100644 --- a/src/utils/rest-api.ts +++ b/src/utils/rest-api.ts @@ -788,3 +788,11 @@ export function searchElementsInfos(searchTerm: string, currentDirectoryUuid: UU } ); } + +export const getBaseName = (caseName: string) => { + const caseNameUrl = `${PREFIX_CASE_QUERIES}/v1/cases/caseBaseName?caseName=${caseName}`; + console.debug(caseNameUrl); + return backendFetchText(caseNameUrl, { + method: 'GET', + }); +};