move editable attribute to table Component

This commit is contained in:
anovazzi1 2024-06-02 18:07:45 -03:00
commit 1a65af7602
3 changed files with 20 additions and 8 deletions

View file

@ -17,6 +17,7 @@ interface TableComponentProps extends AgGridReactProps {
rowData: NonNullable<AgGridReactProps["rowData"]>; rowData: NonNullable<AgGridReactProps["rowData"]>;
alertTitle?: string; alertTitle?: string;
alertDescription?: string; alertDescription?: string;
editable?: boolean | string[];
} }
const TableComponent = forwardRef< const TableComponent = forwardRef<
@ -48,20 +49,30 @@ const TableComponent = forwardRef<
} }
const colDef = props.columnDefs.map((col, index) => { const colDef = props.columnDefs.map((col, index) => {
if (props.onSelectionChanged && index === 0) { let newCol = {
return {
...col, ...col,
headerName: toTitleCase(col.headerName), headerName: toTitleCase(col.headerName),
};
if (props.onSelectionChanged && index === 0) {
newCol = {
...newCol,
checkboxSelection: true, checkboxSelection: true,
headerCheckboxSelection: true, headerCheckboxSelection: true,
headerCheckboxSelectionFilteredOnly: true, headerCheckboxSelectionFilteredOnly: true,
}; };
} else { }
return { console.log(props.editable, col.headerName);
...col, if (
headerName: toTitleCase(col.headerName), (typeof props.editable === "boolean" && props.editable) ||
(Array.isArray(props.editable) &&
props.editable.includes(newCol.headerName ?? ""))
) {
newCol = {
...newCol,
editable: true,
}; };
} }
return newCol;
}); });
return ( return (

View file

@ -7,7 +7,7 @@ const useMessagesTable = (setColumns, setRows, setMessages) => {
try { try {
const data = await getMessagesTable("union", undefined, ["index"]); const data = await getMessagesTable("union", undefined, ["index"]);
const { columns, rows } = data; const { columns, rows } = data;
setColumns(columns.map((col) => ({ ...col, editable: true }))); setColumns(columns);
setRows(rows); setRows(rows);
setMessages(rows); setMessages(rows);
} catch (error) { } catch (error) {

View file

@ -40,6 +40,7 @@ export default function MessagesPage() {
<Card x-chunk="dashboard-04-chunk-2" className="h-full pt-4"> <Card x-chunk="dashboard-04-chunk-2" className="h-full pt-4">
<CardContent className="h-full"> <CardContent className="h-full">
<TableComponent <TableComponent
editable={["Sender", "Sender Name", "Message"]}
overlayNoRowsTemplate="No data available" overlayNoRowsTemplate="No data available"
onSelectionChanged={(event: SelectionChangedEvent) => { onSelectionChanged={(event: SelectionChangedEvent) => {
setSelectedRows( setSelectedRows(