diff --git a/packages/builder/src/components/backend/DataTable/ViewDataTable.svelte b/packages/builder/src/components/backend/DataTable/ViewDataTable.svelte index 9d00edf351..593030985d 100644 --- a/packages/builder/src/components/backend/DataTable/ViewDataTable.svelte +++ b/packages/builder/src/components/backend/DataTable/ViewDataTable.svelte @@ -23,7 +23,6 @@ const params = new URLSearchParams() if (calculation) { params.set("field", field) - // todo, maybe won't work params.set("calculation", calculation) } if (groupBy) { @@ -38,6 +37,8 @@
of
- + {#if view.calculation} +of
+ + {/if} diff --git a/packages/builder/src/components/settings/tabs/Users.svelte b/packages/builder/src/components/settings/tabs/Users.svelte index adaede6e23..3d4a44fc73 100644 --- a/packages/builder/src/components/settings/tabs/Users.svelte +++ b/packages/builder/src/components/settings/tabs/Users.svelte @@ -74,7 +74,7 @@ {#await fetchUsersPromise} Loading... - {:then [object Object]} + {:then users}Something went wrong: {error.message}
{/await} diff --git a/packages/server/src/api/controllers/row.js b/packages/server/src/api/controllers/row.js index a9ce510457..3f5d56e507 100644 --- a/packages/server/src/api/controllers/row.js +++ b/packages/server/src/api/controllers/row.js @@ -11,6 +11,12 @@ const { cloneDeep } = require("lodash") const TABLE_VIEW_BEGINS_WITH = `all${SEPARATOR}${DocumentTypes.TABLE}${SEPARATOR}` +const CALCULATION_TYPES = { + SUM: "sum", + COUNT: "count", + STATS: "stats" +} + validateJs.extend(validateJs.validators.datetime, { parse: function(value) { return new Date(value).getTime() @@ -152,13 +158,12 @@ exports.fetchView = async function(ctx) { group, }) - // TODO: create constants for calculation types if (!calculation) { response.rows = response.rows.map(row => row.doc) ctx.body = await linkRows.attachLinkInfo(instanceId, response.rows) } - if (calculation === "stats") { + if (calculation === CALCULATION_TYPES.STATS) { response.rows = response.rows.map(row => ({ group: row.key, field, @@ -168,13 +173,15 @@ exports.fetchView = async function(ctx) { ctx.body = response.rows } - if (calculation === "count" || calculation === "sum") { - ctx.body = field - ? response.rows.map(row => ({ - field, - value: row.value, - })) - : [{ field: "All Rows", value: response.total_rows }] + if ( + calculation === CALCULATION_TYPES.COUNT || + calculation === CALCULATION_TYPES.SUM + ) { + ctx.body = response.rows.map(row => ({ + group: row.key, + field, + value: row.value, + })) } } diff --git a/packages/server/src/api/controllers/view/viewBuilder.js b/packages/server/src/api/controllers/view/viewBuilder.js index 082db8bebf..550480d52c 100644 --- a/packages/server/src/api/controllers/view/viewBuilder.js +++ b/packages/server/src/api/controllers/view/viewBuilder.js @@ -89,8 +89,7 @@ function parseFilterExpression(filters) { * @param {String?} groupBy - field to group calculation results on, if any */ function parseEmitExpression(field, groupBy) { - if (field) return `emit(doc["${groupBy || "_id"}"], doc["${field}"]);` - return `emit(doc._id, 1);` + return `emit(doc["${groupBy || "_id"}"], doc["${field}"]);` } /** diff --git a/packages/standard-components/src/Test/TestApp.svelte b/packages/standard-components/src/Test/TestApp.svelte index 1ad2cc484e..0c6da55601 100644 --- a/packages/standard-components/src/Test/TestApp.svelte +++ b/packages/standard-components/src/Test/TestApp.svelte @@ -35,7 +35,7 @@ {#await _appPromise} loading -{:then [object Object]} +{:then _} {/await}