-
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
Visualize composite modifications #538
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
208daf7
visualize
Mathieu-Deharbe 79600b0
better css list and scroll system
Mathieu-Deharbe 0f08acd
better display of the network modification label
Mathieu-Deharbe 75e8df4
respect spaces and strong anchors
Mathieu-Deharbe 86831c6
correct localisation imports
Mathieu-Deharbe 5cca28c
Merge branch 'main' into visualize-composite-modifications
Mathieu-Deharbe 8be793a
post conflict solving in commons-ui
Mathieu-Deharbe 0982dfa
Merge branch 'main' into visualize-composite-modifications
Mathieu-Deharbe 19b39f1
post auto review
Mathieu-Deharbe a3b92e0
allows to change composite modification name
Mathieu-Deharbe 00b9ff9
change url
Mathieu-Deharbe 62703c9
prettier
Mathieu-Deharbe 9a373bc
Merge branch 'main' into visualize-composite-modifications
Mathieu-Deharbe e212512
adapt to the new eslint standard
Mathieu-Deharbe dd6c719
corrections post Ghazwa review
Mathieu-Deharbe 14107da
some renaming
Mathieu-Deharbe f263799
Merge branch 'main' into visualize-composite-modifications
Mathieu-Deharbe ab6cad7
handle null case
Mathieu-Deharbe 68d5494
better test syntax
Mathieu-Deharbe ca1f475
Merge branch 'main' into visualize-composite-modifications
Mathieu-Deharbe 618d372
updated endpoint
Mathieu-Deharbe 0e06eeb
corrects getModificationLabel
Mathieu-Deharbe 2ae94b8
Merge branch 'main' into visualize-composite-modifications
Mathieu-Deharbe cd382e5
revert MODIFICATION localization
Mathieu-Deharbe 3a62a60
Merge branch 'main' into visualize-composite-modifications
Mathieu-Deharbe 068a7c1
Merge branch 'main' into visualize-composite-modifications
Mathieu-Deharbe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
164 changes: 164 additions & 0 deletions
164
...nts/dialogs/network-modification/composite-modification/composite-modification-dialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
/** | ||
* Copyright (c) 2024, RTE (http://www.rte-france.com) | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
import { SyntheticEvent, useEffect, useState } from 'react'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import Box from '@mui/material/Box'; | ||
import Divider from '@mui/material/Divider'; | ||
import { useForm } from 'react-hook-form'; | ||
import { useIntl } from 'react-intl'; | ||
import { List, ListItem } from '@mui/material'; | ||
import { | ||
CustomMuiDialog, | ||
FieldConstants, | ||
NetworkModificationMetadata, | ||
NO_SELECTION_FOR_COPY, | ||
unscrollableDialogStyles, | ||
useModificationLabelComputer, | ||
useSnackMessage, | ||
yupConfig as yup, | ||
} from '@gridsuite/commons-ui'; | ||
import { yupResolver } from '@hookform/resolvers/yup'; | ||
import { AppState } from '../../../../redux/types'; | ||
import { useParameterState } from '../../use-parameters-dialog'; | ||
import { PARAM_LANGUAGE } from '../../../../utils/config-params'; | ||
import { fetchCompositeModificationContent, saveCompositeModification } from '../../../../utils/rest-api'; | ||
import CompositeModificationForm from './composite-modification-form'; | ||
import { setSelectionForCopy } from '../../../../redux/actions'; | ||
|
||
const schema = yup.object().shape({ | ||
[FieldConstants.NAME]: yup.string().trim().required('nameEmpty'), | ||
}); | ||
|
||
const emptyFormData = (name?: string) => ({ | ||
[FieldConstants.NAME]: name, | ||
}); | ||
|
||
interface FormData { | ||
[FieldConstants.NAME]: string; | ||
} | ||
|
||
interface CompositeModificationDialogProps { | ||
compositeModificationId: string; | ||
open: boolean; | ||
onClose: (event?: SyntheticEvent) => void; | ||
titleId: string; | ||
name: string; | ||
broadcastChannel: BroadcastChannel; | ||
} | ||
|
||
export default function CompositeModificationDialog({ | ||
compositeModificationId, | ||
open, | ||
onClose, | ||
titleId, | ||
name, | ||
broadcastChannel, | ||
}: Readonly<CompositeModificationDialogProps>) { | ||
const intl = useIntl(); | ||
const [languageLocal] = useParameterState(PARAM_LANGUAGE); | ||
const [isFetching, setIsFetching] = useState(!!compositeModificationId); | ||
const { snackError } = useSnackMessage(); | ||
const selectionForCopy = useSelector((state: AppState) => state.selectionForCopy); | ||
const [modifications, setModifications] = useState<NetworkModificationMetadata[]>([]); | ||
const dispatch = useDispatch(); | ||
|
||
const methods = useForm<FormData>({ | ||
defaultValues: emptyFormData(name), | ||
resolver: yupResolver(schema), | ||
}); | ||
|
||
const { computeLabel } = useModificationLabelComputer(); | ||
const getModificationLabel = (modif: NetworkModificationMetadata) => { | ||
if (!modif) { | ||
return null; | ||
} | ||
const labelData = { | ||
...modif, | ||
...computeLabel(modif), | ||
}; | ||
return intl.formatMessage({ id: `network_modifications.${modif.type}` }, labelData); | ||
}; | ||
|
||
const generateNetworkModificationsList = () => { | ||
return ( | ||
<List sx={unscrollableDialogStyles.scrollableContent}> | ||
{modifications && | ||
modifications.map((modification: NetworkModificationMetadata) => ( | ||
<Box key={modification.uuid}> | ||
<ListItem> | ||
<Box>{getModificationLabel(modification)}</Box> | ||
</ListItem> | ||
<Divider component="li" /> | ||
</Box> | ||
))} | ||
</List> | ||
); | ||
}; | ||
|
||
useEffect(() => { | ||
setIsFetching(true); | ||
fetchCompositeModificationContent(compositeModificationId) | ||
.then((response) => { | ||
if (response) { | ||
setModifications(response); | ||
} | ||
}) | ||
.catch((error) => { | ||
snackError({ | ||
messageTxt: error.message, | ||
headerId: 'retrieveCompositeModificationError', | ||
}); | ||
}) | ||
.finally(() => setIsFetching(false)); | ||
}, [compositeModificationId, name, snackError]); | ||
|
||
const closeAndClear = (event?: SyntheticEvent) => { | ||
onClose(event); | ||
}; | ||
|
||
const onSubmit = (formData: FormData) => { | ||
saveCompositeModification(compositeModificationId, formData[FieldConstants.NAME]) | ||
.then(() => { | ||
if (selectionForCopy.sourceItemUuid === compositeModificationId) { | ||
dispatch(setSelectionForCopy(NO_SELECTION_FOR_COPY)); | ||
broadcastChannel.postMessage({ | ||
NO_SELECTION_FOR_COPY, | ||
}); | ||
} | ||
closeAndClear(); | ||
}) | ||
.catch((errorMessage) => { | ||
snackError({ | ||
messageTxt: errorMessage, | ||
headerId: 'compositeModificationEditingError', | ||
headerValues: { name }, | ||
}); | ||
}); | ||
}; | ||
|
||
return ( | ||
<CustomMuiDialog | ||
open={open} | ||
onClose={closeAndClear} | ||
titleId={titleId} | ||
onSave={onSubmit} | ||
removeOptional | ||
isDataFetching={isFetching} | ||
language={languageLocal} | ||
formSchema={schema} | ||
formMethods={methods} | ||
unscrollableFullHeight | ||
> | ||
{!isFetching && ( | ||
<Box sx={unscrollableDialogStyles.unscrollableContainer}> | ||
<CompositeModificationForm /> | ||
{generateNetworkModificationsList()} | ||
</Box> | ||
)} | ||
</CustomMuiDialog> | ||
); | ||
} |
27 changes: 27 additions & 0 deletions
27
...nents/dialogs/network-modification/composite-modification/composite-modification-form.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Copyright (c) 2024, RTE (http://www.rte-france.com) | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { UniqueNameInput, ElementType, FieldConstants } from '@gridsuite/commons-ui'; | ||
import { elementExists } from 'utils/rest-api'; | ||
import { useSelector } from 'react-redux'; | ||
import { AppState } from 'redux/types'; | ||
import Box from '@mui/material/Box'; | ||
|
||
export default function CompositeModificationForm() { | ||
const activeDirectory = useSelector((state: AppState) => state.activeDirectory); | ||
return ( | ||
<Box> | ||
<UniqueNameInput | ||
name={FieldConstants.NAME} | ||
label="nameProperty" | ||
elementType={ElementType.MODIFICATION} | ||
activeDirectory={activeDirectory} | ||
elementExists={elementExists} | ||
/> | ||
</Box> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
why those changes ?
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.
Because it is how french must be written, it took me 5s, and it can't cause any bug.
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.
Ok to keep it. But for lisibility of PR, tracability of the code, it's always harmful to change things that have nothing to do with the PR's subject