Skip to content

fix: column sort in experiments table#1576

Open
shivoomiess wants to merge 9 commits into
developfrom
SWAP-5630-fix
Open

fix: column sort in experiments table#1576
shivoomiess wants to merge 9 commits into
developfrom
SWAP-5630-fix

Conversation

@shivoomiess

@shivoomiess shivoomiess commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

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

  1. Debugging capabilities were added to React and the local backend to better facilitate future troubleshooting efforts.
  2. The backend's dev script was updated to include the --inspect flag, allowing for easier debugging.
  3. The ExperimentDataSource.ts file 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.
  4. The experiments.cy.ts e2e 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?

  • I have added tests to cover my changes.
  • All relevant doc has been updated

@shivoomiess shivoomiess requested a review from a team as a code owner June 15, 2026 13:24
@shivoomiess shivoomiess requested review from ChongJiaChua, jekabs-karklins and yoganandaness and removed request for a team and ChongJiaChua June 15, 2026 13:24
@shivoomiess shivoomiess self-assigned this Jun 15, 2026
@shivoomiess shivoomiess changed the title Fix: Column sorting not working Experiments Table fix: Column sorting not working Experiments Table Jun 15, 2026
@shivoomiess shivoomiess changed the title fix: Column sorting not working Experiments Table fix: column sorting not working in Experiments table Jun 15, 2026
@shivoomiess shivoomiess changed the title fix: column sorting not working in Experiments table fix: column sort in experiments table Jun 15, 2026
Comment thread apps/backend/package.json
"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",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to update readme about this? @jekabs-karklins

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should not add it here, because we already have the "debug" script. Does that work for you @shivoomiess

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread apps/backend/src/datasources/postgres/ExperimentDataSource.ts Outdated
Comment thread apps/backend/src/datasources/postgres/ExperimentDataSource.ts Outdated
Comment thread apps/e2e/cypress/e2e/experiments.cy.ts
Comment thread apps/e2e/cypress/e2e/experiments.cy.ts Outdated
endsAt = 'endsAt',
}

registerEnumType(ExperimentTableSortField, {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do this in apps/backend/src/resolvers/registerEnums.ts

to?: Date;
}

export enum ExperimentTableSortField {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would prefer to have this in Experiment Model, so it can be used in other queries in the future. Let me know your thoughts.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 sortField GraphQL argument from String to a dedicated ExperimentTableSortField enum 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).

Comment thread .zed/debug.json
Comment on lines +1 to +23
[
{
"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>/**"],
},
]
Comment on lines +94 to +116
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();
Comment on lines +126 to +148
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();
Comment on lines +158 to +180
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.
Comment on lines +35 to +38
registerEnumType(ExperimentTableSortField, {
name: 'ExperimentTableSortField',
description: 'Experiment table columns that support sorting',
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants