Skip to content
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

Highlight updated equipment row #2602

Merged
merged 7 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading