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

chore: remove edit mode from notebook scene #17374

Merged
merged 3 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion cypress/e2e/notebooks.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('Notebooks', () => {
})

it('Insertion suggestions can be dismissed', () => {
cy.visit(urls.notebookEdit('h11RoiwV'))
cy.visit(urls.notebook('h11RoiwV'))
cy.get('.NotebookEditor').type('{enter}')

cy.get('.NotebookRecordingTimestamp--preview').should('exist')
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion frontend/src/models/notebooksModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const openNotebook = async (
if (popoverLogic?.values.visibility === 'visible') {
popoverLogic?.actions.selectNotebook(notebookId)
} else {
router.actions.push(urls.notebookEdit(notebookId))
router.actions.push(urls.notebook(notebookId))
}

popoverLogic?.actions.setInitialAutofocus(focus)
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/scenes/notebooks/Notebook/NotebookPopover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function NotebookPopover(): JSX.Element {
}
}, [ref.current])

const isEditable = visibility !== 'hidden' && !notebook?.is_template
const editable = visibility !== 'hidden' && !notebook?.is_template

return (
<div
Expand Down Expand Up @@ -115,7 +115,7 @@ export function NotebookPopover(): JSX.Element {
<Notebook
key={selectedNotebook}
shortId={selectedNotebook}
editable={isEditable}
editable={editable}
initialAutofocus={initialAutofocus}
/>
)}
Expand Down
34 changes: 5 additions & 29 deletions frontend/src/scenes/notebooks/NotebookScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { notebookLogic } from './Notebook/notebookLogic'
import { Notebook } from './Notebook/Notebook'
import { NotFound } from 'lib/components/NotFound'
import { NotebookSceneLogicProps, notebookSceneLogic } from './notebookSceneLogic'
import { NotebookMode } from '~/types'
import { LemonButton, LemonTag } from '@posthog/lemon-ui'
import { notebookPopoverLogic } from './Notebook/notebookPopoverLogic'
import { NotebookExpandButton, NotebookSyncInfo } from './Notebook/NotebookMeta'
Expand Down Expand Up @@ -32,8 +31,7 @@ export const scene: SceneExport = {
}

export function NotebookScene(): JSX.Element {
const { notebookId, mode } = useValues(notebookSceneLogic)
const { setNotebookMode } = useActions(notebookSceneLogic)
const { notebookId } = useValues(notebookSceneLogic)
const { notebook, notebookLoading, conflictWarningVisible } = useValues(notebookLogic({ shortId: notebookId }))
const { exportJSON } = useActions(notebookLogic({ shortId: notebookId }))
const { selectNotebook, setVisibility } = useActions(notebookPopoverLogic)
Expand Down Expand Up @@ -65,13 +63,13 @@ export function NotebookScene(): JSX.Element {
)
}

const editEnabled = !notebook?.is_template
const isTemplate = notebook?.is_template

return (
<div className="NotebookScene">
<div className="flex items-center justify-between border-b py-2 mb-2 sticky top-0 bg-bg-3000 z-10">
<div className="flex gap-2 items-center">
{notebook?.is_template && <LemonTag type="highlight">TEMPLATE</LemonTag>}
{isTemplate && <LemonTag type="highlight">TEMPLATE</LemonTag>}
<UserActivityIndicator at={notebook?.last_modified_at} by={notebook?.last_modified_by} />
</div>

Expand All @@ -89,7 +87,7 @@ export function NotebookScene(): JSX.Element {
exportJSON()
},
},
editEnabled && {
!isTemplate && {
label: 'Delete',
icon: <IconDelete />,
status: 'danger',
Expand Down Expand Up @@ -135,32 +133,10 @@ export function NotebookScene(): JSX.Element {
>
Pin to side
</LemonButton>

{!editEnabled ? null : mode === NotebookMode.Edit ? (
<>
<LemonButton
size={buttonSize}
type="primary"
onClick={() => setNotebookMode(NotebookMode.View)}
>
Done
</LemonButton>
</>
) : (
<>
<LemonButton
size={buttonSize}
type="primary"
onClick={() => setNotebookMode(NotebookMode.Edit)}
>
Edit
</LemonButton>
</>
)}
</div>
</div>

<Notebook key={notebookId} shortId={notebookId} editable={editEnabled && mode === NotebookMode.Edit} />
<Notebook key={notebookId} shortId={notebookId} editable={!isTemplate} />
</div>
)
}
36 changes: 2 additions & 34 deletions frontend/src/scenes/notebooks/notebookSceneLogic.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { actions, afterMount, connect, kea, key, path, props, reducers, selectors } from 'kea'
import { Breadcrumb, NotebookMode } from '~/types'
import { actionToUrl, urlToAction } from 'kea-router'
import { afterMount, connect, kea, key, path, props, selectors } from 'kea'
import { Breadcrumb } from '~/types'

import type { notebookSceneLogicType } from './notebookSceneLogicType'
import { notebookLogic } from './Notebook/notebookLogic'
Expand All @@ -17,17 +16,6 @@ export const notebookSceneLogic = kea<notebookSceneLogicType>([
values: [notebookLogic(props), ['notebook', 'notebookLoading']],
actions: [notebookLogic(props), ['loadNotebook']],
})),
actions({
setNotebookMode: (mode: NotebookMode) => ({ mode }),
}),
reducers({
mode: [
NotebookMode.View as NotebookMode,
{
setNotebookMode: (_, { mode }) => mode,
},
],
}),
selectors(() => ({
notebookId: [() => [(_, props) => props], (props): string => props.shortId],

Expand All @@ -48,26 +36,6 @@ export const notebookSceneLogic = kea<notebookSceneLogicType>([
],
],
})),
urlToAction(({ props, actions, values }) => ({
[`/notebooks/${props.shortId}(/:mode)`]: (
{ mode } // url params
) => {
const newMode = mode === 'edit' ? NotebookMode.Edit : NotebookMode.View

if (newMode !== values.mode) {
actions.setNotebookMode(newMode)
}
},
})),
actionToUrl(({ values, props }) => {
return {
setNotebookMode: () => {
return values.mode === NotebookMode.View
? urls.notebook(props.shortId)
: urls.notebookEdit(props.shortId)
},
}
}),

afterMount(({ actions }) => {
actions.loadNotebook()
Expand Down
1 change: 0 additions & 1 deletion frontend/src/scenes/scenes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,5 +481,4 @@ export const routes: Record<string, Scene> = {
[urls.feedback()]: Scene.Feedback,
[urls.feedback() + '/*']: Scene.Feedback,
[urls.notebook(':shortId')]: Scene.Notebook,
[urls.notebookEdit(':shortId')]: Scene.Notebook,
}
1 change: 0 additions & 1 deletion frontend/src/scenes/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,4 @@ export const urls = {
tab: 'notebooks',
}).url,
notebook: (shortId: string): string => `/notebooks/${shortId}`,
notebookEdit: (shortId: string): string => `/notebooks/${shortId}/edit`,
}
5 changes: 0 additions & 5 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3021,11 +3021,6 @@ export type NotebookType = NotebookListItemType & {
version: number
}

export enum NotebookMode {
View = 'view',
Edit = 'edit',
}

export enum NotebookNodeType {
Insight = 'ph-insight',
Query = 'ph-query',
Expand Down