From e5271bdef16511a69b585e9a124bf9167dc6c1ec Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 9 Mar 2023 14:15:43 +0000 Subject: [PATCH] Command palette (#9942) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * command palette E2E * tidy up * Improve theming with spectrum badges and dedupe spectrum label usage * Update data section nav to match designs and use panel component * Fix main content layout in data section * Update data section routing for tables * Improve data section routing for tables to account for edge cases * Update internal and sample datasource routing * Update external datasource routing * Update routing for queries and make a top level concept like everything else * Update routing for views * Fix undefined reference when deleting datasource * Reduce network calls and fix issues with stale datasourcenavigator state * Update routing for REST queries and unify routes for normal queries and REST queries * Lint * Fix links for queries from datasource details page * Remove redundant API calls and improve table deletion logic * Improve data entity deletion logic and redirection and fix query details keying * Improve determination of selected item in datasource tree * Update command palette to support new data routes * Update command palette, fix keybind issues and updating loading state * Lint * Fix publish command and fix preview published app URL * Fix BBUI import * Lint * Fix datasource navigator selected state not working for internal DB or sample data * Update command palette to use ctr+k/cmd+k * Update command palette to match new designs and add visible categories * Restore missing styles£ * Use proper theme constants for changing theme in command palette * Add command palette action for inviting users --------- Co-authored-by: Martin McKeaveney --- packages/bbui/src/Modal/Modal.svelte | 10 +- .../commandPalette/CommandPalette.svelte | 333 ++++++++++++++++++ .../builder/app/[application]/_layout.svelte | 21 +- .../data/table/[tableId]/index.svelte | 4 +- 4 files changed, 360 insertions(+), 8 deletions(-) create mode 100644 packages/builder/src/components/commandPalette/CommandPalette.svelte diff --git a/packages/bbui/src/Modal/Modal.svelte b/packages/bbui/src/Modal/Modal.svelte index 45081356c1..f56ef1187f 100644 --- a/packages/bbui/src/Modal/Modal.svelte +++ b/packages/bbui/src/Modal/Modal.svelte @@ -29,6 +29,14 @@ visible = false } + export function toggle() { + if (visible) { + hide() + } else { + show() + } + } + export function cancel() { if (!visible) { return @@ -61,7 +69,7 @@ } } - setContext(Context.Modal, { show, hide, cancel }) + setContext(Context.Modal, { show, hide, toggle, cancel }) onMount(() => { document.addEventListener("keydown", handleKey) diff --git a/packages/builder/src/components/commandPalette/CommandPalette.svelte b/packages/builder/src/components/commandPalette/CommandPalette.svelte new file mode 100644 index 0000000000..cf976a799e --- /dev/null +++ b/packages/builder/src/components/commandPalette/CommandPalette.svelte @@ -0,0 +1,333 @@ + + + + +
+
+ + +
+
+ {#each categories as [name, results], catIdx} +
+ {name} +
+ {#each results as command, cmdIdx} +
runAction(command)} + class:selected={command.idx === selected} + > + + {command.type}:  +
+ {command.name} +
+
+ {/each} +
+
+ {/each} +
+
+
+ + diff --git a/packages/builder/src/pages/builder/app/[application]/_layout.svelte b/packages/builder/src/pages/builder/app/[application]/_layout.svelte index fe5edae1a4..ff728312c1 100644 --- a/packages/builder/src/pages/builder/app/[application]/_layout.svelte +++ b/packages/builder/src/pages/builder/app/[application]/_layout.svelte @@ -10,6 +10,7 @@ Tabs, Tab, Heading, + Modal, notifications, } from "@budibase/bbui" @@ -18,6 +19,7 @@ import { isActive, goto, layout, redirect } from "@roxi/routify" import { capitalise } from "helpers" import { onMount, onDestroy } from "svelte" + import CommandPalette from "components/commandPalette/CommandPalette.svelte" import TourWrap from "components/portal/onboarding/TourWrap.svelte" import TourPopover from "components/portal/onboarding/TourPopover.svelte" import BuilderSidePanel from "./_components/BuilderSidePanel.svelte" @@ -25,12 +27,9 @@ export let application - // Get Package and set store let promise = getPackage() - // let betaAccess = false - - // Sync once when you load the app let hasSynced = false + let commandPaletteModal $: selected = capitalise( $layout.children.find(layout => $isActive(layout.path))?.title ?? "data" @@ -50,7 +49,6 @@ $redirect("../../") } } - // Handles navigation between frontend, backend, automation. // This remembers your last place on each of the sections // e.g. if one of your screens is selected on front end, then @@ -67,6 +65,14 @@ }) } + // Event handler for the command palette + const handleKeyDown = e => { + if (e.key === "k" && (e.ctrlKey || e.metaKey)) { + e.preventDefault() + commandPaletteModal.toggle() + } + } + const initTour = async () => { // Check if onboarding is enabled. if (isEnabled(TENANT_FEATURE_FLAGS.ONBOARDING_TOUR)) { @@ -201,6 +207,11 @@ {/await} + + + + +