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: add notebooks to universal search #17398

Merged
merged 6 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions frontend/src/layout/navigation/TopBar/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export function TopBar(): JSX.Element {
TaxonomicFilterGroupType.Plugins,
TaxonomicFilterGroupType.Experiments,
TaxonomicFilterGroupType.Dashboards,
TaxonomicFilterGroupType.Notebooks,
...groupNamesTaxonomicTypes,
]}
/>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1348,7 +1348,7 @@ const api = {
q = { ...q, created_by: createdBy }
}
if (search) {
q = { ...q, s: search }
q = { ...q, search: search }
}
return await apiRequest.withQueryString(q).get()
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
PersonType,
PluginType,
PropertyDefinition,
NotebookType,
} from '~/types'
import { cohortsModel } from '~/models/cohortsModel'
import { actionsModel } from '~/models/actionsModel'
Expand Down Expand Up @@ -419,6 +420,16 @@ export const taxonomicFilterLogic = kea<taxonomicFilterLogicType>({
render: InlineHogQLEditor,
getPopoverHeader: () => 'HogQL',
},
{
pauldambra marked this conversation as resolved.
Show resolved Hide resolved
name: 'Notebooks',
searchPlaceholder: 'notebooks',
type: TaxonomicFilterGroupType.Notebooks,
value: 'notebooks',
endpoint: `api/projects/${teamId}/notebooks/`,
getName: (notebook: NotebookType) => notebook.title || `Notebook ${notebook.short_id}`,
getValue: (notebook: NotebookType) => notebook.short_id,
getPopoverHeader: () => 'Notebooks',
},
...groupAnalyticsTaxonomicGroups,
...groupAnalyticsTaxonomicGroupNames,
]
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/components/TaxonomicFilter/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export enum TaxonomicFilterGroupType {
GroupNamesPrefix = 'name_groups',
Sessions = 'sessions',
HogQLExpression = 'hogql_expression',
Notebooks = 'notebooks',
}

export interface InfiniteListLogicProps extends TaxonomicFilterLogicProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ function redirectOnSelectItems(
)
} else if (groupType === TaxonomicFilterGroupType.Dashboards) {
router.actions.push(urls.dashboard(value))
} else if (groupType === TaxonomicFilterGroupType.Notebooks) {
router.actions.push(urls.notebook(String(value)))
}
}

Expand Down
24 changes: 23 additions & 1 deletion frontend/src/scenes/notebooks/Nodes/NotebookNodeBacklink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ import { mergeAttributes, Node, NodeViewProps } from '@tiptap/core'
import { NodeViewWrapper, ReactNodeViewRenderer } from '@tiptap/react'
import { InsightModel, NotebookNodeType, NotebookTarget } from '~/types'
import { Link } from '@posthog/lemon-ui'
import { IconGauge, IconBarChart, IconFlag, IconExperiment, IconLive, IconPerson, IconCohort } from 'lib/lemon-ui/icons'
import {
IconGauge,
IconBarChart,
IconFlag,
IconExperiment,
IconLive,
IconPerson,
IconCohort,
IconJournal,
} from 'lib/lemon-ui/icons'
import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
import { urls } from 'scenes/urls'
import clsx from 'clsx'
Expand All @@ -22,6 +31,7 @@ const ICON_MAP = {
events: <IconLive width="1em" height="1em" />,
persons: <IconPerson />,
cohorts: <IconCohort />,
notebooks: <IconJournal />,
}

const Component = (props: NodeViewProps): JSX.Element => {
Expand Down Expand Up @@ -67,6 +77,8 @@ function backlinkHref(id: string, type: TaxonomicFilterGroupType): string {
return urls.experiment(id)
} else if (type === TaxonomicFilterGroupType.Dashboards) {
return urls.dashboard(id)
} else if (type === TaxonomicFilterGroupType.Notebooks) {
return urls.notebook(id)
}
return ''
}
Expand Down Expand Up @@ -139,6 +151,16 @@ export const NotebookNodeBacklink = Node.create({
return { id: id, type: TaxonomicFilterGroupType.Dashboards, title: dashboard.name }
},
}),
posthogNodePasteRule({
find: urls.notebook('(.+)'),
editor: this.editor,
type: this.type,
getAttributes: async (match) => {
const id = match[1]
const notebook = await api.notebooks.get(id)
return { id: id, type: TaxonomicFilterGroupType.Notebooks, title: notebook.title }
},
}),
]
},
})
12 changes: 7 additions & 5 deletions frontend/src/scenes/notebooks/Notebook/BacklinkCommands.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { PluginKey } from '@tiptap/pm/state'
import { Popover } from 'lib/lemon-ui/Popover'
import { forwardRef } from 'react'
import {
TaxonomicDefinitionTypes,
TaxonomicFilterGroup,
TaxonomicFilterGroupType,
TaxonomicFilterLogicProps,
Expand Down Expand Up @@ -41,18 +42,18 @@ const BacklinkCommands = forwardRef<ReactRenderer, BacklinkCommandsProps>(functi
const { editor } = useValues(notebookLogic)

const onSelect = (
{ type }: TaxonomicFilterGroup,
group: TaxonomicFilterGroup,
value: TaxonomicFilterValue,
{ id, name }: { id: number; name: string }
item: TaxonomicDefinitionTypes
): void => {
if (!editor) {
return
}

const attrs = {
id: type === TaxonomicFilterGroupType.Events ? id : value,
title: name,
type: type,
id: group.type === TaxonomicFilterGroupType.Events ? item.id : value,
title: group.getName?.(item),
type: group.type,
}

editor
Expand Down Expand Up @@ -81,6 +82,7 @@ const BacklinkCommands = forwardRef<ReactRenderer, BacklinkCommandsProps>(functi
TaxonomicFilterGroupType.FeatureFlags,
TaxonomicFilterGroupType.Experiments,
TaxonomicFilterGroupType.Dashboards,
TaxonomicFilterGroupType.Notebooks,
],
optionsFromProp: undefined,
popoverEnabled: true,
Expand Down
4 changes: 2 additions & 2 deletions posthog/api/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ def _filter_request(self, request: request.Request, queryset: QuerySet) -> Query
queryset = queryset.filter(
last_modified_at__lt=relative_date_parse(request.GET["date_to"], self.team.timezone_info)
)
elif key == "s":
queryset = queryset.filter(title__icontains=request.GET["s"])
elif key == "search":
pauldambra marked this conversation as resolved.
Show resolved Hide resolved
queryset = queryset.filter(title__icontains=request.GET["search"])
elif key == "contains":
contains = request.GET["contains"]
match_pairs = contains.replace(",", " ").split(" ")
Expand Down
2 changes: 1 addition & 1 deletion posthog/api/test/notebooks/test_notebook_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_filters_based_on_title(self, search_text: str, expected_match_indexes:
]

response = self.client.get(
f"/api/projects/{self.team.id}/notebooks?s={search_text}",
f"/api/projects/{self.team.id}/notebooks?search={search_text}",
)
assert response.status_code == status.HTTP_200_OK

Expand Down