Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(insights): support editing insights by updating source #23092

Merged
merged 6 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions cypress/e2e/insights.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})
4 changes: 2 additions & 2 deletions frontend/src/queries/Query/Query.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface QueryProps<Q extends Node> {
/** 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
Expand Down Expand Up @@ -134,7 +134,7 @@ export function Query<Q extends Node>(props: QueryProps<Q>): JSX.Element | null
<>
<QueryEditor
query={JSON.stringify(query)}
setQuery={(stringQuery) => setQuery?.(JSON.parse(stringQuery))}
setQuery={(stringQuery) => setQuery?.(JSON.parse(stringQuery), true)}
context={queryContext}
/>
<div className="my-4">
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/scenes/insights/Insight.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
Loading