diff --git a/packages/builder/package.json b/packages/builder/package.json index a6988dfd63..41ffe2ba91 100644 --- a/packages/builder/package.json +++ b/packages/builder/package.json @@ -50,7 +50,6 @@ ] }, "dependencies": { - "@beyonk/svelte-notifications": "^2.0.3", "@budibase/bbui": "^1.8.0", "@budibase/client": "^0.0.32", "@nx-js/compiler-util": "^2.0.0", diff --git a/packages/builder/src/App.svelte b/packages/builder/src/App.svelte index b19b8df5c7..7cf7fb864b 100644 --- a/packages/builder/src/App.svelte +++ b/packages/builder/src/App.svelte @@ -4,30 +4,11 @@ import { Router, basepath } from "@sveltech/routify" import { routes } from "../routify/routes" import { store, initialise } from "builderStore" - import AppNotification, { - showAppNotification, - } from "components/common/AppNotification.svelte" - import { NotificationDisplay } from "@beyonk/svelte-notifications" - - function showErrorBanner() { - showAppNotification({ - status: "danger", - message: - "Whoops! Looks like we're having trouble. Please refresh the page.", - }) - } - - onMount(async () => { - window.addEventListener("error", showErrorBanner) - window.addEventListener("unhandledrejection", showErrorBanner) - }) + import NotificationDisplay from "components/common/Notification.svelte"; $basepath = "/_builder" - - - diff --git a/packages/builder/src/builderStore/store/backend.js b/packages/builder/src/builderStore/store/backend.js index 83c241f818..57cadb365a 100644 --- a/packages/builder/src/builderStore/store/backend.js +++ b/packages/builder/src/builderStore/store/backend.js @@ -62,16 +62,6 @@ export const getBackendUiStore = () => { save: async ({ model }) => { const updatedModel = cloneDeep(model) - // // TODO: refactor - // for (let key in updatedModel.schema) { - // const field = updatedModel.schema[key] - // // TODO: use IDs - // if (field.name && field.name !== key) { - // updatedModel.schema[field.name] = field - // delete updatedModel.schema[key] - // } - // } - const SAVE_MODEL_URL = `/api/models` const response = await api.post(SAVE_MODEL_URL, updatedModel) const savedModel = await response.json() diff --git a/packages/builder/src/builderStore/store/notifications.js b/packages/builder/src/builderStore/store/notifications.js new file mode 100644 index 0000000000..cb789b2aef --- /dev/null +++ b/packages/builder/src/builderStore/store/notifications.js @@ -0,0 +1,14 @@ +import { writable } from 'svelte/store' + +export const notificationStore = writable() + +export function send(message, type = 'default', timeout) { + notificationStore.set({ type, message, timeout }) +} + +export const notifier = { + danger: msg => send(msg, "danger"), + warning: msg => send(msg, "warning"), + info: msg => send(msg, "info"), + success: msg => send(msg, "success") +} \ No newline at end of file diff --git a/packages/builder/src/components/common/AppNotification.svelte b/packages/builder/src/components/common/AppNotification.svelte deleted file mode 100644 index 2e8723ab53..0000000000 --- a/packages/builder/src/components/common/AppNotification.svelte +++ /dev/null @@ -1,77 +0,0 @@ - - - diff --git a/packages/builder/src/components/common/LinkedRecordSelector.svelte b/packages/builder/src/components/common/LinkedRecordSelector.svelte index 24c8d8f5d8..bad03f436d 100644 --- a/packages/builder/src/components/common/LinkedRecordSelector.svelte +++ b/packages/builder/src/components/common/LinkedRecordSelector.svelte @@ -8,22 +8,20 @@ export let linked = [] let records = [] + let model = {} let linkedRecords = new Set(linked) $: linked = [...linkedRecords] - $: FIELDS_TO_HIDE = [ - "modelId", - "type", - "_id", - "_rev", - $backendUiStore.selectedModel.name, - modelId - ] + $: FIELDS_TO_HIDE = [$backendUiStore.selectedModel._id] + $: schema = $backendUiStore.selectedModel.schema async function fetchRecords() { const FETCH_RECORDS_URL = `/api/${modelId}/records` const response = await api.get(FETCH_RECORDS_URL) + const modelResponse = await api.get(`/api/models/${modelId}`) + + model = await modelResponse.json() records = await response.json() } @@ -49,9 +47,9 @@ {#each records as record}
linkRecord(record._id)}>
- {#each Object.keys(record).filter(key => !FIELDS_TO_HIDE.includes(key)) as key} + {#each Object.keys(model.schema).filter(key => !FIELDS_TO_HIDE.includes(key)) as key}
- {key} + {model.schema[key].name}

{record[key]}

{/each} diff --git a/packages/builder/src/components/common/Notification.svelte b/packages/builder/src/components/common/Notification.svelte new file mode 100644 index 0000000000..2503db0b8f --- /dev/null +++ b/packages/builder/src/components/common/Notification.svelte @@ -0,0 +1,119 @@ + + +
    + {#each notifications as toast (toast.id)} +
  • +
    {toast.msg}
    +
  • + {/each} +
+ + diff --git a/packages/builder/src/components/database/ModelDataTable/LinkedRecord.svelte b/packages/builder/src/components/database/ModelDataTable/LinkedRecord.svelte index 96e611ad27..8c7d064c0b 100644 --- a/packages/builder/src/components/database/ModelDataTable/LinkedRecord.svelte +++ b/packages/builder/src/components/database/ModelDataTable/LinkedRecord.svelte @@ -5,25 +5,21 @@ import api from "builderStore/api" export let ids = [] - export let header + export let field let records = [] let open = false + let model - $: FIELDS_TO_HIDE = [ - "modelId", - "type", - "_id", - "_rev", - $backendUiStore.selectedModel._id, - $backendUiStore.selectedModel.name, - ] + $: FIELDS_TO_HIDE = [$backendUiStore.selectedModel._id, field.modelId] async function fetchRecords() { const response = await api.post("/api/records/search", { keys: ids, }) + const modelResponse = await api.get(`/api/models/${field.modelId}`) records = await response.json() + model = await modelResponse.json() } $: ids && fetchRecords() @@ -42,15 +38,15 @@ {#if open}
-

{header}

+

{field.name}

{#each records as record}
- {#each Object.keys(record).filter(key => !FIELDS_TO_HIDE.includes(key)) as key} + {#each Object.keys(model.schema).filter(key => !FIELDS_TO_HIDE.includes(key)) as key}
- {key} + {model.schema[key].name}

{record[key]}

{/each} @@ -62,6 +58,10 @@