-
Notifications
You must be signed in to change notification settings - Fork 1
Correction for case base name #592
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
base: main
Are you sure you want to change the base?
Changes from all commits
dbe71f5
7c18d6d
6b0c1fd
285989f
6152bd3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,11 +9,12 @@ import { ChangeEvent, useMemo, useState } from 'react'; | |
import { FormattedMessage, useIntl } from 'react-intl'; | ||
import { Button, CircularProgress, Grid, Input } from '@mui/material'; | ||
import { useController, useFormContext } from 'react-hook-form'; | ||
import { FieldConstants } from '@gridsuite/commons-ui'; | ||
import { FieldConstants, useSnackMessage } from '@gridsuite/commons-ui'; | ||
import { UUID } from 'crypto'; | ||
import { createCaseWithoutDirectoryElementCreation, deleteCase } from '../../../utils/rest-api'; | ||
import { createCaseWithoutDirectoryElementCreation, deleteCase, getBaseName } from '../../../utils/rest-api'; | ||
|
||
export interface UploadNewCaseProps { | ||
modifiedByUser?: boolean; | ||
isNewStudyCreation?: boolean; | ||
getCurrentCaseImportParams?: (uuid: UUID) => void; | ||
handleApiCallError?: ErrorCallback; | ||
|
@@ -23,12 +24,13 @@ const MAX_FILE_SIZE_IN_MO = 100; | |
const MAX_FILE_SIZE_IN_BYTES = MAX_FILE_SIZE_IN_MO * 1024 * 1024; | ||
|
||
export default function UploadNewCase({ | ||
modifiedByUser = false, | ||
isNewStudyCreation = false, | ||
getCurrentCaseImportParams, | ||
handleApiCallError, | ||
}: Readonly<UploadNewCaseProps>) { | ||
const intl = useIntl(); | ||
|
||
const { snackError } = useSnackMessage(); | ||
const [caseFileLoading, setCaseFileLoading] = useState(false); | ||
|
||
const { | ||
|
@@ -58,6 +60,24 @@ export default function UploadNewCase({ | |
return <FormattedMessage id="uploadMessage" />; | ||
}, [caseFileLoading, caseFileName]); | ||
|
||
const fetchBaseName = (currentFile: any) => { | ||
const { name: currentCaseFileName } = currentFile; | ||
const name = isNewStudyCreation ? FieldConstants.STUDY_NAME : FieldConstants.CASE_NAME; | ||
if (currentCaseFileName && !modifiedByUser) { | ||
getBaseName(currentCaseFileName) | ||
.then((response) => { | ||
setValue(name, response, { | ||
shouldValidate: 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. you should not use shouldValidate : true, it will removes check on duplicate name |
||
}); | ||
}) | ||
.catch((error) => { | ||
snackError({ | ||
messageTxt: error.message, | ||
}); | ||
}); | ||
} | ||
}; | ||
|
||
const onChange = (event: ChangeEvent<HTMLInputElement>) => { | ||
event.preventDefault(); | ||
|
||
|
@@ -71,9 +91,7 @@ export default function UploadNewCase({ | |
|
||
if (currentFile.size <= MAX_FILE_SIZE_IN_BYTES) { | ||
onValueChange(currentFile); | ||
|
||
const { name: currentCaseFileName } = currentFile; | ||
|
||
fetchBaseName(currentFile); | ||
if (isNewStudyCreation) { | ||
// Create new case | ||
setCaseFileLoading(true); | ||
|
@@ -95,19 +113,6 @@ export default function UploadNewCase({ | |
.finally(() => { | ||
setCaseFileLoading(false); | ||
}); | ||
} else { | ||
const caseName = getValues(FieldConstants.CASE_NAME); | ||
if (currentCaseFileName && caseName !== currentCaseFileName) { | ||
clearErrors(FieldConstants.CASE_NAME); | ||
setValue( | ||
FieldConstants.CASE_NAME, | ||
currentCaseFileName.substring(0, currentCaseFileName.indexOf('.')), | ||
{ | ||
shouldDirty: true, | ||
shouldValidate: true, | ||
} | ||
); | ||
} | ||
} | ||
} else { | ||
setError(FieldConstants.CASE_FILE, { | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -18,18 +18,19 @@ import { | |||||
FieldErrorAlert, | ||||||
isObjectEmpty, | ||||||
keyGenerator, | ||||||
UniqueNameInput, | ||||||
useConfidentialityWarning, | ||||||
useSnackMessage, | ||||||
} from '@gridsuite/commons-ui'; | ||||||
import { createCase } from '../../../utils/rest-api'; | ||||||
import { useState } from 'react'; | ||||||
import { createCase, elementExists } from '../../../utils/rest-api'; | ||||||
import { HTTP_UNPROCESSABLE_ENTITY_STATUS } from '../../../utils/UIconstants'; | ||||||
import { addUploadingElement, removeUploadingElement } from '../../../redux/actions'; | ||||||
import UploadNewCase from '../commons/upload-new-case'; | ||||||
import { | ||||||
createCaseDialogFormValidationSchema, | ||||||
getCreateCaseDialogFormValidationDefaultValues, | ||||||
} from './create-case-dialog-utils'; | ||||||
import PrefilledNameInput from '../commons/prefilled-name-input'; | ||||||
import { handleMaxElementsExceededError } from '../../utils/rest-errors'; | ||||||
import { AppDispatch } from '../../../redux/store'; | ||||||
import { AppState, UploadingElement } from '../../../redux/types'; | ||||||
|
@@ -57,12 +58,14 @@ export default function CreateCaseDialog({ onClose, open }: Readonly<CreateCaseD | |||||
|
||||||
const { | ||||||
formState: { errors, isValid }, | ||||||
getValues, | ||||||
} = createCaseFormMethods; | ||||||
|
||||||
const isFormValid = isObjectEmpty(errors) && isValid; | ||||||
|
||||||
const activeDirectory = useSelector((state: AppState) => state.activeDirectory); | ||||||
const userId = useSelector((state: AppState) => state.user?.profile.sub); | ||||||
const [modifiedByUser, setModifiedByUser] = useState(false); | ||||||
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.
Suggested change
|
||||||
|
||||||
const handleCreateNewCase = ({ caseName, description, caseFile }: IFormData): void => { | ||||||
const uploadingCase: UploadingElement = { | ||||||
|
@@ -100,6 +103,7 @@ export default function CreateCaseDialog({ onClose, open }: Readonly<CreateCaseD | |||||
// the uploadingCase ghost element will be removed when directory content updated by fetch | ||||||
dispatch(addUploadingElement(uploadingCase)); | ||||||
}; | ||||||
const caseFileStudy = getValues(FieldConstants.CASE_FILE); | ||||||
|
||||||
return ( | ||||||
<CustomMuiDialog | ||||||
|
@@ -115,18 +119,22 @@ export default function CreateCaseDialog({ onClose, open }: Readonly<CreateCaseD | |||||
> | ||||||
<Grid container spacing={2} marginTop="auto" direction="column"> | ||||||
<Grid item> | ||||||
<PrefilledNameInput | ||||||
<UniqueNameInput | ||||||
name={FieldConstants.CASE_NAME} | ||||||
label="nameProperty" | ||||||
elementType={ElementType.CASE} | ||||||
elementExists={elementExists} | ||||||
activeDirectory={activeDirectory} | ||||||
autoFocus={!caseFileStudy} | ||||||
onManualChangeCallback={() => setModifiedByUser(true)} | ||||||
/> | ||||||
</Grid> | ||||||
<Grid item> | ||||||
<DescriptionField /> | ||||||
</Grid> | ||||||
</Grid> | ||||||
<ErrorInput name={FieldConstants.CASE_FILE} InputField={FieldErrorAlert} /> | ||||||
<UploadNewCase /> | ||||||
<UploadNewCase modifiedByUser={modifiedByUser} /> | ||||||
</CustomMuiDialog> | ||||||
); | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
import { useForm } from 'react-hook-form'; | ||
import { Grid } from '@mui/material'; | ||
import { useIntl } from 'react-intl'; | ||
import { useCallback, useEffect } from 'react'; | ||
import { useCallback, useEffect, useState } from 'react'; | ||
import { | ||
CustomMuiDialog, | ||
DescriptionField, | ||
|
@@ -20,14 +20,15 @@ import { | |
keyGenerator, | ||
ModifyElementSelection, | ||
Parameter, | ||
UniqueNameInput, | ||
useConfidentialityWarning, | ||
useSnackMessage, | ||
} from '@gridsuite/commons-ui'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { yupResolver } from '@hookform/resolvers/yup/dist/yup'; | ||
import { UUID } from 'crypto'; | ||
import UploadNewCase from '../commons/upload-new-case'; | ||
import { createStudy, deleteCase, getCaseImportParameters } from '../../../utils/rest-api'; | ||
import { createStudy, deleteCase, elementExists, getCaseImportParameters } from '../../../utils/rest-api'; | ||
import { HTTP_CONNECTION_FAILED_MESSAGE, HTTP_UNPROCESSABLE_ENTITY_STATUS } from '../../../utils/UIconstants'; | ||
import ImportParametersSection from './importParametersSection'; | ||
import { addUploadingElement, removeUploadingElement, setActiveDirectory } from '../../../redux/actions'; | ||
|
@@ -36,7 +37,6 @@ import { | |
CreateStudyDialogFormValues, | ||
getCreateStudyDialogFormDefaultValues, | ||
} from './create-study-dialog-utils'; | ||
import PrefilledNameInput from '../commons/prefilled-name-input'; | ||
import { handleMaxElementsExceededError } from '../../utils/rest-errors'; | ||
import { AppState, UploadingElement } from '../../../redux/types'; | ||
|
||
|
@@ -77,7 +77,7 @@ export default function CreateStudyDialog({ open, onClose, providedExistingCase | |
const activeDirectory = useSelector((state: AppState) => state.activeDirectory); | ||
const selectedDirectory = useSelector((state: AppState) => state.selectedDirectory); | ||
const userId = useSelector((state: AppState) => state.user?.profile.sub); | ||
|
||
const [modifiedByUser, setModifiedByUser] = useState(false); | ||
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. it is not a good thing to put the state of the child here, you render the whole form when the state of the child changes ! |
||
const { elementUuid, elementName } = providedExistingCase || {}; | ||
|
||
const createStudyFormMethods = useForm<CreateStudyDialogFormValues>({ | ||
|
@@ -237,7 +237,7 @@ export default function CreateStudyDialog({ open, onClose, providedExistingCase | |
getCurrentCaseImportParams(providedExistingCase.elementUuid); | ||
} | ||
}, [getCurrentCaseImportParams, providedExistingCase, setValue]); | ||
|
||
const caseFileStudy = getValues(FieldConstants.CASE_FILE); | ||
return ( | ||
<CustomMuiDialog | ||
titleId="createNewStudy" | ||
|
@@ -253,10 +253,14 @@ export default function CreateStudyDialog({ open, onClose, providedExistingCase | |
> | ||
<Grid container spacing={2} marginTop="auto" direction="column"> | ||
<Grid item> | ||
<PrefilledNameInput | ||
<UniqueNameInput | ||
name={FieldConstants.STUDY_NAME} | ||
label="nameProperty" | ||
elementType={ElementType.STUDY} | ||
elementExists={elementExists} | ||
activeDirectory={activeDirectory} | ||
autoFocus={!caseFileStudy} | ||
onManualChangeCallback={() => setModifiedByUser(true)} | ||
/> | ||
</Grid> | ||
<Grid item> | ||
|
@@ -272,6 +276,7 @@ export default function CreateStudyDialog({ open, onClose, providedExistingCase | |
/> | ||
) : ( | ||
<UploadNewCase | ||
modifiedByUser={modifiedByUser} | ||
isNewStudyCreation | ||
getCurrentCaseImportParams={getCurrentCaseImportParams} | ||
handleApiCallError={handleApiCallError} | ||
|
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.