Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

fix(dashboards-list): never replace past the caret in DSL autocomplete (#12384)

Ashwin Bhatkalc70866e4b39c
diff --git a/frontend/src/pages/DashboardsListPageV2/utils/dslTokenizer.test.ts b/frontend/src/pages/DashboardsListPageV2/utils/dslTokenizer.test.ts
index 5de87e6e71..7444a90164 100644
--- a/frontend/src/pages/DashboardsListPageV2/utils/dslTokenizer.test.ts
+++ b/frontend/src/pages/DashboardsListPageV2/utils/dslTokenizer.test.ts
@@ -114,6 +114,23 @@ describe('getCaretContext — stage detection', () => {
expect(ctx.partial).toBe('');
});
+ it('never replaces past the caret when it sits before the operator', () => {
+ const ctx = getCaretContext("env = 'prod'", 4);
+ expect(ctx.stage).toBe('operator');
+ expect(ctx.partial).toBe('');
+ expect(ctx.replaceStart).toBe(4);
+ expect(ctx.replaceEnd).toBe(4);
+ });
+
+ it('never replaces past the caret when it sits before the value', () => {
+ const ctx = getCaretContext("env = 'prod'", 6);
+ expect(ctx.stage).toBe('value');
+ expect(ctx.operator).toBe('=');
+ expect(ctx.partial).toBe('');
+ expect(ctx.replaceStart).toBe(6);
+ expect(ctx.replaceEnd).toBe(6);
+ });
+
it('detects the stage of the term under a mid-string caret', () => {
const q = "env = AND team = 'core'";
// caret right after the first `env ` (index 4) is the operator stage
@@ -142,6 +159,13 @@ describe('spliceAtCaret', () => {
expect(next).toBe("env = 'prod'");
});
+ it('inserts (without duplicating text) at a caret parked before a token', () => {
+ const q = "env = 'prod'";
+ const ctx = getCaretContext(q, 4);
+ const { next } = spliceAtCaret(q, ctx, '!= ');
+ expect(next).toBe("env != = 'prod'");
+ });
+
it('preserves text after the caret', () => {
const q = "env AND team = 'core'";
const ctx = getCaretContext(q, 4); // operator gap after `env`
diff --git a/frontend/src/pages/DashboardsListPageV2/utils/dslTokenizer.ts b/frontend/src/pages/DashboardsListPageV2/utils/dslTokenizer.ts
index c5e02ac1d7..8b7d00e949 100644
--- a/frontend/src/pages/DashboardsListPageV2/utils/dslTokenizer.ts
+++ b/frontend/src/pages/DashboardsListPageV2/utils/dslTokenizer.ts
@@ -328,7 +328,7 @@ export const getCaretContext = (query: string, caret: number): CaretContext => {
fieldKey: scan.key ? scan.key.text : '',
operator: slot.operator,
partial: slot.partial,
- replaceStart: term.start + slot.replaceStartRel,
+ replaceStart: Math.min(term.start + slot.replaceStartRel, pos),
replaceEnd: pos,
};
};