-
Notifications
You must be signed in to change notification settings - Fork 1
Add new contingency list by filter #711
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
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
b1afd69
Components chosen
basseche 4212a0a
Add new filter based contingency list - IHM Ok
basseche 1cac0c5
Merge branch 'main' into contingencyListByFilter
basseche 4e0d846
Save Contingency list ok
basseche 2ab313d
Merge branch 'main' into contingencyListByFilter
basseche 6d55a16
Edtit contingency list Ok
basseche 6c3af4f
All Ok
basseche 8e2eeb8
remove todo
basseche 9b3f7f8
Improve GUI
basseche 21775b2
exclude filter based contingency list from types created by contingen…
basseche 6de6d80
Merge branch 'main' into contingencyListByFilter
basseche 999734f
add filtering
basseche ecc5f99
remove console log
basseche 9af1cd9
Merge branch 'main' into contingencyListByFilter
basseche 5bd6b63
change to adapt to server modifications
basseche 5e53494
add not found
basseche de82257
desactivate sort and filter
basseche b5af04f
fix
basseche c54de55
Merge branch 'main' into contingencyListByFilter
basseche cf5011b
modification to fit back
basseche bc151d9
Merge branch 'main' into contingencyListByFilter
basseche a346a79
review
basseche 3ae3628
change function name commun-ui
basseche 47ed523
Update src/utils/rest-api.ts
basseche 5eff019
Update src/utils/rest-api.ts
basseche a250861
review
basseche dfedcca
review
basseche b63f5f7
move type
thangqp c4339dd
up version commons-ui
basseche 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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
180 changes: 180 additions & 0 deletions
180
...components/dialogs/contingency-list/filter-based/contingency-list-filter-based-dialog.tsx
This file contains hidden or 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,180 @@ | ||
/** | ||
* Copyright (c) 2025, 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 { | ||
CustomMuiDialog, | ||
FieldConstants, | ||
MAX_CHAR_DESCRIPTION, | ||
TreeViewFinderNodeProps, | ||
useSnackMessage, | ||
yupConfig as yup, | ||
} from '@gridsuite/commons-ui'; | ||
import { useForm } from 'react-hook-form'; | ||
import { yupResolver } from '@hookform/resolvers/yup'; | ||
import { useSelector } from 'react-redux'; | ||
import { useCallback, useEffect, useState } from 'react'; | ||
import { UUID } from 'crypto'; | ||
import { ObjectSchema } from 'yup'; | ||
import ContingencyListFilterBasedForm from './contingency-list-filter-based-form'; | ||
import { AppState } from '../../../../redux/types'; | ||
import { | ||
createFilterBasedContingency, | ||
getContingencyList, | ||
saveFilterBasedContingencyList, | ||
} from '../../../../utils/rest-api'; | ||
import { handleNotAllowedError } from '../../../utils/rest-errors'; | ||
import { ContingencyListType } from '../../../../utils/elementType'; | ||
import { getFilterBasedFormDataFromFetchedElement } from '../contingency-list-utils'; | ||
import { FilterBasedContingencyList } from '../../../../utils/contingency-list.type'; | ||
|
||
const schema: ObjectSchema<ContingencyListFilterBasedFormData> = yup.object().shape({ | ||
[FieldConstants.NAME]: yup.string().required(), | ||
[FieldConstants.DESCRIPTION]: yup.string().max(MAX_CHAR_DESCRIPTION), | ||
[FieldConstants.FILTERS]: yup.array().required(), | ||
}); | ||
|
||
export interface ContingencyListFilterBasedFormData { | ||
[FieldConstants.NAME]: string; | ||
[FieldConstants.DESCRIPTION]?: string; | ||
[FieldConstants.FILTERS]: TreeViewFinderNodeProps[]; | ||
} | ||
|
||
const getContingencyListEmptyFormData = (name = '') => ({ | ||
[FieldConstants.NAME]: name, | ||
[FieldConstants.DESCRIPTION]: '', | ||
[FieldConstants.FILTERS]: [], | ||
}); | ||
|
||
const emptyFormData = (name?: string) => getContingencyListEmptyFormData(name); | ||
|
||
export interface FilterBasedContingencyListProps { | ||
titleId: string; | ||
open: boolean; | ||
onClose: () => void; | ||
name?: string; | ||
description?: string; | ||
id?: UUID; | ||
} | ||
|
||
export default function FilterBasedContingencyListDialog({ | ||
titleId, | ||
open, | ||
onClose, | ||
name, | ||
description, | ||
id, | ||
}: Readonly<FilterBasedContingencyListProps>) { | ||
const activeDirectory = useSelector((state: AppState) => state.activeDirectory); | ||
const { snackError } = useSnackMessage(); | ||
const [isFetching, setIsFetching] = useState(!!id); | ||
|
||
const methods = useForm<ContingencyListFilterBasedFormData>({ | ||
defaultValues: emptyFormData(), | ||
resolver: yupResolver(schema), | ||
}); | ||
const { | ||
reset, | ||
formState: { errors }, | ||
} = methods; | ||
|
||
useEffect(() => { | ||
if (id) { | ||
setIsFetching(true); | ||
getContingencyList(ContingencyListType.FILTERS.id, id?.toString()) | ||
.then((response) => { | ||
const formData: ContingencyListFilterBasedFormData = getFilterBasedFormDataFromFetchedElement( | ||
response, | ||
name ?? '', | ||
description ?? '' | ||
); | ||
reset({ ...formData }); | ||
}) | ||
.catch((error) => { | ||
snackError({ | ||
messageTxt: error.message, | ||
headerId: 'cannotRetrieveContingencyList', | ||
}); | ||
}) | ||
.finally(() => setIsFetching(false)); | ||
} | ||
}, [id, name, reset, snackError, description]); | ||
|
||
const closeAndClear = useCallback(() => { | ||
reset(emptyFormData()); | ||
onClose(); | ||
}, [onClose, reset]); | ||
|
||
const onSubmit = useCallback( | ||
(data: ContingencyListFilterBasedFormData) => { | ||
const filterBaseContingencyList: FilterBasedContingencyList = { | ||
filters: data[FieldConstants.FILTERS]?.map((item: TreeViewFinderNodeProps) => { | ||
return { | ||
id: item.id, | ||
}; | ||
}), | ||
}; | ||
|
||
if (id) { | ||
saveFilterBasedContingencyList( | ||
id, | ||
data[FieldConstants.NAME], | ||
data[FieldConstants.DESCRIPTION] ?? '', | ||
filterBaseContingencyList | ||
) | ||
.then(() => closeAndClear()) | ||
.catch((error) => { | ||
if (handleNotAllowedError(error, snackError)) { | ||
return; | ||
} | ||
snackError({ | ||
messageTxt: error.message, | ||
headerId: 'contingencyListEditingError', | ||
headerValues: { name: data[FieldConstants.NAME] }, | ||
}); | ||
}); | ||
} else { | ||
createFilterBasedContingency( | ||
data[FieldConstants.NAME], | ||
data[FieldConstants.DESCRIPTION] ?? '', | ||
filterBaseContingencyList, | ||
activeDirectory | ||
) | ||
.then(() => closeAndClear()) | ||
.catch((error) => { | ||
if (handleNotAllowedError(error, snackError)) { | ||
return; | ||
} | ||
snackError({ | ||
messageTxt: error.message, | ||
headerId: 'contingencyListCreationError', | ||
headerValues: { name: data[FieldConstants.NAME] }, | ||
}); | ||
}); | ||
} | ||
}, | ||
[activeDirectory, closeAndClear, id, snackError] | ||
); | ||
|
||
const nameError = errors[FieldConstants.NAME]; | ||
const isValidating = errors.root?.isValidating; | ||
|
||
return ( | ||
<CustomMuiDialog | ||
titleId={titleId} | ||
open={open} | ||
onClose={closeAndClear} | ||
onSave={onSubmit} | ||
formSchema={schema} | ||
formMethods={methods} | ||
unscrollableFullHeight | ||
disabledSave={Boolean(!!nameError || isValidating)} | ||
isDataFetching={isFetching} | ||
> | ||
<ContingencyListFilterBasedForm /> | ||
</CustomMuiDialog> | ||
); | ||
} |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.