From b4f5522a5e01b915175f17496bdcee91b66f6b5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Keviin=20=C3=85berg=20Kultalahti?= Date: Tue, 23 Mar 2021 12:16:54 +0100 Subject: [PATCH] wip: converts components to use separate stores --- .../builder/src/builderStore/dataBinding.js | 9 ++-- .../builder/src/builderStore/store/backend.js | 49 +------------------ .../src/builderStore/store/frontend.js | 1 - .../CreateAutomationModal.svelte | 5 +- .../EditAutomationPopover.svelte | 5 +- .../automation/SetupPanel/SetupPanel.svelte | 5 +- .../Shared/CreateWebhookModal.svelte | 6 +-- .../backend/DataTable/DataTable.svelte | 19 +++---- .../DataTable/ExternalDataSourceTable.svelte | 4 -- .../popovers/CalculatePopover.svelte | 8 +-- .../DataTable/popovers/FilterPopover.svelte | 7 ++- .../DataTable/popovers/GroupByPopover.svelte | 7 ++- .../popovers/EditQueryPopover.svelte | 23 +-------- .../TableNavigator/TableNavigator.svelte | 7 ++- .../components/settings/tabs/APIKeys.svelte | 4 +- .../[selectedDatasource]/index.svelte | 3 +- .../data/table/[selectedTable]/index.svelte | 6 +-- .../data/view/[selectedView]/index.svelte | 6 +-- 18 files changed, 51 insertions(+), 123 deletions(-) diff --git a/packages/builder/src/builderStore/dataBinding.js b/packages/builder/src/builderStore/dataBinding.js index dee0b86fb3..e76342fb3b 100644 --- a/packages/builder/src/builderStore/dataBinding.js +++ b/packages/builder/src/builderStore/dataBinding.js @@ -1,6 +1,7 @@ import { cloneDeep } from "lodash/fp" import { get } from "svelte/store" -import { backendUiStore, store } from "builderStore" +import { store } from "builderStore" +import { tables as tablesStore, queries as queriesStores } from 'builderStore/store/backend/' import { findComponentPath } from "./storeUtils" import { makePropSafe } from "@budibase/string-templates" import { TableNames } from "../constants" @@ -164,7 +165,7 @@ const getContextBindings = (asset, componentId) => { */ const getUserBindings = () => { let bindings = [] - const tables = get(backendUiStore).tables + const tables = get(tablesStore).list const userTable = tables.find(table => table._id === TableNames.USERS) const schema = { ...userTable.schema, @@ -223,10 +224,10 @@ export const getSchemaForDatasource = (datasource, isForm = false) => { if (datasource) { const { type } = datasource if (type === "query") { - const queries = get(backendUiStore).queries + const queries = get(queriesStores).queries table = queries.find(query => query._id === datasource._id) } else { - const tables = get(backendUiStore).tables + const tables = get(tablesStore).tables table = tables.find(table => table._id === datasource.tableId) } if (table) { diff --git a/packages/builder/src/builderStore/store/backend.js b/packages/builder/src/builderStore/store/backend.js index a7947f3e5e..62826b3b61 100644 --- a/packages/builder/src/builderStore/store/backend.js +++ b/packages/builder/src/builderStore/store/backend.js @@ -1,5 +1,4 @@ -import { writable, get } from "svelte/store" -import { cloneDeep } from "lodash/fp" +import { writable } from "svelte/store" import api from "../api" const INITIAL_BACKEND_UI_STATE = { @@ -16,18 +15,6 @@ export const getBackendUiStore = () => { store.actions = { reset: () => store.set({ ...INITIAL_BACKEND_UI_STATE }), - database: { - select: async db => { - const [tables] = await Promise.all([ - api.get(`/api/tables`).then(r => r.json()), - ]) - - store.update(state => { - state.tables = tables - return state - }) - }, - }, rows: { save: () => store.update(state => { @@ -40,40 +27,6 @@ export const getBackendUiStore = () => { return state }), }, - views: { - select: view => - store.update(state => { - state.selectedView = view - state.selectedTable = {} - return state - }), - delete: async view => { - await api.delete(`/api/views/${view}`) - await store.actions.tables.fetch() - }, - save: async view => { - const response = await api.post(`/api/views`, view) - const json = await response.json() - - const viewMeta = { - name: view.name, - ...json, - } - - store.update(state => { - const viewTable = state.tables.find( - table => table._id === view.tableId - ) - - if (view.originalName) delete viewTable.views[view.originalName] - viewTable.views[view.name] = viewMeta - - state.tables = state.tables - state.selectedView = viewMeta - return state - }) - }, - }, } return store diff --git a/packages/builder/src/builderStore/store/frontend.js b/packages/builder/src/builderStore/store/frontend.js index 2b450eb49f..8c890cc5f5 100644 --- a/packages/builder/src/builderStore/store/frontend.js +++ b/packages/builder/src/builderStore/store/frontend.js @@ -2,7 +2,6 @@ import { get, writable } from "svelte/store" import { cloneDeep } from "lodash/fp" import { allScreens, - backendUiStore, hostingStore, currentAsset, mainLayout, diff --git a/packages/builder/src/components/automation/AutomationPanel/CreateAutomationModal.svelte b/packages/builder/src/components/automation/AutomationPanel/CreateAutomationModal.svelte index abc7bd9f96..d827cfdee8 100644 --- a/packages/builder/src/components/automation/AutomationPanel/CreateAutomationModal.svelte +++ b/packages/builder/src/components/automation/AutomationPanel/CreateAutomationModal.svelte @@ -1,5 +1,6 @@ -{#if $backendUiStore.selectedDatabase._id && selectedTable.name} +{#if $database._id && selectedTable.name} {:else}Create your first table to start building{/if} diff --git a/packages/builder/src/pages/[application]/data/view/[selectedView]/index.svelte b/packages/builder/src/pages/[application]/data/view/[selectedView]/index.svelte index 312e799005..f18f6742b0 100644 --- a/packages/builder/src/pages/[application]/data/view/[selectedView]/index.svelte +++ b/packages/builder/src/pages/[application]/data/view/[selectedView]/index.svelte @@ -1,11 +1,11 @@ -{#if $backendUiStore.selectedDatabase._id && selectedView} +{#if $database._id && selectedView} {:else}Create your first table to start building{/if}