Skip to content

Commit 7b76ac1

Browse files
authored
Grading table improvements (filter by name, username, group) (#3023)
* Make columns resizable * Add floating filter row * Simplify height logic * Add filtering by name, username, and group * Remove log statement
1 parent cfc32e9 commit 7b76ac1

File tree

4 files changed

+34
-19
lines changed

4 files changed

+34
-19
lines changed

src/features/grading/GradingTypes.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,7 @@ export type AllColsSortStates = {
8181

8282
export type ColumnFiltersState = ColumnFilter[];
8383

84-
export type ColumnFilter = {
85-
id: string;
86-
value: unknown;
87-
};
84+
export type ColumnFilter = { id: string; value: unknown };
8885

8986
export type GradingColumnVisibility = ColumnFieldsKeys[];
9087

@@ -163,7 +160,6 @@ export type IGradingTableProperties = {
163160
suppressMenuHide: boolean;
164161
suppressPaginationPanel: boolean;
165162
suppressRowClickSelection: boolean;
166-
tableHeight: string;
167163
tableMargins: string;
168164
};
169165

src/pages/academy/grading/Grading.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ const Grading: React.FC = () => {
153153
gradingOverviews?.data === undefined ? (
154154
loadingDisplay
155155
) : (
156-
<GradingFlex flexDirection="column" className="grading-table-wrapper">
156+
<div className="grading-table-wrapper">
157157
<GradingFlex justifyContent="space-between">
158158
<GradingFlex justifyContent="flex-start" style={{ columnGap: '1.5rem' }}>
159159
<GradingText style={{ fontSize: '1.125rem', opacity: 0.9 }}>
@@ -218,7 +218,7 @@ const Grading: React.FC = () => {
218218
submissions={submissions}
219219
updateEntries={updateGradingOverviewsCallback}
220220
/>
221-
</GradingFlex>
221+
</div>
222222
)
223223
}
224224
fullWidth

src/pages/academy/grading/subcomponents/GradingSubmissionsTable.tsx

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ const GradingSubmissionTable: React.FC<GradingSubmissionTableProps> = ({
9090
const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>([
9191
...tableFilters.columnFilters
9292
]);
93+
const [cellFilters, setCellFilters] = useState<{ id: ColumnFields; value: string }[]>([]);
9394
const [hiddenColumns, setHiddenColumns] = useState<GradingColumnVisibility>(
9495
columnVisibility ? columnVisibility : []
9596
);
@@ -103,7 +104,8 @@ const GradingSubmissionTable: React.FC<GradingSubmissionTableProps> = ({
103104

104105
const defaultColumnDefs: ColDef = {
105106
filter: false,
106-
resizable: false,
107+
floatingFilter: true,
108+
resizable: true,
107109
sortable: true,
108110
headerComponentParams: {
109111
hideColumn: (id: ColumnNameKeys) => handleColumnFilterAdd(id),
@@ -142,8 +144,6 @@ const GradingSubmissionTable: React.FC<GradingSubmissionTableProps> = ({
142144
suppressMenuHide: true,
143145
suppressPaginationPanel: true,
144146
suppressRowClickSelection: true,
145-
tableHeight:
146-
String(ROW_HEIGHT * (rowData.length > 0 ? rowData.length : 2) + HEADER_HEIGHT + 4) + 'px',
147147
tableMargins: '1rem 0 0 0'
148148
};
149149

@@ -162,11 +162,14 @@ const GradingSubmissionTable: React.FC<GradingSubmissionTableProps> = ({
162162
debouncedUpdateSearchValue(e.target.value);
163163
};
164164

165+
const debouncedUpdateCellFilters = useMemo(() => debounce(setCellFilters, 300), []);
166+
165167
// Converts the columnFilters array into backend query parameters.
166168
const backendFilterParams = useMemo(() => {
167169
const filters: Array<{ [key: string]: any }> = [
168170
{ id: ColumnFields.assessmentName, value: searchValue },
169-
...columnFilters
171+
...columnFilters,
172+
...cellFilters
170173
].map(convertFilterToBackendParams);
171174

172175
const params: Record<string, any> = {};
@@ -176,7 +179,7 @@ const GradingSubmissionTable: React.FC<GradingSubmissionTableProps> = ({
176179
});
177180
});
178181
return params;
179-
}, [columnFilters, searchValue]);
182+
}, [cellFilters, columnFilters, searchValue]);
180183

181184
const cellClickedEvent = (event: CellClickedEvent) => {
182185
const colClicked: string = event.colDef.field ? event.colDef.field : '';
@@ -392,13 +395,7 @@ const GradingSubmissionTable: React.FC<GradingSubmissionTableProps> = ({
392395
></InputGroup>
393396
</GradingFlex>
394397

395-
<div
396-
className="ag-theme-quartz"
397-
style={{
398-
height: tableProperties.tableHeight,
399-
margin: tableProperties.tableMargins
400-
}}
401-
>
398+
<div className="ag-theme-quartz" style={{ margin: tableProperties.tableMargins }}>
402399
<AgGridReact
403400
columnDefs={colDefs}
404401
onCellClicked={cellClickedEvent}
@@ -416,6 +413,25 @@ const GradingSubmissionTable: React.FC<GradingSubmissionTableProps> = ({
416413
suppressMenuHide={tableProperties.suppressMenuHide}
417414
suppressPaginationPanel={tableProperties.suppressPaginationPanel}
418415
suppressRowClickSelection={tableProperties.suppressRowClickSelection}
416+
domLayout="autoHeight"
417+
onFilterChanged={e => {
418+
if (!e.afterFloatingFilter) {
419+
return;
420+
}
421+
const filters = e.api.getFilterModel();
422+
const cellFilters = [];
423+
for (const [key, { filter: query }] of Object.entries(filters)) {
424+
switch (key) {
425+
// Fields that BE supports filtering on
426+
case ColumnFields.studentName:
427+
case ColumnFields.studentUsername:
428+
case ColumnFields.groupName:
429+
cellFilters.push({ id: key, value: query });
430+
break;
431+
}
432+
}
433+
debouncedUpdateCellFilters(cellFilters);
434+
}}
419435
/>
420436
</div>
421437

src/pages/academy/grading/subcomponents/gradingSubmissionsTableUtils.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export const generateCols = (filterMode: boolean) => {
6262
...generalColProperties,
6363
headerName: ColumnName.studentName,
6464
field: ColumnFields.studentName,
65+
filter: true,
6566
flex: 1.5,
6667
cellClass: classNames(generalColProperties.cellClass, classes['grading-cell-align-left']),
6768
headerClass: classNames(generalColProperties.headerClass, classes['grading-left-align']),
@@ -82,6 +83,7 @@ export const generateCols = (filterMode: boolean) => {
8283
...generalColProperties,
8384
headerName: ColumnName.studentUsername,
8485
field: ColumnFields.studentUsername,
86+
filter: true,
8587
cellRendererSelector: (params: ICellRendererParams<IGradingTableRow>) => {
8688
return params.data !== undefined
8789
? {
@@ -99,6 +101,7 @@ export const generateCols = (filterMode: boolean) => {
99101
...generalColProperties,
100102
headerName: ColumnName.groupName,
101103
field: ColumnFields.groupName,
104+
filter: true,
102105
flex: 0.75,
103106
cellRendererSelector: (params: ICellRendererParams<IGradingTableRow>) => {
104107
return params.data !== undefined

0 commit comments

Comments
 (0)