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

Fix/hiding columns in table #685

Merged
merged 2 commits into from
Nov 13, 2023
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
2 changes: 1 addition & 1 deletion cypress/e2e/start_page.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('NeoDash E2E Tests', () => {
cy.get('main .react-grid-item:eq(2) .MuiDataGrid-columnHeaders', { timeout: WAITING_TIME })
.should('contain', 'title')
.and('contain', 'released')
.and('not.contain', '__id');
.and('contain', '__id');
cy.get('main .react-grid-item:eq(2) .MuiDataGrid-virtualScroller .MuiDataGrid-row').should('have.length', 5);
cy.get('main .react-grid-item:eq(2) .MuiDataGrid-footerContainer').should('contain', '1–5 of 8');
cy.get('main .react-grid-item:eq(2) .MuiDataGrid-footerContainer button[aria-label="Go to next page"]').click();
Expand Down
11 changes: 4 additions & 7 deletions src/chart/table/TableChart.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { DataGrid } from '@mui/x-data-grid';
import { DataGrid, GridColumnVisibilityModel } from '@mui/x-data-grid';
import { ChartProps } from '../Chart';
import {
evaluateRulesOnDict,
Expand Down Expand Up @@ -27,7 +27,6 @@
const TABLE_HEADER_HEIGHT = 32;
const TABLE_FOOTER_HEIGHT = 62;
const TABLE_ROW_HEIGHT = 52;
const HIDDEN_COLUMN_PREFIX = '__';

const theme = createTheme({
typography: {
Expand Down Expand Up @@ -84,6 +83,7 @@
);

const [notificationOpen, setNotificationOpen] = React.useState(false);
const [columnVisibilityModel, setColumnVisibilityModel] = React.useState<GridColumnVisibilityModel>({});

const useStyles = generateClassDefinitionsBasedOnRules(styleRules);
const classes = useStyles();
Expand Down Expand Up @@ -161,10 +161,6 @@
actionableFields.includes(key)
);
});
const hiddenColumns = Object.assign(
{},
...columns.filter((x) => x.field.startsWith(HIDDEN_COLUMN_PREFIX)).map((x) => ({ [x.field]: false }))
);

const getTransposedRows = (records) => {
// Skip first key
Expand Down Expand Up @@ -256,7 +252,8 @@
rowHeight={tableRowHeight}
rows={rows}
columns={columns}
columnVisibilityModel={hiddenColumns}
columnVisibilityModel={columnVisibilityModel}
onColumnVisibilityModelChange={(newModel) => setColumnVisibilityModel(newModel)}

Check warning on line 256 in src/chart/table/TableChart.tsx

View check run for this annotation

Codecov / codecov/patch

src/chart/table/TableChart.tsx#L256

Added line #L256 was not covered by tests
onCellClick={(e) =>
performActionOnElement(e, actionsRules, { ...props, pageNames: pageNames }, 'Click', 'Table')
}
Expand All @@ -272,7 +269,7 @@
checkboxSelection={hasCheckboxes(actionsRules)}
selectionModel={getCheckboxes(actionsRules, rows, props.getGlobalParameter)}
onSelectionModelChange={(selection) =>
updateCheckBoxes(actionsRules, rows, selection, props.setGlobalParameter)

Check warning on line 272 in src/chart/table/TableChart.tsx

View check run for this annotation

Codecov / codecov/patch

src/chart/table/TableChart.tsx#L272

Added line #L272 was not covered by tests
}
pageSize={tablePageSize > 0 ? tablePageSize : 5}
rowsPerPageOptions={rows.length < 5 ? [rows.length, 5] : [5]}
Expand Down
Loading