Add button action for showing/hiding side panels

This commit is contained in:
Andrew Kingston 2022-11-14 15:02:57 +00:00
parent d3528443d1
commit 7d97ef1ff5
8 changed files with 85 additions and 7 deletions

View File

@ -40,6 +40,7 @@ const INITIAL_FRONTEND_STATE = {
messagePassing: false, messagePassing: false,
continueIfAction: false, continueIfAction: false,
showNotificationAction: false, showNotificationAction: false,
sidePanel: false,
}, },
errors: [], errors: [],
hasAppPackage: false, hasAppPackage: false,

View File

@ -0,0 +1,63 @@
<script>
import { Select, Label } from "@budibase/bbui"
import { onMount } from "svelte"
import { selectedScreen } from "builderStore"
import { findAllMatchingComponents } from "builderStore/componentUtils"
export let parameters
const typeOptions = [
{
label: "Show side panel",
value: "show",
},
{
label: "Hide side panel",
value: "hide",
},
]
$: sidePanelOptions = getSidePanelOptions($selectedScreen)
const getSidePanelOptions = screen => {
const sidePanelComponents = findAllMatchingComponents(
screen.props,
component => component._component.endsWith("/sidepanel")
)
return sidePanelComponents.map(sidePanel => ({
label: sidePanel._instanceName,
value: sidePanel._id,
}))
}
onMount(() => {
if (!parameters.type) {
parameters.type = "show"
}
})
</script>
<div class="root">
<Label small>Type</Label>
<Select
placeholder={null}
bind:value={parameters.type}
options={typeOptions}
/>
{#if parameters.type === "show"}
<Label small>Side Panel</Label>
<Select bind:value={parameters.id} options={sidePanelOptions} />
{/if}
</div>
<style>
.root {
display: grid;
column-gap: var(--spacing-l);
row-gap: var(--spacing-s);
grid-template-columns: 60px 1fr;
align-items: center;
max-width: 400px;
margin: 0 auto;
}
</style>

View File

@ -16,3 +16,4 @@ export { default as ExportData } from "./ExportData.svelte"
export { default as ContinueIf } from "./ContinueIf.svelte" export { default as ContinueIf } from "./ContinueIf.svelte"
export { default as UpdateFieldValue } from "./UpdateFieldValue.svelte" export { default as UpdateFieldValue } from "./UpdateFieldValue.svelte"
export { default as ShowNotification } from "./ShowNotification.svelte" export { default as ShowNotification } from "./ShowNotification.svelte"
export { default as UpdateSidePanel } from "./UpdateSidePanel.svelte"

View File

@ -1,6 +1,7 @@
import * as ActionComponents from "./actions" import * as ActionComponents from "./actions"
import { get } from "svelte/store" import { get } from "svelte/store"
import { store } from "builderStore" import { store } from "builderStore"
// @ts-ignore
import ActionDefinitions from "./manifest.json" import ActionDefinitions from "./manifest.json"
// Defines which actions are available to configure in the front end. // Defines which actions are available to configure in the front end.

View File

@ -116,6 +116,12 @@
"type": "application", "type": "application",
"component": "ShowNotification", "component": "ShowNotification",
"dependsOnFeature": "showNotificationAction" "dependsOnFeature": "showNotificationAction"
},
{
"name": "Update Side Panel",
"type": "application",
"component": "UpdateSidePanel",
"dependsOnFeature": "sidePanel"
} }
] ]
} }

View File

@ -9,7 +9,8 @@
"messagePassing": true, "messagePassing": true,
"rowSelection": true, "rowSelection": true,
"continueIfAction": true, "continueIfAction": true,
"showNotificationAction": true "showNotificationAction": true,
"sidePanel": true
}, },
"layout": { "layout": {
"name": "Layout", "name": "Layout",

View File

@ -43,12 +43,6 @@
> >
<slot /> <slot />
</div> </div>
<div>
<button on:click={() => sidePanelStore.actions.open($component.id)}>
open
</button>
<button on:click={sidePanelStore.actions.close}>close</button>
</div>
<style> <style>
.side-panel { .side-panel {

View File

@ -10,6 +10,7 @@ import {
dataSourceStore, dataSourceStore,
uploadStore, uploadStore,
rowSelectionStore, rowSelectionStore,
sidePanelStore,
} from "stores" } from "stores"
import { API } from "api" import { API } from "api"
import { ActionTypes } from "constants" import { ActionTypes } from "constants"
@ -312,6 +313,15 @@ const showNotificationHandler = action => {
notificationStore.actions[type]?.(message, autoDismiss) notificationStore.actions[type]?.(message, autoDismiss)
} }
const UpdateSidePanelHandler = action => {
const { type, id } = action.parameters
if (type === "hide") {
sidePanelStore.actions.close()
} else if (id) {
sidePanelStore.actions.open(id)
}
}
const handlerMap = { const handlerMap = {
["Save Row"]: saveRowHandler, ["Save Row"]: saveRowHandler,
["Duplicate Row"]: duplicateRowHandler, ["Duplicate Row"]: duplicateRowHandler,
@ -331,6 +341,7 @@ const handlerMap = {
["Export Data"]: exportDataHandler, ["Export Data"]: exportDataHandler,
["Continue if / Stop if"]: continueIfHandler, ["Continue if / Stop if"]: continueIfHandler,
["Show Notification"]: showNotificationHandler, ["Show Notification"]: showNotificationHandler,
["Update Side Panel"]: UpdateSidePanelHandler,
} }
const confirmTextMap = { const confirmTextMap = {