From 4a23ddcdbd4eceaf6e28962d4094e0443a430f52 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 21 Jul 2020 09:31:16 +0000 Subject: [PATCH 01/16] Bump lodash from 4.17.15 to 4.17.19 in /packages/server Bumps [lodash](https://github.com/lodash/lodash) from 4.17.15 to 4.17.19. - [Release notes](https://github.com/lodash/lodash/releases) - [Commits](https://github.com/lodash/lodash/compare/4.17.15...4.17.19) Signed-off-by: dependabot[bot] --- packages/server/yarn.lock | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/server/yarn.lock b/packages/server/yarn.lock index 062563a881..2c8c430566 100644 --- a/packages/server/yarn.lock +++ b/packages/server/yarn.lock @@ -4009,14 +4009,10 @@ lodash.sortby@^4.7.0: version "4.7.0" resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438" -lodash@^4.17.10: +lodash@^4.17.10, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15: version "4.17.19" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.19.tgz#e48ddedbe30b3321783c5b4301fbd353bc1e4a4b" -lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15: - version "4.17.15" - resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548" - loose-envify@^1.0.0: version "1.4.0" resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf" From 99c42786bbd45c31c99a8c5a7e3dcb6d49ae821f Mon Sep 17 00:00:00 2001 From: Michael Shanks Date: Tue, 21 Jul 2020 12:16:05 +0100 Subject: [PATCH 02/16] Form: setting default values on record fields --- .../standard-components/src/DataForm.svelte | 30 ++++++++++++++++--- .../src/DataFormWide.svelte | 30 ++++++++++++++++--- 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/packages/standard-components/src/DataForm.svelte b/packages/standard-components/src/DataForm.svelte index f2aeaec747..e0a41a9ff7 100644 --- a/packages/standard-components/src/DataForm.svelte +++ b/packages/standard-components/src/DataForm.svelte @@ -32,11 +32,35 @@ $: Object.values(inputElements).length && setForm(record) + const createBlankRecord = () => { + if (!schema) return + const newrecord = { + modelId: model, + } + for (let fieldName in schema) { + const field = schema[fieldName] + // defaulting to first one, as a blank value will fail validation + if ( + field.type === "string" && + field.constraints && + field.constraints.inclusion && + field.constraints.inclusion.length > 0 + ) { + newrecord[fieldName] = field.constraints.inclusion[0] + } else if (field.type === "number") newrecord[fieldName] = null + else if (field.type === "boolean") newrecord[fieldName] = false + else if (field.type === "link") newrecord[fieldName] = [] + else newrecord[fieldName] = "" + } + return newrecord + } + async function fetchModel() { const FETCH_MODEL_URL = `/api/models/${model}` const response = await _bb.api.get(FETCH_MODEL_URL) modelDef = await response.json() schema = modelDef.schema + record = createBlankRecord() } async function save() { @@ -81,9 +105,7 @@ el.checked = false } } - record = { - modelId: model, - } + record = createBlankRecord() } const setForm = rec => { @@ -123,7 +145,7 @@ isNew = !recordId || recordId === "new" if (isNew) { - record = { modelId: model } + record = createBlankRecord() } else { const GET_RECORD_URL = `/api/${model}/records/${recordId}` _bb.api diff --git a/packages/standard-components/src/DataFormWide.svelte b/packages/standard-components/src/DataFormWide.svelte index 3afae6f8d9..f15fabf9ea 100644 --- a/packages/standard-components/src/DataFormWide.svelte +++ b/packages/standard-components/src/DataFormWide.svelte @@ -32,11 +32,35 @@ $: Object.values(inputElements).length && setForm(record) + const createBlankRecord = () => { + if (!schema) return + const newrecord = { + modelId: model, + } + for (let fieldName in schema) { + const field = schema[fieldName] + // defaulting to first one, as a blank value will fail validation + if ( + field.type === "string" && + field.constraints && + field.constraints.inclusion && + field.constraints.inclusion.length > 0 + ) { + newrecord[fieldName] = field.constraints.inclusion[0] + } else if (field.type === "number") newrecord[fieldName] = null + else if (field.type === "boolean") newrecord[fieldName] = false + else if (field.type === "link") newrecord[fieldName] = [] + else newrecord[fieldName] = "" + } + return newrecord + } + async function fetchModel() { const FETCH_MODEL_URL = `/api/models/${model}` const response = await _bb.api.get(FETCH_MODEL_URL) modelDef = await response.json() schema = modelDef.schema + record = createBlankRecord() } async function save() { @@ -81,9 +105,7 @@ el.checked = false } } - record = { - modelId: model, - } + record = createBlankRecord() } const setForm = rec => { @@ -123,7 +145,7 @@ isNew = !recordId || recordId === "new" if (isNew) { - record = { modelId: model } + record = createBlankRecord() } else { const GET_RECORD_URL = `/api/${model}/records/${recordId}` _bb.api From fe5bfd843da553e2942e0cf75cea16171fb85ce3 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Tue, 28 Jul 2020 17:43:29 +0100 Subject: [PATCH 03/16] initial table sorting algo --- .../standard-components/src/DataMap.svelte | 31 ----------- .../standard-components/src/DataTable.svelte | 54 +++++++++++++++++-- packages/standard-components/src/index.js | 1 - 3 files changed, 50 insertions(+), 36 deletions(-) delete mode 100644 packages/standard-components/src/DataMap.svelte diff --git a/packages/standard-components/src/DataMap.svelte b/packages/standard-components/src/DataMap.svelte deleted file mode 100644 index 9cbb3c97c2..0000000000 --- a/packages/standard-components/src/DataMap.svelte +++ /dev/null @@ -1,31 +0,0 @@ - - - diff --git a/packages/standard-components/src/DataTable.svelte b/packages/standard-components/src/DataTable.svelte index 0d75b1e4e8..9c9c256bb2 100644 --- a/packages/standard-components/src/DataTable.svelte +++ b/packages/standard-components/src/DataTable.svelte @@ -12,6 +12,8 @@ let headers = [] let store = _bb.store + let sort = {} + let sorted = [] $: cssVariables = { backgroundColor, @@ -20,6 +22,31 @@ borderColor, } + $: data = $store[model] || [] + $: sorted = data + $: { + let result = [...sorted] + + if (!sort.column) sorted = result + + console.log(sort); + + if (sort.direction === "ASC") { + result.sort((a, b) => { + console.log(a[sort.column], b[sort.column]) + return String(a[sort.column]).localeCompare(String(b[sort.column])) + } + ) + } + + if (sort.direction === "DESC") { + result.reverse() + } + + sorted = result + } + $: if (model) fetchData() + const shouldDisplayField = name => { if (name.startsWith("_")) return false // always 'record' @@ -48,8 +75,20 @@ } } - $: data = $store[model] || [] - $: if (model) fetchData() + function sortColumn(column) { + if (column === sort.column) { + sort = { + direction: sort.direction === "ASC" ? "DESC" : null, + column: sort.direction === "ASC" ? sort.column : null, + } + return + } + + sort = { + column, + direction: "ASC", + } + } onMount(async () => { await fetchData() @@ -60,12 +99,15 @@ {#each headers as header} - {header} + sortColumn(header)}> + {header} + {#if sort.column === header}v{/if} + {/each} - {#each data as row} + {#each sorted as row (row._id)} {#each headers as header} {#if row[header]} @@ -120,6 +162,10 @@ display: block; } + th { + cursor: pointer; + } + /* Hide table headers (but not display: none;, for accessibility) */ thead tr { position: absolute; diff --git a/packages/standard-components/src/index.js b/packages/standard-components/src/index.js index a0c6ee025d..067b1e9896 100644 --- a/packages/standard-components/src/index.js +++ b/packages/standard-components/src/index.js @@ -21,6 +21,5 @@ export { default as datachart } from "./DataChart.svelte" export { default as datalist } from "./DataList.svelte" export { default as list } from "./List.svelte" export { default as datasearch } from "./DataSearch.svelte" -export { default as datamap } from "./DataMap.svelte" export { default as embed } from "./Embed.svelte" export { default as recorddetail } from "./RecordDetail.svelte" From 0219f34e71df8e207883925b07d6be356d48ddfb Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Tue, 28 Jul 2020 19:40:52 +0100 Subject: [PATCH 04/16] improved sorting logic --- packages/standard-components/package.json | 1 + .../standard-components/src/DataTable.svelte | 34 +++++-------------- 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/packages/standard-components/package.json b/packages/standard-components/package.json index 516a888a05..20a19aec74 100644 --- a/packages/standard-components/package.json +++ b/packages/standard-components/package.json @@ -38,6 +38,7 @@ "gitHead": "eff4fa93ca1db11b97b5fdedc0c488413e277eb8", "dependencies": { "@beyonk/svelte-googlemaps": "^2.2.0", + "fast-sort": "^2.2.0", "fusioncharts": "^3.15.1-sr.1", "svelte-fusioncharts": "^1.0.0" } diff --git a/packages/standard-components/src/DataTable.svelte b/packages/standard-components/src/DataTable.svelte index 9c9c256bb2..dc301598e8 100644 --- a/packages/standard-components/src/DataTable.svelte +++ b/packages/standard-components/src/DataTable.svelte @@ -1,6 +1,7 @@
+
- - - -

Create new web app

+

Get Started with Budibase

+
+
+ (name = e.target.value)} + on:input={e => (name = e.target.value)} /> +