From 44e3f29a0ba8dad21da08c41217dc58533fbe486 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Keviin=20=C3=85berg=20Kultalahti?= Date: Fri, 26 Mar 2021 09:50:37 +0100 Subject: [PATCH] moves backend stores to "stores" in the root src directory --- packages/builder/rollup.config.js | 4 +++ .../builder/src/builderStore/dataBinding.js | 2 +- .../src/builderStore/store/frontend.js | 2 +- .../store/screenTemplates/index.js | 2 +- .../FlowChart/AutomationBlockTagline.svelte | 2 +- .../CreateAutomationModal.svelte | 2 +- .../EditAutomationPopover.svelte | 2 +- .../automation/SetupPanel/RowSelector.svelte | 2 +- .../automation/SetupPanel/SetupPanel.svelte | 2 +- .../SetupPanel/TableSelector.svelte | 2 +- .../Shared/CreateWebhookModal.svelte | 2 +- .../backend/DataTable/DataTable.svelte | 2 +- .../DataTable/RelationshipDataTable.svelte | 2 +- .../backend/DataTable/ViewDataTable.svelte | 2 +- .../buttons/ManageAccessButton.svelte | 2 +- .../backend/DataTable/cells/RoleCell.svelte | 2 +- .../DataTable/modals/CreateEditColumn.svelte | 2 +- .../DataTable/modals/CreateEditRow.svelte | 2 +- .../DataTable/modals/CreateEditUser.svelte | 4 +-- .../backend/DataTable/modals/DeleteRow.svelte | 2 +- .../backend/DataTable/modals/EditRoles.svelte | 2 +- .../popovers/CalculatePopover.svelte | 2 +- .../popovers/CreateViewPopover.svelte | 4 +-- .../DataTable/popovers/FilterPopover.svelte | 2 +- .../DataTable/popovers/GroupByPopover.svelte | 2 +- .../popovers/ManageAccessPopover.svelte | 2 +- .../DatasourceNavigator.svelte | 2 +- .../modals/CreateDatasourceModal.svelte | 2 +- .../popovers/EditDatasourcePopover.svelte | 2 +- .../TableNavigator/TableNavigator.svelte | 2 +- .../modals/CreateTableModal.svelte | 2 +- .../popovers/EditTablePopover.svelte | 2 +- .../popovers/EditViewPopover.svelte | 2 +- .../common/LinkedRowSelector.svelte | 2 +- .../FrontendNavigatePane.svelte | 2 +- .../NavigationPanel/NewScreenModal.svelte | 4 +-- .../PropertyControls/DatasourceSelect.svelte | 4 +-- .../EventsEditor/actions/ExecuteQuery.svelte | 2 +- .../PropertyControls/RoleSelect.svelte | 2 +- .../PropertyControls/TableSelect.svelte | 2 +- .../components/integration/QueryViewer.svelte | 2 +- .../components/settings/tabs/APIKeys.svelte | 2 +- .../src/pages/[application]/_reset.svelte | 2 +- .../[query]/_layout.svelte | 2 +- .../[selectedDatasource]/[query]/index.svelte | 2 +- .../[selectedDatasource]/_layout.svelte | 2 +- .../[selectedDatasource]/index.svelte | 2 +- .../data/datasource/_layout.svelte | 2 +- .../data/datasource/index.svelte | 2 +- .../data/table/[selectedTable]/_layout.svelte | 2 +- .../data/table/[selectedTable]/index.svelte | 2 +- .../[application]/data/table/_layout.svelte | 2 +- .../[application]/data/table/index.svelte | 2 +- .../data/view/[selectedView]/_layout.svelte | 2 +- .../data/view/[selectedView]/index.svelte | 2 +- .../store => stores}/backend/database.js | 0 .../store => stores}/backend/datasources.js | 4 +-- .../store => stores}/backend/index.js | 0 .../store => stores}/backend/integrations.js | 0 .../store => stores}/backend/permissions.js | 5 ++-- .../store => stores}/backend/queries.js | 5 ++-- .../store => stores}/backend/roles.js | 5 ++-- .../store => stores}/backend/rows.js | 2 +- .../store => stores}/backend/tables.js | 5 ++-- .../src/stores/backend/tests/database.spec.js | 26 +++++++++++++++++++ .../stores/backend/tests/datasources.spec.js | 24 +++++++++++++++++ .../store => stores}/backend/views.js | 4 +-- packages/builder/tests/stores/backend.spec.js | 0 68 files changed, 129 insertions(+), 71 deletions(-) rename packages/builder/src/{builderStore/store => stores}/backend/database.js (100%) rename packages/builder/src/{builderStore/store => stores}/backend/datasources.js (94%) rename packages/builder/src/{builderStore/store => stores}/backend/index.js (100%) rename packages/builder/src/{builderStore/store => stores}/backend/integrations.js (100%) rename packages/builder/src/{builderStore/store => stores}/backend/permissions.js (90%) rename packages/builder/src/{builderStore/store => stores}/backend/queries.js (96%) rename packages/builder/src/{builderStore/store => stores}/backend/roles.js (89%) rename packages/builder/src/{builderStore/store => stores}/backend/rows.js (88%) rename packages/builder/src/{builderStore/store => stores}/backend/tables.js (97%) create mode 100644 packages/builder/src/stores/backend/tests/database.spec.js create mode 100644 packages/builder/src/stores/backend/tests/datasources.spec.js rename packages/builder/src/{builderStore/store => stores}/backend/views.js (93%) delete mode 100644 packages/builder/tests/stores/backend.spec.js diff --git a/packages/builder/rollup.config.js b/packages/builder/rollup.config.js index a9897b1664..397a02b64d 100644 --- a/packages/builder/rollup.config.js +++ b/packages/builder/rollup.config.js @@ -60,6 +60,10 @@ export default { find: "builderStore", replacement: path.resolve(projectRootDir, "src/builderStore"), }, + { + find: "stores", + replacement: path.resolve(projectRootDir, "src/stores"), + }, { find: "constants", replacement: path.resolve(projectRootDir, "src/constants"), diff --git a/packages/builder/src/builderStore/dataBinding.js b/packages/builder/src/builderStore/dataBinding.js index f53fc66a01..a728b6d795 100644 --- a/packages/builder/src/builderStore/dataBinding.js +++ b/packages/builder/src/builderStore/dataBinding.js @@ -4,7 +4,7 @@ import { store } from "builderStore" import { tables as tablesStore, queries as queriesStores, -} from "builderStore/store/backend/" +} from "stores/backend/" import { findComponentPath } from "./storeUtils" import { makePropSafe } from "@budibase/string-templates" import { TableNames } from "../constants" diff --git a/packages/builder/src/builderStore/store/frontend.js b/packages/builder/src/builderStore/store/frontend.js index 58717050dc..ac78f1a829 100644 --- a/packages/builder/src/builderStore/store/frontend.js +++ b/packages/builder/src/builderStore/store/frontend.js @@ -15,7 +15,7 @@ import { queries, database, tables, -} from "builderStore/store/backend/" +} from "stores/backend/" import { fetchComponentLibDefinitions } from "../loadComponentLibraries" import api from "../api" diff --git a/packages/builder/src/builderStore/store/screenTemplates/index.js b/packages/builder/src/builderStore/store/screenTemplates/index.js index 38ae434753..6f068674bf 100644 --- a/packages/builder/src/builderStore/store/screenTemplates/index.js +++ b/packages/builder/src/builderStore/store/screenTemplates/index.js @@ -24,7 +24,7 @@ export default (frontendState, tables) => { }) const fromScratch = enrichTemplate(createFromScratchScreen) - const tableTemplates = allTemplates(tables).map(enrichTemplate) + const tableTemplates = allTemplates(tables.list).map(enrichTemplate) return [ fromScratch, ...tableTemplates.sort((templateA, templateB) => { diff --git a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/AutomationBlockTagline.svelte b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/AutomationBlockTagline.svelte index 318d54943f..99b843ebc6 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/design/PropertiesPanel/PropertyControls/TableSelect.svelte b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/TableSelect.svelte index bde14adcb1..75a0a740f8 100644 --- a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/TableSelect.svelte +++ b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/TableSelect.svelte @@ -1,6 +1,6 @@ diff --git a/packages/builder/src/components/integration/QueryViewer.svelte b/packages/builder/src/components/integration/QueryViewer.svelte index ebdeb997b4..063bbf2309 100644 --- a/packages/builder/src/components/integration/QueryViewer.svelte +++ b/packages/builder/src/components/integration/QueryViewer.svelte @@ -15,7 +15,7 @@ import IntegrationQueryEditor from "components/integration/index.svelte" import ExternalDataSourceTable from "components/backend/DataTable/ExternalDataSourceTable.svelte" import ParameterBuilder from "components/integration/QueryParameterBuilder.svelte" - import { datasources, integrations } from 'builderStore/store/backend/' + import { datasources, integrations } from 'stores/backend/' const PREVIEW_HEADINGS = [ { diff --git a/packages/builder/src/components/settings/tabs/APIKeys.svelte b/packages/builder/src/components/settings/tabs/APIKeys.svelte index 546f24c106..e48af500dc 100644 --- a/packages/builder/src/components/settings/tabs/APIKeys.svelte +++ b/packages/builder/src/components/settings/tabs/APIKeys.svelte @@ -2,7 +2,7 @@ import { Input, Label, TextButton } from "@budibase/bbui" import api from "builderStore/api" import { notifier } from "builderStore/store/notifications" - import { database } from 'builderStore/store/backend/' + import { database } from 'stores/backend/' import analytics from "analytics" let keys = { budibase: "" } diff --git a/packages/builder/src/pages/[application]/_reset.svelte b/packages/builder/src/pages/[application]/_reset.svelte index dcc19e16c1..67df37de01 100644 --- a/packages/builder/src/pages/[application]/_reset.svelte +++ b/packages/builder/src/pages/[application]/_reset.svelte @@ -1,6 +1,6 @@ {#if $database?._id && $tables?.selected?.name} diff --git a/packages/builder/src/pages/[application]/data/table/_layout.svelte b/packages/builder/src/pages/[application]/data/table/_layout.svelte index f94954b840..1a542d9ad8 100644 --- a/packages/builder/src/pages/[application]/data/table/_layout.svelte +++ b/packages/builder/src/pages/[application]/data/table/_layout.svelte @@ -1,5 +1,5 @@ diff --git a/packages/builder/src/builderStore/store/backend/database.js b/packages/builder/src/stores/backend/database.js similarity index 100% rename from packages/builder/src/builderStore/store/backend/database.js rename to packages/builder/src/stores/backend/database.js diff --git a/packages/builder/src/builderStore/store/backend/datasources.js b/packages/builder/src/stores/backend/datasources.js similarity index 94% rename from packages/builder/src/builderStore/store/backend/datasources.js rename to packages/builder/src/stores/backend/datasources.js index 3fb54dd624..0f30695ea3 100644 --- a/packages/builder/src/builderStore/store/backend/datasources.js +++ b/packages/builder/src/stores/backend/datasources.js @@ -1,8 +1,8 @@ import { writable } from "svelte/store" import { queries } from "./" -import api from "../../api" +import api from "builderStore/api" -function createDatasourcesStore() { +export function createDatasourcesStore(_api = api) { const { subscribe, update, set } = writable({ list: [], selected: null, diff --git a/packages/builder/src/builderStore/store/backend/index.js b/packages/builder/src/stores/backend/index.js similarity index 100% rename from packages/builder/src/builderStore/store/backend/index.js rename to packages/builder/src/stores/backend/index.js diff --git a/packages/builder/src/builderStore/store/backend/integrations.js b/packages/builder/src/stores/backend/integrations.js similarity index 100% rename from packages/builder/src/builderStore/store/backend/integrations.js rename to packages/builder/src/stores/backend/integrations.js diff --git a/packages/builder/src/builderStore/store/backend/permissions.js b/packages/builder/src/stores/backend/permissions.js similarity index 90% rename from packages/builder/src/builderStore/store/backend/permissions.js rename to packages/builder/src/stores/backend/permissions.js index 70070f9072..6669ef3270 100644 --- a/packages/builder/src/builderStore/store/backend/permissions.js +++ b/packages/builder/src/stores/backend/permissions.js @@ -1,7 +1,8 @@ import { writable } from "svelte/store" -import api from "../../api" +import api from "builderStore/api" -function createPermissionStore() { + +export function createPermissionStore() { const { subscribe, set } = writable([]) return { diff --git a/packages/builder/src/builderStore/store/backend/queries.js b/packages/builder/src/stores/backend/queries.js similarity index 96% rename from packages/builder/src/builderStore/store/backend/queries.js rename to packages/builder/src/stores/backend/queries.js index ff2eda67ff..8bda870179 100644 --- a/packages/builder/src/builderStore/store/backend/queries.js +++ b/packages/builder/src/stores/backend/queries.js @@ -1,8 +1,9 @@ import { writable, get } from "svelte/store" import { datasources, integrations } from "./" -import api from "../../api" +import api from "builderStore/api" -function createQueriesStore() { + +export function createQueriesStore() { const { subscribe, set, update } = writable({ list: [], selected: null }) return { diff --git a/packages/builder/src/builderStore/store/backend/roles.js b/packages/builder/src/stores/backend/roles.js similarity index 89% rename from packages/builder/src/builderStore/store/backend/roles.js rename to packages/builder/src/stores/backend/roles.js index 1d353e433f..146ba9fbd8 100644 --- a/packages/builder/src/builderStore/store/backend/roles.js +++ b/packages/builder/src/stores/backend/roles.js @@ -1,7 +1,8 @@ import { writable } from "svelte/store" -import api from "../../api" +import api from "builderStore/api" -function createRolesStore() { + +export function createRolesStore() { const { subscribe, set } = writable([]) return { diff --git a/packages/builder/src/builderStore/store/backend/rows.js b/packages/builder/src/stores/backend/rows.js similarity index 88% rename from packages/builder/src/builderStore/store/backend/rows.js rename to packages/builder/src/stores/backend/rows.js index c16941925c..e3872d5873 100644 --- a/packages/builder/src/builderStore/store/backend/rows.js +++ b/packages/builder/src/stores/backend/rows.js @@ -1,7 +1,7 @@ import { writable, get } from "svelte/store" import { views } from "./" -function createRowsStore() { +export function createRowsStore() { const { subscribe } = writable([]) return { diff --git a/packages/builder/src/builderStore/store/backend/tables.js b/packages/builder/src/stores/backend/tables.js similarity index 97% rename from packages/builder/src/builderStore/store/backend/tables.js rename to packages/builder/src/stores/backend/tables.js index 74fd19bef9..c13a3d46ce 100644 --- a/packages/builder/src/builderStore/store/backend/tables.js +++ b/packages/builder/src/stores/backend/tables.js @@ -1,9 +1,10 @@ import { writable, get } from "svelte/store" import { views } from "./" import { cloneDeep } from "lodash/fp" -import api from "../../api" +import api from "builderStore/api" -function createTablesStore() { + +export function createTablesStore() { const store = writable({ list: [], selected: {}, diff --git a/packages/builder/src/stores/backend/tests/database.spec.js b/packages/builder/src/stores/backend/tests/database.spec.js new file mode 100644 index 0000000000..ccaf9c0570 --- /dev/null +++ b/packages/builder/src/stores/backend/tests/database.spec.js @@ -0,0 +1,26 @@ +import { database } from "../" + +describe("Backend DataSources Store", () => { + + let state; + let unsub; + + beforeEach(() => { + unsub = database.subscribe(s => state = s); + }) + afterEach(() => { + unsub() + }) + + it("initialises correctly", () => { + expect(state.list, []) + }) +}) + +const api = { + post: () => ({}), + get: () => ({}), + patch: () => ({}), + delete: () => ({}), + put: () => ({}), + } \ No newline at end of file diff --git a/packages/builder/src/stores/backend/tests/datasources.spec.js b/packages/builder/src/stores/backend/tests/datasources.spec.js new file mode 100644 index 0000000000..02c90d134c --- /dev/null +++ b/packages/builder/src/stores/backend/tests/datasources.spec.js @@ -0,0 +1,24 @@ +import { get } from 'svelte/store' +import { createDatasourcesStore } from "../datasources" + +const mockApi = { + post: () => ({}), + get: () => ({}), + patch: () => ({}), + delete: () => ({}), + put: () => ({}), +} + + +describe("Automation Data Object", () => { + let store + + beforeEach(() => { + store = createDatasourcesStore(mockApi) + }) + + it("Inits properly", () => { + const value = get(store) + expect(value).toBe(true) + }) +}) diff --git a/packages/builder/src/builderStore/store/backend/views.js b/packages/builder/src/stores/backend/views.js similarity index 93% rename from packages/builder/src/builderStore/store/backend/views.js rename to packages/builder/src/stores/backend/views.js index 7a97a9d325..5cd3c60267 100644 --- a/packages/builder/src/builderStore/store/backend/views.js +++ b/packages/builder/src/stores/backend/views.js @@ -1,8 +1,8 @@ import { writable, get } from "svelte/store" import { tables } from "./" -import api from "../../api" +import api from "builderStore/api" -function createViewsStore() { +export function createViewsStore() { const { subscribe, update } = writable({ list: [], selected: null, diff --git a/packages/builder/tests/stores/backend.spec.js b/packages/builder/tests/stores/backend.spec.js deleted file mode 100644 index e69de29bb2..0000000000