Skip to content

feat: improve chart builder tab management UX#8957

Merged
mscolnick merged 1 commit intomainfrom
kg/datatable-chart-builder-tabs
Apr 1, 2026
Merged

feat: improve chart builder tab management UX#8957
mscolnick merged 1 commit intomainfrom
kg/datatable-chart-builder-tabs

Conversation

@kirangadhave
Copy link
Copy Markdown
Contributor

📝 Summary

  • When chart builder is opened and there are no existing charts, automatically create one and switch to that tab
  • When last chart is closed, auto-close the chart builder
  • when active tab is closed, switch to the tab to the right (standard behavior for tabs).
    • Currently we jump to the table tab everytime we close any chart tab
  • fix bugs with tab naming
    • if we closed a tab, the next created tab would have duplicate name
    • switched to monotonically increasing counter for tab names

Before:

Screen.Recording.2026-03-31.at.5.48.26.PM.mov

After:

Screen.Recording.2026-03-31.at.5.49.07.PM.mov

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Apr 1, 2026 0:51am

Request Review

@kirangadhave kirangadhave added the enhancement New feature or request label Apr 1, 2026
@mscolnick mscolnick requested a review from Copilot April 1, 2026 00:58
@mscolnick mscolnick merged commit bcd48ab into main Apr 1, 2026
31 of 32 checks passed
@mscolnick mscolnick deleted the kg/datatable-chart-builder-tabs branch April 1, 2026 01:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves the DataTable chart builder’s tab UX by making tab creation/selection/closure behavior more consistent and by attempting to prevent duplicate tab names.

Changes:

  • Passes an onCloseChartBuilder callback from DataTablePlugin into the chart builder panel.
  • Updates chart tab creation/deletion logic to auto-create an initial chart tab on open, close the chart builder when the last chart tab is removed, and choose the next active tab more like standard tab UIs.
  • Replaces the old “tab number” naming mechanism with a counter-based approach intended to avoid duplicate tab names.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
frontend/src/plugins/impl/DataTablePlugin.tsx Wires onCloseChartBuilder so the chart builder can be programmatically closed when appropriate.
frontend/src/components/data-table/charts/charts.tsx Implements new chart tab lifecycle behavior (auto-create, delete behavior, tab naming counter).

Comment on lines +87 to +103
// Auto-create a default chart tab when chart builder opens with no tabs
if (
displayHeader &&
!prevDisplayHeader.current &&
tabs.length === 0 &&
cellId
) {
prevDisplayHeader.current = displayHeader;
const tabName = getChartTabName(0, NEW_CHART_TYPE);
const newTabs = new Map(tabsMap);
newTabs.set(cellId, [
{ tabName, chartType: NEW_CHART_TYPE, config: getChartDefaults() },
]);
saveTabsMap(newTabs);
setTabCounter(1);
setSelectedTab(tabName);
}
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

The auto-create logic runs during render and calls saveTabsMap, setTabCounter, and setSelectedTab. Updating Jotai/React state during render is unsafe (can break under React 18 concurrent rendering / StrictMode and may trigger render-loop warnings). Move this into a useEffect that runs on the displayHeader transition (closed → open) and only then create the default tab + update selection/counter.

Copilot uses AI. Check for mistakes.
Comment on lines 83 to +85
const [selectedTab, setSelectedTab] = useState(DEFAULT_TAB_NAME);
const [tabCounter, setTabCounter] = useState(tabs.length);
const prevDisplayHeader = useRef(displayHeader);
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

Initializing tabCounter with tabs.length does not guarantee unique/monotonically increasing tab names after deletions. Example: if only "Bar Chart 2" remains, tabs.length is 1 so the next add will again produce "Bar Chart 2". Consider deriving the next counter from existing tab names (e.g., max parsed index + 1) or persisting a per-cell monotonic counter in storage so names never collide.

Copilot uses AI. Check for mistakes.
VishakBaddur pushed a commit to VishakBaddur/marimo that referenced this pull request Apr 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants