From c7e8c35cf2fff0de332996978e66bcd2989cb839 Mon Sep 17 00:00:00 2001 From: Ben White Date: Wed, 8 Nov 2023 09:55:47 +0100 Subject: [PATCH] Added menu to panel --- .../src/scenes/notebooks/NotebookMenu.tsx | 54 ++++++++++++++++++ .../notebooks/NotebookPanel/NotebookPanel.tsx | 15 ++--- .../src/scenes/notebooks/NotebookScene.tsx | 55 ++----------------- 3 files changed, 62 insertions(+), 62 deletions(-) create mode 100644 frontend/src/scenes/notebooks/NotebookMenu.tsx diff --git a/frontend/src/scenes/notebooks/NotebookMenu.tsx b/frontend/src/scenes/notebooks/NotebookMenu.tsx new file mode 100644 index 0000000000000..50729918094b3 --- /dev/null +++ b/frontend/src/scenes/notebooks/NotebookMenu.tsx @@ -0,0 +1,54 @@ +import { useActions, useValues } from 'kea' +import { NotebookLogicProps, notebookLogic } from './Notebook/notebookLogic' +import { LemonButton } from '@posthog/lemon-ui' +import { IconDelete, IconEllipsis, IconExport, IconNotification, IconShare } from 'lib/lemon-ui/icons' +import { LemonMenu } from 'lib/lemon-ui/LemonMenu' +import { notebooksModel } from '~/models/notebooksModel' +import { router } from 'kea-router' +import { urls } from 'scenes/urls' +import './NotebookScene.scss' +import { openNotebookShareDialog } from './Notebook/NotebookShare' + +export function NotebookMenu({ shortId }: NotebookLogicProps): JSX.Element { + const { notebook, showHistory, isLocalOnly } = useValues(notebookLogic({ shortId })) + const { exportJSON, setShowHistory } = useActions(notebookLogic({ shortId })) + + return ( + , + onClick: () => exportJSON(), + }, + { + label: 'History', + icon: , + onClick: () => setShowHistory(!showHistory), + }, + !isLocalOnly && { + label: 'Share', + icon: , + onClick: () => openNotebookShareDialog({ shortId }), + }, + !notebook?.is_template && { + label: 'Delete', + icon: , + status: 'danger', + + onClick: () => { + notebooksModel.actions.deleteNotebook(shortId, notebook?.title) + router.actions.push(urls.notebooks()) + }, + }, + ], + }, + ]} + actionable + > + } status="stealth" size="small" /> + + ) +} diff --git a/frontend/src/scenes/notebooks/NotebookPanel/NotebookPanel.tsx b/frontend/src/scenes/notebooks/NotebookPanel/NotebookPanel.tsx index d2a49064c8dfa..b08ceecd1139e 100644 --- a/frontend/src/scenes/notebooks/NotebookPanel/NotebookPanel.tsx +++ b/frontend/src/scenes/notebooks/NotebookPanel/NotebookPanel.tsx @@ -2,16 +2,16 @@ import { useActions, useValues } from 'kea' import './NotebookPanel.scss' import { Notebook } from '../Notebook/Notebook' import { LemonButton } from '@posthog/lemon-ui' -import { IconOpenInNew, IconShare } from 'lib/lemon-ui/icons' +import { IconOpenInNew } from 'lib/lemon-ui/icons' import { useMemo } from 'react' import { NotebookListMini } from '../Notebook/NotebookListMini' import { NotebookExpandButton, NotebookSyncInfo } from '../Notebook/NotebookMeta' import { notebookLogic } from '../Notebook/notebookLogic' import { useResizeBreakpoints } from 'lib/hooks/useResizeObserver' -import { openNotebookShareDialog } from '../Notebook/NotebookShare' import { notebookPanelLogic } from './notebookPanelLogic' import { NotebookPanelDropzone } from './NotebookPanelDropzone' import { urls } from 'scenes/urls' +import { NotebookMenu } from '../NotebookMenu' export function NotebookPanel(): JSX.Element | null { const { selectedNotebook, initialAutofocus, droppedResource, dropProperties } = useValues(notebookPanelLogic) @@ -52,16 +52,9 @@ export function NotebookPanel(): JSX.Element | null { tooltipPlacement="left" /> - openNotebookShareDialog({ shortId: selectedNotebook })} - status="primary-alt" - icon={} - tooltip="Share notebook" - tooltipPlacement="left" - /> - {contentWidthHasEffect && } + + diff --git a/frontend/src/scenes/notebooks/NotebookScene.tsx b/frontend/src/scenes/notebooks/NotebookScene.tsx index 64e21c6c24410..b9b990a6b4ec2 100644 --- a/frontend/src/scenes/notebooks/NotebookScene.tsx +++ b/frontend/src/scenes/notebooks/NotebookScene.tsx @@ -7,26 +7,14 @@ import { NotebookSceneLogicProps, notebookSceneLogic } from './notebookSceneLogi import { LemonButton, LemonTag } from '@posthog/lemon-ui' import { NotebookExpandButton, NotebookSyncInfo } from './Notebook/NotebookMeta' import { UserActivityIndicator } from 'lib/components/UserActivityIndicator/UserActivityIndicator' -import { - IconArrowRight, - IconDelete, - IconEllipsis, - IconExport, - IconHelpOutline, - IconNotification, - IconShare, -} from 'lib/lemon-ui/icons' -import { LemonMenu } from 'lib/lemon-ui/LemonMenu' -import { notebooksModel } from '~/models/notebooksModel' -import { router } from 'kea-router' -import { urls } from 'scenes/urls' +import { IconArrowRight, IconHelpOutline } from 'lib/lemon-ui/icons' import { LOCAL_NOTEBOOK_TEMPLATES } from './NotebookTemplates/notebookTemplates' import './NotebookScene.scss' import { featureFlagLogic } from 'lib/logic/featureFlagLogic' import { FEATURE_FLAGS } from 'lib/constants' import { NotebookLoadingState } from './Notebook/NotebookLoadingState' -import { openNotebookShareDialog } from './Notebook/NotebookShare' import { notebookPanelLogic } from './NotebookPanel/notebookPanelLogic' +import { NotebookMenu } from './NotebookMenu' interface NotebookSceneProps { shortId?: string @@ -42,8 +30,7 @@ export const scene: SceneExport = { export function NotebookScene(): JSX.Element { const { notebookId, loading } = useValues(notebookSceneLogic) - const { notebook, conflictWarningVisible, showHistory } = useValues(notebookLogic({ shortId: notebookId })) - const { exportJSON, setShowHistory } = useActions(notebookLogic({ shortId: notebookId })) + const { notebook, conflictWarningVisible } = useValues(notebookLogic({ shortId: notebookId })) const { selectNotebook, closeSidePanel } = useActions(notebookPanelLogic) const { selectedNotebook, visibility } = useValues(notebookPanelLogic) @@ -90,42 +77,8 @@ export function NotebookScene(): JSX.Element {
- , - onClick: () => exportJSON(), - }, - { - label: 'History', - icon: , - onClick: () => setShowHistory(!showHistory), - }, - { - label: 'Share', - icon: , - onClick: () => openNotebookShareDialog({ shortId: notebookId }), - }, - !isTemplate && { - label: 'Delete', - icon: , - status: 'danger', + - onClick: () => { - notebooksModel.actions.deleteNotebook(notebookId, notebook?.title) - router.actions.push(urls.notebooks()) - }, - }, - ], - }, - ]} - actionable - > - } status="stealth" size="small" /> - }