fix: column sort in experiments table#1576
Conversation
| "build": "npm run build:validation && npm run generate:uows && rm -rf ./build && tsc", | ||
| "postinstall": "npm run build:validation", | ||
| "dev": "docker compose up -d --remove-orphans && ts-node-dev -r tsconfig-paths/register --respawn -T ./index.ts", | ||
| "dev": "docker compose up -d --remove-orphans && ts-node-dev --inspect=9229 -r tsconfig-paths/register --respawn -T ./index.ts", |
There was a problem hiding this comment.
Do we need to update readme about this? @jekabs-karklins
There was a problem hiding this comment.
I think we should not add it here, because we already have the "debug" script. Does that work for you @shivoomiess
There was a problem hiding this comment.
I think that runs a separate instance of the frontend dev server while reusing existing docker containers? Haven't tried using the debug script separately; we could:
- either add a port number for the inspect in
debug - or make the dev server debuggable (should be fine since we're already in dev?)
There was a problem hiding this comment.
We can add 9229 to the --inspect, however it is the default port, but we can be explicit.
the "debug" script just starts the index.ts with the debug port open, you do need to run docker compose up before running npm run debug
| endsAt = 'endsAt', | ||
| } | ||
|
|
||
| registerEnumType(ExperimentTableSortField, { |
There was a problem hiding this comment.
Can we do this in apps/backend/src/resolvers/registerEnums.ts
| to?: Date; | ||
| } | ||
|
|
||
| export enum ExperimentTableSortField { |
There was a problem hiding this comment.
Would prefer to have this in Experiment Model, so it can be used in other queries in the future. Let me know your thoughts.
There was a problem hiding this comment.
Pull request overview
This PR fixes broken column sorting in the Experiments table by introducing a typed sort-field enum end-to-end (frontend → GraphQL → backend → DB column mapping) and updating UI/test behavior around sortable vs non-sortable columns.
Changes:
- Replaced the experiments
sortFieldGraphQL argument fromStringto a dedicatedExperimentTableSortFieldenum and threaded the type through resolvers/queries/datasources. - Added explicit mappings for sortable fields (UI column field → GraphQL enum → DB column) and disabled sorting for columns not supported at the DB layer.
- Updated Cypress e2e coverage around experiments table sorting interactions and added local debugging configuration/script changes.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| apps/frontend/src/graphql/experiment/getAllExperiments.graphql | Changes sortField variable type to ExperimentTableSortField to match backend typing. |
| apps/frontend/src/components/experiment/ExperimentsTable.tsx | Maps MaterialTable column fields to sort enum values and disables sorting for unsupported columns. |
| apps/e2e/cypress/e2e/experiments.cy.ts | Adds/adjusts e2e coverage for experiments table sorting for multiple roles. |
| apps/backend/src/resolvers/queries/ExperimentsQuery.ts | Introduces ExperimentTableSortField enum and uses it for sortField argument typing. |
| apps/backend/src/queries/ExperimentQueries.ts | Updates getExperiments signature to accept the new sort-field enum. |
| apps/backend/src/datasources/postgres/ExperimentDataSource.ts | Adds enum→DB-column map and uses it to build the SQL ORDER BY. |
| apps/backend/src/datasources/mockups/ExperimentDataSource.ts | Updates mock datasource signature to the new enum sort-field type. |
| apps/backend/src/datasources/ExperimentDataSource.ts | Updates datasource interface signature to the new enum sort-field type. |
| apps/backend/package.json | Adds --inspect=9229 to backend dev for easier debugging. |
| .zed/debug.json | Adds Zed editor debug configurations (currently needs JSON validity fix). |
| [ | ||
| { | ||
| "label": "Launch Debug React in Chrome", | ||
| "adapter": "JavaScript", | ||
| "type": "chrome", | ||
| "request": "launch", | ||
| "console": "integratedTerminal", | ||
| "url": "http://localhost:3000", | ||
| "webRoot": "$ZED_WORKTREE_ROOT/apps/frontend", | ||
| "skipFiles": ["<node_internals>/**"], | ||
| }, | ||
| { | ||
| "label": "Debug Local Backend {attach} (npm run dev)", | ||
| "adapter": "JavaScript", | ||
| "type": "node", | ||
| "request": "attach", | ||
| "port": 9229, | ||
| "address": "localhost", | ||
| "restart": true, | ||
| "localRoot": "$ZED_WORKTREE_ROOT/apps/backend", | ||
| "skipFiles": ["<node_internals>/**"], | ||
| }, | ||
| ] |
| cy.get( | ||
| 'div[data-rfd-draggable-id="1"] [data-testid="mtableheader-sortlabel"]' | ||
| ).click(); | ||
| cy.get('span[aria-sort="ascending"]').click(); | ||
| cy.get('span[aria-sort="descending"]').click(); | ||
|
|
||
| cy.get( | ||
| 'div[data-rfd-draggable-id="2"] [data-testid="mtableheader-sortlabel"]' | ||
| ).click(); | ||
| cy.get('span[aria-sort="ascending"]').click(); | ||
| cy.get('span[aria-sort="descending"]').click(); | ||
|
|
||
| cy.get( | ||
| 'div[data-rfd-draggable-id="3"] [data-testid="mtableheader-sortlabel"]' | ||
| ).click(); | ||
| cy.get('span[aria-sort="ascending"]').click(); | ||
| cy.get('span[aria-sort="descending"]').click(); | ||
|
|
||
| cy.get( | ||
| 'div[data-rfd-draggable-id="4"] [data-testid="mtableheader-sortlabel"]' | ||
| ).click(); | ||
| cy.get('span[aria-sort="ascending"]').click(); | ||
| cy.get('span[aria-sort="descending"]').click(); |
| cy.get( | ||
| 'div[data-rfd-draggable-id="1"] [data-testid="mtableheader-sortlabel"]' | ||
| ).click(); | ||
| cy.get('span[aria-sort="ascending"]').click(); | ||
| cy.get('span[aria-sort="descending"]').click(); | ||
|
|
||
| cy.get( | ||
| 'div[data-rfd-draggable-id="2"] [data-testid="mtableheader-sortlabel"]' | ||
| ).click(); | ||
| cy.get('span[aria-sort="ascending"]').click(); | ||
| cy.get('span[aria-sort="descending"]').click(); | ||
|
|
||
| cy.get( | ||
| 'div[data-rfd-draggable-id="3"] [data-testid="mtableheader-sortlabel"]' | ||
| ).click(); | ||
| cy.get('span[aria-sort="ascending"]').click(); | ||
| cy.get('span[aria-sort="descending"]').click(); | ||
|
|
||
| cy.get( | ||
| 'div[data-rfd-draggable-id="4"] [data-testid="mtableheader-sortlabel"]' | ||
| ).click(); | ||
| cy.get('span[aria-sort="ascending"]').click(); | ||
| cy.get('span[aria-sort="descending"]').click(); |
| cy.get( | ||
| 'div[data-rfd-draggable-id="1"] [data-testid="mtableheader-sortlabel"]' | ||
| ).click(); | ||
| cy.get('span[aria-sort="ascending"]').click(); | ||
| cy.get('span[aria-sort="descending"]').click(); | ||
|
|
||
| cy.get( | ||
| 'div[data-rfd-draggable-id="2"] [data-testid="mtableheader-sortlabel"]' | ||
| ).click(); | ||
| cy.get('span[aria-sort="ascending"]').click(); | ||
| cy.get('span[aria-sort="descending"]').click(); | ||
|
|
||
| cy.get( | ||
| 'div[data-rfd-draggable-id="3"] [data-testid="mtableheader-sortlabel"]' | ||
| ).click(); | ||
| cy.get('span[aria-sort="ascending"]').click(); | ||
| cy.get('span[aria-sort="descending"]').click(); | ||
|
|
||
| cy.get( | ||
| 'div[data-rfd-draggable-id="4"] [data-testid="mtableheader-sortlabel"]' | ||
| ).click(); | ||
| cy.get('span[aria-sort="ascending"]').click(); | ||
| cy.get('span[aria-sort="descending"]').click(); |
| tableValue = [...tableValue, $el.text().toString()]; | ||
| }) | ||
| .then(() => { | ||
| // Explanation: The table has 7 columns. We will sort each column in ascending and descending order and check if the table is sorted correctly. |
| registerEnumType(ExperimentTableSortField, { | ||
| name: 'ExperimentTableSortField', | ||
| description: 'Experiment table columns that support sorting', | ||
| }); |
Description
This PR fixes the issue of column sorting not working properly in the Experiments Table.
Motivation and Context
The column sorting feature in the Experiments Table was not functioning as expected, leading to a less intuitive and potentially confusing user experience. This fix is necessary to ensure that users can sort data in a logical and predictable manner, improving the usability of the table.
Changes
devscript was updated to include the--inspectflag, allowing for easier debugging.ExperimentDataSource.tsfile was updated to include a map of fields that can be sorted. This provides explicit control over which columns can have their sorting functionality enabled.experiments.cy.tse2e test file was updated to include tests for the sorting functionality of each column in the visit table. This ensures that our sorting feature works as expected in the future.How Has This Been Tested?
Fixes Jira Issue
https://jira.ess.eu//browse/SWAP-5630
Depends On
Tests included/Docs Updated?