Skip to content

Commit cda0451

Browse files
authored
Merge pull request #2398 from AtCoder-NoviSteps/#2368
🎨 Enable to change column width in contest table (#2368)
2 parents 9ae3a4d + 22123c4 commit cda0451

File tree

4 files changed

+31
-9
lines changed

4 files changed

+31
-9
lines changed

src/lib/components/TaskTables/TaskTable.svelte

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,10 @@
105105
return totalColumns > 8 ? 'flex flex-wrap' : 'flex flex-wrap xl:table-row';
106106
}
107107
108-
function getBodyCellClasses(taskResult: TaskResult, totalColumns: number): string {
109-
const baseClasses =
110-
totalColumns >= 5
111-
? 'w-1/2 xs:w-1/3 sm:w-1/4 md:w-1/5 lg:w-1/6 px-1 py-1'
112-
: 'w-1/2 xs:w-1/3 sm:w-1/4 px-1 py-1';
113-
const additionalClasses = totalColumns > 8 ? '2xl:w-1/7 py-2' : '';
108+
function getBodyCellClasses(taskResult: TaskResult, tableBodyCellWidth: string): string {
114109
const backgroundColor = getBackgroundColor(taskResult);
115110
116-
return `${baseClasses} ${additionalClasses} ${backgroundColor}`;
111+
return `${tableBodyCellWidth} ${backgroundColor}`;
117112
}
118113
119114
function getBackgroundColor(taskResult: TaskResult): string {
@@ -244,7 +239,10 @@
244239

245240
<TableBodyCell
246241
id={contestId + '-' + taskTableHeaderId}
247-
class={getBodyCellClasses(taskResult, totalColumns)}
242+
class={getBodyCellClasses(
243+
taskResult,
244+
contestTable.displayConfig.tableBodyCellsWidth,
245+
)}
248246
>
249247
{#if taskResult}
250248
<TaskTableBodyCell

src/lib/types/contest_table_provider.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,14 @@ export type ContestTablesMetaData = {
125125
* @interface ContestTableDisplayConfig
126126
* @property {boolean} isShownHeader - Whether to display the table header
127127
* @property {boolean} isShownRoundLabel - Whether to display round labels in the contest table
128-
* @property {string} roundLabelWidth - tailwind CSS width for the round label column, e.g., "w-16" or "w-20"
128+
* @property {string} roundLabelWidth - tailwind CSS width for the round label column, e.g., "xl:w-16" or "xl:w-20"
129+
* @property {string} tableBodyCellsWidth - tailwind CSS width for the table body cells, e.g., "w-1/2 xs:w-1/3 sm:w-1/4 md:w-1/5 lg:w-1/6 px-1 py-1"
129130
* @property {boolean} isShownTaskIndex - Whether to display task index in the contest table cells
130131
*/
131132
export interface ContestTableDisplayConfig {
132133
isShownHeader: boolean;
133134
isShownRoundLabel: boolean;
134135
roundLabelWidth: string;
136+
tableBodyCellsWidth: string;
135137
isShownTaskIndex: boolean;
136138
}

src/lib/utils/contest_table_provider.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export abstract class ContestTableProviderBase implements ContestTableProvider {
9999
isShownHeader: true,
100100
isShownRoundLabel: true,
101101
roundLabelWidth: 'xl:w-16', // Default width for task index column
102+
tableBodyCellsWidth: 'w-1/2 xs:w-1/3 sm:w-1/4 md:w-1/5 lg:w-1/6 px-1 py-1', // Default width for table body cells
102103
isShownTaskIndex: false,
103104
};
104105
}
@@ -232,6 +233,7 @@ export class EDPCProvider extends ContestTableProviderBase {
232233
isShownHeader: false,
233234
isShownRoundLabel: false,
234235
roundLabelWidth: '', // No specific width for task index in EDPC
236+
tableBodyCellsWidth: 'w-1/2 xs:w-1/3 sm:w-1/4 md:w-1/5 lg:w-1/6 2xl:w-1/7 px-1 py-2',
235237
isShownTaskIndex: true,
236238
};
237239
}
@@ -264,6 +266,7 @@ export class TDPCProvider extends ContestTableProviderBase {
264266
isShownHeader: false,
265267
isShownRoundLabel: false,
266268
roundLabelWidth: '', // No specific width for task index in TDPC
269+
tableBodyCellsWidth: 'w-1/2 xs:w-1/3 sm:w-1/4 md:w-1/5 lg:w-1/6 2xl:w-1/7 px-1 py-2',
267270
isShownTaskIndex: true,
268271
};
269272
}
@@ -298,6 +301,7 @@ export class JOIFirstQualRoundProvider extends ContestTableProviderBase {
298301
isShownHeader: true,
299302
isShownRoundLabel: true,
300303
isShownTaskIndex: false,
304+
tableBodyCellsWidth: 'w-1/2 md:w-1/3 lg:w-1/4 px-1 py-1',
301305
roundLabelWidth: 'xl:w-28',
302306
};
303307
}
@@ -331,6 +335,7 @@ export class Typical90Provider extends ContestTableProviderBase {
331335
isShownHeader: false,
332336
isShownRoundLabel: false,
333337
roundLabelWidth: '', // No specific width for the round label in Typical90
338+
tableBodyCellsWidth: 'w-1/2 lg:w-1/3 xl:w-1/4 px-1 py-2',
334339
isShownTaskIndex: true,
335340
};
336341
}

src/test/lib/utils/contest_table_provider.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ describe('ContestTableProviderBase and implementations', () => {
143143
expect(displayConfig.isShownHeader).toBe(true);
144144
expect(displayConfig.isShownRoundLabel).toBe(true);
145145
expect(displayConfig.roundLabelWidth).toBe('xl:w-16');
146+
expect(displayConfig.tableBodyCellsWidth).toBe(
147+
'w-1/2 xs:w-1/3 sm:w-1/4 md:w-1/5 lg:w-1/6 px-1 py-1',
148+
);
146149
expect(displayConfig.isShownTaskIndex).toBe(false);
147150
});
148151
});
@@ -183,6 +186,9 @@ describe('ContestTableProviderBase and implementations', () => {
183186
expect(displayConfig.isShownHeader).toBe(true);
184187
expect(displayConfig.isShownRoundLabel).toBe(true);
185188
expect(displayConfig.roundLabelWidth).toBe('xl:w-16');
189+
expect(displayConfig.tableBodyCellsWidth).toBe(
190+
'w-1/2 xs:w-1/3 sm:w-1/4 md:w-1/5 lg:w-1/6 px-1 py-1',
191+
);
186192
expect(displayConfig.isShownTaskIndex).toBe(false);
187193
});
188194
});
@@ -223,6 +229,9 @@ describe('ContestTableProviderBase and implementations', () => {
223229
expect(displayConfig.isShownHeader).toBe(true);
224230
expect(displayConfig.isShownRoundLabel).toBe(true);
225231
expect(displayConfig.roundLabelWidth).toBe('xl:w-16');
232+
expect(displayConfig.tableBodyCellsWidth).toBe(
233+
'w-1/2 xs:w-1/3 sm:w-1/4 md:w-1/5 lg:w-1/6 px-1 py-1',
234+
);
226235
expect(displayConfig.isShownTaskIndex).toBe(false);
227236
});
228237
});
@@ -243,6 +252,9 @@ describe('ContestTableProviderBase and implementations', () => {
243252
expect(displayConfig.isShownHeader).toBe(false);
244253
expect(displayConfig.isShownRoundLabel).toBe(false);
245254
expect(displayConfig.roundLabelWidth).toBe('');
255+
expect(displayConfig.tableBodyCellsWidth).toBe(
256+
'w-1/2 xs:w-1/3 sm:w-1/4 md:w-1/5 lg:w-1/6 2xl:w-1/7 px-1 py-2',
257+
);
246258
expect(displayConfig.isShownTaskIndex).toBe(true);
247259
});
248260

@@ -270,6 +282,9 @@ describe('ContestTableProviderBase and implementations', () => {
270282
expect(displayConfig.isShownHeader).toBe(false);
271283
expect(displayConfig.isShownRoundLabel).toBe(false);
272284
expect(displayConfig.roundLabelWidth).toBe('');
285+
expect(displayConfig.tableBodyCellsWidth).toBe(
286+
'w-1/2 xs:w-1/3 sm:w-1/4 md:w-1/5 lg:w-1/6 2xl:w-1/7 px-1 py-2',
287+
);
273288
expect(displayConfig.isShownTaskIndex).toBe(true);
274289
});
275290

@@ -334,6 +349,7 @@ describe('ContestTableProviderBase and implementations', () => {
334349
expect(displayConfig.isShownHeader).toBe(true);
335350
expect(displayConfig.isShownRoundLabel).toBe(true);
336351
expect(displayConfig.roundLabelWidth).toBe('xl:w-28');
352+
expect(displayConfig.tableBodyCellsWidth).toBe('w-1/2 md:w-1/3 lg:w-1/4 px-1 py-1');
337353
expect(displayConfig.isShownTaskIndex).toBe(false);
338354
});
339355

@@ -434,6 +450,7 @@ describe('ContestTableProviderBase and implementations', () => {
434450
expect(displayConfig.isShownHeader).toBe(false);
435451
expect(displayConfig.isShownRoundLabel).toBe(false);
436452
expect(displayConfig.roundLabelWidth).toBe('');
453+
expect(displayConfig.tableBodyCellsWidth).toBe('w-1/2 lg:w-1/3 xl:w-1/4 px-1 py-2');
437454
expect(displayConfig.isShownTaskIndex).toBe(true);
438455
});
439456

0 commit comments

Comments
 (0)