From a645df082c7c0684f120e3841bba70631155c28d Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Tue, 28 Apr 2020 14:39:35 +0100 Subject: [PATCH] clientId fetching before app load, custom views, fixed schema --- packages/builder/package.json | 3 +- packages/builder/src/App.svelte | 18 +- packages/builder/src/builderStore/api.js | 11 +- .../builder/src/builderStore/store/backend.js | 12 +- .../builder/src/builderStore/store/index.js | 3 +- .../src/components/common/ErrorsBox.svelte | 2 +- .../ModelDataTable/ModelDataTable.svelte | 6 +- .../components/database/ModelDataTable/api.js | 2 +- .../CreateEditModel/CreateEditModel.svelte | 1 - .../modals/CreateEditModel/FieldView.svelte | 51 +- .../modals/CreateEditRecord.svelte | 11 +- .../modals/CreateEditView.svelte | 95 +- .../modals/RecordFieldControl.svelte | 6 +- .../src/components/nav/HierarchyRow.svelte | 49 +- .../nav/SchemaManagementDrawer.svelte | 78 +- .../database/[selectedDatabase]/index.svelte | 2 +- packages/cli/src/commands/init/index.js | 2 +- packages/cli/src/commands/init/initHandler.js | 14 +- packages/cli/src/commands/new/index.js | 2 +- packages/cli/src/commands/run/index.js | 2 +- packages/cli/src/common.js | 3 +- packages/cli/yarn.lock | 3226 +---------------- packages/common/lib/records/getNewRecord.js | 3 +- packages/server/.gitignore | 1 + packages/server/db/client.js | 23 +- packages/server/db/index.js | 2 +- packages/server/db/initialiseClientDb.js | 5 +- .../server/middleware/controllers/client.js | 4 + .../server/middleware/controllers/record.js | 6 +- .../server/middleware/controllers/static.js | 1 + .../server/middleware/controllers/view.js | 21 +- packages/server/middleware/routers.js | 6 +- .../server/middleware/routes/neo/client.js | 1 + .../server/middleware/routes/neo/record.js | 2 +- .../server/middleware/routes/neo/static.js | 2 +- packages/server/utilities/builder/index.js | 5 +- packages/server/utilities/runtimePackages.js | 4 +- 37 files changed, 237 insertions(+), 3448 deletions(-) diff --git a/packages/builder/package.json b/packages/builder/package.json index cc36e98dc1..d92f64ce17 100644 --- a/packages/builder/package.json +++ b/packages/builder/package.json @@ -59,6 +59,7 @@ "@babel/preset-env": "^7.5.5", "@babel/runtime": "^7.5.5", "@rollup/plugin-alias": "^3.0.1", + "@rollup/plugin-json": "^4.0.3", "@sveltech/routify": "1.5.0-beta.40", "babel-jest": "^24.8.0", "browser-sync": "^2.26.7", @@ -81,4 +82,4 @@ "svelte": "^3.0.0" }, "gitHead": "115189f72a850bfb52b65ec61d932531bf327072" -} \ No newline at end of file +} diff --git a/packages/builder/src/App.svelte b/packages/builder/src/App.svelte index 6d007631ca..1dbc111cb3 100644 --- a/packages/builder/src/App.svelte +++ b/packages/builder/src/App.svelte @@ -16,7 +16,15 @@ }) } - onMount(() => { + onMount(async () => { + const res = await fetch(`/api/client/id`) + const json = await res.json() + + store.update(state => { + state.clientId = json + return state + }) + window.addEventListener("error", showErrorBanner) window.addEventListener("unhandledrejection", showErrorBanner) }) @@ -26,6 +34,8 @@ - - - +{#if $store.clientId} + + + +{/if} diff --git a/packages/builder/src/builderStore/api.js b/packages/builder/src/builderStore/api.js index 49ae3ed586..46345fd213 100644 --- a/packages/builder/src/builderStore/api.js +++ b/packages/builder/src/builderStore/api.js @@ -1,5 +1,5 @@ -const apiCall = method => (url, body) => - fetch(url, { +const apiCall = method => async (url, body) => { + const response = await fetch(url, { method: method, headers: { "Content-Type": "application/json", @@ -7,6 +7,13 @@ const apiCall = method => (url, body) => body: body && JSON.stringify(body), }) + // if (response.status === 500) { + // throw new Error("Server Error"); + // } + + return response; +} + const post = apiCall("POST") const get = apiCall("GET") const patch = apiCall("PATCH") diff --git a/packages/builder/src/builderStore/store/backend.js b/packages/builder/src/builderStore/store/backend.js index 7f975e6168..bcdd9ad5fe 100644 --- a/packages/builder/src/builderStore/store/backend.js +++ b/packages/builder/src/builderStore/store/backend.js @@ -8,12 +8,9 @@ import { export const getBackendUiStore = () => { const INITIAL_BACKEND_UI_STATE = { - selectedView: { - records: [], - name: "", - }, breadcrumbs: [], models: [], + views: [], users: [], selectedDatabase: {}, selectedModel: {}, @@ -24,12 +21,15 @@ export const getBackendUiStore = () => { store.actions = { database: { select: async db => { - const response = await api.get(`/api/${db.id}/models`) - const models = await response.json() + const modelsResponse = await api.get(`/api/${db.id}/models`) + const viewsResponse = await api.get(`/api/${db.id}/views`) + const models = await modelsResponse.json() + const views = await viewsResponse.json() store.update(state => { state.selectedDatabase = db state.breadcrumbs = [db.name] state.models = models + state.views = views; return state }) } diff --git a/packages/builder/src/builderStore/store/index.js b/packages/builder/src/builderStore/store/index.js index aaac7ba6ec..b65b489454 100644 --- a/packages/builder/src/builderStore/store/index.js +++ b/packages/builder/src/builderStore/store/index.js @@ -43,8 +43,7 @@ export const getStore = () => { libraries: null, showSettings: false, useAnalytics: true, - appId: "", - clientId: "budibase" + appId: "" } const store = writable(initial) diff --git a/packages/builder/src/components/common/ErrorsBox.svelte b/packages/builder/src/components/common/ErrorsBox.svelte index 727ef3f2b3..dffb383ec5 100644 --- a/packages/builder/src/components/common/ErrorsBox.svelte +++ b/packages/builder/src/components/common/ErrorsBox.svelte @@ -7,7 +7,7 @@ {#if hasErrors}
{#each errors as error} -
{error.field ? `${error.field}: ` : ''}{error.error}
+
{error.dataPath} {error.message}
{/each}
{/if} diff --git a/packages/builder/src/components/database/ModelDataTable/ModelDataTable.svelte b/packages/builder/src/components/database/ModelDataTable/ModelDataTable.svelte index 23d16ab483..f6a5db8949 100644 --- a/packages/builder/src/components/database/ModelDataTable/ModelDataTable.svelte +++ b/packages/builder/src/components/database/ModelDataTable/ModelDataTable.svelte @@ -77,10 +77,6 @@ currentPage * ITEMS_PER_PAGE + ITEMS_PER_PAGE ) - // async function fetchRecordsForView(view, instance) { - // return await api.fetchDataForView($backendUiStore.selectedView) - // } - function drillIntoRecord(record) { backendUiStore.update(state => { state.breadcrumbs = [...state.breadcrumbs, record.type, record.id] @@ -100,7 +96,7 @@

- {takeRight(2, $backendUiStore.breadcrumbs).join(' / ')} + {$backendUiStore.selectedModel.name}

diff --git a/packages/builder/src/components/database/ModelDataTable/api.js b/packages/builder/src/components/database/ModelDataTable/api.js index d35348b180..eea7cfa6af 100644 --- a/packages/builder/src/components/database/ModelDataTable/api.js +++ b/packages/builder/src/components/database/ModelDataTable/api.js @@ -30,11 +30,11 @@ export async function loadRecord(key, { appname, instanceId }) { export async function saveRecord(record, instanceId) { const SAVE_RECORDS_URL = `/api/${instanceId}/records` const response = await api.post(SAVE_RECORDS_URL, record) + return await response.json() } export async function fetchDataForView(viewName, instanceId) { - // const FETCH_RECORDS_URL = `/_builder/instance/${appname}/${instanceId}/api/listRecords/${viewName}` const FETCH_RECORDS_URL = `/api/${instanceId}/${viewName}/records` const response = await api.get(FETCH_RECORDS_URL) diff --git a/packages/builder/src/components/database/ModelDataTable/modals/CreateEditModel/CreateEditModel.svelte b/packages/builder/src/components/database/ModelDataTable/modals/CreateEditModel/CreateEditModel.svelte index af190c7c61..243f20aefd 100644 --- a/packages/builder/src/components/database/ModelDataTable/modals/CreateEditModel/CreateEditModel.svelte +++ b/packages/builder/src/components/database/ModelDataTable/modals/CreateEditModel/CreateEditModel.svelte @@ -89,7 +89,6 @@
{key}
-
{meta.type} {} let errors = [] - let draftField = cloneDeep(field); + let draftField = cloneDeep(field) const save = () => { - // errors = validate.field(allFields)(clonedField) - // if (errors.length > 0) return - // field.typeOptions = cloneDeep(clonedField.typeOptions) - schema[field.name] = draftField; - goBack(); - // onFinished({ ...field, ...clonedField }) + schema[field.name] = draftField + goBack() } @@ -43,37 +40,23 @@ + options={FIELD_TYPES} /> {#if field.type === 'string'} - - - {:else if field.type === 'bool'} - - + + + {:else if field.type === 'boolean'} + + {:else if field.format === 'datetime'} - - - + + + {:else if field.type === 'number'} - - + + {:else if draftField.type.startsWith('array')} - + diff --git a/packages/builder/src/components/database/ModelDataTable/modals/CreateEditRecord.svelte b/packages/builder/src/components/database/ModelDataTable/modals/CreateEditRecord.svelte index 90755da980..d2e03f28f7 100644 --- a/packages/builder/src/components/database/ModelDataTable/modals/CreateEditRecord.svelte +++ b/packages/builder/src/components/database/ModelDataTable/modals/CreateEditRecord.svelte @@ -13,6 +13,10 @@ import * as api from "../api" import ErrorsBox from "components/common/ErrorsBox.svelte" + const CLASS_NAME_MAP = { + boolean: "uk-checkbox" + } + export let record = {} export let onClosed @@ -57,16 +61,15 @@ backendUiStore.update(state => { state.selectedView = state.selectedView - return state onClosed(); + return state }) }

Create / Edit Record

- - {JSON.stringify(errors)} +
{#if !record}
@@ -81,7 +84,7 @@ {#each modelSchema as [key, meta]}
diff --git a/packages/builder/src/components/database/ModelDataTable/modals/CreateEditView.svelte b/packages/builder/src/components/database/ModelDataTable/modals/CreateEditView.svelte index fa08b7b90c..9636584f6e 100644 --- a/packages/builder/src/components/database/ModelDataTable/modals/CreateEditView.svelte +++ b/packages/builder/src/components/database/ModelDataTable/modals/CreateEditView.svelte @@ -3,50 +3,39 @@ import CodeArea from "components/common/CodeArea.svelte" import Button from "components/common/Button.svelte" import Dropdown from "components/common/Dropdown.svelte" - import { store } from "builderStore" + import { store, backendUiStore } from "builderStore" import { filter, some, map, compose } from "lodash/fp" - import { - hierarchy as hierarchyFunctions, - common, - } from "../../../../../../core/src/" import ErrorsBox from "components/common/ErrorsBox.svelte" import ActionButton from "components/common/ActionButton.svelte" + import api from "builderStore/api" const SNIPPET_EDITORS = { MAP: "Map", FILTER: "Filter", - SHARD: "Shard Name", + REDUCE: "Reduce", } - let view - let indexableModels = [] + const COUCHDB_FUNCTION = `function(doc) { + + }` + + export let onClosed + export let view = {} + let currentSnippetEditor = SNIPPET_EDITORS.MAP - const indexableModelsFromIndex = compose( - map(node => ({ - node, - isallowed: - view.allowedModelNodeIds && - view.allowedModelNodeIds.some(id => node.nodeId === id), - })), - filter(hierarchyFunctions.isModel), - filter(hierarchyFunctions.isDecendant($store.currentNode.parent())), - hierarchyFunctions.getFlattenedHierarchy - ) + $: instanceId = $backendUiStore.selectedDatabase.id - store.subscribe($store => { - view = $store.currentNode - indexableModels = indexableModelsFromIndex($store.hierarchy) - }) + function deleteView() {} - const toggleAllowedModel = model => { - if (model.isallowed) { - view.allowedModelNodeIds = view.allowedModelNodeIds.filter( - id => id !== model.node.nodeId - ) - } else { - view.allowedModelNodeIds.push(model.node.nodeId) - } + async function saveView() { + const SAVE_VIEW_URL = `/api/${instanceId}/views` + const response = await api.post(SAVE_VIEW_URL, view) + backendUiStore.update(state => { + state.views = [...state.views, response.view] + return state + }) + onClosed(); } @@ -63,26 +52,6 @@
-
- -
-
- -
-
- Which models would you like to add to this view? -
- {#each indexableModels as model} - toggleAllowedModel(model)} /> - {model.node.name} - {/each}

Snippets

@@ -98,18 +67,14 @@ {:else if currentSnippetEditor === SNIPPET_EDITORS.FILTER} - {:else if currentSnippetEditor === SNIPPET_EDITORS.SHARD} - + {:else if currentSnippetEditor === SNIPPET_EDITORS.REDUCE} + {/if} - + Save - - {#if !$store.currentNodeIsNew} - Delete - {/if} - + Delete