From 215e35961504c22d56d5f4238e6dd18173690d2c Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 4 Oct 2024 09:29:41 +0100 Subject: [PATCH 01/48] Add uiMetadata to viewV2 --- packages/server/src/api/controllers/view/viewsV2.ts | 2 ++ packages/types/src/documents/app/view.ts | 1 + 2 files changed, 3 insertions(+) diff --git a/packages/server/src/api/controllers/view/viewsV2.ts b/packages/server/src/api/controllers/view/viewsV2.ts index 0257c86ded..22a9b85c3e 100644 --- a/packages/server/src/api/controllers/view/viewsV2.ts +++ b/packages/server/src/api/controllers/view/viewsV2.ts @@ -107,6 +107,7 @@ export async function create(ctx: Ctx) { sort: view.sort, schema, primaryDisplay: view.primaryDisplay, + uiMetadata: view.uiMetadata, } const result = await sdk.views.create(tableId, parsedView) ctx.status = 201 @@ -143,6 +144,7 @@ export async function update(ctx: Ctx) { sort: view.sort, schema, primaryDisplay: view.primaryDisplay, + 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 77bbb3e4d1..f836e18f24 100644 --- a/packages/types/src/documents/app/view.ts +++ b/packages/types/src/documents/app/view.ts @@ -74,6 +74,7 @@ export interface ViewV2 { type?: SortType } schema?: ViewV2Schema + uiMetadata?: Record } export type ViewV2Schema = Record From a563adc2c07e721a96a2c52571decf89e29ba5d3 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 4 Oct 2024 09:43:23 +0100 Subject: [PATCH 02/48] Update tests --- packages/server/src/api/routes/tests/viewV2.spec.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/server/src/api/routes/tests/viewV2.spec.ts b/packages/server/src/api/routes/tests/viewV2.spec.ts index 83b26bc687..7bfa52e0b4 100644 --- a/packages/server/src/api/routes/tests/viewV2.spec.ts +++ b/packages/server/src/api/routes/tests/viewV2.spec.ts @@ -177,6 +177,9 @@ describe.each([ visible: true, }, }, + uiMetadata: { + foo: "bar", + }, } const res = await config.api.viewV2.create(newView) @@ -640,6 +643,9 @@ describe.each([ readonly: true, }, }, + uiMetadata: { + foo: "bar", + }, } await config.api.viewV2.update(updatedData) From 27508d934dc7df489638c686317a894877b1a407 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Fri, 4 Oct 2024 10:45:03 +0100 Subject: [PATCH 03/48] Validate that you cannot create a calculation view with more than 5 calculation fields. --- .../src/api/routes/tests/viewV2.spec.ts | 47 +++++++++++++++++++ packages/server/src/sdk/app/views/index.ts | 8 ++++ 2 files changed, 55 insertions(+) diff --git a/packages/server/src/api/routes/tests/viewV2.spec.ts b/packages/server/src/api/routes/tests/viewV2.spec.ts index a1a4475ee5..7ad1be4c1f 100644 --- a/packages/server/src/api/routes/tests/viewV2.spec.ts +++ b/packages/server/src/api/routes/tests/viewV2.spec.ts @@ -568,6 +568,53 @@ describe.each([ expect(sum.calculationType).toEqual(CalculationType.SUM) expect(sum.field).toEqual("Price") }) + + it("cannot create a calculation view with more than 5 aggregations", async () => { + await config.api.viewV2.create( + { + tableId: table._id!, + name: generator.guid(), + schema: { + sum: { + visible: true, + calculationType: CalculationType.SUM, + field: "Price", + }, + count: { + visible: true, + calculationType: CalculationType.COUNT, + field: "Price", + }, + min: { + visible: true, + calculationType: CalculationType.MIN, + field: "Price", + }, + max: { + visible: true, + calculationType: CalculationType.MAX, + field: "Price", + }, + avg: { + visible: true, + calculationType: CalculationType.AVG, + field: "Price", + }, + sum2: { + visible: true, + calculationType: CalculationType.SUM, + field: "Price", + }, + }, + }, + { + status: 400, + body: { + message: "Calculation views can only have a maximum of 5 fields", + }, + } + ) + }) }) describe("update", () => { diff --git a/packages/server/src/sdk/app/views/index.ts b/packages/server/src/sdk/app/views/index.ts index 73785edd98..be7259b057 100644 --- a/packages/server/src/sdk/app/views/index.ts +++ b/packages/server/src/sdk/app/views/index.ts @@ -64,6 +64,14 @@ async function guardCalculationViewSchema( view: Omit ) { const calculationFields = helpers.views.calculationFields(view) + + if (Object.keys(calculationFields).length > 5) { + throw new HTTPError( + "Calculation views can only have a maximum of 5 fields", + 400 + ) + } + for (const calculationFieldName of Object.keys(calculationFields)) { const schema = calculationFields[calculationFieldName] const isCount = schema.calculationType === CalculationType.COUNT From 696b2c38db48100506edff971a8aa24545b67fdd Mon Sep 17 00:00:00 2001 From: andz-bb Date: Fri, 4 Oct 2024 10:54:14 +0100 Subject: [PATCH 04/48] persist app sort method selection by saving it against the user --- .../pages/builder/portal/apps/index.svelte | 3 +- packages/builder/src/stores/portal/apps.js | 89 +++++++++++-------- packages/builder/src/stores/portal/index.js | 2 +- packages/types/src/api/web/auth.ts | 1 + packages/types/src/documents/global/user.ts | 1 + .../worker/src/api/routes/validation/users.ts | 1 + 6 files changed, 58 insertions(+), 39 deletions(-) diff --git a/packages/builder/src/pages/builder/portal/apps/index.svelte b/packages/builder/src/pages/builder/portal/apps/index.svelte index 9a073d041f..ddd37dc4a3 100644 --- a/packages/builder/src/pages/builder/portal/apps/index.svelte +++ b/packages/builder/src/pages/builder/portal/apps/index.svelte @@ -26,6 +26,7 @@ licensing, environment, enrichedApps, + sortBy, } from "stores/portal" import { goto } from "@roxi/routify" import AppRow from "components/start/AppRow.svelte" @@ -247,7 +248,7 @@