diff --git a/packages/builder/src/components/backend/DataTable/buttons/grid/GridViewCalculationButton.svelte b/packages/builder/src/components/backend/DataTable/buttons/grid/GridViewCalculationButton.svelte
index 6bed99cac9..33931cdd3e 100644
--- a/packages/builder/src/components/backend/DataTable/buttons/grid/GridViewCalculationButton.svelte
+++ b/packages/builder/src/components/backend/DataTable/buttons/grid/GridViewCalculationButton.svelte
@@ -1,11 +1,26 @@
@@ -13,7 +28,12 @@
-
+
Show calculations which are based on
diff --git a/packages/builder/src/pages/builder/app/[application]/data/table/[tableId]/[viewId]/index.svelte b/packages/builder/src/pages/builder/app/[application]/data/table/[tableId]/[viewId]/index.svelte
index 715268d901..112722363a 100644
--- a/packages/builder/src/pages/builder/app/[application]/data/table/[tableId]/[viewId]/index.svelte
+++ b/packages/builder/src/pages/builder/app/[application]/data/table/[tableId]/[viewId]/index.svelte
@@ -17,6 +17,7 @@
let generateButton
$: view = $viewsV2.selected
+ $: calculation = view?.uiMetadata?.calculation
$: id = view?.id
$: datasource = {
type: "viewV2",
@@ -28,9 +29,6 @@
$: currentTheme = $themeStore?.theme
$: darkMode = !currentTheme.includes("light")
- $: currentTheme = $themeStore?.theme
- $: darkMode = !currentTheme.includes("light")
-
const makeRowActionButtons = actions => {
return (actions || []).map(action => ({
text: action.name,
@@ -58,14 +56,14 @@
buttonsCollapsed
>
- {#if view?.calculation}
+ {#if calculation}
{/if}
- {#if !view?.calculation}
+ {#if !calculation}
generateButton?.show()} />
diff --git a/packages/builder/src/pages/builder/app/[application]/data/table/[tableId]/_components/CreateViewButton.svelte b/packages/builder/src/pages/builder/app/[application]/data/table/[tableId]/_components/CreateViewButton.svelte
index 8f6eba3f0b..c420bb508e 100644
--- a/packages/builder/src/pages/builder/app/[application]/data/table/[tableId]/_components/CreateViewButton.svelte
+++ b/packages/builder/src/pages/builder/app/[application]/data/table/[tableId]/_components/CreateViewButton.svelte
@@ -38,9 +38,11 @@
const newView = await viewsV2.create({
name: trimmedName,
tableId: table._id,
- schema: calculation ? {} : enrichSchema(table.schema),
+ schema: enrichSchema(table.schema),
primaryDisplay: calculation ? undefined : table.primaryDisplay,
- calculation,
+ uiMetadata: {
+ calculation,
+ },
})
notifications.success(`View ${name} created`)
$goto(`./${newView.id}`)
diff --git a/packages/frontend-core/src/fetch/ViewV2Fetch.js b/packages/frontend-core/src/fetch/ViewV2Fetch.js
index 40135746df..191cb87b54 100644
--- a/packages/frontend-core/src/fetch/ViewV2Fetch.js
+++ b/packages/frontend-core/src/fetch/ViewV2Fetch.js
@@ -39,6 +39,18 @@ export default class ViewV2Fetch extends DataFetch {
this.options
const { cursor, query, definition } = get(this.store)
+ // If this is a calculation view and there are no schema fields then do nothing
+ console.log(definition)
+ if (
+ definition.calculation &&
+ !Object.keys(definition.schema || {}).length
+ ) {
+ return {
+ rows: [],
+ hasNextPage: false,
+ }
+ }
+
// If sort/filter params are not defined, update options to store the
// params built in to this view. This ensures that we can accurately
// compare old and new params and skip a redundant API call.
diff --git a/packages/server/src/api/controllers/view/viewsV2.ts b/packages/server/src/api/controllers/view/viewsV2.ts
index 70434ad4c5..1d19e2d19c 100644
--- a/packages/server/src/api/controllers/view/viewsV2.ts
+++ b/packages/server/src/api/controllers/view/viewsV2.ts
@@ -106,7 +106,7 @@ export async function create(ctx: Ctx) {
sort: view.sort,
schema,
primaryDisplay: view.primaryDisplay,
- calculation: view.calculation,
+ uiMetadata: view.uiMetadata,
}
const result = await sdk.views.create(tableId, parsedView)
ctx.status = 201
@@ -142,7 +142,7 @@ export async function update(ctx: Ctx) {
sort: view.sort,
schema,
primaryDisplay: view.primaryDisplay,
- calculation: view.calculation,
+ uiMetadata: view.uiMetadata,
}
const result = await sdk.views.update(tableId, parsedView)
diff --git a/packages/types/src/documents/app/view.ts b/packages/types/src/documents/app/view.ts
index 04ee6b01a1..9c558a8fb5 100644
--- a/packages/types/src/documents/app/view.ts
+++ b/packages/types/src/documents/app/view.ts
@@ -72,7 +72,7 @@ export interface ViewV2 {
type?: SortType
}
schema?: Record
- calculation?: boolean
+ uiMetadata?: Record
}
export type ViewSchema = ViewCountOrSumSchema | ViewStatisticsSchema