diff --git a/.changeset/late-days-fix.md b/.changeset/late-days-fix.md new file mode 100644 index 0000000000..f7660a2d4c --- /dev/null +++ b/.changeset/late-days-fix.md @@ -0,0 +1,6 @@ +--- +'@evidence-dev/core-components': patch +--- + +Enable changing column IDs in DataTable component. +See story /story/viz-datatable--reactive-datatable for an example diff --git a/packages/ui/core-components/sources/faker-demo-source/clients.yaml b/packages/ui/core-components/sources/faker-demo-source/clients.yaml new file mode 100644 index 0000000000..314c326fa0 --- /dev/null +++ b/packages/ui/core-components/sources/faker-demo-source/clients.yaml @@ -0,0 +1,7 @@ +rows: 20 +schema: + id: + type: id + client_name: + category: company + item: name \ No newline at end of file diff --git a/packages/ui/core-components/sources/faker-demo-source/monthly_revenues.yaml b/packages/ui/core-components/sources/faker-demo-source/monthly_revenues.yaml new file mode 100644 index 0000000000..252ebe538d --- /dev/null +++ b/packages/ui/core-components/sources/faker-demo-source/monthly_revenues.yaml @@ -0,0 +1,25 @@ +rows: 100 +schema: + client_id: + type: fk + withBias: true + target: + table: clients.yaml + year: + category: number + item: int + options: + - min: 2022 + max: 2025 + month: + category: number + item: int + options: + - min: 1 + max: 12 + revenue: + category: number + item: int + options: + - min: 1000 + max: 10000 diff --git a/packages/ui/core-components/src/lib/unsorted/viz/table/DataTable.stories.svelte b/packages/ui/core-components/src/lib/unsorted/viz/table/DataTable.stories.svelte index c9855a7f1e..0bc0581b73 100644 --- a/packages/ui/core-components/src/lib/unsorted/viz/table/DataTable.stories.svelte +++ b/packages/ui/core-components/src/lib/unsorted/viz/table/DataTable.stories.svelte @@ -32,6 +32,33 @@ @@ -365,91 +392,19 @@

AreaMap Error

- + { + const screen = within(canvasElement); + expect(await screen.findByRole('columnheader', { name: '2024-01' })).toBeInTheDocument(); + await userEvent.click(await screen.findByRole('button', { name: '2023' })); + expect(await screen.findByRole('columnheader', { name: '2023-01' })).toBeInTheDocument(); + }} +> + + + + + + + diff --git a/packages/ui/core-components/src/lib/unsorted/viz/table/_DataTable.svelte b/packages/ui/core-components/src/lib/unsorted/viz/table/_DataTable.svelte index 00ae99bfa2..73f5f8b266 100644 --- a/packages/ui/core-components/src/lib/unsorted/viz/table/_DataTable.svelte +++ b/packages/ui/core-components/src/lib/unsorted/viz/table/_DataTable.svelte @@ -478,11 +478,24 @@ let fullscreen = false; /** @type {number} */ let innerHeight; + + let synced = false; + + $: { + /* + A temporary solution to fix a synchronization issue with with these 2 pieces of state. + There must be a better way to handle this but it is difficult to reason about the various state updates + of this component due to the large number of props and reactive statements. + */ + let orderedColumnIds = orderedColumns.map((column) => column.id); + let columnSummaryIds = columnSummary.map((column) => column.id); + synced = orderedColumnIds.every((id) => columnSummaryIds.includes(id)); + } -{#if !isFullPage && innerHeight !== undefined} +{#if !isFullPage && innerHeight !== undefined && synced} {@const ROW_HEIGHT = compact ? 17.5 : 23} @@ -508,7 +521,7 @@ {/if} -{#if error === undefined} +{#if error === undefined && synced} {#each columnSummary as column} @@ -523,65 +536,84 @@ {/each} -
(hovering = true)} - on:mouseleave={() => (hovering = false)} - > - {#if search} - {}} /> - {/if} - -
- - - - - - - - - - {#if groupBy && groupedData && searchValue === ''} - {#each sortedGroupNames as groupName} - {#if groupType === 'accordion'} - - {#if groupToggleStates[groupName]} + {#key columnSummary} +
(hovering = true)} + on:mouseleave={() => (hovering = false)} + > + {#if search} + {}} /> + {/if} + +
+
- -
+ + + + + + + + + {#if groupBy && groupedData && searchValue === ''} + {#each sortedGroupNames as groupName} + {#if groupType === 'accordion'} + + {#if groupToggleStates[groupName]} + + {/if} + {:else if groupType === 'section'} + {#if subtotals} + + {/if} {/if} - {:else if groupType === 'section'} - - {#if subtotals} - - {/if} - {/if} - {/each} - {:else} - - {/if} + {/each} + {:else} + + {/if} + + {#if totalRow && searchValue === ''} + + {/if} + +
+ +
+
- {#if totalRow && searchValue === ''} - - {/if} - - -
+
No Results
-
No Results
- - {#if paginated && pageCount > 1} - + {:else} + + {/if} + + {/key} {#if generateMarkdown} {#if queryID}