diff --git a/packages/bbui/src/index.js b/packages/bbui/src/index.js index 16f069f4e7..3e86d01a0d 100644 --- a/packages/bbui/src/index.js +++ b/packages/bbui/src/index.js @@ -81,6 +81,3 @@ export { default as clickOutside } from "./Actions/click_outside" // Stores export { notifications, createNotificationStore } from "./Stores/notifications" - -// Utils -export * from "./utils/helpers" diff --git a/packages/builder/src/builderStore/uuid.js b/packages/builder/src/builderStore/uuid.js deleted file mode 100644 index 149da83c68..0000000000 --- a/packages/builder/src/builderStore/uuid.js +++ /dev/null @@ -1,9 +0,0 @@ -export function uuid() { - // always want to make this start with a letter, as this makes it - // easier to use with template string bindings in the client - return "cxxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g, c => { - const r = (Math.random() * 16) | 0, - v = c == "x" ? r : (r & 0x3) | 0x8 - return v.toString(16) - }) -} diff --git a/packages/builder/src/constants/lucene.js b/packages/builder/src/constants/lucene.js index 132790739c..159b66e35d 100644 --- a/packages/builder/src/constants/lucene.js +++ b/packages/builder/src/constants/lucene.js @@ -1,58 +1,3 @@ -/** - * Operator options for lucene queries - */ -export const OperatorOptions = { - Equals: { - value: "equal", - label: "Equals", - }, - NotEquals: { - value: "notEqual", - label: "Not equals", - }, - Empty: { - value: "empty", - label: "Is empty", - }, - NotEmpty: { - value: "notEmpty", - label: "Is not empty", - }, - StartsWith: { - value: "string", - label: "Starts with", - }, - Like: { - value: "fuzzy", - label: "Like", - }, - MoreThan: { - value: "rangeLow", - label: "More than", - }, - LessThan: { - value: "rangeHigh", - label: "Less than", - }, - Contains: { - value: "equal", - label: "Contains", - }, - NotContains: { - value: "notEqual", - label: "Does Not Contain", - }, -} - -export const NoEmptyFilterStrings = [ - OperatorOptions.StartsWith.value, - OperatorOptions.Like.value, - OperatorOptions.Equals.value, - OperatorOptions.NotEquals.value, - OperatorOptions.Contains.value, - OperatorOptions.NotContains.value, -] - /** * Returns the valid operator options for a certain data type * @param type the data type diff --git a/packages/client/package.json b/packages/client/package.json index af286bf683..4d917b2080 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -20,6 +20,7 @@ }, "dependencies": { "@budibase/bbui": "^1.0.27-alpha.19", + "@budibase/frontend-core": "^1.0.27-alpha.19", "@budibase/standard-components": "^0.9.139", "@budibase/string-templates": "^1.0.27-alpha.19", "regexparam": "^1.3.0", diff --git a/packages/client/src/api/api.js b/packages/client/src/api/api.js deleted file mode 100644 index 2476030eb0..0000000000 --- a/packages/client/src/api/api.js +++ /dev/null @@ -1,97 +0,0 @@ -import { notificationStore } from "stores" -import { ApiVersion } from "constants" - -/** - * API cache for cached request responses. - */ -let cache = {} - -/** - * Handler for API errors. - */ -const handleError = error => { - return { error } -} - -/** - * Performs an API call to the server. - * App ID header is always correctly set. - */ -const makeApiCall = async ({ method, url, body, json = true }) => { - try { - const requestBody = json ? JSON.stringify(body) : body - const inBuilder = window["##BUDIBASE_IN_BUILDER##"] - const headers = { - Accept: "application/json", - "x-budibase-app-id": window["##BUDIBASE_APP_ID##"], - "x-budibase-api-version": ApiVersion, - ...(json && { "Content-Type": "application/json" }), - ...(!inBuilder && { "x-budibase-type": "client" }), - } - const response = await fetch(url, { - method, - headers, - body: requestBody, - credentials: "same-origin", - }) - switch (response.status) { - case 200: - return response.json() - case 401: - notificationStore.actions.error("Invalid credentials") - return handleError(`Invalid credentials`) - case 404: - notificationStore.actions.warning("Not found") - return handleError(`${url}: Not Found`) - case 400: - return handleError(`${url}: Bad Request`) - case 403: - notificationStore.actions.error( - "Your session has expired, or you don't have permission to access that data" - ) - return handleError(`${url}: Forbidden`) - default: - if (response.status >= 200 && response.status < 400) { - return response.json() - } - return handleError(`${url} - ${response.statusText}`) - } - } catch (error) { - return handleError(error) - } -} - -/** - * Performs an API call to the server and caches the response. - * Future invocation for this URL will return the cached result instead of - * hitting the server again. - */ -const makeCachedApiCall = async params => { - const identifier = params.url - if (!identifier) { - return null - } - if (!cache[identifier]) { - cache[identifier] = makeApiCall(params) - cache[identifier] = await cache[identifier] - } - return await cache[identifier] -} - -/** - * Constructs an API call function for a particular HTTP method. - */ -const requestApiCall = method => async params => { - const { url, cache = false } = params - const fixedUrl = `/${url}`.replace("//", "/") - const enrichedParams = { ...params, method, url: fixedUrl } - return await (cache ? makeCachedApiCall : makeApiCall)(enrichedParams) -} - -export default { - post: requestApiCall("POST"), - get: requestApiCall("GET"), - patch: requestApiCall("PATCH"), - del: requestApiCall("DELETE"), - error: handleError, -} diff --git a/packages/client/src/components/app/DataProvider.svelte b/packages/client/src/components/app/DataProvider.svelte index 71c54db4da..383824d65a 100644 --- a/packages/client/src/components/app/DataProvider.svelte +++ b/packages/client/src/components/app/DataProvider.svelte @@ -2,8 +2,7 @@ import { getContext } from "svelte" import { ProgressCircle, Pagination } from "@budibase/bbui" import Placeholder from "./Placeholder.svelte" - import { fetchData } from "utils/fetch/fetchData.js" - import { buildLuceneQuery } from "builder/src/helpers/lucene" + import { fetchData, LuceneUtils } from "@budibase/frontend-core" export let dataSource export let filter @@ -18,7 +17,7 @@ // We need to manage our lucene query manually as we want to allow components // to extend it let queryExtensions = {} - $: defaultQuery = buildLuceneQuery(filter) + $: defaultQuery = LuceneUtils.buildLuceneQuery(filter) $: query = extendQuery(defaultQuery, queryExtensions) // Keep our data fetch instance up to date diff --git a/packages/client/src/components/app/dynamic-filter/DynamicFilter.svelte b/packages/client/src/components/app/dynamic-filter/DynamicFilter.svelte index 20909d011c..d70bc34198 100644 --- a/packages/client/src/components/app/dynamic-filter/DynamicFilter.svelte +++ b/packages/client/src/components/app/dynamic-filter/DynamicFilter.svelte @@ -3,7 +3,7 @@ import { getContext, onDestroy } from "svelte" import { ModalContent, Modal } from "@budibase/bbui" import FilterModal from "./FilterModal.svelte" - import { buildLuceneQuery } from "builder/src/helpers/lucene" + import { LuceneUtils } from "@budibase/frontend-core" import Button from "../Button.svelte" export let dataProvider @@ -32,7 +32,7 @@ // Add query extension to data provider $: { if (filters?.length) { - const queryExtension = buildLuceneQuery(filters) + const queryExtension = LuceneUtils.buildLuceneQuery(filters) addExtension?.($component.id, queryExtension) } else { removeExtension?.($component.id) diff --git a/packages/client/src/components/app/dynamic-filter/FilterModal.svelte b/packages/client/src/components/app/dynamic-filter/FilterModal.svelte index f303c69aaf..f732dc8ef2 100644 --- a/packages/client/src/components/app/dynamic-filter/FilterModal.svelte +++ b/packages/client/src/components/app/dynamic-filter/FilterModal.svelte @@ -11,14 +11,12 @@ Select, } from "@budibase/bbui" import { generate } from "shortid" - import { - getValidOperatorsForType, - OperatorOptions, - } from "builder/src/constants/lucene" + import { LuceneUtils } from "@budibase/frontend-core" export let schemaFields export let filters = [] + const operatorOptions = LuceneUtils.OperatorOptions const BannedTypes = ["link", "attachment", "formula", "json"] $: fieldOptions = (schemaFields ?? []) @@ -31,7 +29,7 @@ { id: generate(), field: null, - operator: OperatorOptions.Equals.value, + operator: operatorOptions.Equals.value, value: null, valueType: "Value", }, @@ -53,11 +51,11 @@ expression.type = schemaFields.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] ?? operatorOptions.Equals.value onOperatorChange(expression, expression.operator) } @@ -72,8 +70,8 @@ const onOperatorChange = (expression, operator) => { const noValueOptions = [ - OperatorOptions.Empty.value, - OperatorOptions.NotEmpty.value, + operatorOptions.Empty.value, + operatorOptions.NotEmpty.value, ] expression.noValue = noValueOptions.includes(operator) if (expression.noValue) { @@ -109,7 +107,7 @@ />