diff --git a/lerna.json b/lerna.json index 9d0fb72b23..0e026aefc5 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "2.19.1", + "version": "2.19.3", "npmClient": "yarn", "packages": [ "packages/*", diff --git a/package.json b/package.json index 4f81d216ad..499952a441 100644 --- a/package.json +++ b/package.json @@ -106,7 +106,6 @@ "axios": "1.6.3", "xml2js": "0.6.2", "unset-value": "2.0.1", - "got": "13.0.0", "passport": "0.6.0" }, "engines": { diff --git a/packages/account-portal b/packages/account-portal index cc12291732..8c446c4ba3 160000 --- a/packages/account-portal +++ b/packages/account-portal @@ -1 +1 @@ -Subproject commit cc12291732ee902dc832bc7d93cf2086ffdf0cff +Subproject commit 8c446c4ba385592127fa31755d3b64467b291882 diff --git a/packages/builder/package.json b/packages/builder/package.json index 273994ed0e..52db8e11bc 100644 --- a/packages/builder/package.json +++ b/packages/builder/package.json @@ -23,7 +23,6 @@ "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "/internals/mocks/fileMock.js", "\\.(css|less|sass|scss)$": "identity-obj-proxy", "components(.*)$": "/src/components$1", - "builderStore(.*)$": "/src/builderStore$1", "stores(.*)$": "/src/stores$1", "analytics(.*)$": "/src/analytics$1", "constants/backend": "/src/constants/backend/index.js" diff --git a/packages/builder/src/api.js b/packages/builder/src/api.js index ac878bf82f..6441b4ff48 100644 --- a/packages/builder/src/api.js +++ b/packages/builder/src/api.js @@ -3,14 +3,14 @@ import { CookieUtils, Constants, } from "@budibase/frontend-core" -import { store } from "./builderStore" +import { appStore } from "stores/builder" import { get } from "svelte/store" import { auth, navigation } from "./stores/portal" export const API = createAPIClient({ attachHeaders: headers => { // Attach app ID header from store - let appId = get(store).appId + let appId = get(appStore).appId if (appId) { headers["x-budibase-app-id"] = appId } diff --git a/packages/builder/src/builderStore/index.js b/packages/builder/src/builderStore/index.js deleted file mode 100644 index b58d196024..0000000000 --- a/packages/builder/src/builderStore/index.js +++ /dev/null @@ -1,158 +0,0 @@ -import { getFrontendStore } from "./store/frontend" -import { getAutomationStore } from "./store/automation" -import { getTemporalStore } from "./store/temporal" -import { getThemeStore } from "./store/theme" -import { getUserStore } from "./store/users" -import { getDeploymentStore } from "./store/deployments" -import { derived, get } from "svelte/store" -import { findComponent, findComponentPath } from "./componentUtils" -import { RoleUtils } from "@budibase/frontend-core" -import { createHistoryStore } from "builderStore/store/history" -import { cloneDeep } from "lodash/fp" -import { getHoverStore } from "./store/hover" - -export const store = getFrontendStore() -export const automationStore = getAutomationStore() -export const themeStore = getThemeStore() -export const temporalStore = getTemporalStore() -export const userStore = getUserStore() -export const deploymentStore = getDeploymentStore() -export const hoverStore = getHoverStore() - -// Setup history for screens -export const screenHistoryStore = createHistoryStore({ - getDoc: id => get(store).screens?.find(screen => screen._id === id), - selectDoc: store.actions.screens.select, - afterAction: () => { - // Ensure a valid component is selected - if (!get(selectedComponent)) { - store.update(state => ({ - ...state, - selectedComponentId: get(selectedScreen)?.props._id, - })) - } - }, -}) -store.actions.screens.save = screenHistoryStore.wrapSaveDoc( - store.actions.screens.save -) -store.actions.screens.delete = screenHistoryStore.wrapDeleteDoc( - store.actions.screens.delete -) - -// Setup history for automations -export const automationHistoryStore = createHistoryStore({ - getDoc: automationStore.actions.getDefinition, - selectDoc: automationStore.actions.select, -}) -automationStore.actions.save = automationHistoryStore.wrapSaveDoc( - automationStore.actions.save -) -automationStore.actions.delete = automationHistoryStore.wrapDeleteDoc( - automationStore.actions.delete -) - -export const selectedScreen = derived(store, $store => { - return $store.screens.find(screen => screen._id === $store.selectedScreenId) -}) - -export const selectedLayout = derived(store, $store => { - return $store.layouts?.find(layout => layout._id === $store.selectedLayoutId) -}) - -export const selectedComponent = derived( - [store, selectedScreen], - ([$store, $selectedScreen]) => { - if ( - $selectedScreen && - $store.selectedComponentId?.startsWith(`${$selectedScreen._id}-`) - ) { - return $selectedScreen?.props - } - if (!$selectedScreen || !$store.selectedComponentId) { - return null - } - const selected = findComponent( - $selectedScreen?.props, - $store.selectedComponentId - ) - - const clone = selected ? cloneDeep(selected) : selected - store.actions.components.migrateSettings(clone) - return clone - } -) - -// For legacy compatibility only, but with the new design UI this is just -// the selected screen -export const currentAsset = selectedScreen - -export const sortedScreens = derived(store, $store => { - return $store.screens.slice().sort((a, b) => { - // Sort by role first - const roleA = RoleUtils.getRolePriority(a.routing.roleId) - const roleB = RoleUtils.getRolePriority(b.routing.roleId) - if (roleA !== roleB) { - return roleA > roleB ? -1 : 1 - } - // Then put home screens first - const homeA = !!a.routing.homeScreen - const homeB = !!b.routing.homeScreen - if (homeA !== homeB) { - return homeA ? -1 : 1 - } - // Then sort alphabetically by each URL param - const aParams = a.routing.route.split("/") - const bParams = b.routing.route.split("/") - let minParams = Math.min(aParams.length, bParams.length) - for (let i = 0; i < minParams; i++) { - if (aParams[i] === bParams[i]) { - continue - } - return aParams[i] < bParams[i] ? -1 : 1 - } - // Then sort by the fewest amount of URL params - return aParams.length < bParams.length ? -1 : 1 - }) -}) - -export const selectedComponentPath = derived( - [store, selectedScreen], - ([$store, $selectedScreen]) => { - return findComponentPath( - $selectedScreen?.props, - $store.selectedComponentId - ).map(component => component._id) - } -) - -// Derived automation state -export const selectedAutomation = derived(automationStore, $automationStore => { - if (!$automationStore.selectedAutomationId) { - return null - } - return $automationStore.automations?.find( - x => x._id === $automationStore.selectedAutomationId - ) -}) - -// Derive map of resource IDs to other users. -// We only ever care about a single user in each resource, so if multiple users -// share the same datasource we can just overwrite them. -export const userSelectedResourceMap = derived(userStore, $userStore => { - let map = {} - $userStore.forEach(user => { - const resource = user.builderMetadata?.selectedResourceId - if (resource) { - if (!map[resource]) { - map[resource] = [] - } - map[resource].push(user) - } - }) - return map -}) - -export const isOnlyUser = derived(userStore, $userStore => { - return $userStore.length < 2 -}) diff --git a/packages/builder/src/builderStore/store/hover.js b/packages/builder/src/builderStore/store/hover.js deleted file mode 100644 index 5db9272975..0000000000 --- a/packages/builder/src/builderStore/store/hover.js +++ /dev/null @@ -1,27 +0,0 @@ -import { get, writable } from "svelte/store" -import { store as builder } from "builderStore" - -export const getHoverStore = () => { - const initialValue = { - componentId: null, - } - - const store = writable(initialValue) - - const update = (componentId, notifyClient = true) => { - if (componentId === get(store).componentId) { - return - } - store.update(state => { - state.componentId = componentId - return state - }) - if (notifyClient) { - builder.actions.preview.sendEvent("hover-component", componentId) - } - } - return { - subscribe: store.subscribe, - actions: { update }, - } -} diff --git a/packages/builder/src/builderStore/tests/dataBinding.test.js b/packages/builder/src/builderStore/tests/dataBinding.test.js deleted file mode 100644 index 039e33a94d..0000000000 --- a/packages/builder/src/builderStore/tests/dataBinding.test.js +++ /dev/null @@ -1,545 +0,0 @@ -import { expect, describe, it, vi } from "vitest" -import { - runtimeToReadableBinding, - readableToRuntimeBinding, - updateReferencesInObject, -} from "../dataBinding" - -vi.mock("@budibase/frontend-core") -vi.mock("builderStore/componentUtils") -vi.mock("builderStore/store") -vi.mock("builderStore/store/theme") -vi.mock("builderStore/store/temporal") - -describe("runtimeToReadableBinding", () => { - const bindableProperties = [ - { - category: "Current User", - icon: "User", - providerId: "user", - readableBinding: "Current User.firstName", - runtimeBinding: "[user].[firstName]", - type: "context", - }, - { - category: "Bindings", - icon: "Brackets", - readableBinding: "Binding.count", - runtimeBinding: "count", - type: "context", - }, - ] - it("should convert a runtime binding to a readable one", () => { - const textWithBindings = `Hello {{ [user].[firstName] }}! The count is {{ count }}.` - expect( - runtimeToReadableBinding( - bindableProperties, - textWithBindings, - "readableBinding" - ) - ).toEqual( - `Hello {{ Current User.firstName }}! The count is {{ Binding.count }}.` - ) - }) - - it("should not convert to readable binding if it is already readable", () => { - const textWithBindings = `Hello {{ [user].[firstName] }}! The count is {{ Binding.count }}.` - expect( - runtimeToReadableBinding( - bindableProperties, - textWithBindings, - "readableBinding" - ) - ).toEqual( - `Hello {{ Current User.firstName }}! The count is {{ Binding.count }}.` - ) - }) -}) - -describe("readableToRuntimeBinding", () => { - const bindableProperties = [ - { - category: "Current User", - icon: "User", - providerId: "user", - readableBinding: "Current User.firstName", - runtimeBinding: "[user].[firstName]", - type: "context", - }, - { - category: "Bindings", - icon: "Brackets", - readableBinding: "Binding.count", - runtimeBinding: "count", - type: "context", - }, - ] - it("should convert a readable binding to a runtime one", () => { - const textWithBindings = `Hello {{ Current User.firstName }}! The count is {{ Binding.count }}.` - expect( - readableToRuntimeBinding( - bindableProperties, - textWithBindings, - "runtimeBinding" - ) - ).toEqual(`Hello {{ [user].[firstName] }}! The count is {{ count }}.`) - }) -}) - -describe("updateReferencesInObject", () => { - it("should increment steps in sequence on 'add'", () => { - let obj = [ - { - id: "a0", - parameters: { - text: "Alpha", - }, - }, - { - id: "a1", - parameters: { - text: "Apple", - }, - }, - { - id: "b2", - parameters: { - text: "Banana {{ actions.1.row }}", - }, - }, - { - id: "c3", - parameters: { - text: "Carrot {{ actions.1.row }}", - }, - }, - { - id: "d4", - parameters: { - text: "Dog {{ actions.3.row }}", - }, - }, - { - id: "e5", - parameters: { - text: "Eagle {{ actions.4.row }}", - }, - }, - ] - updateReferencesInObject({ - obj, - modifiedIndex: 0, - action: "add", - label: "actions", - }) - - expect(obj).toEqual([ - { - id: "a0", - parameters: { - text: "Alpha", - }, - }, - { - id: "a1", - parameters: { - text: "Apple", - }, - }, - { - id: "b2", - parameters: { - text: "Banana {{ actions.2.row }}", - }, - }, - { - id: "c3", - parameters: { - text: "Carrot {{ actions.2.row }}", - }, - }, - { - id: "d4", - parameters: { - text: "Dog {{ actions.4.row }}", - }, - }, - { - id: "e5", - parameters: { - text: "Eagle {{ actions.5.row }}", - }, - }, - ]) - }) - - it("should decrement steps in sequence on 'delete'", () => { - let obj = [ - { - id: "a1", - parameters: { - text: "Apple", - }, - }, - { - id: "b2", - parameters: { - text: "Banana {{ actions.1.row }}", - }, - }, - { - id: "d4", - parameters: { - text: "Dog {{ actions.3.row }}", - }, - }, - { - id: "e5", - parameters: { - text: "Eagle {{ actions.4.row }}", - }, - }, - ] - updateReferencesInObject({ - obj, - modifiedIndex: 2, - action: "delete", - label: "actions", - }) - - expect(obj).toEqual([ - { - id: "a1", - parameters: { - text: "Apple", - }, - }, - { - id: "b2", - parameters: { - text: "Banana {{ actions.1.row }}", - }, - }, - { - id: "d4", - parameters: { - text: "Dog {{ actions.2.row }}", - }, - }, - { - id: "e5", - parameters: { - text: "Eagle {{ actions.3.row }}", - }, - }, - ]) - }) - - it("should handle on 'move' to a lower index", () => { - let obj = [ - { - id: "a1", - parameters: { - text: "Apple", - }, - }, - { - id: "b2", - parameters: { - text: "Banana {{ actions.0.row }}", - }, - }, - { - id: "e5", - parameters: { - text: "Eagle {{ actions.3.row }}", - }, - }, - { - id: "c3", - parameters: { - text: "Carrot {{ actions.0.row }}", - }, - }, - { - id: "d4", - parameters: { - text: "Dog {{ actions.2.row }}", - }, - }, - ] - updateReferencesInObject({ - obj, - modifiedIndex: 2, - action: "move", - label: "actions", - originalIndex: 4, - }) - - expect(obj).toEqual([ - { - id: "a1", - parameters: { - text: "Apple", - }, - }, - { - id: "b2", - parameters: { - text: "Banana {{ actions.0.row }}", - }, - }, - { - id: "e5", - parameters: { - text: "Eagle {{ actions.4.row }}", - }, - }, - { - id: "c3", - parameters: { - text: "Carrot {{ actions.0.row }}", - }, - }, - { - id: "d4", - parameters: { - text: "Dog {{ actions.3.row }}", - }, - }, - ]) - }) - - it("should handle on 'move' to a higher index", () => { - let obj = [ - { - id: "b2", - parameters: { - text: "Banana {{ actions.0.row }}", - }, - }, - { - id: "c3", - parameters: { - text: "Carrot {{ actions.0.row }}", - }, - }, - { - id: "a1", - parameters: { - text: "Apple", - }, - }, - { - id: "d4", - parameters: { - text: "Dog {{ actions.2.row }}", - }, - }, - { - id: "e5", - parameters: { - text: "Eagle {{ actions.3.row }}", - }, - }, - ] - updateReferencesInObject({ - obj, - modifiedIndex: 2, - action: "move", - label: "actions", - originalIndex: 0, - }) - - expect(obj).toEqual([ - { - id: "b2", - parameters: { - text: "Banana {{ actions.2.row }}", - }, - }, - { - id: "c3", - parameters: { - text: "Carrot {{ actions.2.row }}", - }, - }, - { - id: "a1", - parameters: { - text: "Apple", - }, - }, - { - id: "d4", - parameters: { - text: "Dog {{ actions.1.row }}", - }, - }, - { - id: "e5", - parameters: { - text: "Eagle {{ actions.3.row }}", - }, - }, - ]) - }) - - it("should handle on 'move' of action being referenced, dragged to a higher index", () => { - let obj = [ - { - "##eventHandlerType": "Validate Form", - id: "cCD0Dwcnq", - }, - { - "##eventHandlerType": "Close Screen Modal", - id: "3fbbIOfN0H", - }, - { - "##eventHandlerType": "Save Row", - parameters: { - tableId: "ta_bb_employee", - }, - id: "aehg5cTmhR", - }, - { - "##eventHandlerType": "Close Side Panel", - id: "mzkpf86cxo", - }, - { - "##eventHandlerType": "Navigate To", - id: "h0uDFeJa8A", - }, - { - parameters: { - autoDismiss: true, - type: "success", - message: "{{ actions.1.row }}", - }, - "##eventHandlerType": "Show Notification", - id: "JEI5lAyJZ", - }, - ] - updateReferencesInObject({ - obj, - modifiedIndex: 2, - action: "move", - label: "actions", - originalIndex: 1, - }) - - expect(obj).toEqual([ - { - "##eventHandlerType": "Validate Form", - id: "cCD0Dwcnq", - }, - { - "##eventHandlerType": "Close Screen Modal", - id: "3fbbIOfN0H", - }, - { - "##eventHandlerType": "Save Row", - parameters: { - tableId: "ta_bb_employee", - }, - id: "aehg5cTmhR", - }, - { - "##eventHandlerType": "Close Side Panel", - id: "mzkpf86cxo", - }, - { - "##eventHandlerType": "Navigate To", - id: "h0uDFeJa8A", - }, - { - parameters: { - autoDismiss: true, - type: "success", - message: "{{ actions.2.row }}", - }, - "##eventHandlerType": "Show Notification", - id: "JEI5lAyJZ", - }, - ]) - }) - - it("should handle on 'move' of action being referenced, dragged to a lower index", () => { - let obj = [ - { - "##eventHandlerType": "Save Row", - parameters: { - tableId: "ta_bb_employee", - }, - id: "aehg5cTmhR", - }, - { - "##eventHandlerType": "Validate Form", - id: "cCD0Dwcnq", - }, - { - "##eventHandlerType": "Close Screen Modal", - id: "3fbbIOfN0H", - }, - { - "##eventHandlerType": "Close Side Panel", - id: "mzkpf86cxo", - }, - { - "##eventHandlerType": "Navigate To", - id: "h0uDFeJa8A", - }, - { - parameters: { - autoDismiss: true, - type: "success", - message: "{{ actions.4.row }}", - }, - "##eventHandlerType": "Show Notification", - id: "JEI5lAyJZ", - }, - ] - updateReferencesInObject({ - obj, - modifiedIndex: 0, - action: "move", - label: "actions", - originalIndex: 4, - }) - - expect(obj).toEqual([ - { - "##eventHandlerType": "Save Row", - parameters: { - tableId: "ta_bb_employee", - }, - id: "aehg5cTmhR", - }, - { - "##eventHandlerType": "Validate Form", - id: "cCD0Dwcnq", - }, - { - "##eventHandlerType": "Close Screen Modal", - id: "3fbbIOfN0H", - }, - { - "##eventHandlerType": "Close Side Panel", - id: "mzkpf86cxo", - }, - { - "##eventHandlerType": "Navigate To", - id: "h0uDFeJa8A", - }, - { - parameters: { - autoDismiss: true, - type: "success", - message: "{{ actions.0.row }}", - }, - "##eventHandlerType": "Show Notification", - id: "JEI5lAyJZ", - }, - ]) - }) -}) diff --git a/packages/builder/src/components/automation/AutomationBuilder/AutomationBuilder.svelte b/packages/builder/src/components/automation/AutomationBuilder/AutomationBuilder.svelte index b80ba45086..caeb33cb14 100644 --- a/packages/builder/src/components/automation/AutomationBuilder/AutomationBuilder.svelte +++ b/packages/builder/src/components/automation/AutomationBuilder/AutomationBuilder.svelte @@ -1,5 +1,5 @@ diff --git a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/ActionModal.svelte b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/ActionModal.svelte index fbc79b967c..a8711d220b 100644 --- a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/ActionModal.svelte +++ b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/ActionModal.svelte @@ -9,11 +9,11 @@ Tags, Tag, } from "@budibase/bbui" - import { automationStore, selectedAutomation } from "builderStore" + import { automationStore, selectedAutomation } from "stores/builder" import { admin, licensing } from "stores/portal" import { externalActions } from "./ExternalActions" import { TriggerStepID, ActionStepID } from "constants/backend/automations" - import { checkForCollectStep } from "builderStore/utils" + import { checkForCollectStep } from "helpers/utils" export let blockIdx export let lastStep diff --git a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/AutomationBlockTagline.svelte b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/AutomationBlockTagline.svelte index c18368b1b1..8732623dcf 100644 --- a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/AutomationBlockTagline.svelte +++ b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/AutomationBlockTagline.svelte @@ -1,7 +1,7 @@ diff --git a/packages/builder/src/components/automation/AutomationPanel/AutomationList.svelte b/packages/builder/src/components/automation/AutomationPanel/AutomationList.svelte index cce0f4eeab..9d946fe55d 100644 --- a/packages/builder/src/components/automation/AutomationPanel/AutomationList.svelte +++ b/packages/builder/src/components/automation/AutomationPanel/AutomationList.svelte @@ -4,7 +4,7 @@ automationStore, selectedAutomation, userSelectedResourceMap, - } from "builderStore" + } from "stores/builder" import NavItem from "components/common/NavItem.svelte" import EditAutomationPopover from "./EditAutomationPopover.svelte" import { notifications } from "@budibase/bbui" diff --git a/packages/builder/src/components/automation/AutomationPanel/AutomationPanel.svelte b/packages/builder/src/components/automation/AutomationPanel/AutomationPanel.svelte index d8651f238a..582db950fe 100644 --- a/packages/builder/src/components/automation/AutomationPanel/AutomationPanel.svelte +++ b/packages/builder/src/components/automation/AutomationPanel/AutomationPanel.svelte @@ -7,7 +7,7 @@ automationStore, selectedAutomation, userSelectedResourceMap, - } from "builderStore" + } from "stores/builder" import NavItem from "components/common/NavItem.svelte" import EditAutomationPopover from "./EditAutomationPopover.svelte" diff --git a/packages/builder/src/components/automation/AutomationPanel/CreateAutomationModal.svelte b/packages/builder/src/components/automation/AutomationPanel/CreateAutomationModal.svelte index 9f279427d9..41bffba19e 100644 --- a/packages/builder/src/components/automation/AutomationPanel/CreateAutomationModal.svelte +++ b/packages/builder/src/components/automation/AutomationPanel/CreateAutomationModal.svelte @@ -1,5 +1,5 @@ diff --git a/packages/builder/src/components/backend/DatasourceNavigator/DatasourceNavigator.svelte b/packages/builder/src/components/backend/DatasourceNavigator/DatasourceNavigator.svelte index 23697bf2c7..23081c92c4 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/DatasourceNavigator.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/DatasourceNavigator.svelte @@ -3,13 +3,13 @@ import { Layout } from "@budibase/bbui" import { BUDIBASE_INTERNAL_DB_ID } from "constants/backend" import { - database, datasources, queries, tables, views, viewsV2, - } from "stores/backend" + userSelectedResourceMap, + } from "stores/builder" import EditDatasourcePopover from "./popovers/EditDatasourcePopover.svelte" import EditQueryPopover from "./popovers/EditQueryPopover.svelte" import NavItem from "components/common/NavItem.svelte" @@ -21,7 +21,6 @@ } from "helpers/data/utils" import IntegrationIcon from "./IntegrationIcon.svelte" import { TableNames } from "constants" - import { userSelectedResourceMap } from "builderStore" import { enrichDatasources } from "./datasourceUtils" import { onMount } from "svelte" @@ -75,69 +74,67 @@ searchTerm && !showAppUsersTable && !enrichedDataSources.find(ds => ds.show) -{#if $database?._id} -
- {#if showAppUsersTable} - selectTable(TableNames.USERS)} - selectedBy={$userSelectedResourceMap[TableNames.USERS]} - /> - {/if} - {#each enrichedDataSources.filter(ds => ds.show) as datasource} - selectDatasource(datasource)} - on:iconClick={() => toggleNode(datasource)} - selectedBy={$userSelectedResourceMap[datasource._id]} - > -
- -
- {#if datasource._id !== BUDIBASE_INTERNAL_DB_ID} - - {/if} -
- - {#if datasource.open} - - {#each datasource.queries as query} - $goto(`./query/${query._id}`)} - selectedBy={$userSelectedResourceMap[query._id]} - > - - - {/each} +
+ {#if showAppUsersTable} + selectTable(TableNames.USERS)} + selectedBy={$userSelectedResourceMap[TableNames.USERS]} + /> + {/if} + {#each enrichedDataSources.filter(ds => ds.show) as datasource} + selectDatasource(datasource)} + on:iconClick={() => toggleNode(datasource)} + selectedBy={$userSelectedResourceMap[datasource._id]} + > +
+ +
+ {#if datasource._id !== BUDIBASE_INTERNAL_DB_ID} + {/if} - {/each} - {#if showNoResults} - -
- There aren't any datasources matching that name -
-
+
+ + {#if datasource.open} + + {#each datasource.queries as query} + $goto(`./query/${query._id}`)} + selectedBy={$userSelectedResourceMap[query._id]} + > + + + {/each} {/if} -
-{/if} + {/each} + {#if showNoResults} + +
+ There aren't any datasources matching that name +
+
+ {/if} +
diff --git a/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/DeleteRow.svelte b/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/DeleteRow.svelte index 1e79c51051..b8459ac0eb 100644 --- a/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/DeleteRow.svelte +++ b/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/DeleteRow.svelte @@ -1,6 +1,6 @@ diff --git a/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/SaveRow.svelte b/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/SaveRow.svelte index 9f70272d78..a1fe773455 100644 --- a/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/SaveRow.svelte +++ b/packages/builder/src/components/design/settings/controls/ButtonActionEditor/actions/SaveRow.svelte @@ -1,8 +1,12 @@ - + diff --git a/packages/builder/src/components/design/settings/controls/ColumnEditor/CellDrawer.svelte b/packages/builder/src/components/design/settings/controls/ColumnEditor/CellDrawer.svelte index 9e53f7f1cf..f5167e3657 100644 --- a/packages/builder/src/components/design/settings/controls/ColumnEditor/CellDrawer.svelte +++ b/packages/builder/src/components/design/settings/controls/ColumnEditor/CellDrawer.svelte @@ -7,7 +7,7 @@ Layout, Label, } from "@budibase/bbui" - import { store } from "builderStore" + import { themeStore } from "stores/builder" import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte" export let column @@ -46,7 +46,7 @@ (column.background = e.detail)} - spectrumTheme={$store.theme} + spectrumTheme={$themeStore.theme} /> @@ -54,7 +54,7 @@ (column.color = e.detail)} - spectrumTheme={$store.theme} + spectrumTheme={$themeStore.theme} /> diff --git a/packages/builder/src/components/design/settings/controls/ColumnEditor/ColumnEditor.svelte b/packages/builder/src/components/design/settings/controls/ColumnEditor/ColumnEditor.svelte index cebb429ac4..2b9fa573c2 100644 --- a/packages/builder/src/components/design/settings/controls/ColumnEditor/ColumnEditor.svelte +++ b/packages/builder/src/components/design/settings/controls/ColumnEditor/ColumnEditor.svelte @@ -3,11 +3,8 @@ import { createEventDispatcher } from "svelte" import ColumnDrawer from "./ColumnDrawer.svelte" import { cloneDeep } from "lodash/fp" - import { - getDatasourceForProvider, - getSchemaForDatasource, - } from "builderStore/dataBinding" - import { currentAsset } from "builderStore" + import { getDatasourceForProvider, getSchemaForDatasource } from "dataBinding" + import { selectedScreen } from "stores/builder" import { getFields } from "helpers/searchFields" export let componentInstance @@ -21,8 +18,8 @@ let boundValue $: text = getText(value) - $: datasource = getDatasourceForProvider($currentAsset, componentInstance) - $: schema = getSchema($currentAsset, datasource) + $: datasource = getDatasourceForProvider($selectedScreen, componentInstance) + $: schema = getSchema($selectedScreen, datasource) $: options = allowCellEditing ? Object.keys(schema || {}) : enrichedSchemaFields?.map(field => field.name) diff --git a/packages/builder/src/components/design/settings/controls/DataProviderSelect.svelte b/packages/builder/src/components/design/settings/controls/DataProviderSelect.svelte index 9fd220e798..2e74cac0f4 100644 --- a/packages/builder/src/components/design/settings/controls/DataProviderSelect.svelte +++ b/packages/builder/src/components/design/settings/controls/DataProviderSelect.svelte @@ -1,14 +1,14 @@ diff --git a/packages/builder/src/components/design/settings/controls/DataSourceSelect/DataSourceSelect.svelte b/packages/builder/src/components/design/settings/controls/DataSourceSelect/DataSourceSelect.svelte index 3eb69e9a3b..14cbc973a1 100644 --- a/packages/builder/src/components/design/settings/controls/DataSourceSelect/DataSourceSelect.svelte +++ b/packages/builder/src/components/design/settings/controls/DataSourceSelect/DataSourceSelect.svelte @@ -2,7 +2,7 @@ import { readableToRuntimeBinding, runtimeToReadableBinding, - } from "builderStore/dataBinding" + } from "dataBinding" import { Button, Popover, @@ -17,19 +17,20 @@ notifications, } from "@budibase/bbui" import { createEventDispatcher } from "svelte" - import { store, currentAsset } from "builderStore" import { tables as tablesStore, queries as queriesStore, viewsV2 as viewsV2Store, views as viewsStore, + selectedScreen, + componentStore, datasources, integrations, - } from "stores/backend" + } from "stores/builder" import BindingBuilder from "components/integration/QueryBindingBuilder.svelte" import IntegrationQueryEditor from "components/integration/index.svelte" import { makePropSafe as safe } from "@budibase/string-templates" - import { findAllComponents } from "builderStore/componentUtils" + import { findAllComponents } from "helpers/components" import ClientBindingPanel from "components/common/bindings/ClientBindingPanel.svelte" import DataSourceCategory from "components/design/settings/controls/DataSourceSelect/DataSourceCategory.svelte" import { API } from "api" @@ -75,11 +76,11 @@ ...query, type: "query", })) - $: dataProviders = findAllComponents($currentAsset.props) + $: dataProviders = findAllComponents($selectedScreen.props) .filter(component => { return ( component._component?.endsWith("/dataprovider") && - component._id !== $store.selectedComponentId + component._id !== $componentStore.selectedComponentId ) }) .map(provider => ({ diff --git a/packages/builder/src/components/design/settings/controls/EditComponentPopover.svelte b/packages/builder/src/components/design/settings/controls/EditComponentPopover.svelte index 04bb925873..4e645fe343 100644 --- a/packages/builder/src/components/design/settings/controls/EditComponentPopover.svelte +++ b/packages/builder/src/components/design/settings/controls/EditComponentPopover.svelte @@ -1,9 +1,9 @@
diff --git a/packages/builder/src/components/design/settings/controls/FieldSelect.svelte b/packages/builder/src/components/design/settings/controls/FieldSelect.svelte index 7d1741df17..e50a0e8030 100644 --- a/packages/builder/src/components/design/settings/controls/FieldSelect.svelte +++ b/packages/builder/src/components/design/settings/controls/FieldSelect.svelte @@ -1,10 +1,7 @@ diff --git a/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/GridColumnConfiguration.svelte b/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/GridColumnConfiguration.svelte index 4286328367..439bf5e261 100644 --- a/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/GridColumnConfiguration.svelte +++ b/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/GridColumnConfiguration.svelte @@ -1,9 +1,6 @@ diff --git a/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/PrimaryColumnFieldSetting.svelte b/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/PrimaryColumnFieldSetting.svelte index 1cb29ac6e7..57423e8667 100644 --- a/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/PrimaryColumnFieldSetting.svelte +++ b/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/PrimaryColumnFieldSetting.svelte @@ -4,7 +4,7 @@ import { setContext } from "svelte" import { writable } from "svelte/store" import { FieldTypeToComponentMap } from "../FieldConfiguration/utils" - import { store } from "builderStore" + import { componentStore } from "stores/builder" export let item export let anchor @@ -35,7 +35,7 @@ const component = `@budibase/standard-components/${ FieldTypeToComponentMap[item.columnType] }` - return store.actions.components.getDefinition(component)?.icon + return componentStore.getDefinition(component)?.icon } $: icon = getIcon(item) diff --git a/packages/builder/src/components/design/settings/controls/LayoutSelect.svelte b/packages/builder/src/components/design/settings/controls/LayoutSelect.svelte index eed01c0d94..a7966eb671 100644 --- a/packages/builder/src/components/design/settings/controls/LayoutSelect.svelte +++ b/packages/builder/src/components/design/settings/controls/LayoutSelect.svelte @@ -1,5 +1,5 @@ diff --git a/packages/builder/src/components/design/settings/controls/RelationshipFilterEditor.svelte b/packages/builder/src/components/design/settings/controls/RelationshipFilterEditor.svelte index 0eb93732c3..43f158bef3 100644 --- a/packages/builder/src/components/design/settings/controls/RelationshipFilterEditor.svelte +++ b/packages/builder/src/components/design/settings/controls/RelationshipFilterEditor.svelte @@ -1,14 +1,10 @@ diff --git a/packages/builder/src/components/design/settings/controls/ValidationEditor/ValidationDrawer.svelte b/packages/builder/src/components/design/settings/controls/ValidationEditor/ValidationDrawer.svelte index 25c7651d35..3a98de94cd 100644 --- a/packages/builder/src/components/design/settings/controls/ValidationEditor/ValidationDrawer.svelte +++ b/packages/builder/src/components/design/settings/controls/ValidationEditor/ValidationDrawer.svelte @@ -10,12 +10,9 @@ Input, DatePicker, } from "@budibase/bbui" - import { currentAsset, selectedComponent } from "builderStore" - import { findClosestMatchingComponent } from "builderStore/componentUtils" - import { - getSchemaForDatasource, - getDatasourceForProvider, - } from "builderStore/dataBinding" + import { selectedScreen, selectedComponent } from "stores/builder" + import { findClosestMatchingComponent } from "helpers/components" + import { getSchemaForDatasource, getDatasourceForProvider } from "dataBinding" import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte" import { generate } from "shortid" @@ -127,13 +124,14 @@ ], } - const resolveDatasource = (currentAsset, componentInstance, parent) => { + const resolveDatasource = (selectedScreen, componentInstance, parent) => { return ( - getDatasourceForProvider(currentAsset, parent || componentInstance) || {} + getDatasourceForProvider(selectedScreen, parent || componentInstance) || + {} ) } - $: dataSourceSchema = getDataSourceSchema($currentAsset, $selectedComponent) + $: dataSourceSchema = getDataSourceSchema($selectedScreen, $selectedComponent) $: field = fieldName || $selectedComponent?.field $: schemaRules = parseRulesFromSchema(field, dataSourceSchema || {}) $: fieldType = type?.split("/")[1] || "string" diff --git a/packages/builder/src/components/integration/AccessLevelSelect.svelte b/packages/builder/src/components/integration/AccessLevelSelect.svelte index 3dc24983d3..05b336c3b3 100644 --- a/packages/builder/src/components/integration/AccessLevelSelect.svelte +++ b/packages/builder/src/components/integration/AccessLevelSelect.svelte @@ -1,6 +1,6 @@ diff --git a/packages/builder/src/components/start/AppRow.svelte b/packages/builder/src/components/start/AppRow.svelte index 212ab4c6f8..c05ae4c624 100644 --- a/packages/builder/src/components/start/AppRow.svelte +++ b/packages/builder/src/components/start/AppRow.svelte @@ -11,6 +11,7 @@ $: editing = app.sessions?.length $: isBuilder = sdk.users.isBuilder($auth.user, app?.devId) + $: unclickable = !isBuilder && !app.deployed const handleDefaultClick = () => { if (!isBuilder) { @@ -31,11 +32,17 @@ } const goToApp = () => { - window.open(`/app/${app.name}`, "_blank") + if (app.deployed && app.url) { + window.open(`/app${app.url}`, "_blank") + } } -
+
@@ -74,7 +81,7 @@ Edit
- {:else} + {:else if app.deployed}
@@ -94,7 +101,7 @@ transition: border 130ms ease-out; border: 1px solid transparent; } - .app-row:hover { + .app-row:not(.unclickable):hover { cursor: pointer; border-color: var(--spectrum-global-color-gray-300); } diff --git a/packages/builder/src/components/start/CreateAppModal.svelte b/packages/builder/src/components/start/CreateAppModal.svelte index 9e831f5bd9..b582232207 100644 --- a/packages/builder/src/components/start/CreateAppModal.svelte +++ b/packages/builder/src/components/start/CreateAppModal.svelte @@ -7,7 +7,7 @@ ModalContent, Dropzone, } from "@budibase/bbui" - import { store, automationStore } from "builderStore" + import { initialise } from "stores/builder" import { API } from "api" import { apps, admin, auth } from "stores/portal" import { onMount } from "svelte" @@ -132,8 +132,9 @@ // Select Correct Application/DB in prep for creating user const pkg = await API.fetchAppPackage(createdApp.instance._id) - await store.actions.initialise(pkg) - await automationStore.actions.fetch() + + await initialise(pkg) + // Update checklist - in case first app await admin.init() diff --git a/packages/builder/src/components/start/ImportAppModal.svelte b/packages/builder/src/components/start/ImportAppModal.svelte index 1bc32dc7a4..4c88593514 100644 --- a/packages/builder/src/components/start/ImportAppModal.svelte +++ b/packages/builder/src/components/start/ImportAppModal.svelte @@ -9,7 +9,7 @@ Body, } from "@budibase/bbui" import { API } from "api" - import { automationStore, store } from "../../builderStore" + import { initialise } from "stores/builder" export let app @@ -28,8 +28,8 @@ const appId = app.devId await API.updateAppFromExport(appId, data) const pkg = await API.fetchAppPackage(appId) - await store.actions.initialise(pkg) - await automationStore.actions.fetch() + await initialise(pkg) + notifications.success("App updated successfully") } catch (err) { notifications.error(`Failed to update app - ${err.message || err}`) diff --git a/packages/builder/src/components/usage/Usage.svelte b/packages/builder/src/components/usage/Usage.svelte index 897a7da3dd..da1bb4489a 100644 --- a/packages/builder/src/components/usage/Usage.svelte +++ b/packages/builder/src/components/usage/Usage.svelte @@ -1,6 +1,6 @@ @@ -31,7 +30,7 @@ on:click|self={close} >
diff --git a/packages/builder/src/pages/builder/app/[application]/_layout.svelte b/packages/builder/src/pages/builder/app/[application]/_layout.svelte index 1df2a90250..c7f8c98e73 100644 --- a/packages/builder/src/pages/builder/app/[application]/_layout.svelte +++ b/packages/builder/src/pages/builder/app/[application]/_layout.svelte @@ -1,11 +1,13 @@ -{#if $store.builderSidePanel} +{#if $builderStore.builderSidePanel} {/if} -
+
- {#if $store.initialised} + {#if $appStore.initialised}
- {$store.name} + {$appStore.name}
@@ -190,7 +182,7 @@ {/await}
-{#if $store.showPreview} +{#if $previewStore.showPreview} {/if} diff --git a/packages/builder/src/pages/builder/app/[application]/automation/[automationId]/_layout.svelte b/packages/builder/src/pages/builder/app/[application]/automation/[automationId]/_layout.svelte index 3be71a1bbe..9d5f716e0e 100644 --- a/packages/builder/src/pages/builder/app/[application]/automation/[automationId]/_layout.svelte +++ b/packages/builder/src/pages/builder/app/[application]/automation/[automationId]/_layout.svelte @@ -1,5 +1,5 @@ -{#if $database._id && query} +{#if query} {#if isRestQuery} {:else} diff --git a/packages/builder/src/pages/builder/app/[application]/data/query/index.svelte b/packages/builder/src/pages/builder/app/[application]/data/query/index.svelte index 6e53f69bcc..277970defa 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/query/index.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/query/index.svelte @@ -1,6 +1,6 @@ -{#if $database._id && datasource && query} +{#if datasource && query} {#if isRestQuery} {:else} diff --git a/packages/builder/src/pages/builder/app/[application]/data/table/[tableId]/_layout.svelte b/packages/builder/src/pages/builder/app/[application]/data/table/[tableId]/_layout.svelte index e166a509c4..8c60dbdd69 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/table/[tableId]/_layout.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/table/[tableId]/_layout.svelte @@ -1,12 +1,11 @@ -{#if $database?._id && $tables?.selected?.name} +{#if $tables?.selected?.name} {#if duplicates?.length}
diff --git a/packages/builder/src/pages/builder/app/[application]/data/table/index.svelte b/packages/builder/src/pages/builder/app/[application]/data/table/index.svelte index f513d8ceb9..3f21e48672 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/table/index.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/table/index.svelte @@ -1,6 +1,6 @@ -{#if $database._id && selectedView} +{#if selectedView} {:else}Create your first table to start building{/if} diff --git a/packages/builder/src/pages/builder/app/[application]/data/view/v2/[viewId]/_layout.svelte b/packages/builder/src/pages/builder/app/[application]/data/view/v2/[viewId]/_layout.svelte index 8ddd6adbd0..3d0cffc387 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/view/v2/[viewId]/_layout.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/view/v2/[viewId]/_layout.svelte @@ -1,12 +1,11 @@ diff --git a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/[componentId]/_components/Navigation/index.svelte b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/[componentId]/_components/Navigation/index.svelte index f9f994ce67..50e1ad0cf8 100644 --- a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/[componentId]/_components/Navigation/index.svelte +++ b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/[componentId]/_components/Navigation/index.svelte @@ -17,15 +17,20 @@ Select, Combobox, } from "@budibase/bbui" - import { selectedScreen, store } from "builderStore" + import { + themeStore, + selectedScreen, + screenStore, + navigationStore, + } from "stores/builder" import { DefaultAppTheme } from "constants" - $: screenRouteOptions = $store.screens + $: screenRouteOptions = $screenStore.screens .map(screen => screen.routing?.route) .filter(x => x != null) const updateShowNavigation = async e => { - await store.actions.screens.updateSetting( + await screenStore.updateSetting( get(selectedScreen), "showNavigation", e.detail @@ -34,9 +39,9 @@ const update = async (key, value) => { try { - let navigation = $store.navigation + let navigation = $navigationStore navigation[key] = value - await store.actions.navigation.save(navigation) + await navigationStore.save(navigation) } catch (error) { notifications.error("Error updating navigation settings") } @@ -45,7 +50,7 @@ @@ -56,13 +61,13 @@
Show nav on this screen
- {#if $selectedScreen.showNavigation} + {#if $selectedScreen?.showNavigation}
@@ -81,25 +86,25 @@
update("navigation", "Top")} /> update("navigation", "Left")} /> - {#if $store.navigation.navigation === "Top"} + {#if $navigationStore.navigation === "Top"}
update("sticky", e.detail)} />
@@ -108,7 +113,7 @@ update("title", e.detail)} updateOnChange={false} /> @@ -133,8 +138,8 @@
update("navBackground", e.detail)} /> @@ -142,8 +147,8 @@
update("navTextColor", e.detail)} />
@@ -159,15 +164,15 @@
update("hideLogo", !e.detail)} /> - {#if !$store.navigation.hideLogo} + {#if !$navigationStore.hideLogo}
update("logoUrl", e.detail)} updateOnChange={false} /> @@ -175,7 +180,7 @@
update("logoLinkUrl", e.detail)} options={screenRouteOptions} /> @@ -183,7 +188,7 @@
update("openLogoLinkInNewTab", !!e.detail)} /> {/if} diff --git a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/[componentId]/_components/Screen/AppThemeSelect.svelte b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/[componentId]/_components/Screen/AppThemeSelect.svelte index 86a897bf60..9c63ef4d13 100644 --- a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/[componentId]/_components/Screen/AppThemeSelect.svelte +++ b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/[componentId]/_components/Screen/AppThemeSelect.svelte @@ -1,11 +1,11 @@ diff --git a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/[componentId]/_components/Screen/ThemePanel.svelte b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/[componentId]/_components/Screen/ThemePanel.svelte index 13a008fae0..8b3128f852 100644 --- a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/[componentId]/_components/Screen/ThemePanel.svelte +++ b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/[componentId]/_components/Screen/ThemePanel.svelte @@ -7,21 +7,17 @@ Icon, Body, } from "@budibase/bbui" - import { store } from "builderStore" - import { get } from "svelte/store" + import { themeStore, appStore } from "stores/builder" import { DefaultAppTheme } from "constants" import AppThemeSelect from "./AppThemeSelect.svelte" import ButtonRoundnessSelect from "./ButtonRoundnessSelect.svelte" import PropertyControl from "components/design/settings/controls/PropertyControl.svelte" - $: customTheme = $store.customTheme || {} + $: customTheme = $themeStore.customTheme || {} const update = async (property, value) => { try { - store.actions.customTheme.save({ - ...get(store).customTheme, - [property]: value, - }) + themeStore.saveCustom({ [property]: value }, $appStore.appId) } catch (error) { notifications.error("Error updating custom theme") } @@ -49,7 +45,7 @@ value={customTheme.primaryColor || DefaultAppTheme.primaryColor} onChange={val => update("primaryColor", val)} props={{ - spectrumTheme: $store.theme, + spectrumTheme: $themeStore.theme, }} /> update("primaryColorHover", val)} props={{ - spectrumTheme: $store.theme, + spectrumTheme: $themeStore.theme, }} /> diff --git a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/[componentId]/_components/Screen/index.svelte b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/[componentId]/_components/Screen/index.svelte index 778fa303cc..8a544eac86 100644 --- a/packages/builder/src/pages/builder/app/[application]/design/[screenId]/[componentId]/_components/Screen/index.svelte +++ b/packages/builder/src/pages/builder/app/[application]/design/[screenId]/[componentId]/_components/Screen/index.svelte @@ -1,7 +1,7 @@ - -
-
- {#each tabs as tab} - { - activeTab = tab - }} - > - {capitalise(tab)} - - {/each} +{#if $selectedScreen} + +
+
+ {#each tabs as tab} + { + activeTab = tab + }} + > + {capitalise(tab)} + + {/each} +
-
- - {#if activeTab === "theme"} - - {:else} - - {/if} - - + + {#if activeTab === "theme"} + + {:else} + + {/if} + + +{/if}