Skip to content

refac: pivot data store orchestration - #9538

Merged
djbarnwal merged 4 commits into
mainfrom
refac/simplify-pivot-data-store
Jun 12, 2026
Merged

refac: pivot data store orchestration#9538
djbarnwal merged 4 commits into
mainfrom
refac/simplify-pivot-data-store

Conversation

@djbarnwal

@djbarnwal djbarnwal commented Jun 9, 2026

Copy link
Copy Markdown
Member

Refactors the pivot data store internals to make the data flow easier to follow while preserving the existing PivotDataStore API.

  • Extracted pivot query planning into pivot-query-plan.ts
  • Extracted pivot data cache, row assembly, show-more, and final state helpers into pivot-data-assembly.ts
  • Simplified pivot-data-store.ts by replacing inline paging/sort/cache/final-state logic with named helpers
  • Added focused tests for the newly extracted pure helper behavior

Flattened nested derived stores in pivot-data-store.ts with two moves:

  1. A local derivedSwitch helper (~15 lines). It's like derived, but the callback can return either a plain PivotDataState or another store; a returned store is subscribed and its values forwarded (with proper cleanup, same as the old .subscribe(set) trick). This is essentially RxJS's switchMap for Svelte stores.
  2. Four named stage functions chained linearly instead of nested closures, matching the existing doc-comment diagram:
  • createColumnAxesStage — column headers, builds the query plan
  • createRowAxesStage — row skeleton, global + column totals
  • createCellDataStage — measure totals per row, cell data, column defs
  • createExpandedDataStage — expanded rows, final assembly

Checklist:

  • Covered by tests
  • Ran it and it works as intended
  • Reviewed the diff before requesting a review
  • Checked for unhandled edge cases
  • Linked the issues it closes
  • Checked if the docs need to be updated. If so, create a separate Linear DOCS issue
  • Intend to cherry-pick into the release branch
  • I'm proud of this work!

@AdityaHegde AdityaHegde left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Note that the pivot folder is growing. We should look into creating subfoders in a follow up. Claude's suggestion,

pivot/
  data/
    pivot-data-store.ts
    pivot-data-config.ts
    pivot-query-plan.ts
    pivot-data-assembly.ts
    pivot-queries.ts
    pivot-table-transformations.ts
    pivot-expansion.ts
    pivot-infinite-scroll.ts
  components/                     # all 25 .svelte files + regular-table-style.css
  table/                         # presentation logic for the grid
    pivot-column-definition.ts
    pivot-column-width-utils.ts
    pivot-cell-classes.ts
    regular-table-utils.ts
  selection/
    pivot-click-selection.ts
    pivot-row-selection.ts
    pivot-selection-indices.ts
    swapListener.ts
  time-pill/
    time-pill-store.ts
    time-pill-utils.ts
  pivot-utils.ts                  # stays at root: shared, imported widely
  pivot-constants.ts
  pivot-merge-filters.ts
  types.ts
  tests/                          # already exists; co-locate specs here

Comment thread web-common/src/features/dashboards/pivot/pivot-data-store.ts Outdated
);
let cellData = pivotSkeleton;
if (tableCellData !== null) {
if (tableCellData.isFetching) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is a behavioural change right? We will show a loading state while fetching data vs showing old data. Is it intended?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, this was unintended. Fixed now.

@djbarnwal
djbarnwal requested a review from AdityaHegde June 12, 2026 10:00
@djbarnwal
djbarnwal merged commit 5f8d687 into main Jun 12, 2026
16 of 17 checks passed
@djbarnwal
djbarnwal deleted the refac/simplify-pivot-data-store branch June 12, 2026 13:50
@nishantmonu51 nishantmonu51 mentioned this pull request Aug 9, 2026
8 tasks
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.

2 participants