From a701933f48ad5f4f141cd85d18f9f86938cbe410 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Mon, 23 Oct 2023 17:57:25 +0100 Subject: [PATCH] Frontend changes for the user column migration work. --- packages/frontend-core/src/api/tables.js | 9 +++++++ .../components/grid/cells/HeaderCell.svelte | 24 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/packages/frontend-core/src/api/tables.js b/packages/frontend-core/src/api/tables.js index a08e35d3d8..34d2371e1a 100644 --- a/packages/frontend-core/src/api/tables.js +++ b/packages/frontend-core/src/api/tables.js @@ -140,4 +140,13 @@ export const buildTableEndpoints = API => ({ }, }) }, + migrateColumn: async ({ tableId, oldColumn, newColumn }) => { + return await API.post({ + url: `/api/tables/${tableId}/migrate`, + body: { + oldColumn, + newColumn, + }, + }) + }, }) diff --git a/packages/frontend-core/src/components/grid/cells/HeaderCell.svelte b/packages/frontend-core/src/components/grid/cells/HeaderCell.svelte index d6cbcb582d..01c759a15c 100644 --- a/packages/frontend-core/src/components/grid/cells/HeaderCell.svelte +++ b/packages/frontend-core/src/components/grid/cells/HeaderCell.svelte @@ -10,6 +10,7 @@ export let orderable = true const { + API, reorder, isReordering, isResizing, @@ -114,6 +115,24 @@ open = false } + const migrateUserColumn = async () => { + let subtype = "users" + if (column.schema.relationshipType === "one-to-many") { + subtype = "user" + } + + await API.migrateColumn({ + tableId: $definition._id, + oldColumn: column.schema, + newColumn: { + name: `${column.schema.name} migrated`, + type: "bb_reference", + subtype, + }, + }) + open = false + } + const duplicateColumn = async () => { open = false @@ -262,6 +281,11 @@ > Hide column + {#if column.schema.type === "link" && column.schema.tableId === "ta_users"} + + Migrate to user column + + {/if} {/if}