Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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
26 changes: 0 additions & 26 deletions src/pages/common/multi-chips-renderer-component.tsx

This file was deleted.

52 changes: 0 additions & 52 deletions src/pages/common/multi-select-editor-component.tsx

This file was deleted.

24 changes: 24 additions & 0 deletions src/pages/common/table-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* 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 { ColDef, RowSelectionOptions } from 'ag-grid-community';

export const defaultColDef: ColDef = {
editable: false,
resizable: true,
minWidth: 50,
rowDrag: false,
sortable: true,
};

export const defaultRowSelection: RowSelectionOptions = {
mode: 'multiRow',
enableClickSelection: false,
checkboxes: true,
headerCheckbox: true,
hideDisabledCheckboxes: false,
};
94 changes: 94 additions & 0 deletions src/pages/common/table-selection.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/**
* 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 { FunctionComponent, useCallback, useMemo, useRef, useState } from 'react';
import { FormattedMessage } from 'react-intl';
import { CustomAGGrid } from '@gridsuite/commons-ui';
import { Grid, Typography } from '@mui/material';
import { AgGridReact } from 'ag-grid-react';
import { ColDef, GetRowIdParams, GridReadyEvent } from 'ag-grid-community';
import { defaultColDef, defaultRowSelection } from './table-config';

export interface TableSelectionProps {
itemName: string;
tableItems: string[];
tableSelectedItems?: string[];
onSelectionChanged: (selectedItems: string[]) => void;
}

const TableSelection: FunctionComponent<TableSelectionProps> = (props) => {
const [selectedRowsLength, setSelectedRowsLength] = useState(0);
const gridRef = useRef<AgGridReact>(null);

const handleEquipmentSelectionChanged = useCallback(() => {
const selectedRows = gridRef.current?.api.getSelectedRows();
if (selectedRows == null) {
setSelectedRowsLength(0);
props.onSelectionChanged([]);
} else {
setSelectedRowsLength(selectedRows.length);
props.onSelectionChanged(selectedRows.map((r) => r.id));
}
}, [props]);

const rowData = useMemo(() => {
return props.tableItems.map((str) => ({ id: str }));
}, [props.tableItems]);

const columnDefs = useMemo(
(): ColDef[] => [
{
field: 'id',
filter: true,
sortable: true,
tooltipField: 'id',
flex: 1,
},
],
[]
);

function getRowId(params: GetRowIdParams): string {
return params.data.id;
}

const onGridReady = useCallback(
({ api }: GridReadyEvent) => {
api?.forEachNode((n) => {
if (props.tableSelectedItems !== undefined && n.id && props.tableSelectedItems.includes(n.id)) {
n.setSelected(true);
}
});
},
[props.tableSelectedItems]
);

return (
<Grid item container direction={'column'} style={{ height: '100%' }}>
<Grid item>
<Typography variant="subtitle1">
<FormattedMessage id={props.itemName}></FormattedMessage>
{` (${selectedRowsLength} / ${rowData?.length ?? 0})`}
</Typography>
</Grid>
<Grid item xs>
<CustomAGGrid
gridId="table-selection"
ref={gridRef}
rowData={rowData}
columnDefs={columnDefs}
defaultColDef={defaultColDef}
rowSelection={defaultRowSelection}
getRowId={getRowId}
onSelectionChanged={handleEquipmentSelectionChanged}
onGridReady={onGridReady}
/>
</Grid>
</Grid>
);
};
export default TableSelection;
191 changes: 0 additions & 191 deletions src/pages/groups/GroupsPage.tsx

This file was deleted.

Loading
Loading