Skip to content

Commit b19fac1

Browse files
authored
feat(customers): Filter insight by group in GroupFeedCanvas (#42250)
## Problem When viewing a group feed canvas, we need to automatically filter the notebook content to only show data relevant to the specific group being viewed. Currently, the canvas does not apply any group-specific filters. ## Changes * Created a group filter based on the group type index and group key * Used the aggregation label from the groups model to provide a human-readable label for the filter This ensures that when users view a group's feed canvas, they only see data relevant to that specific group. ![Kapture 2025-11-28 at 11 06 52](https://github.com/user-attachments/assets/3d86892c-156c-4c96-8ffe-bded75571bdc) Caption: adding events node to group canvas returns only events related to that group (performed by their related person). The filter is set as a `fixedProperties`, so it doesn't show up as removable. Adding trends node shows only events related to the group too (and the counts match). The filter in this case is removable, but set as default. ## How did you test this code? Tested by: 1. Viewing group feed canvases for different groups and group types and verifying that only data for the selected group appears 2. Checking that the filter is correctly applied with the proper group type and key 3. Confirming that the aggregation label is displayed correctly in the filter 4. Ensuring each insight type available is filtered correctly ## Changelog: Yes
1 parent 03b7366 commit b19fac1

File tree

1 file changed

+77
-58
lines changed

1 file changed

+77
-58
lines changed
Lines changed: 77 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import { BindLogic } from 'kea'
1+
import { BindLogic, useValues } from 'kea'
22

33
import { uuid } from 'lib/utils'
44
import { groupLogic } from 'scenes/groups/groupLogic'
55
import { Notebook } from 'scenes/notebooks/Notebook/Notebook'
6+
import { notebookLogic } from 'scenes/notebooks/Notebook/notebookLogic'
67

7-
import { Group } from '~/types'
8+
import { groupsModel } from '~/models/groupsModel'
9+
import { AnyPropertyFilter, Group, PropertyFilterType, PropertyOperator } from '~/types'
810

911
interface GroupFeedCanvasProps {
1012
group: Group
@@ -14,69 +16,86 @@ interface GroupFeedCanvasProps {
1416
export const GroupFeedCanvas = ({ group, tabId }: GroupFeedCanvasProps): JSX.Element => {
1517
const groupKey = group.group_key
1618
const groupTypeIndex = group.group_type_index
19+
const { aggregationLabel } = useValues(groupsModel)
20+
21+
const shortId = `canvas-${groupKey}-${tabId}`
22+
const mode = 'canvas'
23+
24+
const groupFilter: AnyPropertyFilter[] = [
25+
{
26+
type: PropertyFilterType.EventMetadata,
27+
key: `$group_${groupTypeIndex}`,
28+
label: aggregationLabel(groupTypeIndex).singular,
29+
value: groupKey,
30+
operator: PropertyOperator.Exact,
31+
},
32+
]
1733

1834
return (
19-
<BindLogic logic={groupLogic} props={{ groupKey, groupTypeIndex, tabId }}>
20-
<Notebook
21-
editable={false}
22-
shortId={`canvas-${groupKey}-${tabId}`}
23-
mode="canvas"
24-
initialContent={{
25-
type: 'doc',
26-
content: [
27-
{
28-
type: 'ph-usage-metrics',
29-
attrs: {
30-
groupKey,
31-
groupTypeIndex,
32-
tabId,
33-
nodeId: uuid(),
34-
children: [
35-
{
36-
type: 'ph-group',
37-
attrs: {
38-
id: groupKey,
39-
groupTypeIndex,
40-
tabId,
41-
nodeId: uuid(),
42-
title: 'Info',
35+
<BindLogic logic={notebookLogic} props={{ shortId, mode, canvasFiltersOverride: groupFilter }}>
36+
<BindLogic logic={groupLogic} props={{ groupKey, groupTypeIndex, tabId }}>
37+
<Notebook
38+
editable={false}
39+
shortId={`canvas-${groupKey}-${tabId}`}
40+
mode="canvas"
41+
canvasFiltersOverride={groupFilter}
42+
initialContent={{
43+
type: 'doc',
44+
content: [
45+
{
46+
type: 'ph-usage-metrics',
47+
attrs: {
48+
groupKey,
49+
groupTypeIndex,
50+
tabId,
51+
nodeId: uuid(),
52+
children: [
53+
{
54+
type: 'ph-group',
55+
attrs: {
56+
id: groupKey,
57+
groupTypeIndex,
58+
tabId,
59+
nodeId: uuid(),
60+
title: 'Info',
61+
},
4362
},
44-
},
45-
{
46-
type: 'ph-group-properties',
47-
attrs: {
48-
nodeId: uuid(),
63+
{
64+
type: 'ph-group-properties',
65+
attrs: {
66+
nodeId: uuid(),
67+
},
4968
},
50-
},
51-
{
52-
type: 'ph-related-groups',
53-
attrs: {
54-
id: groupKey,
55-
groupTypeIndex,
56-
nodeId: uuid(),
57-
title: 'Related people',
58-
type: 'person',
69+
{
70+
type: 'ph-related-groups',
71+
attrs: {
72+
id: groupKey,
73+
groupTypeIndex,
74+
nodeId: uuid(),
75+
title: 'Related people',
76+
type: 'person',
77+
},
5978
},
60-
},
61-
],
79+
],
80+
},
81+
},
82+
{
83+
type: 'ph-issues',
84+
attrs: { groupKey, groupTypeIndex, tabId, nodeId: uuid() },
6285
},
63-
},
64-
{
65-
type: 'ph-issues',
66-
attrs: { groupKey, groupTypeIndex, tabId, nodeId: uuid() },
67-
},
68-
{
69-
type: 'ph-llm-trace',
70-
attrs: {
71-
groupKey,
72-
groupTypeIndex,
73-
tabId,
74-
nodeId: uuid(),
86+
{
87+
type: 'ph-llm-trace',
88+
attrs: {
89+
groupKey,
90+
groupTypeIndex,
91+
tabId,
92+
nodeId: uuid(),
93+
},
7594
},
76-
},
77-
],
78-
}}
79-
/>
95+
],
96+
}}
97+
/>
98+
</BindLogic>
8099
</BindLogic>
81100
)
82101
}

0 commit comments

Comments
 (0)