Skip to content

Commit

Permalink
feat: Re-add the scratchpad to the menu and fix persistence (#18214)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite authored Oct 26, 2023
1 parent fa58cb6 commit 578a602
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 7 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ -21,7 +21,7 @@ import { InsightVizNode, Node, NodeKind } from '~/queries/schema'

export const SCRATCHPAD_NOTEBOOK: NotebookListItemType = {
short_id: 'scratchpad',
title: 'Scratchpad',
title: 'My scratchpad',
created_at: '',
created_by: null,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function NotebookListMini({ selectedNotebookId }: NotebookListMiniProps):

const selectedTitle =
selectedNotebookId === 'scratchpad'
? 'Scratchpad'
? 'My scratchpad'
: notebookTemplates.find((notebook) => notebook.short_id === selectedNotebookId)?.title ||
notebooks.find((notebook) => notebook.short_id === selectedNotebookId)?.title ||
'Untitled'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { NotebookNodeType, NotebookType } from '~/types'
export const NOTEBOOKS_VERSION = '1'

export function migrate(notebook: NotebookType): NotebookType {
let content = notebook.content.content
let content = notebook.content?.content

if (!content) {
return notebook
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/scenes/notebooks/Notebook/notebookLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export const notebookLogic = kea<notebookLogicType>([
reducers(({ props }) => ({
localContent: [
null as JSONContent | null,
{ persist: props.mode === 'notebook', prefix: NOTEBOOKS_VERSION },
{ persist: props.mode !== 'canvas', prefix: NOTEBOOKS_VERSION },
{
setLocalContent: (_, { jsonContent }) => jsonContent,
clearLocalContent: () => null,
Expand Down Expand Up @@ -198,7 +198,7 @@ export const notebookLogic = kea<notebookLogicType>([
if (props.shortId === SCRATCHPAD_NOTEBOOK.short_id) {
response = {
...values.scratchpadNotebook,
content: {},
content: null,
text_content: null,
version: 0,
}
Expand All @@ -215,7 +215,7 @@ export const notebookLogic = kea<notebookLogicType>([

const notebook = migrate(response)

if (!values.notebook) {
if (!values.notebook && notebook.content) {
// If this is the first load we need to override the content fully
values.editor?.setContent(notebook.content)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ export function NotebookSelectList(props: NotebookSelectProps): JSX.Element {
<LemonButton fullWidth icon={<IconPlus />} onClick={openNewNotebook}>
New notebook
</LemonButton>
<LemonButton
fullWidth
onClick={() => {
setShowPopover(false)
openAndAddToNotebook('scratchpad', false)
}}
>
My scratchpad
</LemonButton>
</div>
<LemonDivider />
<div className="overflow-y-auto flex-1">
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3060,7 +3060,7 @@ export type NotebookListItemType = {
}

export type NotebookType = NotebookListItemType & {
content: JSONContent // TODO: Type this better
content: JSONContent | null
version: number
// used to power text-based search
text_content?: string | null
Expand Down

0 comments on commit 578a602

Please sign in to comment.