kgabryje opened a new pull request, #40334:
URL: https://github.com/apache/superset/pull/40334

   ### SUMMARY
   
   Adds the production frontend for the Versioning epic 
([sc-103156](https://app.shortcut.com/preset/story/103156)) on top of Mike's 
backend in #39603. Implements the "View version history" experience on 
**Explore** (chart edit page) and **Dashboard** view per the [Figma 
designs](https://www.figma.com/design/xZj5lRx0gC9HPt3e9RskxL/Version-History?node-id=2202-2688).
 Gated behind a new `VERSION_HISTORY` feature flag (default `False`).
   
   🚧 **Draft — stacks on #39603.** The diff currently shows both #39603's 
backend commits and this PR's 11 commits. Once #39603 merges, I'll rebase this 
branch onto master and the diff will reduce to only the frontend changes (+3006 
/ -20 lines, 45 files in `superset-frontend/` plus the feature-flag entry in 
`superset/config.py`).
   
   **What this PR adds:**
   
   - **Shared primitives** under 
`superset-frontend/src/features/versionHistory/`:
     - `VersionHistoryPanel` — right-side Drawer with version list, search, 
date-grouped sections
     - `PreviewBanner` — top banner shown while previewing a historical 
version, with Close / Open as new / Restore actions
     - `RestoreConfirmModal` — destructive-action confirmation
     - Hooks: `useVersionList`, `useVersionSnapshot`, `useRestoreVersion`
     - Two React contexts: `VersionHistoryContext` (panel/preview state, URL 
roundtrip via `?version_uuid=`) and `ChartPreviewContext` (chart shadow-render)
     - Utils: `summarizeChange`, `formatChangeTitle`, `groupVersionsByDate`, 
`snapshotToFormData`, `forkActions` — change-formatting logic ported from 
Mike's demo dropdown
   - **Explore wiring**:
     - "View version history" menu item in the chart actions menu, gated on the 
feature flag, disabled when `hasUnsavedChanges` with tooltip "Exit edit mode to 
view version history"
     - Chart shadow-renders snapshot `form_data` via `ChartPreviewContext` 
during preview — no Redux mutation
     - Save button disabled while previewing
     - "Open as new chart" hydrates the snapshot into `form_data` and POSTs a 
new chart with name pattern `{original} (copy from {date})`
   - **Dashboard wiring**:
     - "View version history" menu item at the bottom of the dashboard actions 
menu, gated on the flag, disabled in edit mode
     - Inline preview via the **captured-original** Redux pattern: 
`ENTER_VERSION_PREVIEW` / `EXIT_VERSION_PREVIEW` actions, three reducers 
extended (`dashboardState`, `sliceEntities`, `dashboardLayout`), 
`undoableDashboardLayout.TRACKED_ACTIONS` updated. Enter captures live 
`sliceEntities` + `dashboardLayout` into `dashboardState.versionPreview` and 
swaps in the snapshot's `slices` + parsed `position_json`; exit restores the 
captured originals. No refetch.
     - `DashboardPreviewBanner` mounts above `DashboardGrid` in 
`DashboardContainer.tsx`
     - "Open as new dashboard" POSTs to `/api/v1/dashboard/` with the 
snapshot's fields
   - **Feature flag** `VERSION_HISTORY` added to `superset/config.py` 
`DEFAULT_FEATURE_FLAGS` (default `False`), the frontend `FeatureFlag` enum, and 
`docs/static/feature-flags.json`.
   
   **What is NOT in this PR** (deferred to follow-up tickets):
   
   - **Datasets** — the backend exposes the same endpoints for datasets, but 
the UI is scoped to Explore + Dashboard for V1.
   - **AI attribution UI** — the backend `changed_by` is rendered as the user 
name; the "AI" tag for chatbot-authored versions is deferred until the 
chatbot's identity in `changed_by.username` is stable.
   - **Tags / owners / roles in restore** — backend leaves these at their live 
values per spec; no UI surface needed.
   - **Per-chart position inside a dashboard** — `position_json` is versioned 
as an opaque blob (restored wholesale on dashboard restore); finer-grained 
layout versioning is Phase 2.
   - **Diff-content search** — search box filters version *titles*, not the 
full structured diff payload.
   - **Open question (worth a comment thread)**: dashboard fork uses `POST 
/api/v1/dashboard/` and the resulting forked dashboard's `position_json` 
references the *live* charts at those IDs, not snapshot-state copies of those 
charts. This matches "Open as new" semantics elsewhere in Superset and is what 
the design intent suggests; flagging here in case a fully-isolated snapshot 
fork is preferred.
   
   ### BEFORE/AFTER SCREENSHOTS
   
   _To attach after stack-base settles. Figma source of truth: [Version 
History](https://www.figma.com/design/xZj5lRx0gC9HPt3e9RskxL/Version-History?node-id=2202-2688)._
   
   ### TESTING INSTRUCTIONS
   
   Enable the flag and seed history against #39603's endpoints. The plan below 
assumes Mike's backend branch is checked out.
   
   1. **Enable the feature flag** in `superset_config.py`:
   ```python
   FEATURE_FLAGS = {"VERSION_HISTORY": True}
   ```
   
   2. **Chart preview + restore**:
      - Open any chart in Explore. Make 3 edits and Save 3 times to seed 
version history.
      - Click the three-dot menu → `View version history`. Right-side panel 
opens listing versions newest-first, with author + timestamp.
      - Click a version row → preview banner appears at the top, chart 
re-renders the historical `form_data`, Save button is disabled.
      - Click `Restore this version` → confirm modal → success toast → panel 
refreshes with the restore as the new latest version.
      - With preview open, copy the URL, paste in new tab → preview reopens on 
the same version (URL roundtrip).
   
   3. **Chart fork (Open as new chart)**:
      - Open the panel, click the three-dot menu on any version row → `Open as 
new chart`.
      - New chart created with name `{original} (copy from {YYYY-MM-DD})`. 
Success toast. Navigates to the new chart's explore URL.
   
   4. **Dashboard preview + restore**:
      - Open any dashboard. Make changes via edit mode, save, repeat to seed.
      - Three-dot menu → `View version history`. Panel opens. (In edit mode the 
menu item is disabled with a tooltip.)
      - Click a version row → grid re-renders the historical layout + slice 
data via the captured-original swap; banner appears above the grid.
      - `Close preview` → grid restores to live state.
      - `Restore this version` → confirm modal → success → page reflects the 
restored state.
   
   5. **Dashboard fork (Open as new dashboard)**:
      - Panel → three-dot menu on a version → `Open as new dashboard`. New 
dashboard created with snapshot's layout. Navigate.
   
   6. **Feature flag off**: disable `VERSION_HISTORY` → menu items vanish, 
panels do not mount, no console errors.
   
   7. **Tests**:
   ```bash
   cd superset-frontend
   npm run type
   npm test -- src/features/versionHistory
   npm test -- src/dashboard/reducers
   ```
   
   ### ADDITIONAL INFORMATION
   
   - [x] Has associated issue: 
[sc-103156](https://app.shortcut.com/preset/story/103156)
   - [x] Required feature flags: `VERSION_HISTORY` (added in this PR)
   - [x] Changes UI
   - [ ] Includes DB Migration
   - [ ] Introduces new feature or API _(introduces new feature; consumes APIs 
from #39603)_
   - [ ] Removes existing feature or API
   
   **Depends on:** #39603 (backend versioning endpoints)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to