Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

feat: add config actions to Command Pallete (#1028)

Myles Scolnick413bc9dbb20a
diff --git a/frontend/src/components/app-config/user-config-form.tsx b/frontend/src/components/app-config/user-config-form.tsx
index 22d2035db2..60df943c8c 100644
--- a/frontend/src/components/app-config/user-config-form.tsx
+++ b/frontend/src/components/app-config/user-config-form.tsx
@@ -106,7 +106,6 @@ export const UserConfigForm: React.FC = () => {
<div>
<FormField
control={form.control}
- disabled={isWasm}
name="save.format_on_save"
render={({ field }) => (
<FormItem className="flex flex-row items-start space-x-2 space-y-0">
diff --git a/frontend/src/components/editor/actions/useConfigActions.tsx b/frontend/src/components/editor/actions/useConfigActions.tsx
new file mode 100644
index 0000000000..8cd09d9ef6
--- /dev/null
+++ b/frontend/src/components/editor/actions/useConfigActions.tsx
@@ -0,0 +1,93 @@
+/* Copyright 2024 Marimo. All rights reserved. */
+import { saveAppConfig, saveUserConfig } from "@/core/network/requests";
+import { ActionButton } from "./types";
+import { APP_WIDTHS, AppConfig, UserConfig } from "@/core/config/config-schema";
+import { useAppConfig, useUserConfig } from "@/core/config/config";
+import { useTheme } from "@/theme/useTheme";
+
+export function useConfigActions() {
+ const { theme } = useTheme();
+ const [config, setConfig] = useUserConfig();
+ const [appConfig, setAppConfig] = useAppConfig();
+
+ const handleUserConfig = async (values: UserConfig) => {
+ await saveUserConfig({ config: values }).then(() => {
+ setConfig(values);
+ });
+ };
+
+ const handleAppConfig = async (values: AppConfig) => {
+ await saveAppConfig({ config: values }).then(() => {
+ setAppConfig(values);
+ });
+ };
+
+ const actions: ActionButton[] = [
+ ...APP_WIDTHS.filter((width) => width !== appConfig.width).map((width) => ({
+ label: `App config > Set width=${width}`,
+ handle: () => {
+ handleAppConfig({
+ ...appConfig,
+ width: width,
+ });
+ },
+ })),
+ {
+ label: "Config > Toggle dark mode",
+ handle: () => {
+ handleUserConfig({
+ ...config,
+ display: {
+ // We don't use the config from the setting since
+ // we want to resolve 'system' to it's current value.
+ ...config.display,
+ theme: theme === "dark" ? "light" : "dark",
+ },
+ });
+ },
+ },
+ {
+ label: "Config > Switch keymap to VIM",
+ hidden: config.keymap.preset === "vim",
+ handle: () => {
+ handleUserConfig({
+ ...config,
+ keymap: {
+ ...config.keymap,
+ preset: "vim",
+ },
+ });
+ },
+ },
+ {
+ // Adding VIM here to make it easy to search
+ label: "Config > Switch keymap to default (current: VIM)",
+ hidden: config.keymap.preset === "default",
+ handle: () => {
+ handleUserConfig({
+ ...config,
+ keymap: {
+ ...config.keymap,
+ preset: "default",
+ },
+ });
+ },
+ },
+ {
+ label: config.completion.copilot
+ ? "Config > Disable GitHub Copilot"
+ : "Config > Enable GitHub Copilot",
+ handle: () => {
+ handleUserConfig({
+ ...config,
+ completion: {
+ ...config.completion,
+ copilot: !config.completion.copilot,
+ },
+ });
+ },
+ },
+ ];
+
+ return actions.filter((a) => !a.hidden);
+}
diff --git a/frontend/src/components/editor/controls/command-palette.tsx b/frontend/src/components/editor/controls/command-palette.tsx
index a72efd79ca..54ef2601ea 100644
--- a/frontend/src/components/editor/controls/command-palette.tsx
+++ b/frontend/src/components/editor/controls/command-palette.tsx
@@ -21,6 +21,7 @@ import { parseShortcut } from "@/core/hotkeys/shortcuts";
import { isParentAction, flattenActions } from "../actions/types";
import { useCellActionButtons } from "../actions/useCellActionButton";
import { lastFocusedCellAtom } from "@/core/cells/focus";
+import { useConfigActions } from "../actions/useConfigActions";
export const commandPaletteAtom = atom(false);
@@ -28,10 +29,16 @@ export const CommandPalette = () => {
const [open, setOpen] = useAtom(commandPaletteAtom);
const registeredActions = useRegisteredActions();
const lastFocusedCell = useAtomValue(lastFocusedCellAtom);
+ // Cell actions
let cellActions = useCellActionButtons({ cell: lastFocusedCell }).flat();
cellActions = flattenActions(cellActions);
+ // Notebook actions
+ const configActions = useConfigActions();
let notebookActions = useNotebookActions();
- notebookActions = flattenActions(notebookActions);
+ notebookActions = [
+ ...flattenActions(notebookActions),
+ ...flattenActions(configActions),
+ ];
const notebookActionsWithoutHotkeys = notebookActions.filter(
(action) => !action.hotkey,