@@ -9,16 +9,26 @@ import { insightDataLogic } from 'scenes/insights/insightDataLogic'
99import { insightLogic } from 'scenes/insights/insightLogic'
1010import { useSummarizeInsight } from 'scenes/insights/summarizeInsight'
1111import { createPostHogWidgetNode } from 'scenes/notebooks/Nodes/NodeWrapper'
12+ import { notebookLogic } from 'scenes/notebooks/Notebook/notebookLogic'
1213import { urls } from 'scenes/urls'
1314
1415import { Query } from '~/queries/Query/Query'
1516import { DataTableNode , InsightQueryNode , InsightVizNode , NodeKind , QuerySchema } from '~/queries/schema/schema-general'
16- import { containsHogQLQuery , isHogQLQuery , isInsightVizNode , isNodeWithSource } from '~/queries/utils'
17+ import {
18+ containsHogQLQuery ,
19+ isActorsQuery ,
20+ isDataTableNode ,
21+ isEventsQuery ,
22+ isHogQLQuery ,
23+ isInsightVizNode ,
24+ isNodeWithSource ,
25+ isSavedInsightNode ,
26+ } from '~/queries/utils'
1727import { InsightLogicProps , InsightShortId } from '~/types'
1828
1929import { NotebookNodeAttributeProperties , NotebookNodeProps , NotebookNodeType } from '../types'
2030import { notebookNodeLogic } from './notebookNodeLogic'
21- import { SHORT_CODE_REGEX_MATCH_GROUPS } from './utils'
31+ import { SHORT_CODE_REGEX_MATCH_GROUPS , mergeProperties } from './utils'
2232
2333const DEFAULT_QUERY : QuerySchema = {
2434 kind : NodeKind . DataTableNode ,
@@ -39,6 +49,7 @@ const Component = ({
3949 const nodeLogic = useMountedLogic ( notebookNodeLogic )
4050 const { expanded } = useValues ( nodeLogic )
4151 const { setTitlePlaceholder } = useActions ( nodeLogic )
52+ const { canvasFiltersOverride } = useValues ( notebookLogic )
4253 const summarizeInsight = useSummarizeInsight ( )
4354
4455 const insightLogicProps = {
@@ -77,17 +88,17 @@ const Component = ({
7788 } , [ query , insightName ] )
7889
7990 const modifiedQuery = useMemo ( ( ) => {
80- const modifiedQuery = { ...query , full : false }
91+ let modifiedQuery = { ...query , full : false }
8192
82- if ( NodeKind . DataTableNode === modifiedQuery . kind || NodeKind . SavedInsightNode === modifiedQuery . kind ) {
93+ if ( isDataTableNode ( modifiedQuery ) || isSavedInsightNode ( modifiedQuery ) ) {
8394 modifiedQuery . showOpenEditorButton = false
8495 modifiedQuery . full = false
8596 modifiedQuery . showHogQLEditor = false
8697 modifiedQuery . embedded = true
8798 modifiedQuery . showTimings = false
8899 }
89100
90- if ( NodeKind . InsightVizNode === modifiedQuery . kind || NodeKind . SavedInsightNode === modifiedQuery . kind ) {
101+ if ( isInsightVizNode ( modifiedQuery ) || isSavedInsightNode ( modifiedQuery ) ) {
91102 modifiedQuery . showFilters = false
92103 modifiedQuery . showHeader = false
93104 modifiedQuery . showTable = false
@@ -96,7 +107,7 @@ const Component = ({
96107 }
97108
98109 return modifiedQuery
99- } , [ query ] )
110+ } , [ query , canvasFiltersOverride ] )
100111
101112 if ( ! expanded ) {
102113 return null
@@ -129,18 +140,21 @@ const Component = ({
129140
130141type NotebookNodeQueryAttributes = {
131142 query : QuerySchema
143+ /* Wether canvasFiltersOverride is applied, as we should apply it only once */
144+ isDefaultFilterApplied : boolean
132145}
133146
134147export const Settings = ( {
135148 attributes,
136149 updateAttributes,
137150} : NotebookNodeAttributeProperties < NotebookNodeQueryAttributes > ) : JSX . Element => {
138- const { query } = attributes
151+ const { query, isDefaultFilterApplied } = attributes
152+ const { canvasFiltersOverride } = useValues ( notebookLogic )
139153
140154 const modifiedQuery = useMemo ( ( ) => {
141155 const modifiedQuery = { ...query , full : false }
142156
143- if ( NodeKind . DataTableNode === modifiedQuery . kind || NodeKind . SavedInsightNode === modifiedQuery . kind ) {
157+ if ( isDataTableNode ( modifiedQuery ) || isSavedInsightNode ( modifiedQuery ) ) {
144158 modifiedQuery . showOpenEditorButton = false
145159 modifiedQuery . showHogQLEditor = true
146160 modifiedQuery . showResultsTable = false
@@ -160,18 +174,39 @@ export const Settings = ({
160174 modifiedQuery . showColumnConfigurator = true
161175 }
162176
163- if ( NodeKind . InsightVizNode === modifiedQuery . kind || NodeKind . SavedInsightNode === modifiedQuery . kind ) {
177+ if ( isInsightVizNode ( modifiedQuery ) || isSavedInsightNode ( modifiedQuery ) ) {
164178 modifiedQuery . showFilters = true
165179 modifiedQuery . showHeader = true
166180 modifiedQuery . showResults = false
167181 modifiedQuery . embedded = true
168182 }
169183
184+ if (
185+ isInsightVizNode ( modifiedQuery ) &&
186+ ! isHogQLQuery ( modifiedQuery . source ) &&
187+ ! isActorsQuery ( modifiedQuery . source ) &&
188+ ! isDefaultFilterApplied
189+ ) {
190+ modifiedQuery . source . properties = mergeProperties (
191+ modifiedQuery . source . properties ?? [ ] ,
192+ canvasFiltersOverride
193+ )
194+ updateAttributes ( { ...attributes , isDefaultFilterApplied : true } )
195+ }
196+
197+ if ( isDataTableNode ( modifiedQuery ) && isEventsQuery ( modifiedQuery . source ) && ! isDefaultFilterApplied ) {
198+ modifiedQuery . source . fixedProperties = mergeProperties (
199+ modifiedQuery . source . properties ?? [ ] ,
200+ canvasFiltersOverride
201+ )
202+ updateAttributes ( { ...attributes , isDefaultFilterApplied : true } )
203+ }
204+
170205 return modifiedQuery
171- } , [ query ] )
206+ } , [ query , canvasFiltersOverride ] )
172207
173208 const detachSavedInsight = ( ) : void => {
174- if ( attributes . query . kind === NodeKind . SavedInsightNode ) {
209+ if ( isSavedInsightNode ( attributes . query ) ) {
175210 const insightProps : InsightLogicProps = { dashboardItemId : attributes . query . shortId }
176211 const dataLogic = insightDataLogic . findMounted ( insightProps )
177212
@@ -181,7 +216,7 @@ export const Settings = ({
181216 }
182217 }
183218
184- return attributes . query . kind === NodeKind . SavedInsightNode ? (
219+ return isSavedInsightNode ( attributes . query ) ? (
185220 < div className = "p-3 deprecated-space-y-2" >
186221 < div className = "text-lg font-semibold" > Insight created outside of this notebook</ div >
187222 < div >
@@ -241,9 +276,12 @@ export const NotebookNodeQuery = createPostHogWidgetNode<NotebookNodeQueryAttrib
241276 query : {
242277 default : DEFAULT_QUERY ,
243278 } ,
279+ isDefaultFilterApplied : {
280+ default : false ,
281+ } ,
244282 } ,
245283 href : ( { query } ) =>
246- query . kind === NodeKind . SavedInsightNode
284+ isSavedInsightNode ( query )
247285 ? urls . insightView ( query . shortId )
248286 : isInsightVizNode ( query )
249287 ? urls . insightNew ( { query } )
@@ -257,6 +295,7 @@ export const NotebookNodeQuery = createPostHogWidgetNode<NotebookNodeQueryAttrib
257295 kind : NodeKind . SavedInsightNode ,
258296 shortId : match [ 1 ] as InsightShortId ,
259297 } ,
298+ isDefaultFilterApplied : false ,
260299 }
261300 } ,
262301 } ,
0 commit comments