-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
}); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling |
||
} | ||
} | ||
} | ||
}, [caseFile, modifiedByUser, apiCallErrorMessage, caseFileErrorMessage, setValue, clearErrors, name]); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -788,3 +788,11 @@ export function searchElementsInfos(searchTerm: string, currentDirectoryUuid: UU | |
} | ||
); | ||
} | ||
|
||
export const getBaseName = (caseName: string) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add |
||
const caseNameUrl = `${PREFIX_CASE_QUERIES}/v1/cases/caseBaseName?caseName=${caseName}`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. encodeURIComponent(caseName) |
||
console.debug(caseNameUrl); | ||
return backendFetchText(caseNameUrl, { | ||
method: 'GET', | ||
}); | ||
}; |
There was a problem hiding this comment.
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) {