From cc765ef6b44e38ed5e7f82faae7a886b0726a3c5 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 14 Jan 2025 15:44:10 +0000 Subject: [PATCH] Use global context when requesting client context and no component is selected --- packages/client/src/constants.js | 1 + packages/client/src/index.js | 6 ++++-- packages/client/src/stores/components.js | 3 ++- packages/client/src/stores/screens.js | 6 +++--- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/client/src/constants.js b/packages/client/src/constants.js index f7e3e86d40..a3d06fd48f 100644 --- a/packages/client/src/constants.js +++ b/packages/client/src/constants.js @@ -15,6 +15,7 @@ export const ActionTypes = { export const DNDPlaceholderID = "dnd-placeholder" export const ScreenslotType = "screenslot" +export const ScreenslotID = "screenslot" export const GridRowHeight = 24 export const GridColumns = 12 export const GridSpacing = 4 diff --git a/packages/client/src/index.js b/packages/client/src/index.js index 9cef52bb1e..e3f5c34d3e 100644 --- a/packages/client/src/index.js +++ b/packages/client/src/index.js @@ -86,8 +86,10 @@ const loadBudibase = async () => { dndStore.actions.reset() } } else if (type === "request-context") { - const { selectedComponentInstance } = get(componentStore) - const context = selectedComponentInstance?.getDataContext() + const { selectedComponentInstance, screenslotInstance } = + get(componentStore) + const instance = selectedComponentInstance || screenslotInstance + const context = instance?.getDataContext() let stringifiedContext = null try { stringifiedContext = JSON.stringify(context) diff --git a/packages/client/src/stores/components.js b/packages/client/src/stores/components.js index d4afa6c7f1..8a8f82883d 100644 --- a/packages/client/src/stores/components.js +++ b/packages/client/src/stores/components.js @@ -6,7 +6,7 @@ import { screenStore } from "./screens" import { builderStore } from "./builder" import Router from "../components/Router.svelte" import * as AppComponents from "../components/app/index.js" -import { ScreenslotType } from "../constants.js" +import { ScreenslotID, ScreenslotType } from "../constants.js" export const BudibasePrefix = "@budibase/standard-components/" @@ -43,6 +43,7 @@ const createComponentStore = () => { selectedComponentDefinition: definition, selectedComponentPath: selectedPath?.map(component => component._id), mountedComponentCount: Object.keys($store.mountedComponents).length, + screenslotInstance: $store.mountedComponents[ScreenslotID], } } ) diff --git a/packages/client/src/stores/screens.js b/packages/client/src/stores/screens.js index bc87216660..7261ca375a 100644 --- a/packages/client/src/stores/screens.js +++ b/packages/client/src/stores/screens.js @@ -7,7 +7,7 @@ import { dndIndex, dndParent, dndIsNewComponent, dndBounds } from "./dnd.js" import { RoleUtils } from "@budibase/frontend-core" import { findComponentById, findComponentParent } from "../utils/components.js" import { Helpers } from "@budibase/bbui" -import { DNDPlaceholderID } from "constants" +import { DNDPlaceholderID, ScreenslotID, ScreenslotType } from "constants" const createScreenStore = () => { const store = derived( @@ -163,8 +163,8 @@ const createScreenStore = () => { _component: "@budibase/standard-components/layout", _children: [ { - _component: "screenslot", - _id: "screenslot", + _component: ScreenslotType, + _id: ScreenslotID, _styles: { normal: { flex: "1 1 auto",