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

Add isVisibleToRole102 prop to DataGrid component #346

Merged
merged 5 commits into from
Oct 11, 2024
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
26 changes: 24 additions & 2 deletions components/DataGrid/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,31 @@ interface paramsType {
getRowId?: (row: any) => string;
loading?: boolean;
heighted?: boolean;
isVisibleToRole102?: boolean;
}

/**
* DataGrid component for rendering a data grid with customizable rows, columns, and various options.
*
* @param {Object} props - The properties object.
* @param {Array} props.rows - The data rows to be displayed in the grid.
* @param {Array} props.columns - The column definitions for the grid.
* @param {Function} props.onCellClick - Callback function to handle cell click events.
* @param {Function} props.getRowId - Function to get the unique identifier for each row.
* @param {boolean} [props.loading=false] - Flag to indicate if the grid is in a loading state.
* @param {boolean} [props.heighted=false] - Flag to control the auto height behavior of the grid.
* @param {boolean} [props.isVisibleToRole102=false] - Flag to control visibility of certain toolbar options for role 102.
*
* @returns {JSX.Element} The rendered data grid component.
*/
function Index({
rows,
columns,
onCellClick,
getRowId,
loading = false,
heighted = false,
isVisibleToRole102 = false,
}: paramsType) {
const [pageSize, setPageSize] = useState<number>(25);

Expand All @@ -91,8 +107,14 @@ function Index({
toolbar: {
showQuickFilter: true,
quickFilterProps: { debounceMs: 500 },
printOptions: { disableToolbarButton: role === 102 || role === 1 },
csvOptions: { disableToolbarButton: role === 102 || role === 1 },
printOptions: {
disableToolbarButton:
(role === 102 && !isVisibleToRole102) || role === 1,
},
csvOptions: {
disableToolbarButton:
(role === 102 && !isVisibleToRole102) || role === 1,
},
},
}}
disableDensitySelector
Expand Down
7 changes: 6 additions & 1 deletion pages/admin/rc/[rcid]/event/[eventId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,12 @@ function Event() {
/>
</Modal>
</Stack>
<DataGrid columns={cols} getRowId={(row) => row.ID} rows={students} />
<DataGrid
columns={cols}
getRowId={(row) => row.ID}
rows={students}
isVisibleToRole102
/>
<Modal open={openNew} onClose={handleCloseNew}>
<EnrollToEvent
handleClose={handleCloseNew}
Expand Down
7 changes: 6 additions & 1 deletion pages/admin/rc/[rcid]/proforma/[proformaid]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,12 @@ function Index() {
</div>
</Stack>

<DataGrid rows={rows} columns={columns} loading={loading} />
<DataGrid
rows={rows}
columns={columns}
loading={loading}
isVisibleToRole102
/>
</Stack>
</Grid>
<Grid item xs={12}>
Expand Down
Loading