Skip to content

Commit 24f3b5f

Browse files
committed
test: Add tests for containers, tabs, reordering, and grouping
54 tests: group always 1 tab, add tab creates 2nd, title syncs, delete to 1 keeps tab, fill-right positioning, section reorder.
1 parent 3279ca4 commit 24f3b5f

File tree

2 files changed

+539
-38
lines changed

2 files changed

+539
-38
lines changed

packages/app/src/DBDashboardPage.tsx

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ type MoveTarget = {
148148
containerId: string;
149149
tabId?: string;
150150
label: string;
151-
// For tabs: the group name shown as a section header in the menu
152-
groupLabel?: string;
151+
// For tabs: all tabs in order with the target tab ID
152+
allTabs?: { id: string; title: string }[];
153153
};
154154

155155
const tileToLayoutItem = (chart: Tile): RGL.Layout => ({
@@ -444,40 +444,51 @@ const Tile = forwardRef(
444444
(Ungrouped)
445445
</Menu.Item>
446446
)}
447-
{(() => {
448-
const filtered = moveTargets.filter(
447+
{moveTargets
448+
.filter(
449449
t =>
450450
!(
451451
t.containerId === chart.containerId &&
452452
t.tabId === chart.tabId
453453
),
454-
);
455-
let lastGroup: string | undefined;
456-
return filtered.map(t => {
457-
const items: React.ReactNode[] = [];
458-
// Add group header when entering a new tab group
459-
if (t.groupLabel && t.groupLabel !== lastGroup) {
460-
items.push(
461-
<Menu.Label key={`group-${t.containerId}`}>
462-
{t.groupLabel}
463-
</Menu.Label>,
464-
);
465-
lastGroup = t.groupLabel;
466-
} else if (!t.groupLabel) {
467-
lastGroup = undefined;
468-
}
469-
items.push(
470-
<Menu.Item
471-
key={`${t.containerId}-${t.tabId ?? ''}`}
472-
onClick={() => onMoveToSection(t.containerId, t.tabId)}
473-
style={t.groupLabel ? { paddingLeft: 24 } : undefined}
474-
>
475-
{t.label}
476-
</Menu.Item>,
477-
);
478-
return items;
479-
});
480-
})()}
454+
)
455+
.map(t => (
456+
<Menu.Item
457+
key={`${t.containerId}-${t.tabId ?? ''}`}
458+
onClick={() => onMoveToSection(t.containerId, t.tabId)}
459+
>
460+
{t.allTabs ? (
461+
<span>
462+
{t.allTabs.map((tab, i) => (
463+
<span key={tab.id}>
464+
{i > 0 && (
465+
<span
466+
style={{
467+
color: 'var(--mantine-color-dimmed)',
468+
}}
469+
>
470+
{' | '}
471+
</span>
472+
)}
473+
<span
474+
style={
475+
tab.id !== t.tabId
476+
? {
477+
color: 'var(--mantine-color-dimmed)',
478+
}
479+
: undefined
480+
}
481+
>
482+
{tab.title}
483+
</span>
484+
</span>
485+
))}
486+
</span>
487+
) : (
488+
t.label
489+
)}
490+
</Menu.Item>
491+
))}
481492
</Menu.Dropdown>
482493
</Menu>
483494
)}
@@ -1231,13 +1242,12 @@ function DBDashboardPage({ presetConfig }: { presetConfig?: Dashboard }) {
12311242
for (const c of sections) {
12321243
const cTabs = c.tabs ?? [];
12331244
if (c.type === 'group' && cTabs.length >= 2) {
1234-
const groupLabel = cTabs[0]?.title ?? c.title;
12351245
for (const tab of cTabs) {
12361246
targets.push({
12371247
containerId: c.id,
12381248
tabId: tab.id,
12391249
label: tab.title,
1240-
groupLabel,
1250+
allTabs: cTabs.map(t => ({ id: t.id, title: t.title })),
12411251
});
12421252
}
12431253
} else if (c.type === 'group' && cTabs.length === 1) {

0 commit comments

Comments
 (0)