feat(toolbar): redesign query result toolbar layout
This commit is contained in:
13 files changed
+592
-362
No files matched your search
@@ -1,25 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { nextResultToolbarLayout } from "@/lib/tabs/resultToolbarLayout";
|
||||
|
||||
describe("nextResultToolbarLayout", () => {
|
||||
it("never compacts fewer than two results", () => {
|
||||
expect(nextResultToolbarLayout({ resultCount: 1, compact: true, expandedRequiredWidth: 900, toolbarWidth: 700, tabsViewportWidth: 100, tabsContentWidth: 300 })).toEqual({ compact: false });
|
||||
});
|
||||
|
||||
it("keeps the expanded layout when tabs fit", () => {
|
||||
expect(nextResultToolbarLayout({ resultCount: 2, compact: false, toolbarWidth: 800, tabsViewportWidth: 300, tabsContentWidth: 300 })).toEqual({ compact: false });
|
||||
});
|
||||
|
||||
it("compacts on overflow and records the expanded width requirement", () => {
|
||||
expect(nextResultToolbarLayout({ resultCount: 3, compact: false, toolbarWidth: 800, tabsViewportWidth: 240, tabsContentWidth: 300 })).toEqual({ compact: true, expandedRequiredWidth: 860 });
|
||||
});
|
||||
|
||||
it("stays compact after compact controls remove the current overflow", () => {
|
||||
expect(nextResultToolbarLayout({ resultCount: 3, compact: true, expandedRequiredWidth: 860, toolbarWidth: 850, tabsViewportWidth: 320, tabsContentWidth: 300 })).toEqual({ compact: true, expandedRequiredWidth: 860 });
|
||||
});
|
||||
|
||||
it("expands only after the required width and hysteresis are available", () => {
|
||||
expect(nextResultToolbarLayout({ resultCount: 3, compact: true, expandedRequiredWidth: 860, toolbarWidth: 867, tabsViewportWidth: 337, tabsContentWidth: 300 })).toEqual({ compact: true, expandedRequiredWidth: 860 });
|
||||
expect(nextResultToolbarLayout({ resultCount: 3, compact: true, expandedRequiredWidth: 860, toolbarWidth: 868, tabsViewportWidth: 338, tabsContentWidth: 300 })).toEqual({ compact: false });
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,3 @@
|
||||
export const DATA_GRID_COMPACT_TOPBAR_WIDTH = 900;
|
||||
|
||||
export type DataGridReloadIntent = "refresh";
|
||||
@@ -1,35 +0,0 @@
|
||||
const OVERFLOW_TOLERANCE_PX = 1;
|
||||
const EXPAND_HYSTERESIS_PX = 8;
|
||||
|
||||
export interface ResultToolbarLayoutState {
|
||||
compact: boolean;
|
||||
expandedRequiredWidth?: number;
|
||||
}
|
||||
|
||||
export interface ResultToolbarLayoutInput extends ResultToolbarLayoutState {
|
||||
resultCount: number;
|
||||
toolbarWidth: number;
|
||||
tabsViewportWidth: number;
|
||||
tabsContentWidth: number;
|
||||
}
|
||||
|
||||
export function nextResultToolbarLayout(input: ResultToolbarLayoutInput): ResultToolbarLayoutState {
|
||||
if (input.resultCount < 2) return { compact: false };
|
||||
if (input.toolbarWidth <= 0 || input.tabsViewportWidth <= 0) {
|
||||
return { compact: input.compact, expandedRequiredWidth: input.expandedRequiredWidth };
|
||||
}
|
||||
|
||||
if (input.compact) {
|
||||
if (input.expandedRequiredWidth === undefined || input.toolbarWidth >= input.expandedRequiredWidth + EXPAND_HYSTERESIS_PX) {
|
||||
return { compact: false };
|
||||
}
|
||||
return { compact: true, expandedRequiredWidth: input.expandedRequiredWidth };
|
||||
}
|
||||
|
||||
const overflowWidth = input.tabsContentWidth - input.tabsViewportWidth;
|
||||
if (overflowWidth <= OVERFLOW_TOLERANCE_PX) return { compact: false };
|
||||
return {
|
||||
compact: true,
|
||||
expandedRequiredWidth: input.toolbarWidth + overflowWidth,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user