diff --git a/frontend/src/scenes/notebooks/Nodes/NotebookNodeQuery.tsx b/frontend/src/scenes/notebooks/Nodes/NotebookNodeQuery.tsx index 197b49ce9edb8..20a4812f40411 100644 --- a/frontend/src/scenes/notebooks/Nodes/NotebookNodeQuery.tsx +++ b/frontend/src/scenes/notebooks/Nodes/NotebookNodeQuery.tsx @@ -9,11 +9,21 @@ import { insightDataLogic } from 'scenes/insights/insightDataLogic' import { insightLogic } from 'scenes/insights/insightLogic' import { useSummarizeInsight } from 'scenes/insights/summarizeInsight' import { createPostHogWidgetNode } from 'scenes/notebooks/Nodes/NodeWrapper' +import { notebookLogic } from 'scenes/notebooks/Notebook/notebookLogic' import { urls } from 'scenes/urls' import { Query } from '~/queries/Query/Query' import { DataTableNode, InsightQueryNode, InsightVizNode, NodeKind, QuerySchema } from '~/queries/schema/schema-general' -import { containsHogQLQuery, isHogQLQuery, isInsightVizNode, isNodeWithSource } from '~/queries/utils' +import { + containsHogQLQuery, + isActorsQuery, + isDataTableNode, + isEventsQuery, + isHogQLQuery, + isInsightVizNode, + isNodeWithSource, + isSavedInsightNode, +} from '~/queries/utils' import { InsightLogicProps, InsightShortId } from '~/types' import { NotebookNodeAttributeProperties, NotebookNodeProps, NotebookNodeType } from '../types' @@ -77,9 +87,9 @@ const Component = ({ }, [query, insightName]) const modifiedQuery = useMemo(() => { - const modifiedQuery = { ...query, full: false } + let modifiedQuery = { ...query, full: false } - if (NodeKind.DataTableNode === modifiedQuery.kind || NodeKind.SavedInsightNode === modifiedQuery.kind) { + if (isDataTableNode(modifiedQuery) || isSavedInsightNode(modifiedQuery)) { modifiedQuery.showOpenEditorButton = false modifiedQuery.full = false modifiedQuery.showHogQLEditor = false @@ -87,7 +97,7 @@ const Component = ({ modifiedQuery.showTimings = false } - if (NodeKind.InsightVizNode === modifiedQuery.kind || NodeKind.SavedInsightNode === modifiedQuery.kind) { + if (isInsightVizNode(modifiedQuery) || isSavedInsightNode(modifiedQuery)) { modifiedQuery.showFilters = false modifiedQuery.showHeader = false modifiedQuery.showTable = false @@ -129,18 +139,21 @@ const Component = ({ type NotebookNodeQueryAttributes = { query: QuerySchema + /* Whether canvasFiltersOverride is applied, as we should apply it only once */ + isDefaultFilterApplied: boolean } export const Settings = ({ attributes, updateAttributes, }: NotebookNodeAttributeProperties): JSX.Element => { - const { query } = attributes + const { query, isDefaultFilterApplied } = attributes + const { canvasFiltersOverride } = useValues(notebookLogic) const modifiedQuery = useMemo(() => { const modifiedQuery = { ...query, full: false } - if (NodeKind.DataTableNode === modifiedQuery.kind || NodeKind.SavedInsightNode === modifiedQuery.kind) { + if (isDataTableNode(modifiedQuery) || isSavedInsightNode(modifiedQuery)) { modifiedQuery.showOpenEditorButton = false modifiedQuery.showHogQLEditor = true modifiedQuery.showResultsTable = false @@ -160,18 +173,33 @@ export const Settings = ({ modifiedQuery.showColumnConfigurator = true } - if (NodeKind.InsightVizNode === modifiedQuery.kind || NodeKind.SavedInsightNode === modifiedQuery.kind) { + if (isInsightVizNode(modifiedQuery) || isSavedInsightNode(modifiedQuery)) { modifiedQuery.showFilters = true modifiedQuery.showHeader = true modifiedQuery.showResults = false modifiedQuery.embedded = true } + if ( + isInsightVizNode(modifiedQuery) && + !isHogQLQuery(modifiedQuery.source) && + !isActorsQuery(modifiedQuery.source) && + !isDefaultFilterApplied + ) { + modifiedQuery.source.properties = canvasFiltersOverride + updateAttributes({ ...attributes, isDefaultFilterApplied: true }) + } + + if (isDataTableNode(modifiedQuery) && isEventsQuery(modifiedQuery.source) && !isDefaultFilterApplied) { + modifiedQuery.source.fixedProperties = canvasFiltersOverride + updateAttributes({ ...attributes, isDefaultFilterApplied: true }) + } + return modifiedQuery - }, [query]) + }, [query, canvasFiltersOverride]) const detachSavedInsight = (): void => { - if (attributes.query.kind === NodeKind.SavedInsightNode) { + if (isSavedInsightNode(attributes.query)) { const insightProps: InsightLogicProps = { dashboardItemId: attributes.query.shortId } const dataLogic = insightDataLogic.findMounted(insightProps) @@ -181,7 +209,7 @@ export const Settings = ({ } } - return attributes.query.kind === NodeKind.SavedInsightNode ? ( + return isSavedInsightNode(attributes.query) ? (
Insight created outside of this notebook
@@ -241,9 +269,12 @@ export const NotebookNodeQuery = createPostHogWidgetNode - query.kind === NodeKind.SavedInsightNode + isSavedInsightNode(query) ? urls.insightView(query.shortId) : isInsightVizNode(query) ? urls.insightNew({ query }) @@ -257,6 +288,7 @@ export const NotebookNodeQuery = createPostHogWidgetNode boolean, fn: () => any): Promise { @@ -151,6 +153,7 @@ export const notebookLogic = kea([ setAccessDeniedToNotebook: true, }), reducers(({ props }) => ({ + canvasFiltersOverride: [props.canvasFiltersOverride ?? ([] as AnyPropertyFilter[])], isShareModalOpen: [ false, { diff --git a/frontend/src/scenes/persons/PersonFeedCanvas.tsx b/frontend/src/scenes/persons/PersonFeedCanvas.tsx index 43a7c975d34ad..6c0dc574c5fb8 100644 --- a/frontend/src/scenes/persons/PersonFeedCanvas.tsx +++ b/frontend/src/scenes/persons/PersonFeedCanvas.tsx @@ -1,10 +1,11 @@ -import { useValues } from 'kea' +import { BindLogic, useValues } from 'kea' import { uuid } from 'lib/utils' import { preflightLogic } from 'scenes/PreflightCheck/preflightLogic' import { Notebook } from 'scenes/notebooks/Notebook/Notebook' +import { notebookLogic } from 'scenes/notebooks/Notebook/notebookLogic' -import { PersonType } from '~/types' +import { AnyPropertyFilter, PersonType, PropertyFilterType, PropertyOperator } from '~/types' type PersonFeedCanvasProps = { person: PersonType @@ -15,61 +16,74 @@ const PersonFeedCanvas = ({ person }: PersonFeedCanvasProps): JSX.Element => { const id = person.id const distinctId = person.distinct_ids[0] + const shortId = `canvas-${id}` + const mode = 'canvas' + + const personFilter: AnyPropertyFilter[] = [ + { + type: PropertyFilterType.EventMetadata, + key: 'person_id', + value: id, + operator: PropertyOperator.Exact, + }, + ] return ( - + + ], + }} + /> + ) }