-
Notifications
You must be signed in to change notification settings - Fork 4
add field description to modification #3546
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
Changes from 12 commits
a3e97aa
3511693
1d9168f
143d9f3
416b9e0
22cecf2
87cef39
17c5c2a
fa3fd9f
ff7700a
0415424
bed8e2a
1dcc6d6
d8cfbbb
cf392a1
b55ac84
adbd106
98a4363
5b5875f
87a888a
fc27ab6
4e52563
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 |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| /** | ||
| * 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 { ICellRendererParams } from 'ag-grid-community'; | ||
| import { DescriptionModificationDialog, EditNoteIcon, NetworkModificationMetadata } from '@gridsuite/commons-ui'; | ||
| import React, { SetStateAction, useCallback, useState } from 'react'; | ||
| import { Tooltip } from '@mui/material'; | ||
| import { useIsAnyNodeBuilding } from '../../../utils/is-any-node-building-hook'; | ||
| import { useSelector } from 'react-redux'; | ||
| import { AppState } from '../../../../redux/reducer'; | ||
| import IconButton from '@mui/material/IconButton'; | ||
| import type { UUID } from 'node:crypto'; | ||
| import { setModificationDescription } from '../../../../services/study/network-modifications'; | ||
|
|
||
| export interface DescriptionRendererProps extends ICellRendererParams<NetworkModificationMetadata> { | ||
| setModifications: React.Dispatch<SetStateAction<NetworkModificationMetadata[]>>; | ||
| hoveredRowIndex: number; | ||
| } | ||
|
|
||
| const DescriptionRenderer = (props: DescriptionRendererProps) => { | ||
| const { data, api, node } = props; | ||
| const studyUuid = useSelector((state: AppState) => state.studyUuid); | ||
| const currentNode = useSelector((state: AppState) => state.currentTreeNode); | ||
| const [isLoading, setIsLoading] = useState(false); | ||
| const isAnyNodeBuilding = useIsAnyNodeBuilding(); | ||
| const mapDataLoading = useSelector((state: AppState) => state.mapDataLoading); | ||
| const [openDescModificationDialog, setOpenDescModificationDialog] = useState(false); | ||
|
|
||
| const modificationUuid = data?.uuid; | ||
| const description: string | undefined = data?.description; | ||
EtienneLt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const empty: boolean = !description; | ||
EtienneLt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const updateModification = useCallback( | ||
| async (uuid: UUID, descriptionRecord: Record<string, string>) => { | ||
| setIsLoading(true); | ||
|
|
||
| return setModificationDescription(studyUuid, currentNode?.id, uuid, descriptionRecord.description).finally( | ||
| () => { | ||
| setIsLoading(false); | ||
| } | ||
| ); | ||
| }, | ||
| [studyUuid, currentNode?.id] | ||
| ); | ||
|
|
||
| const handleDescDialogClose = useCallback(() => { | ||
| setOpenDescModificationDialog(false); | ||
| api.stopEditing(); | ||
| }, [api]); | ||
|
|
||
| const handleModifyDescription = () => { | ||
| if (isLoading) { | ||
flomillot marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return; | ||
| } | ||
| setOpenDescModificationDialog(true); | ||
| }; | ||
|
|
||
| return ( | ||
| <> | ||
| {openDescModificationDialog && modificationUuid && ( | ||
| <DescriptionModificationDialog | ||
| open | ||
| description={description ?? ''} | ||
| elementUuid={modificationUuid} | ||
| onClose={handleDescDialogClose} | ||
| updateElement={updateModification} | ||
| /> | ||
| )} | ||
| <Tooltip title={description} arrow> | ||
| <IconButton | ||
| color="primary" | ||
| onClick={handleModifyDescription} | ||
| disabled={isLoading || isAnyNodeBuilding || mapDataLoading} | ||
| > | ||
| <EditNoteIcon empty={empty} hidden={node.rowIndex !== props.hoveredRowIndex} /> | ||
flomillot marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </IconButton> | ||
| </Tooltip> | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| export default DescriptionRenderer; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ | |
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| */ | ||
|
|
||
| import React, { SetStateAction, useCallback, useEffect, useMemo, useRef } from 'react'; | ||
| import React, { SetStateAction, useCallback, useEffect, useMemo, useRef, useState } from 'react'; | ||
| import { | ||
| CustomAGGrid, | ||
| type MuiStyles, | ||
|
|
@@ -15,6 +15,7 @@ import { | |
| } from '@gridsuite/commons-ui'; | ||
| import type { | ||
| CellClickedEvent, | ||
| CellMouseOverEvent, | ||
| ColDef, | ||
| GetRowIdParams, | ||
| IRowDragItem, | ||
|
|
@@ -39,6 +40,7 @@ import SwitchCellRenderer from './switch-cell-renderer'; | |
| import { AGGRID_LOCALES } from '../../../../translations/not-intl/aggrid-locales'; | ||
| import { ExcludedNetworkModifications } from './network-modification-menu.type'; | ||
| import { AgGridReact } from 'ag-grid-react'; | ||
| import DescriptionRenderer from './DescriptionRenderer'; | ||
|
|
||
| const styles = { | ||
| container: (theme) => ({ | ||
|
|
@@ -89,6 +91,7 @@ const NetworkModificationsTable: React.FC<NetworkModificationsTableProps> = ({ | |
| const rootNetworks = useSelector((state: AppState) => state.rootNetworks); | ||
| const isMonoRootStudy = useSelector((state: AppState) => state.isMonoRootStudy); | ||
| const highlightedModificationUuid = useSelector((state: AppState) => state.highlightedModificationUuid); | ||
| const [hoveredRowIndex, setHoveredRowIndex] = useState<number>(); | ||
|
||
|
|
||
| const intl = useIntl(); | ||
| const { computeLabel } = useModificationLabelComputer(); | ||
|
|
@@ -143,6 +146,15 @@ const NetworkModificationsTable: React.FC<NetworkModificationsTableProps> = ({ | |
| flex: 1, | ||
| cellStyle: { cursor: 'pointer' }, | ||
| }, | ||
| { | ||
| colId: 'modificationDescription', | ||
| cellRenderer: DescriptionRenderer, | ||
| cellRendererParams: { | ||
| setModifications: setModifications, | ||
| hoveredRowIndex: hoveredRowIndex, | ||
| }, | ||
| width: 30, | ||
| }, | ||
| { | ||
| cellRenderer: SwitchCellRenderer, | ||
| cellRendererParams: { | ||
|
|
@@ -199,6 +211,7 @@ const NetworkModificationsTable: React.FC<NetworkModificationsTableProps> = ({ | |
| currentRootNetworkUuid, | ||
| modificationsToExclude, | ||
| setModificationsToExclude, | ||
| hoveredRowIndex, | ||
| ]); | ||
|
|
||
| const getRowId = (params: GetRowIdParams<NetworkModificationMetadata>) => params.data.uuid; | ||
|
|
@@ -245,6 +258,10 @@ const NetworkModificationsTable: React.FC<NetworkModificationsTableProps> = ({ | |
| checkboxes: true, | ||
| headerCheckbox: true, | ||
| }} | ||
| onCellMouseOver={(event: CellMouseOverEvent<NetworkModificationMetadata>) => | ||
| setHoveredRowIndex(event.rowIndex ?? -1) | ||
| } | ||
| onCellMouseOut={() => setHoveredRowIndex(-1)} | ||
flomillot marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| defaultColDef={defaultColumnDefinition} | ||
| onCellClicked={handleCellClick} | ||
| onRowSelected={onRowSelected} | ||
|
|
||
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.
Don't import the whole react dependency, but just dispatch like it's done for set state action.
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.
Actually you made me realise that I don't need that prop anymore. Removed : 1dcc6d6
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.
Okay, but you still import React
Uh oh!
There was an error while loading. Please reload this page.
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.
sorry : removed here : adbd106