Repository navigation
feat(ui): a host can activate a saved view and read the view list through the DataTable view API - #140
Closed
maxidragon wants to merge 2 commits into
Closed
feat(ui): a host can activate a saved view and read the view list through the DataTable view API#140maxidragon wants to merge 2 commits into
maxidragon wants to merge 2 commits into
Conversation
A host page that wants its own saved-view switcher (tabs above the table, say) instead of DataTable's built-in "Views" dropdown could not build one: the imperative view API had no way to activate a view, and the list of views stayed inside the component's query. Three additive members close the gap: - `DataTableViewApi.activatePerspective(id)` applies a personal or role view through the same path the built-in switcher takes; `null` clears to "No view", an unknown id is a no-op. - `DataTableViewApi.getPerspectives()` returns the personal views, role views and active view id (empty arrays while loading). - `DataTablePerspectiveConfig.onPerspectivesChange` pushes the same shape whenever the list or the active view changes, so the host switcher re-renders without polling. All three sit behind the `perspectives.use` check the built-in switcher uses: a user without it gets the empty state, even when the list was pre-seeded through `initialState.response`. The built-in dropdown and sidebar are unchanged.
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Required additions break the exported handle’s compatibility, and the documentation example omits role views.
Review effort: Balanced
Findings: 1
Open (2)
What changed in this PR
Adds host-controlled saved-view switching to DataTable.
Changes:
- Exposes perspective listing, activation, and change notifications.
- Adds coverage for activation and permission gating.
- Documents a custom tabs-based switcher.
| File | Description |
|---|---|
packages/ui/src/backend/DataTable.tsx |
Extends the perspective API. |
packages/ui/src/backend/__tests__/DataTable.perspectiveViewApi.test.tsx |
Tests the new API behavior. |
apps/docs/docs/framework/admin-ui/perspectives.mdx |
Documents custom view switchers. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
The example rendered only personal views, so copying it hid every role view even though activatePerspective switches both.
This comment has been minimized.
This comment has been minimized.
DS lint — 287 findings (+40 vs develop)
New findings
|
|
Found 4 test failures on Blacksmith runners: Failures
|
Author
|
CI failure is unrelated. I fixed it in #143, but looks like CI on |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Problem
A host page may want to render its own switcher for saved views, such as tabs above the table, instead of DataTable's built-in "Views" dropdown. DataTable already exposes an imperative handle for host-built controls (
viewApiRef→getCurrentSettings,getDirtyState,saveCurrentView,openViewsSidebar), but two pieces were missing:handlePerspectiveActivate→applyPerspectiveSettings) was internal.Without both, a host switcher can't be built. With both, it takes a few lines.
Solution
Three additive members. Nothing existing changes:
DataTableViewApi.activatePerspective(id: string | null)nullclears to "No view" like the dropdown's "All views" entry (empty settings, no active id). An unknown id is a no-op and doesn't throw.DataTableViewApi.getPerspectives(){ perspectives, rolePerspectives, activePerspectiveId }as the built-in switcher sees them. Empty arrays while the list loads.DataTablePerspectiveConfig.onPerspectivesChange(state)getPerspectives(). Fires with the same shape whenever the list or the active view changes, so a host switcher re-renders without polling.The state shape is exported as
DataTablePerspectivesState.All three use the same
perspectives.usegate as the built-in switcher. A user without the feature gets the empty state and a no-opactivatePerspective. This holds even when the list was pre-seeded throughinitialState.response.Compatibility
onPerspectivesChange. The handle gains two members, both required becauseDataTableViewApiis whatDataTablehands out and hosts only read it. The one kind of code this affects is a test that builds a stand-in handle by hand as aDataTableViewApiobject literal: it has to addactivatePerspectiveandgetPerspectives.apps/docs/docs/framework/admin-ui/perspectives.mdxgains a "Rendering your own view switcher" section with aTabsexample that renders personal and role views.Verification
packages/ui/src/backend/__tests__/DataTable.perspectiveViewApi.test.tsxhas 6 cases. The perspectives API is mocked through seeded query data, as in the existing view-API suites. The cases cover:filters,sortingandcolumnVisibility, asserted throughonFiltersApply,onSortingChangeandgetCurrentSettings()activatePerspective(null)clears to no viewgetPerspectives()reflects the response, andonPerspectivesChangefires on load and again after activationperspectives.usegets the empty state, and activation is a no-oponPerspectivesChangecases.npx jest src/backend/__tests__/DataTableinpackages/ui: 19 suites, 107 tests, all passing.yarn typecheck(packages/ui) is clean. ESLint shows no new findings on the changed files.Labels
needs-qabecause the change is underpackages/ui/src/, although nothing visible changes unless a host uses the new members.risk-lowbecause the change is purely additive and opt-in.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.