Skip to content

DataView: Sort breaks when columns reorder #763

Description

@pascazzioIsAbyayalan

Description

KuadrantDataView stores the active sort column by index in state. When the columns array changes (e.g., inserting a "Namespace" column in MyAPIKeysPage when switching to all-namespaces mode), the stored index points to the wrong column.

Current Behaviour

  1. User sorts by "Status" (column at index 3)
  2. User switches to all-namespaces view
  3. Namespace column is inserted at index 1
  4. "Status" is now at index 4
  5. sortBy.index still has 3, pointing to wrong column
  6. Wrong column appears sorted

Expected Behaviour

Store the column ID instead of index, then derive the index from the current columns array on each render:

const [sortState, setSortState] = useState(() => getInitialSortState(columns));
const sortIndex = columns.findIndex((column) => column.id === sortState.id);
const sortBy: ISortBy = sortIndex >= 0 ? { index: sortIndex, direction: sortState.direction } : {};

Location

src/components/KuadrantDataView.tsx:170

Related

CodeRabbit comment in PR #734

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingtriage/acceptedReviewed, prioritised, and ready for work

Type

No type

Projects

  • Status
    Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions