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): restore saved views without stale URL state (#2094, from #2071)

xerj-org11a5add56b2d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 223a30d60..e16b97fac 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -42,6 +42,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Release-download snapshots now refuse malformed existing JSONL history without
replacing its contents. Repair the history file and rerun the snapshot command.
+- Playground saved views immediately restore the current dashboard, replace
+ stale URL filters when navigating, and preserve custom time-range endpoints.
+
- `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 e8277e786..997cb29be 100644
--- a/landing/playground/app.bundle.js
+++ b/landing/playground/app.bundle.js
@@ -5492,6 +5492,7 @@ borrows the accent color.`
name,
dashId,
time: state.time,
+ timeCustom: state.time === "CUSTOM" ? { ...state.timeCustom } : null,
cluster: state.cluster,
filters: currentFilters(),
savedAt: (/* @__PURE__ */ new Date()).toISOString()
@@ -5505,11 +5506,21 @@ borrows the accent color.`
const v = loadViews().find((x) => x.id === id);
if (!v) return;
state.time = v.time;
+ if (v.timeCustom) {
+ state.timeCustom = { ...v.timeCustom };
+ localStorage.setItem("xerj.timeFrom", state.timeCustom.from || "");
+ localStorage.setItem("xerj.timeTo", state.timeCustom.to || "");
+ }
state.cluster = v.cluster || state.cluster;
state.filters[v.dashId] = { ...v.filters || {} };
saveFilters(v.dashId);
localStorage.setItem(LS.time, state.time);
- location.hash = "#/dashboards/" + v.dashId;
+ state.section = "dashboards";
+ state.route = v.dashId;
+ writeUrlState();
+ const hash = "#/dashboards/" + v.dashId;
+ if (location.hash === hash) render();
+ else location.hash = hash;
}
function relTime(iso) {
if (!iso) return "";
diff --git a/landing/playground/src/app.js b/landing/playground/src/app.js
index 7ba39bc9f..eaca22c31 100644
--- a/landing/playground/src/app.js
+++ b/landing/playground/src/app.js
@@ -277,6 +277,7 @@ function saveCurrentView() {
name,
dashId,
time: state.time,
+ timeCustom: state.time === 'CUSTOM' ? { ...state.timeCustom } : null,
cluster: state.cluster,
filters: currentFilters(),
savedAt: new Date().toISOString(),
@@ -290,11 +291,22 @@ function applyView(id) {
const v = loadViews().find((x) => x.id === id);
if (!v) return;
state.time = v.time;
+ if (v.timeCustom) {
+ state.timeCustom = { ...v.timeCustom };
+ localStorage.setItem('xerj.timeFrom', state.timeCustom.from || '');
+ localStorage.setItem('xerj.timeTo', state.timeCustom.to || '');
+ }
state.cluster = v.cluster || state.cluster;
state.filters[v.dashId] = { ...(v.filters || {}) };
saveFilters(v.dashId);
localStorage.setItem(LS.time, state.time);
- location.hash = '#/dashboards/' + v.dashId;
+ // Publish the restored context before hashchange reads the URL again.
+ state.section = 'dashboards';
+ state.route = v.dashId;
+ writeUrlState();
+ const hash = '#/dashboards/' + v.dashId;
+ if (location.hash === hash) render();
+ else location.hash = hash;
}
function relTime(iso) {
diff --git a/scripts/landing/test_saved_views.cjs b/scripts/landing/test_saved_views.cjs
new file mode 100644
index 000000000..7f9d46984
--- /dev/null
+++ b/scripts/landing/test_saved_views.cjs
@@ -0,0 +1,39 @@
+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');
+const view = {id:'saved',dashId:'ai-overview',time:'7D',cluster:'prod-us',filters:{service:'auth'}};
+function page(saved = view, options = {}) {
+ return mount(bundle,{...options,storage:{...options.storage,'xerj.views':JSON.stringify([saved])}});
+}
+test('applying a view on the current dashboard repaints and updates the share URL',async()=>{
+ const p=page();await p.flush();const before=p.renders;
+ await p.click('data-view-apply','saved');
+ assert.ok(p.renders>before);
+ const params=new URLSearchParams(p.location.search);
+ assert.equal(params.get('t'),'7D');assert.equal(params.get('c'),'prod-us');assert.equal(params.get('f'),'service:auth');
+ assert.match(p.app.innerHTML,/PROD-US/);
+});
+test('cross-dashboard restoration wins over the previous URL context',async()=>{
+ const p=page({...view,dashId:'rag-quality'},{search:'?t=1H&c=staging&f=service:old'});await p.flush();
+ await p.click('data-view-apply','saved');
+ assert.equal(p.location.hash,'#/dashboards/rag-quality');
+ const params=new URLSearchParams(p.location.search);
+ assert.equal(params.get('t'),'7D');assert.equal(params.get('c'),'prod-us');assert.equal(params.get('f'),'service:auth');
+ assert.deepEqual(JSON.parse(p.localStorage['xerj.filters.rag-quality']),{service:'auth'});
+});
+test('custom saved views restore their endpoints and persist them for reload',async()=>{
+ const timeCustom={from:'2026-01-01T00:00',to:'2026-01-03T00:00'};
+ const p=page({...view,time:'CUSTOM',timeCustom},{storage:{'xerj.timeFrom':'2025-01-01T00:00','xerj.timeTo':'2025-01-02T00:00'}});await p.flush();await p.click('data-view-apply','saved');
+ assert.equal(p.localStorage['xerj.timeFrom'],timeCustom.from);assert.equal(p.localStorage['xerj.timeTo'],timeCustom.to);
+ const params=new URLSearchParams(p.location.search);assert.equal(params.get('tfrom'),timeCustom.from);assert.equal(params.get('tto'),timeCustom.to);
+});
+test('saving a custom view captures both endpoints',async()=>{
+ const p=page(view,{search:'?t=CUSTOM&tfrom=2026-01-01T00:00&tto=2026-01-03T00:00'});await p.flush();await p.click('data-view-save');
+ const saved=JSON.parse(p.localStorage['xerj.views']).at(-1);
+ assert.deepEqual(saved.timeCustom,{from:'2026-01-01T00:00',to:'2026-01-03T00:00'});
+});
+test('unknown saved view is a no-op',async()=>{
+ const p=page();await p.flush();const before=p.renders;await p.click('data-view-apply','missing');assert.equal(p.renders,before);
+});
diff --git a/scripts/seo/README.md b/scripts/seo/README.md
index 440d8ed08..6c7e058c1 100644
--- a/scripts/seo/README.md
+++ b/scripts/seo/README.md
@@ -43,6 +43,10 @@ fixture; it does not run XERJ or contact external services.
Regenerate its committed bundle from `landing/` using
`esbuild playground/src/app.js --bundle --outfile=playground/app.bundle.js`.
+Playground saved views restore the saved time range, cluster and filters;
+custom views also save their FROM/TO endpoints. Legacy saved views without
+endpoints retain the current custom endpoints.
+
## 1. Architecture
```