From ef8ca0bae6ca3cabe04bfe9813192a8adc94a17d Mon Sep 17 00:00:00 2001 From: Ben White Date: Wed, 8 Nov 2023 09:38:19 +0100 Subject: [PATCH] Fixes --- .../notebooks/Nodes/NotebookNodeMention.tsx | 2 +- .../notebooks/Notebook/BacklinkCommands.tsx | 140 ------------------ 2 files changed, 1 insertion(+), 141 deletions(-) delete mode 100644 frontend/src/scenes/notebooks/Notebook/BacklinkCommands.tsx diff --git a/frontend/src/scenes/notebooks/Nodes/NotebookNodeMention.tsx b/frontend/src/scenes/notebooks/Nodes/NotebookNodeMention.tsx index 1b33b5ba9d1ea..e446a8b302fce 100644 --- a/frontend/src/scenes/notebooks/Nodes/NotebookNodeMention.tsx +++ b/frontend/src/scenes/notebooks/Nodes/NotebookNodeMention.tsx @@ -45,7 +45,7 @@ export const NotebookNodeMention = Node.create({ atom: true, serializedText: (attrs: NotebookNodeMentionAttrs): string => { - // timestamp is not a block so `getText` does not add a separator. + // mention is not a block so `getText` does not add a separator. // we need to add it manually return `(member:${attrs.id})` }, diff --git a/frontend/src/scenes/notebooks/Notebook/BacklinkCommands.tsx b/frontend/src/scenes/notebooks/Notebook/BacklinkCommands.tsx deleted file mode 100644 index ef925ef805870..0000000000000 --- a/frontend/src/scenes/notebooks/Notebook/BacklinkCommands.tsx +++ /dev/null @@ -1,140 +0,0 @@ -import { Extension } from '@tiptap/core' -import { ReactRenderer } from '@tiptap/react' -import Suggestion from '@tiptap/suggestion' -import { PluginKey } from '@tiptap/pm/state' - -import { Popover } from 'lib/lemon-ui/Popover' -import { forwardRef } from 'react' -import { - TaxonomicDefinitionTypes, - TaxonomicFilterGroup, - TaxonomicFilterGroupType, - TaxonomicFilterLogicProps, - TaxonomicFilterValue, -} from 'lib/components/TaxonomicFilter/types' -import { TaxonomicFilter } from 'lib/components/TaxonomicFilter/TaxonomicFilter' -import { EditorRange } from './utils' -import { useValues } from 'kea' -import { notebookLogic } from './notebookLogic' -import { NotebookNodeType } from '~/types' - -type BacklinkCommandsProps = { - query?: string - range?: EditorRange - onClose: () => void - decorationNode?: any -} - -const BacklinkCommandsPopover = forwardRef(function BacklinkCommandsPopover( - props: BacklinkCommandsProps, - ref -): JSX.Element | null { - return ( - } visible referenceElement={props.decorationNode} /> - ) -}) - -const BacklinkCommands = forwardRef(function BacklinkCommands({ - range = { from: 0, to: 0 }, - query, - onClose, -}): JSX.Element | null { - const { editor } = useValues(notebookLogic) - - const onSelect = ( - group: TaxonomicFilterGroup, - value: TaxonomicFilterValue, - item: TaxonomicDefinitionTypes - ): void => { - if (!editor) { - return - } - - const attrs = { - id: group.type === TaxonomicFilterGroupType.Events ? item.id : value, - title: group.getName?.(item), - type: group.type, - } - - editor - .deleteRange(range) - .insertContentAt(range, [ - { type: NotebookNodeType.Backlink, attrs }, - { type: 'text', text: ' ' }, - ]) - .run() - } - - if (!editor) { - return null - } - - const taxonomicFilterLogicProps: TaxonomicFilterLogicProps = { - groupType: TaxonomicFilterGroupType.Events, - value: query, - onChange: onSelect, - onClose: onClose, - taxonomicGroupTypes: [ - TaxonomicFilterGroupType.Events, - TaxonomicFilterGroupType.Persons, - TaxonomicFilterGroupType.Cohorts, - TaxonomicFilterGroupType.Insights, - TaxonomicFilterGroupType.FeatureFlags, - TaxonomicFilterGroupType.Experiments, - TaxonomicFilterGroupType.Dashboards, - TaxonomicFilterGroupType.Notebooks, - ], - optionsFromProp: undefined, - popoverEnabled: true, - selectFirstItem: true, - taxonomicFilterLogicKey: 'notebook', - } - - return -}) - -const BacklinkCommandsPluginKey = new PluginKey('backlink-commands') - -export const BacklinkCommandsExtension = Extension.create({ - name: 'backlink-commands', - - addProseMirrorPlugins() { - return [ - Suggestion({ - pluginKey: BacklinkCommandsPluginKey, - editor: this.editor, - char: '@', - allow: ({ range }) => range.to - range.from === 1, - render: () => { - let renderer: ReactRenderer - - const onClose = (): void => { - renderer.destroy() - this.editor.chain().focus().run() - } - - return { - onStart: (props) => { - renderer = new ReactRenderer(BacklinkCommandsPopover, { - props: { ...props, onClose }, - editor: props.editor, - }) - }, - - onUpdate(props) { - renderer.updateProps(props) - - if (!props.clientRect) { - return - } - }, - - onExit() { - onClose() - }, - } - }, - }), - ] - }, -})