Skip to content

Commit

Permalink
Highlight updated equipment row (#2602)
Browse files Browse the repository at this point in the history
Signed-off-by: achour94 <berrahmaachour@gmail.com>
  • Loading branch information
achour94 authored Feb 25, 2025
1 parent 0cae539 commit 7618220
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export function useCustomColumn(tabIndex: number) {
valueGetter: createValueGetter(colDef),
editable: false,
suppressMovable: true,
enableCellChangeFlash: true,
};
}),
[tableDefinition.columns, tableDefinition.name, tabIndex, createValueGetter]
Expand Down
23 changes: 22 additions & 1 deletion src/components/spreadsheet/table-wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export const TableWrapper: FunctionComponent<TableWrapperProps> = ({
const [manualTabSwitch, setManualTabSwitch] = useState<boolean>(true);

const [rowData, setRowData] = useState<Identifiable[]>([]);
const [equipmentToUpdateId, setEquipmentToUpdateId] = useState<string | null>(null);

const isLockedColumnNamesEmpty = useMemo(() => formattedLockedColumns.size === 0, [formattedLockedColumns.size]);

Expand Down Expand Up @@ -190,9 +191,28 @@ export const TableWrapper: FunctionComponent<TableWrapperProps> = ({
[tableDefinition.type]
);

const highlightUpdatedEquipment = useCallback(() => {
if (!equipmentToUpdateId) {
return;
}

const api = gridRef.current?.api;
const rowNode = api?.getRowNode(equipmentToUpdateId);

if (rowNode && api) {
api.flashCells({
rowNodes: [rowNode],
flashDuration: 1000,
});
}

setEquipmentToUpdateId(null);
}, [equipmentToUpdateId]);

const { equipments, errorMessage, isFetching } = useSpreadsheetEquipments(
tableDefinition.type,
formatFetchedEquipmentsHandler
formatFetchedEquipmentsHandler,
highlightUpdatedEquipment
);

useEffect(() => {
Expand Down Expand Up @@ -314,6 +334,7 @@ export const TableWrapper: FunctionComponent<TableWrapperProps> = ({
const onRowClicked = useCallback(
(event: RowClickedEvent) => {
const equipmentId = event.data.id;
setEquipmentToUpdateId(equipmentId);
handleOpenModificationDialog(equipmentId);
},
[handleOpenModificationDialog]
Expand Down
5 changes: 4 additions & 1 deletion src/components/spreadsheet/use-spreadsheet-equipments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ type FormatFetchedEquipments = (equipments: Identifiable[]) => Identifiable[];

export const useSpreadsheetEquipments = (
type: SpreadsheetEquipmentType,
formatFetchedEquipments: FormatFetchedEquipments
formatFetchedEquipments: FormatFetchedEquipments,
highlightUpdatedEquipment: () => void
) => {
const dispatch = useDispatch();
const allEquipments = useSelector((state: AppState) => state.spreadsheetNetwork);
Expand Down Expand Up @@ -122,6 +123,7 @@ export const useSpreadsheetEquipments = (
if (impactedSubstationsIds.length > 0 && studyUuid && currentRootNetworkUuid && currentNode?.id) {
// The formatting of the fetched equipments is done in the reducer
fetchAllEquipments(studyUuid, nodeId, currentRootNetworkUuid, impactedSubstationsIds).then((values) => {
highlightUpdatedEquipment();
dispatch(updateEquipments(values, nodeId));
});
resetImpactedSubstationsIds();
Expand Down Expand Up @@ -163,6 +165,7 @@ export const useSpreadsheetEquipments = (
resetImpactedSubstationsIds,
resetDeletedEquipments,
resetImpactedElementTypes,
highlightUpdatedEquipment,
]);

useEffect(() => {
Expand Down

0 comments on commit 7618220

Please sign in to comment.