From 8e07beda920f8248552f1593253275f2e2859065 Mon Sep 17 00:00:00 2001 From: Nikita Vorobev Date: Wed, 19 Jun 2024 18:17:32 +0100 Subject: [PATCH 1/4] fix(insights): support editing insights by updating source --- cypress/e2e/insights.cy.ts | 27 +++++++++++++++++------- frontend/src/queries/Query/Query.tsx | 6 ++++-- frontend/src/scenes/insights/Insight.tsx | 4 ++-- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/cypress/e2e/insights.cy.ts b/cypress/e2e/insights.cy.ts index 1bbfa1adfdfc5..b2973f1c15010 100644 --- a/cypress/e2e/insights.cy.ts +++ b/cypress/e2e/insights.cy.ts @@ -114,13 +114,24 @@ describe('Insights', () => { cy.get('[data-attr=insight-tags]').should('not.exist') }) - describe('view source', () => { - it('can open the query editor', () => { - insight.newInsight('TRENDS') - insight.save() - cy.get('[data-attr="more-button"]').click() - cy.get('[data-attr="show-insight-source"]').click() - cy.get('[data-attr="query-editor"]').should('exist') - }) + it.only('can edit via the query editor', () => { + insight.newInsight('TRENDS') + insight.save() + cy.get('[data-attr="more-button"]').click() + cy.get('[data-attr="show-insight-source"]').click() + // Find "day" + cy.get('.monaco-editor') + .click() + // change subject to currently focused element + .focused() + .type('{ctrl}f') + .focused() + .type('day') + + // Remove day and add hour + cy.get('.monaco-editor').click().focused().type('{leftArrow}{leftArrow}{backspace}{backspace}{backspace}hour') + cy.get('[data-attr=query-editor-save]').click() + + cy.get('[data-attr="interval-filter').contains('hour').should('exist') }) }) diff --git a/frontend/src/queries/Query/Query.tsx b/frontend/src/queries/Query/Query.tsx index d565f29d6d9ac..3e5da3c8f6e0d 100644 --- a/frontend/src/queries/Query/Query.tsx +++ b/frontend/src/queries/Query/Query.tsx @@ -31,7 +31,7 @@ export interface QueryProps { /** The query to render */ query: Q | string | null /** Set this if you're controlling the query parameter */ - setQuery?: (query: Q) => void + setQuery?: (query: Q, isSourceUpdate?: boolean) => void /** Custom components passed down to a few query nodes (e.g. custom table columns) */ context?: QueryContext @@ -134,7 +134,9 @@ export function Query(props: QueryProps): JSX.Element | null <> setQuery?.(JSON.parse(stringQuery))} + setQuery={(stringQuery) => + setQuery?.(JSON.parse(stringQuery), /* isSourceUpdate= */ true) + } context={queryContext} />
diff --git a/frontend/src/scenes/insights/Insight.tsx b/frontend/src/scenes/insights/Insight.tsx index df9a7d4786998..fd7c7f367d279 100644 --- a/frontend/src/scenes/insights/Insight.tsx +++ b/frontend/src/scenes/insights/Insight.tsx @@ -48,8 +48,8 @@ export function Insight({ insightId }: InsightSceneProps): JSX.Element { const actuallyShowQueryEditor = insightMode === ItemMode.Edit && showQueryEditor - const setQuery = (query: Node): void => { - if (!isInsightVizNode(query)) { + const setQuery = (query: Node, isSourceUpdate?: boolean): void => { + if (!isInsightVizNode(query) || isSourceUpdate) { setInsightQuery(query) } } From c98790c259397ca0352f460d9d07d3aa4791c89d Mon Sep 17 00:00:00 2001 From: Nikita Vorobev Date: Wed, 19 Jun 2024 18:36:44 +0100 Subject: [PATCH 2/4] remove it.only --- cypress/e2e/insights.cy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypress/e2e/insights.cy.ts b/cypress/e2e/insights.cy.ts index b2973f1c15010..c01d8faf4ce8d 100644 --- a/cypress/e2e/insights.cy.ts +++ b/cypress/e2e/insights.cy.ts @@ -114,7 +114,7 @@ describe('Insights', () => { cy.get('[data-attr=insight-tags]').should('not.exist') }) - it.only('can edit via the query editor', () => { + it('can edit via the query editor', () => { insight.newInsight('TRENDS') insight.save() cy.get('[data-attr="more-button"]').click() From 3dd2fad29ee529fcfc31efd5c3d45e620d7f3835 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Oberm=C3=BCller?= Date: Tue, 25 Jun 2024 10:47:21 +0200 Subject: [PATCH 3/4] Update frontend/src/queries/Query/Query.tsx --- frontend/src/queries/Query/Query.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/queries/Query/Query.tsx b/frontend/src/queries/Query/Query.tsx index 3e5da3c8f6e0d..171fa498f4370 100644 --- a/frontend/src/queries/Query/Query.tsx +++ b/frontend/src/queries/Query/Query.tsx @@ -135,7 +135,7 @@ export function Query(props: QueryProps): JSX.Element | null - setQuery?.(JSON.parse(stringQuery), /* isSourceUpdate= */ true) + setQuery?.(JSON.parse(stringQuery), true) } context={queryContext} /> From 7302897ee3fd39f8f65f4e189f75528ad2feb4e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Obermu=CC=88ller?= Date: Tue, 25 Jun 2024 10:51:59 +0200 Subject: [PATCH 4/4] formatting --- frontend/src/queries/Query/Query.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/frontend/src/queries/Query/Query.tsx b/frontend/src/queries/Query/Query.tsx index 171fa498f4370..3215e3bdb8cd4 100644 --- a/frontend/src/queries/Query/Query.tsx +++ b/frontend/src/queries/Query/Query.tsx @@ -134,9 +134,7 @@ export function Query(props: QueryProps): JSX.Element | null <> - setQuery?.(JSON.parse(stringQuery), true) - } + setQuery={(stringQuery) => setQuery?.(JSON.parse(stringQuery), true)} context={queryContext} />