Skip to content

Commit c87c30d

Browse files
fix(TanStackTable): fix column alignment inconsistency
- reverted #7901 and #7923 - dropped support for TanStack columnVisibility
1 parent 778043a commit c87c30d

File tree

9 files changed

+18
-32
lines changed

9 files changed

+18
-32
lines changed

.circleci/config.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,10 @@ jobs:
302302
- run:
303303
name: Install Playwright dependencies
304304
working_directory: tests
305-
command: yarn install; yarn prepare
305+
command: |
306+
wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo tee /etc/apt/trusted.gpg.d/google.asc >/dev/null
307+
yarn install
308+
yarn prepare
306309
307310
- run:
308311
name: Run Playwright tests

client/app/bundles/course/assessment/pages/AssessmentStatistics/LiveFeedbackStatisticsTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ const LiveFeedbackStatisticsTable: FC<Props> = (props) => {
316316
getValue: (datum) => datum.courseUser.email,
317317
},
318318
title: t(translations.email),
319-
hidden: true,
319+
className: 'hidden',
320320
cell: (datum) => (
321321
<div className="flex grow items-center">
322322
{datum.courseUser.email}

client/app/bundles/course/assessment/pages/AssessmentStatistics/StudentAttemptCountTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ const StudentAttemptCountTable: FC<Props> = ({ includePhantom }) => {
234234
},
235235
{
236236
title: t(translations.email),
237-
hidden: true,
237+
className: 'hidden',
238238
csvDownloadable: true,
239239
searchProps: { getValue: (datum) => datum.courseUser.email },
240240
cell: (datum) => (

client/app/bundles/course/assessment/pages/AssessmentStatistics/StudentGradesPerQuestionTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ const StudentGradesPerQuestionTable: FC<Props> = ({ includePhantom }) => {
188188
getValue: (datum) => datum.courseUser.email,
189189
},
190190
title: t(translations.email),
191-
hidden: true,
191+
className: 'hidden',
192192
cell: (datum) => (
193193
<div className="flex grow items-center">{datum.courseUser.email}</div>
194194
),

client/app/bundles/course/statistics/pages/StatisticsIndex/students/StudentStatisticsTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ const StudentsStatisticsTable: FC<Props> = (props) => {
113113
{
114114
of: 'email',
115115
title: t(translations.email),
116-
hidden: true,
116+
className: 'hidden',
117117
cell: (student) => student.email,
118118
csvDownloadable: true,
119119
},

client/app/lib/components/table/TanStackTableBuilder/csvGenerator.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { unparse } from 'papaparse';
55
import { ColumnTemplate, Data } from '../builder';
66

77
interface CsvGenerator<D extends Data> {
8-
initialColumnsLength: number;
98
headers: string[];
109
rows: () => Row<D>[];
1110
getRealColumn: (index: number) => ColumnTemplate<D> | undefined;
@@ -20,7 +19,6 @@ const generateCsv = <D extends Data>(
2019
options.rows().forEach((row) => {
2120
const rowData = row
2221
.getAllCells()
23-
.slice(options.initialColumnsLength)
2422
.reduce<string[]>((cells, cell, index) => {
2523
const realColumn = options.getRealColumn(index);
2624
const csvDownloadable = realColumn?.csvDownloadable;

client/app/lib/components/table/TanStackTableBuilder/useTanStackTableBuilder.tsx

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type TanStackTableProps<D> = TableProps<
3030
const useTanStackTableBuilder = <D extends object>(
3131
props: TableTemplate<D>,
3232
): TanStackTableProps<D> => {
33-
const [columns, getRealColumn, initialColumnsLength] = buildTanStackColumns(
33+
const [columns, getRealColumn] = buildTanStackColumns(
3434
props.columns,
3535
props.indexing?.rowSelectable,
3636
props.indexing?.indices,
@@ -83,12 +83,6 @@ const useTanStackTableBuilder = <D extends object>(
8383
columnFilters,
8484
globalFilter: searchKeyword.trim(),
8585
pagination,
86-
columnVisibility: Object.fromEntries(
87-
props.columns.map((column) => [
88-
column.of ?? column.title,
89-
!column.hidden,
90-
]),
91-
),
9286
},
9387
initialState: {
9488
sorting: props.sort?.initially && [
@@ -101,17 +95,18 @@ const useTanStackTableBuilder = <D extends object>(
10195
});
10296

10397
const generateAndDownloadCsv = async (): Promise<void> => {
104-
const headers = table.options.columns
105-
.slice(initialColumnsLength)
106-
.reduce<string[]>((acc, column, index) => {
98+
const headers = table.options.columns.reduce<string[]>(
99+
(acc, column, index) => {
107100
const header = column.header || column.id;
108101
if (header && (getRealColumn(index)?.csvDownloadable ?? false)) {
109102
acc.push(header as string);
110103
}
111104
return acc;
112-
}, []);
105+
},
106+
[],
107+
);
108+
113109
const csvData = await generateCsv({
114-
initialColumnsLength,
115110
headers,
116111
rows: () => table.getCoreRowModel().rows,
117112
getRealColumn,

client/app/lib/components/table/builder/ColumnTemplate.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ interface ColumnTemplate<D extends Data> {
2828
sortable?: boolean;
2929
filterable?: boolean;
3030
searchable?: boolean;
31-
hidden?: boolean;
3231
csvDownloadable?: boolean;
3332
filterProps?: FilteringProps<D>;
3433
csvValue?: (value) => string;

client/app/lib/components/table/builder/buildColumns.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,24 @@ type TemplateAccessor<D extends Data> = (
44
builtColumnIndex: number,
55
) => ColumnTemplate<D> | undefined;
66

7-
export type BuiltColumns<D extends Data, C> = [
8-
C[],
9-
TemplateAccessor<D>,
10-
number,
11-
];
7+
export type BuiltColumns<D extends Data, C> = [C[], TemplateAccessor<D>];
128

139
export const buildColumns = <D extends Data, C>(
1410
columns: ColumnTemplate<D>[],
1511
getColumn: (column: ColumnTemplate<D>) => C,
1612
initial: C[] = [],
1713
): BuiltColumns<D, C> => {
18-
const initialColumnsLength = initial.length;
1914
const defToColumns: Record<number, ColumnTemplate<D>> = {};
2015

2116
const defColumns = columns.reduce<C[]>((columnDefs, column) => {
2217
if (column.unless) return columnDefs;
2318

2419
columnDefs.push(getColumn(column));
2520

26-
defToColumns[columnDefs.length - 1 - initialColumnsLength] = column;
21+
defToColumns[columnDefs.length - 1] = column;
2722

2823
return columnDefs;
2924
}, initial);
3025

31-
return [
32-
defColumns,
33-
(index): ColumnTemplate<D> => defToColumns[index],
34-
initialColumnsLength,
35-
];
26+
return [defColumns, (index): ColumnTemplate<D> => defToColumns[index]];
3627
};

0 commit comments

Comments
 (0)