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

feat: use passed in setQuery value to update insight viz node #17417

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 5 additions & 1 deletion frontend/src/queries/nodes/InsightViz/InsightViz.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ let uniqueNode = 0

export function InsightViz({ uniqueKey, query, setQuery, context, readOnly }: InsightVizProps): JSX.Element {
const [key] = useState(() => `InsightViz.${uniqueKey || uniqueNode++}`)
const insightProps: InsightLogicProps = context?.insightProps || { dashboardItemId: `new-AdHoc.${key}`, query }
const insightProps: InsightLogicProps = context?.insightProps || {
dashboardItemId: `new-AdHoc.${key}`,
query,
setQuery,
}
const dataNodeLogicProps: DataNodeLogicProps = {
query: query.source,
key: insightVizDataNodeKey(insightProps),
Expand Down
8 changes: 2 additions & 6 deletions frontend/src/queries/nodes/InsightViz/TrendsSeries.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useValues, useActions } from 'kea'
import { groupsModel } from '~/models/groupsModel'
import { ActionFilter } from 'scenes/insights/filters/ActionFilter/ActionFilter'
import { InsightType, FilterType, InsightLogicProps } from '~/types'
import { InsightType, FilterType, EditorFilterProps } from '~/types'
import { alphabet } from 'lib/utils'
import { MathAvailability } from 'scenes/insights/filters/ActionFilter/ActionFilterRow/ActionFilterRow'
import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
Expand All @@ -13,11 +13,7 @@ import { actionsAndEventsToSeries } from '../InsightQuery/utils/filtersToQueryNo

import { insightVizDataLogic } from 'scenes/insights/insightVizDataLogic'

type TrendsSeriesProps = {
insightProps: InsightLogicProps
}

export function TrendsSeries({ insightProps }: TrendsSeriesProps): JSX.Element | null {
export function TrendsSeries({ insightProps }: EditorFilterProps): JSX.Element | null {
const { querySource, isTrends, isLifecycle, isStickiness, display, hasFormula } = useValues(
insightVizDataLogic(insightProps)
)
Expand Down
7 changes: 0 additions & 7 deletions frontend/src/scenes/insights/insightLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import { toLocalFilters } from './filters/ActionFilter/entityFilterLogic'
import { loaders } from 'kea-loaders'
import { queryExportContext } from '~/queries/query'
import { tagsModel } from '~/models/tagsModel'
import { isInsightVizNode } from '~/queries/utils'
import { userLogic } from 'scenes/userLogic'
import { transformLegacyHiddenLegendKeys } from 'scenes/funnels/funnelUtils'
import { summarizeInsight } from 'scenes/insights/summarizeInsight'
Expand Down Expand Up @@ -389,12 +388,6 @@ export const insightLogic = kea<insightLogicType>([
],
insightName: [(s) => [s.insight, s.derivedName], (insight, derivedName) => insight.name || derivedName],
insightId: [(s) => [s.insight], (insight) => insight?.id || null],
isFilterBasedInsight: [
(s) => [s.insight],
(insight) => Object.keys(insight.filters || {}).length > 0 && !insight.query,
],
isQueryBasedInsight: [(s) => [s.insight], (insight) => !!insight.query],
isInsightVizQuery: [(s) => [s.insight], (insight) => isInsightVizNode(insight.query)],
canEditInsight: [
(s) => [s.insight],
(insight) =>
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/scenes/insights/insightVizDataLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
InsightFilter,
InsightQueryNode,
InsightVizNode,
Node,
NodeKind,
TrendsQuery,
} from '~/queries/schema'
Expand Down Expand Up @@ -191,7 +190,7 @@ export const insightVizDataLogic = kea<insightVizDataLogicType>([
timezone: [(s) => [s.insightData], (insightData) => insightData?.timezone || 'UTC'],
}),

listeners(({ actions, values }) => ({
listeners(({ actions, values, props }) => ({
updateDateRange: ({ dateRange }) => {
const localQuerySource = values.querySource
? values.querySource
Expand Down Expand Up @@ -235,10 +234,11 @@ export const insightVizDataLogic = kea<insightVizDataLogicType>([
? values.query
: queryFromKind(NodeKind.TrendsQuery, values.filterTestAccountsDefault)
if (localQuery && isInsightVizNode(localQuery)) {
actions.setQuery({
const newQuery = {
...localQuery,
source: { ...(localQuery as InsightVizNode).source, ...querySource },
} as Node)
} as InsightVizNode
props.setQuery ? props.setQuery(newQuery) : actions.setQuery(newQuery)
}
},
setQuery: ({ query }) => {
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2055,6 +2055,8 @@ export interface InsightLogicProps {
doNotLoad?: boolean
/** query when used as ad-hoc insight */
query?: InsightVizNode
/** callback when query changes in ad-hoc insight */
setQuery?: (node: InsightVizNode) => void
}

export interface SetInsightOptions {
Expand Down
Loading