From 3a3f4f0538dd096ee3e073eb105f6e1aca68612f Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 20 Jan 2022 11:19:37 +0000 Subject: [PATCH] Update usages of utils and helpers in the builder --- packages/builder/package.json | 1 + packages/builder/src/builderStore/api.js | 4 +- .../builder/src/builderStore/dataBinding.js | 16 ++--- .../src/builderStore/store/frontend.js | 8 +-- .../store/screenTemplates/utils/Component.js | 4 +- .../store/screenTemplates/utils/Screen.js | 4 +- .../builder/src/builderStore/store/theme.js | 4 +- .../SetupPanel/AutomationBlockSetup.svelte | 4 +- .../auth/RestAuthenticationBuilder.svelte | 4 +- .../Datasources/CreateEditRelationship.svelte | 4 +- .../ConditionalUIDrawer.svelte | 17 +++--- .../FilterEditor/FilterDrawer.svelte | 19 +++--- .../builder/src/helpers/fetchTableData.js | 4 +- .../builder/src/pages/builder/_layout.svelte | 15 ++--- .../builder/portal/manage/auth/index.svelte | 4 +- .../app/dynamic-filter/FilterModal.svelte | 12 ++-- packages/frontend-core/src/constants.js | 59 ++++++++++++++++++- packages/frontend-core/src/utils/cookies.js | 6 -- packages/frontend-core/src/utils/lucene.js | 47 +-------------- 19 files changed, 120 insertions(+), 116 deletions(-) diff --git a/packages/builder/package.json b/packages/builder/package.json index 59e21a15cc..bb67fcafea 100644 --- a/packages/builder/package.json +++ b/packages/builder/package.json @@ -67,6 +67,7 @@ "dependencies": { "@budibase/bbui": "^1.0.44-alpha.7", "@budibase/client": "^1.0.44-alpha.7", + "@budibase/frontend-core": "^1.0.44-alpha.7", "@budibase/colorpicker": "1.1.2", "@budibase/string-templates": "^1.0.44-alpha.7", "@sentry/browser": "5.19.1", diff --git a/packages/builder/src/builderStore/api.js b/packages/builder/src/builderStore/api.js index 897d3a74db..9dfd8af854 100644 --- a/packages/builder/src/builderStore/api.js +++ b/packages/builder/src/builderStore/api.js @@ -1,6 +1,6 @@ import { store } from "./index" import { get as svelteGet } from "svelte/store" -import { removeCookie, Cookies } from "./cookies" +import { CookieUtils, Constants } from "@budibase/frontend-core" const apiCall = method => @@ -16,7 +16,7 @@ const apiCall = if (url.includes("/api/templates")) { return { json: () => [] } } - removeCookie(Cookies.Auth) + CookieUtils.removeCookie(Constants.Cookies.Auth) // reload after removing cookie, go to login if (!url.includes("self") && !url.includes("login")) { location.reload() diff --git a/packages/builder/src/builderStore/dataBinding.js b/packages/builder/src/builderStore/dataBinding.js index 0f3cffc4fb..23dede9fe2 100644 --- a/packages/builder/src/builderStore/dataBinding.js +++ b/packages/builder/src/builderStore/dataBinding.js @@ -15,10 +15,7 @@ import { encodeJSBinding, } from "@budibase/string-templates" import { TableNames } from "../constants" -import { - convertJSONSchemaToTableSchema, - getJSONArrayDatasourceSchema, -} from "./jsonUtils" +import { JSONUtils } from "@budibase/frontend-core" import ActionDefinitions from "components/design/PropertiesPanel/PropertyControls/ButtonActionEditor/manifest.json" // Regex to match all instances of template strings @@ -439,7 +436,7 @@ export const getSchemaForDatasource = (asset, datasource, isForm = false) => { else if (type === "jsonarray") { table = tables.find(table => table._id === datasource.tableId) let tableSchema = table?.schema - schema = getJSONArrayDatasourceSchema(tableSchema, datasource) + schema = JSONUtils.getJSONArrayDatasourceSchema(tableSchema, datasource) } // Otherwise we assume we're targeting an internal table or a plus @@ -471,9 +468,12 @@ export const getSchemaForDatasource = (asset, datasource, isForm = false) => { Object.keys(schema).forEach(fieldKey => { const fieldSchema = schema[fieldKey] if (fieldSchema?.type === "json") { - const jsonSchema = convertJSONSchemaToTableSchema(fieldSchema, { - squashObjects: true, - }) + const jsonSchema = JSONUtils.convertJSONSchemaToTableSchema( + fieldSchema, + { + squashObjects: true, + } + ) Object.keys(jsonSchema).forEach(jsonKey => { jsonAdditions[`${fieldKey}.${jsonKey}`] = { type: jsonSchema[jsonKey].type, diff --git a/packages/builder/src/builderStore/store/frontend.js b/packages/builder/src/builderStore/store/frontend.js index fdfe450edf..fdd4599e18 100644 --- a/packages/builder/src/builderStore/store/frontend.js +++ b/packages/builder/src/builderStore/store/frontend.js @@ -27,7 +27,7 @@ import { findComponent, getComponentSettings, } from "../componentUtils" -import { uuid } from "../uuid" +import { Helpers } from "@budibase/bbui" import { removeBindings } from "../dataBinding" const INITIAL_FRONTEND_STATE = { @@ -397,7 +397,7 @@ export const getFrontendStore = () => { } return { - _id: uuid(), + _id: Helpers.uuid(), _component: definition.component, _styles: { normal: {}, hover: {}, active: {} }, _instanceName: `New ${definition.name}`, @@ -551,7 +551,7 @@ export const getFrontendStore = () => { if (!component) { return } - component._id = uuid() + component._id = Helpers.uuid() component._children?.forEach(randomizeIds) } randomizeIds(componentToPaste) @@ -664,7 +664,7 @@ export const getFrontendStore = () => { newLink = cloneDeep(nav._children[0]) // Set our new props - newLink._id = uuid() + newLink._id = Helpers.uuid() newLink._instanceName = `${title} Link` newLink.url = url newLink.text = title diff --git a/packages/builder/src/builderStore/store/screenTemplates/utils/Component.js b/packages/builder/src/builderStore/store/screenTemplates/utils/Component.js index 182736a1d5..93aa925aa6 100644 --- a/packages/builder/src/builderStore/store/screenTemplates/utils/Component.js +++ b/packages/builder/src/builderStore/store/screenTemplates/utils/Component.js @@ -1,4 +1,4 @@ -import { uuid } from "builderStore/uuid" +import { Helpers } from "@budibase/bbui" import { BaseStructure } from "./BaseStructure" export class Component extends BaseStructure { @@ -6,7 +6,7 @@ export class Component extends BaseStructure { super(false) this._children = [] this._json = { - _id: uuid(), + _id: Helpers.uuid(), _component: name, _styles: { normal: {}, diff --git a/packages/builder/src/builderStore/store/screenTemplates/utils/Screen.js b/packages/builder/src/builderStore/store/screenTemplates/utils/Screen.js index 04ff1f4ba2..272f627163 100644 --- a/packages/builder/src/builderStore/store/screenTemplates/utils/Screen.js +++ b/packages/builder/src/builderStore/store/screenTemplates/utils/Screen.js @@ -1,5 +1,5 @@ import { BaseStructure } from "./BaseStructure" -import { uuid } from "builderStore/uuid" +import { Helpers } from "@budibase/bbui" export class Screen extends BaseStructure { constructor() { @@ -7,7 +7,7 @@ export class Screen extends BaseStructure { this._json = { layoutId: "layout_private_master", props: { - _id: uuid(), + _id: Helpers.uuid(), _component: "@budibase/standard-components/container", _styles: { normal: {}, diff --git a/packages/builder/src/builderStore/store/theme.js b/packages/builder/src/builderStore/store/theme.js index fd6b05df59..d4d7460ed2 100644 --- a/packages/builder/src/builderStore/store/theme.js +++ b/packages/builder/src/builderStore/store/theme.js @@ -1,4 +1,4 @@ -import { localStorageStore } from "./localStorage" +import { createLocalStorageStore } from "@budibase/frontend-core" export const getThemeStore = () => { const themeElement = document.documentElement @@ -6,7 +6,7 @@ export const getThemeStore = () => { theme: "darkest", options: ["lightest", "light", "dark", "darkest"], } - const store = localStorageStore("bb-theme", initialValue) + const store = createLocalStorageStore("bb-theme", initialValue) // Update theme class when store changes store.subscribe(state => { diff --git a/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte b/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte index 928897d6f5..aa84013d46 100644 --- a/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte +++ b/packages/builder/src/components/automation/SetupPanel/AutomationBlockSetup.svelte @@ -28,7 +28,7 @@ import ModalBindableInput from "components/common/bindings/ModalBindableInput.svelte" import FilterDrawer from "components/design/PropertiesPanel/PropertyControls/FilterEditor/FilterDrawer.svelte" // need the client lucene builder to convert to the structure API expects - import { buildLuceneQuery } from "helpers/lucene" + import { LuceneUtils } from "@budibase/frontend-core" export let block export let testData @@ -131,7 +131,7 @@ } function saveFilters(key) { - const filters = buildLuceneQuery(tempFilters) + const filters = LuceneUtils.buildLuceneQuery(tempFilters) const defKey = `${key}-def` inputData[key] = filters inputData[defKey] = tempFilters diff --git a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationBuilder.svelte b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationBuilder.svelte index 7bbd2402f0..92f1269a82 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationBuilder.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationBuilder.svelte @@ -2,7 +2,7 @@ import { Table, Modal, Layout, ActionButton } from "@budibase/bbui" import AuthTypeRenderer from "./AuthTypeRenderer.svelte" import RestAuthenticationModal from "./RestAuthenticationModal.svelte" - import { uuid } from "builderStore/uuid" + import { Helpers } from "@budibase/bbui" export let configs = [] @@ -29,7 +29,7 @@ return c }) } else { - config._id = uuid() + config._id = Helpers.uuid() configs = [...configs, config] } } diff --git a/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte b/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte index 104fd7cb5a..f3ed0f163a 100644 --- a/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte +++ b/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte @@ -9,7 +9,7 @@ Body, } from "@budibase/bbui" import { tables } from "stores/backend" - import { uuid } from "builderStore/uuid" + import { Helpers } from "@budibase/bbui" import { writable } from "svelte/store" export let save @@ -151,7 +151,7 @@ const manyToMany = fromRelationship.relationshipType === RelationshipTypes.MANY_TO_MANY // main is simply used to know this is the side the user configured it from - const id = uuid() + const id = Helpers.uuid() if (!manyToMany) { delete fromRelationship.through delete toRelationship.through diff --git a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/ConditionalUIDrawer.svelte b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/ConditionalUIDrawer.svelte index e303729d0b..11d19edf7c 100644 --- a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/ConditionalUIDrawer.svelte +++ b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/ConditionalUIDrawer.svelte @@ -12,7 +12,7 @@ import { dndzone } from "svelte-dnd-action" import { generate } from "shortid" import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte" - import { OperatorOptions, getValidOperatorsForType } from "constants/lucene" + import { LuceneUtils, Constants } from "@budibase/frontend-core" import { selectedComponent } from "builderStore" import { getComponentForSettingType } from "./componentSettings" import PropertyControl from "./PropertyControl.svelte" @@ -83,7 +83,7 @@ valueType: "string", id: generate(), action: "hide", - operator: OperatorOptions.Equals.value, + operator: Constants.OperatorOptions.Equals.value, }, ] } @@ -108,13 +108,13 @@ } const getOperatorOptions = condition => { - return getValidOperatorsForType(condition.valueType) + return LuceneUtils.getValidOperatorsForType(condition.valueType) } const onOperatorChange = (condition, newOperator) => { const noValueOptions = [ - OperatorOptions.Empty.value, - OperatorOptions.NotEmpty.value, + Constants.OperatorOptions.Empty.value, + Constants.OperatorOptions.NotEmpty.value, ] condition.noValue = noValueOptions.includes(newOperator) if (condition.noValue) { @@ -127,9 +127,12 @@ condition.referenceValue = null // Ensure a valid operator is set - const validOperators = getValidOperatorsForType(newType).map(x => x.value) + const validOperators = LuceneUtils.getValidOperatorsForType(newType).map( + x => x.value + ) if (!validOperators.includes(condition.operator)) { - condition.operator = validOperators[0] ?? OperatorOptions.Equals.value + condition.operator = + validOperators[0] ?? Constants.OperatorOptions.Equals.value onOperatorChange(condition, condition.operator) } } diff --git a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/FilterEditor/FilterDrawer.svelte b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/FilterEditor/FilterDrawer.svelte index 8d7f50a527..a8b998fdee 100644 --- a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/FilterEditor/FilterDrawer.svelte +++ b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/FilterEditor/FilterDrawer.svelte @@ -13,7 +13,7 @@ import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte" import ClientBindingPanel from "components/common/bindings/ClientBindingPanel.svelte" import { generate } from "shortid" - import { getValidOperatorsForType, OperatorOptions } from "constants/lucene" + import { LuceneUtils, Constants } from "@budibase/frontend-core" import { getFields } from "helpers/searchFields" export let schemaFields @@ -32,7 +32,7 @@ { id: generate(), field: null, - operator: OperatorOptions.Equals.value, + operator: Constants.OperatorOptions.Equals.value, value: null, valueType: "Value", }, @@ -54,11 +54,12 @@ expression.type = enrichedSchemaFields.find(x => x.name === field)?.type // Ensure a valid operator is set - const validOperators = getValidOperatorsForType(expression.type).map( - x => x.value - ) + const validOperators = LuceneUtils.getValidOperatorsForType( + expression.type + ).map(x => x.value) if (!validOperators.includes(expression.operator)) { - expression.operator = validOperators[0] ?? OperatorOptions.Equals.value + expression.operator = + validOperators[0] ?? Constants.OperatorOptions.Equals.value onOperatorChange(expression, expression.operator) } @@ -73,8 +74,8 @@ const onOperatorChange = (expression, operator) => { const noValueOptions = [ - OperatorOptions.Empty.value, - OperatorOptions.NotEmpty.value, + Constants.OperatorOptions.Empty.value, + Constants.OperatorOptions.NotEmpty.value, ] expression.noValue = noValueOptions.includes(operator) if (expression.noValue) { @@ -110,7 +111,7 @@ />