Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change the way we get case base name #579

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/components/dialogs/commons/prefilled-name-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have to check the caseName trimming maybe
if (caseName.trim().length > 0) {

getBaseName(caseName).then((response) => {
setValue(name, response, {
shouldDirty: true,
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add error handling
.catch((error) => { console.error('Error fetching base name:', error); });

}
}
}
}, [caseFile, modifiedByUser, apiCallErrorMessage, caseFileErrorMessage, setValue, clearErrors, name]);
Expand Down
8 changes: 8 additions & 0 deletions src/utils/rest-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -788,3 +788,11 @@ export function searchElementsInfos(searchTerm: string, currentDirectoryUuid: UU
}
);
}

export const getBaseName = (caseName: string) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add console.info('Get base name for case', caseName);
or something else

const caseNameUrl = `${PREFIX_CASE_QUERIES}/v1/cases/caseBaseName?caseName=${caseName}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

encodeURIComponent(caseName)

console.debug(caseNameUrl);
return backendFetchText(caseNameUrl, {
method: 'GET',
});
};
Loading