diff --git a/cypress/e2e/insights.cy.ts b/cypress/e2e/insights.cy.ts index 1bbfa1adfdfc5..c01d8faf4ce8d 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('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..3215e3bdb8cd4 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,7 @@ export function Query(props: QueryProps): JSX.Element | null <> setQuery?.(JSON.parse(stringQuery))} + setQuery={(stringQuery) => setQuery?.(JSON.parse(stringQuery), true)} context={queryContext} />
diff --git a/frontend/src/scenes/insights/Insight.tsx b/frontend/src/scenes/insights/Insight.tsx index 071015465baa7..17d05aee1f686 100644 --- a/frontend/src/scenes/insights/Insight.tsx +++ b/frontend/src/scenes/insights/Insight.tsx @@ -42,8 +42,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) } }