-
Notifications
You must be signed in to change notification settings - Fork 329
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: wasm loading styles and hide save (#3396)
- Loading branch information
Showing
5 changed files
with
110 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* Copyright 2024 Marimo. All rights reserved. */ | ||
import { expect, describe, it } from "vitest"; | ||
import { store } from "@/core/state/jotai"; | ||
import { hasAnyOutputAtom } from "../state"; | ||
import { notebookAtom } from "@/core/cells/cells"; | ||
import type { NotebookState } from "@/core/cells/cells"; | ||
import { MultiColumn, CollapsibleTree } from "@/utils/id-tree"; | ||
import type { OutputMessage } from "@/core/kernel/messages"; | ||
import type { CellId } from "@/core/cells/ids"; | ||
import { createRef } from "react"; | ||
import { createCellRuntimeState } from "@/core/cells/types"; | ||
import { createCell } from "@/core/cells/types"; | ||
|
||
describe("hasAnyOutputAtom", () => { | ||
const createNotebookState = ( | ||
outputs: Array<OutputMessage | null>, | ||
): NotebookState => ({ | ||
cellIds: new MultiColumn([ | ||
CollapsibleTree.from(outputs.map((_, i) => `${i}` as CellId)), | ||
]), | ||
cellData: Object.fromEntries( | ||
outputs.map((_, i) => [ | ||
`${i}` as CellId, | ||
createCell({ id: `${i}` as CellId }), | ||
]), | ||
), | ||
cellRuntime: Object.fromEntries( | ||
outputs.map((output, i) => [ | ||
`${i}` as CellId, | ||
createCellRuntimeState({ | ||
output, | ||
outline: { items: [] }, | ||
}), | ||
]), | ||
), | ||
cellHandles: Object.fromEntries( | ||
outputs.map((_, i) => [`${i}` as CellId, createRef()]), | ||
), | ||
cellLogs: [], | ||
scrollKey: null, | ||
history: [], | ||
}); | ||
|
||
it("should return false when there are no outputs", () => { | ||
store.set(notebookAtom, createNotebookState([null, null])); | ||
expect(store.get(hasAnyOutputAtom)).toBe(false); | ||
}); | ||
|
||
it("should return false when all outputs are empty", () => { | ||
store.set( | ||
notebookAtom, | ||
createNotebookState([ | ||
{ channel: "output", mimetype: "text/plain", data: "", timestamp: 0 }, | ||
{ channel: "output", mimetype: "text/plain", data: "", timestamp: 0 }, | ||
]), | ||
); | ||
expect(store.get(hasAnyOutputAtom)).toBe(false); | ||
}); | ||
|
||
it("should return true when there is at least one non-empty output", () => { | ||
store.set( | ||
notebookAtom, | ||
createNotebookState([ | ||
{ channel: "output", mimetype: "text/plain", data: "", timestamp: 0 }, | ||
{ | ||
channel: "output", | ||
mimetype: "text/plain", | ||
data: "hello", | ||
timestamp: 0, | ||
}, | ||
]), | ||
); | ||
expect(store.get(hasAnyOutputAtom)).toBe(true); | ||
}); | ||
|
||
it("should handle various output types", () => { | ||
store.set( | ||
notebookAtom, | ||
createNotebookState([ | ||
{ | ||
channel: "output", | ||
mimetype: "application/json", | ||
data: { foo: "bar" }, | ||
timestamp: 0, | ||
}, | ||
{ channel: "output", mimetype: "text/plain", data: "", timestamp: 0 }, | ||
]), | ||
); | ||
expect(store.get(hasAnyOutputAtom)).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
/* Copyright 2024 Marimo. All rights reserved. */ | ||
import { atom } from "jotai"; | ||
import { notebookAtom } from "../cells/cells"; | ||
import { isOutputEmpty } from "../cells/outputs"; | ||
|
||
export const wasmInitializationAtom = atom<string>("Initializing..."); | ||
|
||
export const hasAnyOutputAtom = atom<boolean>((get) => { | ||
const notebook = get(notebookAtom); | ||
return Object.values(notebook.cellRuntime).some((runtime) => | ||
Boolean(runtime.output), | ||
return Object.values(notebook.cellRuntime).some( | ||
(runtime) => !isOutputEmpty(runtime.output), | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters