Skip to content

fix: wire up column sort in Process Instances table#2838

Open
photon-cat wants to merge 1 commit into
mainfrom
fix/process-instances-column-sort
Open

fix: wire up column sort in Process Instances table#2838
photon-cat wants to merge 1 commit into
mainfrom
fix/process-instances-column-sort

Conversation

@photon-cat
Copy link
Copy Markdown

@photon-cat photon-cat commented May 28, 2026

Summary

  • The Process Instances table rendered MUI's TableSortLabel arrow on every header, but had no click handler or active state — hovering showed a sort affordance that did nothing.
  • Wires the click through to the existing report_metadata.order_by, which the backend already supports for stock columns.
  • Removes the misleading arrow from "Started by" since the backend can't sort on that derived field.

Behavior

  • Click a sortable header → sort descending
  • Click again → ascending
  • Click a third time → clear back to default (-start_in_seconds, -id)
  • Active column shows the up/down arrow; inactive columns show no arrow
  • Sortable columns: Id, Process, Start, End, Last milestone, Status

Test plan

  • Click Status header on Process Instances list — rows reorder, arrow points down
  • Click Status again — rows reverse, arrow points up
  • Click Status a third time — sort clears, default ordering returns
  • Click Start header — sorts by start time descending
  • Verify "Started by" column has no sort arrow (it's a backend join field)
  • Verify sort persists across pagination

The TableSortLabel arrow was rendered on every header but had no click
handler or active state — hovering showed a sort affordance that did
nothing. Backend already supports order_by on stock columns, so wire
the click through to the existing report_metadata.order_by.

- Click a sortable header to sort desc, click again for asc, click
  again to clear back to default
- Active column shows up/down arrow; inactive columns no arrow
- Sortable: Id, Process, Start, End, Last milestone, Status
- "Started by" is not sortable in the backend (it's a join field, not
  a stock column), so the misleading arrow is removed from that header
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 28, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

ProcessInstanceListTable now supports client-side column sorting. A new sortOrderBy state tracks the current sort configuration, which is displayed via TableSortLabel headers for sortable columns. Clicking a header cycles the sort direction through none → descending → ascending. The active sort state is passed to the backend in the request payload.

Changes

Column sort state and rendering

Layer / File(s) Summary
Sort state and interaction logic
spiffworkflow-frontend/src/components/ProcessInstanceListTable.tsx
Declares sortOrderBy state to track active sort columns and directions. Defines a fixed set of sortable accessors, a helper to compute sort direction from state, and a click handler that cycles through sort states. Refactors header column construction to incorporate the sortable columns and actions column option.
Header rendering with sort controls
spiffworkflow-frontend/src/components/ProcessInstanceListTable.tsx
Renders per-column table headers with TableSortLabel for sortable columns, setting current sort direction from sortOrderBy. Non-sortable columns render as plain text headers.
Request payload integration
spiffworkflow-frontend/src/components/ProcessInstanceListTable.tsx
Injects sortOrderBy into the backend request's report_metadata as order_by when sort is active. Adds sortOrderBy to the getProcessInstances useCallback dependency list.

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: wire up column sort in Process Instances table' directly and clearly summarizes the main change: enabling column sorting functionality in the Process Instances table component.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The PR description clearly describes the changeset: wiring up column sort functionality in the Process Instances table, including specific behavior details and test cases.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/process-instances-column-sort

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ec6af099ce

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +488 to +490
setSortOrderBy([`-${accessor}`]);
} else if (current === 'desc') {
setSortOrderBy([accessor]);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Append a stable tiebreaker for paginated sorts

When a user sorts by a non-unique column such as status or process name, the request now sends only that single order_by field, and the backend paginates directly over that SQL ordering. For process lists with many identical values across pages, the database can return ties in arbitrary order between page requests, which can make rows appear on multiple pages or be skipped. Please include a deterministic secondary key such as id when generating the sort order.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
spiffworkflow-frontend/src/components/ProcessInstanceListTable.tsx (2)

468-475: 💤 Low value

Move SORTABLE_ACCESSORS outside the component to avoid recreation on every render.

This Set is constant and doesn't depend on props or state. Defining it inside the component causes unnecessary allocation on each render.

Suggested refactor
+const SORTABLE_ACCESSORS = new Set([
+  'id',
+  'process_model_display_name',
+  'start_in_seconds',
+  'end_in_seconds',
+  'last_milestone_bpmn_name',
+  'status',
+]);
+
 export default function ProcessInstanceListTable({
   // ...
 }: OwnProps) {
   // ...
-  const SORTABLE_ACCESSORS = new Set([
-    'id',
-    'process_model_display_name',
-    'start_in_seconds',
-    'end_in_seconds',
-    'last_milestone_bpmn_name',
-    'status',
-  ]);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@spiffworkflow-frontend/src/components/ProcessInstanceListTable.tsx` around
lines 468 - 475, Move the constant Set named SORTABLE_ACCESSORS out of the
ProcessInstanceListTable component so it isn't re-created on every render;
locate the declaration of SORTABLE_ACCESSORS (currently defined inside the
component) and hoist it to module scope (above the component) so the component
can reference the single shared Set instance without allocating a new one each
render.

598-627: 💤 Low value

Prefer accessor over label for the React key to avoid potential duplicates.

Using col.label as the key could cause issues if two columns share the same header text. Using accessor (with a fallback for the actions column) is more robust.

Suggested change
                   return (
                     <TableCell
-                      key={col.label}
+                      key={col.accessor ?? col.label}
                       title={
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@spiffworkflow-frontend/src/components/ProcessInstanceListTable.tsx` around
lines 598 - 627, The TableCell key currently uses col.label which can duplicate;
change it to use col.accessor as the primary key with a fallback (e.g.,
'actions' or another unique identifier) for columns without an accessor so keys
are stable and unique—update the mapping over headerColumns where TableCell is
rendered (reference: headerColumns, col.accessor, col.label, TableCell key).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@spiffworkflow-frontend/src/components/ProcessInstanceListTable.tsx`:
- Around line 468-475: Move the constant Set named SORTABLE_ACCESSORS out of the
ProcessInstanceListTable component so it isn't re-created on every render;
locate the declaration of SORTABLE_ACCESSORS (currently defined inside the
component) and hoist it to module scope (above the component) so the component
can reference the single shared Set instance without allocating a new one each
render.
- Around line 598-627: The TableCell key currently uses col.label which can
duplicate; change it to use col.accessor as the primary key with a fallback
(e.g., 'actions' or another unique identifier) for columns without an accessor
so keys are stable and unique—update the mapping over headerColumns where
TableCell is rendered (reference: headerColumns, col.accessor, col.label,
TableCell key).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4f5a467a-9717-43f2-801e-08342d298190

📥 Commits

Reviewing files that changed from the base of the PR and between e108274 and ec6af09.

📒 Files selected for processing (1)
  • spiffworkflow-frontend/src/components/ProcessInstanceListTable.tsx

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.

1 participant