Skip to content

Commit

Permalink
simplify update actions
Browse files Browse the repository at this point in the history
  • Loading branch information
thmsobrmlr committed Oct 16, 2023
1 parent 2f7a306 commit 8a9377e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 39 deletions.
3 changes: 2 additions & 1 deletion frontend/src/scenes/insights/insightVizDataLogic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ describe('insightVizDataLogic', () => {
})
})

it('updates insight filter for other insight query kinds', () => {
it('updates the insight filter for other insight query kinds', () => {
builtInsightVizDataLogic.actions.updateQuerySource(funnelsQueryDefault)

expectLogic(builtInsightDataLogic, () => {
Expand All @@ -238,6 +238,7 @@ describe('insightVizDataLogic', () => {
...funnelsQueryDefault.funnelsFilter,
layout: FunnelLayout.horizontal,
},
trendsFilter: {}, // we currently don't remove insight filters of previous query kinds
},
},
})
Expand Down
53 changes: 15 additions & 38 deletions frontend/src/scenes/insights/insightVizDataLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ export const insightVizDataLogic = kea<insightVizDataLogicType>([
(s) => [s.query],
(query) => (isNodeWithSource(query) && isInsightQueryNode(query.source) ? query.source : null),
],
localQuerySource: [
(s) => [s.querySource, s.filterTestAccountsDefault],
(querySource, filterTestAccountsDefault) =>
querySource ? querySource : queryFromKind(NodeKind.TrendsQuery, filterTestAccountsDefault).source,
],

isTrends: [(s) => [s.querySource], (q) => isTrendsQuery(q)],
isFunnels: [(s) => [s.querySource], (q) => isFunnelsQuery(q)],
Expand Down Expand Up @@ -191,53 +196,25 @@ export const insightVizDataLogic = kea<insightVizDataLogicType>([

listeners(({ actions, values, props }) => ({
updateDateRange: ({ dateRange }) => {
const localQuerySource = values.querySource
? values.querySource
: queryFromKind(NodeKind.TrendsQuery, values.filterTestAccountsDefault).source
if (isInsightQueryNode(localQuerySource)) {
const newQuerySource = { ...localQuerySource, dateRange }
actions.updateQuerySource(newQuerySource)
}
actions.updateQuerySource({ dateRange: { ...values.dateRange, ...dateRange } })
},
updateBreakdown: ({ breakdown }) => {
const localQuerySource = values.querySource
? values.querySource
: queryFromKind(NodeKind.TrendsQuery, values.filterTestAccountsDefault).source
if (isInsightQueryNode(localQuerySource)) {
const newQuerySource = {
...localQuerySource,
breakdown: { ...(localQuerySource as TrendsQuery).breakdown, ...breakdown },
}
actions.updateQuerySource(newQuerySource)
}
actions.updateQuerySource({ breakdown: { ...values.breakdown, ...breakdown } } as Partial<TrendsQuery>)
},
updateInsightFilter: ({ insightFilter }) => {
const localQuerySource = values.querySource
? values.querySource
: queryFromKind(NodeKind.TrendsQuery, values.filterTestAccountsDefault).source
if (isInsightQueryNode(localQuerySource)) {
const filterProperty = filterPropertyForQuery(localQuerySource)
const newQuerySource = { ...localQuerySource }
newQuerySource[filterProperty] = {
...localQuerySource[filterProperty],
...insightFilter,
}
actions.updateQuerySource(newQuerySource)
}
const filterProperty = filterPropertyForQuery(values.localQuerySource)
actions.updateQuerySource({
[filterProperty]: { ...values.localQuerySource[filterProperty], ...insightFilter },
})
},
updateDisplay: ({ display }) => {
actions.updateInsightFilter({ display })
},
updateQuerySource: ({ querySource }) => {
const localQuery = values.query
? values.query
: queryFromKind(NodeKind.TrendsQuery, values.filterTestAccountsDefault)
if (localQuery && isInsightVizNode(localQuery)) {
actions.setQuery({
...localQuery,
source: { ...(localQuery as InsightVizNode).source, ...querySource },
} as Node)
}
actions.setQuery({
...values.query,
source: { ...values.querySource, ...querySource },
} as Node)
},
setQuery: ({ query }) => {
if (isInsightVizNode(query)) {
Expand Down

0 comments on commit 8a9377e

Please sign in to comment.