Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/fixed-collaborate-sidebar-group-order.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Dashboard: the Collaborate sidebar group (Inbox, Calendar, Meetings, Inception (spek)) no longer disappears into the Dashboard group when the section layout is applied, and now sits right after Dashboard, before Agents.
209 changes: 209 additions & 0 deletions dashboard/test/sidebar-collaborate-group.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
'use strict';

// The Collaborate sidebar group (Inbox, Calendar, Meetings, Inception (spek))
// must survive the dashboard layout sidebar sort. Those sections are in
// DASHBOARD_LAYOUT_TEMPLATE (so their cards get layout padding, collapse
// defaults and ordering), and dashboardSortSidebar used to re-home every
// layout-listed nav link into #dashboard-section-nav-group, which emptied and
// hid Collaborate. This test renders the real sidebar markup and the real
// layout functions from the generated page, applies a saved layout that puts
// the Collaborate sections first, and checks the group keeps its links, in
// order, right after Dashboard and before Agents.
const { test } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');

const indexHtml = fs.readFileSync(path.join(__dirname, '..', '..', 'src', 'pkg', 'dashboard', 'static', 'index.html'), 'utf8');

const DASHBOARD_GROUP_ID = 'dashboard-section-nav-group';
const AGENT_GROUP_ID = 'oc-agent-nav-group';
const COLLABORATE_LABEL = 'Collaborate';
const COLLABORATE_LINKS = ['Inbox', 'Calendar', 'Meetings', 'Inception (spek)'];
const COLLABORATE_SECTIONS = ['inbox-section', 'calendar-section', 'meetings-section', 'sessions-section'];
const LAYOUT_KEY = 'hive.dashboard.layout';

function extractFunction(name) {
const start = indexHtml.indexOf('function ' + name + '(');
assert.notEqual(start, -1, `${name} function exists`);
const brace = indexHtml.indexOf('{', start);
let depth = 0;
for (let i = brace; i < indexHtml.length; i++) {
const ch = indexHtml[i];
if (ch === '{') depth++;
if (ch === '}') depth--;
if (depth === 0) return indexHtml.slice(start, i + 1);
}
throw new Error(`unterminated ${name}`);
}

function extractVar(name) {
const m = new RegExp('var ' + name + '=[^;]+;').exec(indexHtml);
assert.ok(m, `${name} var exists`);
return m[0];
}

// Minimal element model: enough DOM for the sidebar sort/drag helpers.
class El {
constructor(attrs) {
this.attrs = Object.assign({}, attrs);
this.children = [];
this.parentElement = null;
this.hidden = 'hidden' in this.attrs;
this.textContent = this.attrs._text || '';
this.dataset = {};
}
get id() { return this.attrs.id || ''; }
hasClass(c) { return (this.attrs.class || '').split(/\s+/).includes(c); }
getAttribute(n) { return n in this.attrs ? this.attrs[n] : null; }
setAttribute(n, v) { this.attrs[n] = String(v); }
removeAttribute(n) { delete this.attrs[n]; }
appendChild(ch) {
if (ch.parentElement) ch.parentElement.children = ch.parentElement.children.filter((x) => x !== ch);
ch.parentElement = this;
this.children.push(ch);
return ch;
}
descendants() { return this.children.flatMap((c) => [c, ...c.descendants()]); }
closest(sel) {
assert.equal(sel, '.oc-nav-group', `unexpected closest(${sel})`);
for (let el = this; el; el = el.parentElement) if (el.hasClass('oc-nav-group')) return el;
return null;
}
querySelectorAll(sel) {
if (sel === '.oc-nav-item') return this.descendants().filter((e) => e.hasClass('oc-nav-item'));
if (sel === ':scope > [data-dashboard-section]') return this.children.filter((c) => c.attrs['data-dashboard-section']);
throw new Error(`unexpected querySelectorAll(${sel})`);
}
querySelector() { return null; }
}

function parseAttrs(s) {
const out = {};
for (const m of s.matchAll(/([\w-]+)(?:="([^"]*)")?/g)) out[m[1]] = m[2] === undefined ? '' : m[2];
return out;
}

// Build the sidebar tree from the generated page: every .oc-nav-group in
// source order, its heading, and its .oc-nav-item links.
function buildSidebar() {
const navStart = indexHtml.indexOf('<nav id="oc-sidebar"');
assert.notEqual(navStart, -1, 'sidebar nav exists');
const nav = indexHtml.slice(navStart, indexHtml.indexOf('</nav>', navStart));
const sidebar = new El({ id: 'oc-sidebar' });
const starts = [...nav.matchAll(/<div class="oc-nav-group"([^>]*)>/g)];
assert.ok(starts.length > 0, 'sidebar has nav groups');
starts.forEach((m, i) => {
const seg = nav.slice(m.index, i + 1 < starts.length ? starts[i + 1].index : nav.length);
const group = sidebar.appendChild(new El(Object.assign({ class: 'oc-nav-group' }, parseAttrs(m[1]))));
const label = /<div class="oc-nav-label">([^<]+)</.exec(seg) || /oc-tree-arrow">[^<]*<\/span>\s*<span>([^<]+)</.exec(seg);
group.label = label ? label[1].trim() : '';
for (const a of seg.matchAll(/<a ([^>]*class="oc-nav-item[^"]*"[^>]*)>([\s\S]*?)<\/a>/g)) {
const text = /<span class="oc-nav-text">([^<]*)</.exec(a[2]);
group.appendChild(new El(Object.assign(parseAttrs(a[1]), { _text: text ? text[1] : '' })));
}
});
return sidebar;
}

function makeContext({ saved, sessionsEnabled }) {
const sidebar = buildSidebar();
const store = {};
if (saved) store[LAYOUT_KEY] = JSON.stringify(saved);
const root = new El({ id: 'hive-dashboard-root' });
const all = () => sidebar.descendants();
const ctx = {
window: { _lastStatus: { features: { experiment_lab: true } }, _sessionsEnabled: sessionsEnabled },
localStorage: {
getItem: (k) => (k in store ? store[k] : null),
setItem: (k, v) => { store[k] = String(v); },
removeItem: (k) => { delete store[k]; },
},
document: {
getElementById: (id) => (id === root.id ? root : all().find((e) => e.id === id) || null),
querySelectorAll: (sel) => {
if (sel === '.oc-nav-item[data-section]') return all().filter((e) => e.hasClass('oc-nav-item') && e.attrs['data-section']);
if (sel === '.oc-nav-group') return sidebar.children;
throw new Error(`unexpected document.querySelectorAll(${sel})`);
},
},
dashboardRegionEl: () => root,
dashboardEnsureSidebarHandles: () => {},
sidebar,
root,
};
vm.createContext(ctx);
const src = [
extractVar('DASHBOARD_LAYOUT_VERSION'),
extractVar('DASHBOARD_LAYOUT_TEMPLATE'),
extractVar('DASHBOARD_LAYOUT_CARD_SELECTOR'),
extractVar('DASHBOARD_LAYOUT_KEY'),
extractVar('DASHBOARD_SIDEBAR_HOME_ID'),
...['dashboardAliasSectionId', 'dashboardFeatureEnabled', 'experimentLabEnabled', 'sessionsFeatureEnabled',
'dashboardFeatureSectionHidden', 'dashboardLayoutAllIds', 'dashboardLayoutNormalize', 'dashboardLayoutRead',
'dashboardLayoutCurrent', 'dashboardSidebarLayoutItems', 'dashboardSidebarItemInOwnGroup',
'dashboardSidebarNavItems', 'dashboardSidebarLayoutFromDom', 'dashboardSortSidebar'].map(extractFunction),
].join('\n');
vm.runInContext(src, ctx);
// Lay the main-page cards out the way dashboardApplyLayout would for the saved layout.
const order = vm.runInContext('dashboardLayoutNormalize(dashboardLayoutRead()).main', ctx);
order.forEach((id) => root.appendChild(new El({ id, 'data-dashboard-section': id })));
return ctx;
}

function groupByLabel(ctx, label) { return ctx.sidebar.children.find((g) => g.label === label); }
function linkTexts(group) { return group.querySelectorAll('.oc-nav-item').map((e) => e.textContent); }

const SAVED_COLLABORATE_FIRST = { v: 1, main: [...COLLABORATE_SECTIONS, 'overview-section', 'governor', 'pr-throughput-section'] };

for (const sessionsEnabled of [true, false]) {
test(`Collaborate keeps Inbox, Calendar, Meetings, Inception (spek) after the sidebar sort (sessions ${sessionsEnabled ? 'on' : 'off'})`, () => {
const ctx = makeContext({ saved: SAVED_COLLABORATE_FIRST, sessionsEnabled });
const layout = vm.runInContext('DASHBOARD_LAYOUT_TEMPLATE.main', ctx);
for (const id of COLLABORATE_SECTIONS) assert.ok(layout.includes(id), `${id} is still a layout section`);

vm.runInContext('dashboardSortSidebar()', ctx);

const collaborate = groupByLabel(ctx, COLLABORATE_LABEL);
assert.ok(collaborate, 'Collaborate heading exists');
assert.equal(collaborate.hidden, false, 'Collaborate group is visible');
assert.deepEqual(linkTexts(collaborate), COLLABORATE_LINKS);

const dashboard = ctx.document.getElementById(DASHBOARD_GROUP_ID);
const inDashboard = dashboard.querySelectorAll('.oc-nav-item').map((e) => e.getAttribute('data-section'));
for (const id of COLLABORATE_SECTIONS) assert.ok(!inDashboard.includes(id), `${id} is not in the Dashboard group`);
// Links authored in the Dashboard group are still sorted by the saved layout.
assert.deepEqual(inDashboard, ['overview-section', 'governor', 'pr-throughput-section', 'activity-monitor-section']);
});
}

test('sidebar group order is Dashboard, Collaborate, Agents, Resources, Intelligence, Admin, Help', () => {
const ctx = makeContext({ saved: null, sessionsEnabled: true });
vm.runInContext('dashboardSortSidebar()', ctx);
const groups = ctx.sidebar.children;
const dash = groups.findIndex((g) => g.id === DASHBOARD_GROUP_ID);
const collab = groups.findIndex((g) => g.label === COLLABORATE_LABEL);
const agents = groups.findIndex((g) => g.id === AGENT_GROUP_ID);
assert.equal(dash, 0, 'Dashboard is the first group');
assert.equal(collab, dash + 1, 'Collaborate comes right after Dashboard');
assert.equal(agents, collab + 1, 'Agents comes right after Collaborate');
assert.deepEqual(groups.map((g) => g.label).filter((l) => l !== 'Filters'),
['Dashboard', 'Collaborate', 'Agents', 'Resources', 'Intelligence', 'Admin', 'Help']);
});

test('reordering Dashboard links from the sidebar keeps Collaborate sections where the layout had them', () => {
const ctx = makeContext({ saved: SAVED_COLLABORATE_FIRST, sessionsEnabled: true });
vm.runInContext('dashboardSortSidebar()', ctx);
const dashboard = ctx.document.getElementById(DASHBOARD_GROUP_ID);
// Move Governor to the top of the Dashboard group, as a drag would.
const governor = dashboard.children.find((e) => e.getAttribute('data-section') === 'governor');
dashboard.children = [governor, ...dashboard.children.filter((e) => e !== governor)];
const before = [...vm.runInContext('dashboardLayoutNormalize(dashboardLayoutCurrent()).main', ctx)];
const main = [...vm.runInContext('dashboardSidebarLayoutFromDom().main', ctx)];
// Governor and Overview trade slots; every other section, Collaborate included, keeps its place.
const want = before.map((id) => (id === 'governor' ? 'overview-section' : id === 'overview-section' ? 'governor' : id));
assert.deepEqual(main, want);
for (const id of COLLABORATE_SECTIONS) assert.equal(main.indexOf(id), before.indexOf(id), `${id} keeps its layout position`);
assert.equal(new Set(main).size, main.length, 'no duplicate sections');
});
2 changes: 1 addition & 1 deletion src/docs/dashboard-design-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -491,9 +491,9 @@ Sidebar groups now map the existing destinations without changing IDs, `data-act
| Group | Items |
| --- | --- |
| Overview | Governor |
| Collaborate | Inbox, Calendar, Meetings, Inception (spek) |
| Agents | Dynamic agent tree, `+ agent`, `+ group` |
| Resources | Repos, Contributors |
| Collaborate | Inbox, Calendar, Meetings, Inception (spek) |
| Intelligence | Advisory, ACMM Eval, Knowledge, Experiment Lab |
| Admin | Tokens, Cost, Audit Log |
| Help | FAQ, Getting Started, API Spec (Redoc), Getting Started Guide, Report an Issue |
Expand Down
4 changes: 2 additions & 2 deletions src/docs/dashboard-glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ The operator sidebar keeps the existing destinations, IDs, `data-action` handler
| Group | Items |
| --- | --- |
| Dashboard | Overview, Governor, Throughput |
| Collaborate | Inbox, Calendar, Meetings, Inception (spek) |
| Agents | Dynamic agent tree, `+ Add agent`, `+ Group` |
| Resources | Projects, Contributors |
| Collaborate | Inbox, Calendar, Meetings, Inception (spek) |
| Intelligence | Advisory, ACMM Eval, Knowledge, Experiment Lab |
| Admin | Tokens, Cost, Review, Agents, Agent activity, Audit Log, Diagnostics |
| Help | FAQ, Getting Started, API Spec (Redoc), Getting Started Guide, Join our Discord, Report an Issue |

On the v6 line the sidebar also lists Runs and Platform. Sections hidden by the ACMM level or a feature setting are hidden from the sidebar too.
Links stay in the group they are listed under here: reordering Dashboard sections (the sidebar grip or a saved layout) only reorders the Dashboard group, never moves a Collaborate, Resources, Intelligence, Admin or Help link into it. On the v6 line the sidebar also lists Runs and Platform. Sections hidden by the ACMM level or a feature setting are hidden from the sidebar too.

Count badges use the shared `.badge-count` recipe. Zero counts render as dimmed `0` badges with `data-zero`.

Expand Down
10 changes: 7 additions & 3 deletions src/pkg/dashboard/dashboard_section_reorder_9062_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var DASHBOARD_LAYOUT_REGIONS=['main'];
var ` + dashboardDefaultLayoutTemplate9062 + `;
var DASHBOARD_LAYOUT_GRIP_SELECTOR='[data-dashboard-grip]';
var DASHBOARD_LAYOUT_CARD_SELECTOR='[data-dashboard-section]';
var DASHBOARD_SIDEBAR_HOME_ID='dashboard-section-nav-group';
var DASHBOARD_LAYOUT_ANCHOR_ID='dash-notices';
var DASHBOARD_LAYOUT_PRESETS_KEY='hive.layout.presets';
var DASHBOARD_LAYOUT_APPLIED_KEY='hive.layout.applied';
Expand Down Expand Up @@ -199,7 +200,7 @@ func TestDashboardApplyResetAndSidebarSort(t *testing.T) {
t.Skip("node not on PATH — dashboard layout apply/sidebar behavior was NOT executed by this run")
}
html := indexHTML(t)
funcs := []string{"dashboardCanHideSection", "dashboardHiddenSectionsRead", "dashboardHiddenSectionsWrite", "dashboardSectionHidden", "dashboardApplyHiddenSections", "dashboardEnsureSections", "dashboardRegionEl", "dashboardCardEl", "dashboardLayoutAnnounce", "dashboardLayoutAllIds", "dashboardLayoutNormalize", "dashboardLayoutCurrent", "dashboardLayoutEquals", "dashboardLayoutExtraKeys", "dashboardLayoutSnapshot", "dashboardNormalizeSnapshot", "dashboardSnapshotEquals", "dashboardLayoutDefaultSnapshot", "dashboardReadLayoutPresets", "dashboardWriteLayoutPresets", "dashboardReadAppliedLayout", "dashboardMarkAppliedLayout", "dashboardRenderLayoutPresets", "dashboardUpdateLayoutMenuState", "dashboardUpdateResetButton", "dashboardLayoutWrite", "dashboardIsSectionNode", "dashboardTopAnchor", "dashboardPinNoticeAnchor", "dashboardFirstSection", "dashboardInsertSection", "dashboardApplyLayout", "dashboardSidebarNavItems", "dashboardSortSidebar", "resetDashboardLayout"}
funcs := []string{"dashboardCanHideSection", "dashboardHiddenSectionsRead", "dashboardHiddenSectionsWrite", "dashboardSectionHidden", "dashboardApplyHiddenSections", "dashboardEnsureSections", "dashboardRegionEl", "dashboardCardEl", "dashboardLayoutAnnounce", "dashboardLayoutAllIds", "dashboardLayoutNormalize", "dashboardLayoutCurrent", "dashboardLayoutEquals", "dashboardLayoutExtraKeys", "dashboardLayoutSnapshot", "dashboardNormalizeSnapshot", "dashboardSnapshotEquals", "dashboardLayoutDefaultSnapshot", "dashboardReadLayoutPresets", "dashboardWriteLayoutPresets", "dashboardReadAppliedLayout", "dashboardMarkAppliedLayout", "dashboardRenderLayoutPresets", "dashboardUpdateLayoutMenuState", "dashboardUpdateResetButton", "dashboardLayoutWrite", "dashboardIsSectionNode", "dashboardTopAnchor", "dashboardPinNoticeAnchor", "dashboardFirstSection", "dashboardInsertSection", "dashboardApplyLayout", "dashboardSidebarLayoutItems", "dashboardSidebarItemInOwnGroup", "dashboardSidebarNavItems", "dashboardSortSidebar", "resetDashboardLayout"}
var b strings.Builder
b.WriteString(dashboardLayoutPreamble9062())
b.WriteString(`
Expand Down Expand Up @@ -251,8 +252,11 @@ dashboardApplyLayout(dashboardLayoutNormalize({v:2, main:['faq-section','governo
let first = root.querySelectorAll(':scope > '+DASHBOARD_LAYOUT_CARD_SELECTOR).slice(0,4).map(e => e.getAttribute('data-dashboard-section')).join(',');
if (first !== 'faq-section,overview-section,governor,pr-throughput-section') throw new Error('page order '+first);
let nav = navGroup.children.map(e => e.getAttribute('data-section')).join(',');
if (nav !== 'faq-section,overview-section,governor,pr-throughput-section') throw new Error('sidebar order '+nav);
if (oldGroup.hidden !== true) throw new Error('empty old nav group not hidden');
if (nav !== 'faq-section,governor') throw new Error('sidebar order '+nav);
// Links authored in another named sidebar group stay there (Collaborate fix).
let own = oldGroup.children.map(e => e.getAttribute('data-section')).join(',');
if (own !== 'overview-section,pr-throughput-section') throw new Error('named group links moved: '+own);
if (oldGroup.hidden === true) throw new Error('named nav group with its own links hidden');
if (helpGroup.hidden === true) throw new Error('non-section help group hidden');
dashboardLayoutWrite();
if (JSON.parse(localStorage.data[DASHBOARD_LAYOUT_KEY]).main[0] !== 'faq-section') throw new Error('layout not written');
Expand Down
Loading
Loading