diff --git a/changelog.d/fixed-collaborate-sidebar-group-order.md b/changelog.d/fixed-collaborate-sidebar-group-order.md new file mode 100644 index 0000000000..ec0624f8cc --- /dev/null +++ b/changelog.d/fixed-collaborate-sidebar-group-order.md @@ -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. diff --git a/dashboard/test/sidebar-collaborate-group.test.js b/dashboard/test/sidebar-collaborate-group.test.js new file mode 100644 index 0000000000..d7883d1e54 --- /dev/null +++ b/dashboard/test/sidebar-collaborate-group.test.js @@ -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('