Skip to content

armgit / xerj

Public Imported from GitHub
0

AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.

fix(playground): resolve custom dashboard templates consistently (#2088, from #2072)

xerj-org174ba6510110
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 52ce83de6..731d33286 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -26,6 +26,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
+- Playground user dashboards resolve their inherited template for chart data
+ and panel editing. Cloning a user dashboard retains the underlying template;
+ missing or cyclic template references keep the blank fallback. Custom
+ dashboard layout overrides also survive reloading the page.
+
- `xerj search` and a plain-string `xerj_search` rank a file that contains
the query as an exact phrase (a pasted error message or log line) at the
top. The bag-of-words leg alone let a short `defs` list sharing two of the
diff --git a/landing/playground/app.bundle.js b/landing/playground/app.bundle.js
index 310d930f7..ea2ce788d 100644
--- a/landing/playground/app.bundle.js
+++ b/landing/playground/app.bundle.js
@@ -3486,7 +3486,7 @@ When the engine grows a \`/v1/users/me\` endpoint, this store syncs up.`
(byGroup[g] = byGroup[g] || []).push(d);
}
const activeDashObj = dashboards.find((d) => d.id === activeDash);
- const activeGroup = activeDashObj?.group || (groups[0]?.id || "other");
+ const activeGroup = activeDashObj ? activeDashObj.group || "other" : groups[0]?.id || "other";
const orderedGroups = [];
const seen = /* @__PURE__ */ new Set();
for (const g of groups) {
@@ -5121,13 +5121,19 @@ borrows the accent color.`
hidden: hidden.has(id)
});
} else if (user) {
- const source = user.clonedFrom ? byId[user.clonedFrom] : null;
+ let templateId = user.clonedFrom;
+ const visited = /* @__PURE__ */ new Set([id]);
+ while (templateId && custom[templateId] && !visited.has(templateId)) {
+ visited.add(templateId);
+ templateId = custom[templateId].clonedFrom;
+ }
+ const source = templateId ? byId[templateId] : null;
out.push({
id,
name: names[id] || user.name,
render: source?.render || blankRender(user.name),
isUser: true,
- clonedFrom: user.clonedFrom,
+ clonedFrom: source ? source.id : user.clonedFrom,
dataSource: user.dataSource,
hidden: hidden.has(id)
});
@@ -5575,7 +5581,7 @@ borrows the accent color.`
}
function loadAllLayouts() {
const out = {};
- for (const id of Object.keys(registry)) {
+ for (const { id } of mergedDashboards(defaults, { includeHidden: true })) {
try {
const raw = localStorage.getItem(LS.layout(id));
if (raw) out[id] = JSON.parse(raw);
@@ -5650,6 +5656,9 @@ borrows the accent color.`
fn(ov);
saveLayout(dashId);
}
+ function editableDashboard(id) {
+ return mergedDashboards(defaults, { includeHidden: true }).find((d) => d.id === id);
+ }
var SIZES = [2, 3, 4, 6, 8, 12];
function renderEditChrome(p) {
const sizes = SIZES.map(
@@ -5715,7 +5724,7 @@ borrows the accent color.`
const dash = allDash.find((d) => d.id === state.route) || dashboardsInSection(state.section, allDash)[0] || registry["ai-overview"];
const navDash = mergedDashboards(defaults);
const dashboardsForSection = dashboardsInSection("dashboards", navDash);
- if (dash.id === "search-discover" && !state.search.result) {
+ if ((dash.clonedFrom || dash.id) === "search-discover" && !state.search.result) {
runSearchNow();
}
const activeFilters = currentFilters();
@@ -5732,7 +5741,7 @@ borrows the accent color.`
state.loading = true;
try {
const result = await query({
- dashId: dash.id,
+ dashId: dash.clonedFrom || dash.id,
range: state.time,
customRange: state.time === "CUSTOM" ? state.timeCustom : null,
cluster: state.cluster,
@@ -5988,7 +5997,7 @@ borrows the accent color.`
if (sz) {
const pid = sz.getAttribute("data-panel");
const cols = parseInt(sz.getAttribute("data-size"), 10);
- const dash = registry[state.route];
+ const dash = editableDashboard(state.route);
const view = dash.render({ data: {}, time: state.time });
mutate(state.route, view.panels, (ov) => {
ov.cols[pid] = cols;
@@ -5999,7 +6008,7 @@ borrows the accent color.`
const rm = e.target.closest("[data-remove]");
if (rm) {
const pid = rm.getAttribute("data-panel");
- const dash = registry[state.route];
+ const dash = editableDashboard(state.route);
const view = dash.render({ data: {}, time: state.time });
mutate(state.route, view.panels, (ov) => {
if (!ov.hidden.includes(pid)) ov.hidden.push(pid);
@@ -6188,7 +6197,7 @@ borrows the accent color.`
const typeId = add.getAttribute("data-add");
const t = chartTypes[typeId];
if (!t) return;
- const dash = registry[state.route];
+ const dash = editableDashboard(state.route);
const view = dash.render({ data: {}, time: state.time });
mutate(state.route, view.panels, (ov) => {
ov.added = ov.added || [];
@@ -6314,7 +6323,7 @@ borrows the accent color.`
const insertAfter = sec.classList.contains("drop-after");
document.querySelectorAll(".drop-before, .drop-after").forEach((el) => el.classList.remove("drop-before", "drop-after"));
if (!targetId || targetId === dragSrcId) return;
- const dash = registry[state.route];
+ const dash = editableDashboard(state.route);
const view = dash.render({ data: {}, time: state.time });
mutate(state.route, view.panels, (ov) => {
const fullOrder = ov.order && ov.order.length ? ov.order.slice() : view.panels.map((p) => p.id);
diff --git a/landing/playground/src/app.js b/landing/playground/src/app.js
index 4aee28495..7ba39bc9f 100644
--- a/landing/playground/src/app.js
+++ b/landing/playground/src/app.js
@@ -427,7 +427,7 @@ async function buildSectionData(sectionId) {
function loadAllLayouts() {
const out = {};
- for (const id of Object.keys(registry)) {
+ for (const { id } of mergedDashboards(defaults, { includeHidden: true })) {
try {
const raw = localStorage.getItem(LS.layout(id));
if (raw) out[id] = JSON.parse(raw);
@@ -511,6 +511,11 @@ function mutate(dashId, defaultPanels, fn) {
saveLayout(dashId);
}
+// Resolve editable user dashboards through the same metadata as the renderer.
+function editableDashboard(id) {
+ return mergedDashboards(defaults, { includeHidden: true }).find(d => d.id === id);
+}
+
// ---------- render ----------------------------------------
const SIZES = [2, 3, 4, 6, 8, 12];
@@ -594,7 +599,7 @@ async function render() {
const dashboardsForSection = dashboardsInSection('dashboards', navDash);
// For the SEARCH dashboard, eagerly run the search so panels see hits.
- if (dash.id === 'search-discover' && !state.search.result) {
+ if ((dash.clonedFrom || dash.id) === 'search-discover' && !state.search.result) {
runSearchNow();
}
@@ -614,7 +619,7 @@ async function render() {
state.loading = true;
try {
const result = await query({
- dashId: dash.id,
+ dashId: dash.clonedFrom || dash.id,
range: state.time,
customRange: state.time === 'CUSTOM' ? state.timeCustom : null,
cluster: state.cluster,
@@ -926,7 +931,7 @@ document.addEventListener('click', (e) => {
if (sz) {
const pid = sz.getAttribute('data-panel');
const cols = parseInt(sz.getAttribute('data-size'), 10);
- const dash = registry[state.route];
+ const dash = editableDashboard(state.route);
const view = dash.render({ data: {}, time: state.time });
mutate(state.route, view.panels, (ov) => { ov.cols[pid] = cols; });
render();
@@ -936,7 +941,7 @@ document.addEventListener('click', (e) => {
const rm = e.target.closest('[data-remove]');
if (rm) {
const pid = rm.getAttribute('data-panel');
- const dash = registry[state.route];
+ const dash = editableDashboard(state.route);
const view = dash.render({ data: {}, time: state.time });
mutate(state.route, view.panels, (ov) => {
if (!ov.hidden.includes(pid)) ov.hidden.push(pid);
@@ -1137,7 +1142,7 @@ document.addEventListener('click', (e) => {
const typeId = add.getAttribute('data-add');
const t = chartTypes[typeId];
if (!t) return;
- const dash = registry[state.route];
+ const dash = editableDashboard(state.route);
const view = dash.render({ data: {}, time: state.time });
mutate(state.route, view.panels, (ov) => {
ov.added = ov.added || [];
@@ -1273,7 +1278,7 @@ document.addEventListener('drop', (e) => {
document.querySelectorAll('.drop-before, .drop-after').forEach((el) => el.classList.remove('drop-before', 'drop-after'));
if (!targetId || targetId === dragSrcId) return;
- const dash = registry[state.route];
+ const dash = editableDashboard(state.route);
const view = dash.render({ data: {}, time: state.time });
mutate(state.route, view.panels, (ov) => {
const fullOrder = ov.order && ov.order.length ? ov.order.slice() : view.panels.map((p) => p.id);
diff --git a/landing/playground/src/data/dashboard-store.js b/landing/playground/src/data/dashboard-store.js
index f99866e5c..02e6c8bdc 100644
--- a/landing/playground/src/data/dashboard-store.js
+++ b/landing/playground/src/data/dashboard-store.js
@@ -85,13 +85,19 @@ export function mergedDashboards(defaults, { includeHidden = false } = {}) {
});
} else if (user) {
// A user-created dashboard — borrow the render from its template.
- const source = user.clonedFrom ? byId[user.clonedFrom] : null;
+ let templateId = user.clonedFrom;
+ const visited = new Set([id]);
+ while (templateId && custom[templateId] && !visited.has(templateId)) {
+ visited.add(templateId);
+ templateId = custom[templateId].clonedFrom;
+ }
+ const source = templateId ? byId[templateId] : null;
out.push({
id,
name: names[id] || user.name,
render: source?.render || blankRender(user.name),
isUser: true,
- clonedFrom: user.clonedFrom,
+ clonedFrom: source ? source.id : user.clonedFrom,
dataSource: user.dataSource,
hidden: hidden.has(id),
});
diff --git a/landing/playground/src/ux/chrome.js b/landing/playground/src/ux/chrome.js
index 5619aa733..75f0ddeaf 100644
--- a/landing/playground/src/ux/chrome.js
+++ b/landing/playground/src/ux/chrome.js
@@ -76,7 +76,9 @@ export const Nav = ({
}
// Determine the active group from the active dashboard.
const activeDashObj = dashboards.find((d) => d.id === activeDash);
- const activeGroup = activeDashObj?.group || (groups[0]?.id || 'other');
+ const activeGroup = activeDashObj
+ ? (activeDashObj.group || 'other')
+ : (groups[0]?.id || 'other');
// Stable order: the `groups` registry. Any group that exists in
// data but not in the registry is appended at the end.
diff --git a/scripts/landing/playground_fixture.cjs b/scripts/landing/playground_fixture.cjs
new file mode 100644
index 000000000..5e5284e77
--- /dev/null
+++ b/scripts/landing/playground_fixture.cjs
@@ -0,0 +1,20 @@
+const fs = require('node:fs');
+const vm = require('node:vm');
+function mount(bundle, { hash = '#/dashboards/ai-overview', search = '', storage = {} } = {}) {
+ const events = {}, pending = [], errors = [];
+ const localStorage = { ...storage };
+ Object.defineProperties(localStorage, {
+ getItem: {value:key => localStorage[key] ?? null}, setItem:{value:(key,val) => localStorage[key]=String(val)}, removeItem:{value:key=>delete localStorage[key]},
+ });
+ let html = '', renders = 0;
+ const app = { set innerHTML(v) { html=v; renders++; }, get innerHTML() { return html; }, setAttribute() {} };
+ const document = { body: { scrollHeight: 1000 }, getElementById:()=>app, querySelector:()=>null, querySelectorAll:()=>[], addEventListener:(type,fn)=>(events[type]??=[]).push(fn), documentElement:{ getAttribute:()=> 'day', setAttribute(){}, classList:{add(){},toggle(){}} } };
+ let currentHash=hash;
+ const location = { pathname:'/playground/', search, get hash(){return currentHash;}, set hash(value){if(value!==currentHash){currentHash=value;pending.push(()=>events.hashchange?.forEach(fn=>fn()));}} };
+ const history = { replaceState(_,__,url) { const u=new URL(url,'http://localhost'); location.search=u.search; currentHash=u.hash; } };
+ const window = { addEventListener:(type,fn)=>(events[type]??=[]).push(fn), scrollTo(){} };
+ const context = {document,localStorage,location,history,window,URLSearchParams,URL,console,performance,Date,Math,setInterval(){return 1;},clearInterval(){},requestAnimationFrame(fn){fn();},confirm(){return true;},prompt(){return 'saved';}};
+ vm.runInNewContext(fs.readFileSync(bundle,'utf8'),context);
+ return {app,localStorage,location,errors,get renders(){return renders;}, async flush(){for(let i=0;i<8;i++){await Promise.resolve();while(pending.length)pending.shift()();}}, async click(attr,value=''){const attrs=typeof attr==='object'?attr:{[attr]:value}; const el={getAttribute:k=>attrs[k]??null};const target={closest:selector=>Object.keys(attrs).some(k=>selector===`[${k}]`)?el:null};for(const fn of events.click||[])fn({target,preventDefault(){}});await this.flush();} };
+}
+module.exports={mount};
diff --git a/scripts/landing/test_custom_dashboards.cjs b/scripts/landing/test_custom_dashboards.cjs
new file mode 100644
index 000000000..ec2833b7e
--- /dev/null
+++ b/scripts/landing/test_custom_dashboards.cjs
@@ -0,0 +1,70 @@
+const assert = require('node:assert/strict');
+const {test} = require('node:test');
+const path = require('node:path');
+const {mount} = require('./playground_fixture.cjs');
+const bundle = path.join(__dirname, '../../landing/playground/app.bundle.js');
+function page(custom, id = 'user-copy') {
+ return mount(bundle, { hash: '#/dashboards/' + id, storage: {
+ 'xerj.dashboards': JSON.stringify({order:Object.keys(custom),custom}),
+ 'xerj.edit':'1',
+ }});
+}
+for (const [template, label] of [['rag-quality','GROUNDING SCORE'],['logs-overview','EVENTS'],['system','CPU']]) {
+ test(`a ${template} clone receives its template data`,async()=>{
+ const p=page({'user-copy':{name:'My dashboard',clonedFrom:template}});await p.flush();
+ assert.match(p.app.innerHTML,/MY DASHBOARD/);
+ assert.ok(p.app.innerHTML.includes(label));
+ assert.doesNotMatch(p.app.innerHTML,/Cannot read properties|Cannot convert undefined|\.map is not a function/);
+ });
+}
+test('a clone of a user dashboard retains its underlying template',async()=>{
+ const p=page({'user-original':{name:'First RAG',clonedFrom:'rag-quality'},'user-copy':{name:'Second RAG',clonedFrom:'user-original'}});await p.flush();
+ assert.match(p.app.innerHTML,/GROUNDING SCORE/);
+ assert.doesNotMatch(p.app.innerHTML,/NO TEMPLATE|Cannot read properties/);
+});
+test('adding a panel to a custom dashboard persists the addition',async()=>{
+ const p=page({'user-copy':{name:'My dashboard',clonedFrom:'ai-overview'}});await p.flush();
+ await p.click('data-add','metric');
+ const layout=JSON.parse(p.localStorage['xerj.layout.user-copy']);
+ assert.equal(layout.added.length,1);assert.equal(layout.added[0].type,'metric');
+});
+test('custom dashboard panels can be resized and removed',async()=>{
+ const p=page({'user-copy':{name:'My dashboard',clonedFrom:'rag-quality'}});await p.flush();
+ await p.click({'data-size':'6','data-panel':'grounding'});
+ let layout=JSON.parse(p.localStorage['xerj.layout.user-copy']);assert.equal(layout.cols.grounding,6);
+ await p.click({'data-remove':'','data-panel':'grounding'});
+ layout=JSON.parse(p.localStorage['xerj.layout.user-copy']);assert.ok(layout.hidden.includes('grounding'));
+});
+test('cyclic user templates terminate in the blank fallback',async()=>{
+ const p=page({'user-copy':{name:'Cycle',clonedFrom:'user-other'},'user-other':{name:'Other',clonedFrom:'user-copy'}});await p.flush();assert.match(p.app.innerHTML,/NO TEMPLATE/);
+});
+test('a missing template keeps the documented blank fallback',async()=>{
+ const p=page({'user-copy':{name:'Orphan',clonedFrom:'removed-template'}});await p.flush();assert.match(p.app.innerHTML,/NO TEMPLATE/);
+});
+
+for (const [id, custom] of [
+ ['user-copy', {'user-copy':{name:'My RAG',clonedFrom:'rag-quality'}}],
+ ['rag-quality', {}],
+]) {
+ test(`${id} retains resized, hidden and added panels after a fresh boot`,async()=>{
+ const p=page(custom,id);await p.flush();
+ await p.click({'data-size':'6','data-panel':'grounding'});
+ await p.click({'data-remove':'','data-panel':'halluc'});
+ await p.click('data-add','metric');
+ const stored=JSON.parse(p.localStorage['xerj.layout.'+id]);
+ assert.equal(stored.cols.grounding,6);assert.ok(stored.hidden.includes('halluc'));
+ const restored=mount(bundle,{hash:'#/dashboards/'+id,storage:{...p.localStorage}});await restored.flush();
+ assert.doesNotMatch(restored.app.innerHTML,/HALLUCINATION RATE/);
+ assert.ok(restored.app.innerHTML.includes(stored.added[0].id));
+ assert.match(restored.app.innerHTML,/data-panel="grounding"[^>]*style="grid-column: span 6/);
+ });
+}
+
+test('the active custom dashboard is exposed in its expanded navigation group',async()=>{
+ const p=page({'user-copy':{name:'My dashboard',clonedFrom:'ai-overview'}});await p.flush();
+ assert.match(p.app.innerHTML,/<button[^>]+data-dash-group="other"[^>]+aria-expanded="true"/);
+ assert.match(p.app.innerHTML,/data-dash="user-copy" class="active"/);
+});
+test('default dashboards retain their expanded registered navigation group',async()=>{
+ const p=page({},'ai-overview');await p.flush();assert.match(p.app.innerHTML,/<button[^>]+data-dash-group="ai"[^>]+aria-expanded="true"/);
+});
diff --git a/scripts/seo/README.md b/scripts/seo/README.md
index a4375ec47..1004dca49 100644
--- a/scripts/seo/README.md
+++ b/scripts/seo/README.md
@@ -14,6 +14,14 @@ repository root is always the invocation.
---
+The dependency-free playground state regressions run the committed browser
+bundle with controlled browser state: `node --test scripts/landing/test_*.cjs`
+(Node 22, also run by the SEO job). To regenerate the playground bundle, run
+`esbuild playground/src/app.js --bundle --outfile=playground/app.bundle.js`
+from `landing/`. Custom dashboards inherit their template's data and render
+functions while keeping their own layout overrides. Clones can themselves be
+cloned; missing or cyclic template references produce the blank fallback.
+
## 1. Architecture
```