diff --git a/packages/server/src/api/controllers/row/index.ts b/packages/server/src/api/controllers/row/index.ts index 0f0d99f1c3..9292dd4cf3 100644 --- a/packages/server/src/api/controllers/row/index.ts +++ b/packages/server/src/api/controllers/row/index.ts @@ -71,8 +71,9 @@ export async function patch( } export const save = async (ctx: UserCtx) => { - const appId = ctx.appId const { tableId } = utils.getSourceId(ctx) + const { sourceId } = ctx.params + const appId = ctx.appId const body = ctx.request.body // user metadata doesn't exist yet - don't allow creation @@ -85,9 +86,9 @@ export const save = async (ctx: UserCtx) => { return patch(ctx as UserCtx) } const { row, table, squashed } = tableId.includes("datasource_plus") - ? await sdk.rows.save(tableId, ctx.request.body, ctx.user?._id) + ? await sdk.rows.save(sourceId, ctx.request.body, ctx.user?._id) : await quotas.addRow(() => - sdk.rows.save(tableId, ctx.request.body, ctx.user?._id) + sdk.rows.save(sourceId, ctx.request.body, ctx.user?._id) ) ctx.status = 200 ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:save`, appId, row, table) diff --git a/packages/server/src/api/controllers/row/staticFormula.ts b/packages/server/src/api/controllers/row/staticFormula.ts index 2e913c2b96..777379db14 100644 --- a/packages/server/src/api/controllers/row/staticFormula.ts +++ b/packages/server/src/api/controllers/row/staticFormula.ts @@ -123,7 +123,11 @@ export async function updateAllFormulasInTable(table: Table) { export async function finaliseRow( table: Table, row: Row, - { oldTable, updateFormula }: { oldTable?: Table; updateFormula: boolean } = { + { + oldTable, + updateFormula, + fromViewId, + }: { oldTable?: Table; updateFormula: boolean; fromViewId?: string } = { updateFormula: true, } ) { @@ -154,6 +158,8 @@ export async function finaliseRow( if (updateFormula) { await updateRelatedFormula(table, enrichedRow) } - const squashed = await linkRows.squashLinks(table, enrichedRow) + const squashed = await linkRows.squashLinks(table, enrichedRow, { + fromViewId, + }) return { row: enrichedRow, squashed, table } } diff --git a/packages/server/src/api/routes/tests/row.spec.ts b/packages/server/src/api/routes/tests/row.spec.ts index 129e1e25d2..86b7f5deb3 100644 --- a/packages/server/src/api/routes/tests/row.spec.ts +++ b/packages/server/src/api/routes/tests/row.spec.ts @@ -2618,7 +2618,7 @@ describe.each([ return rows.find(r => r._id === row._id!) }, ], - // ["from original saved row", (row: Row) => row], + ["from original saved row", (row: Row) => row], ] it.each(testScenarios)( diff --git a/packages/server/src/sdk/app/rows/external.ts b/packages/server/src/sdk/app/rows/external.ts index 770284d55a..7630e5638b 100644 --- a/packages/server/src/sdk/app/rows/external.ts +++ b/packages/server/src/sdk/app/rows/external.ts @@ -27,10 +27,11 @@ export async function getRow( } export async function save( - tableId: string, + tableOrViewId: string, inputs: Row, userId: string | undefined ) { + const { tableId, viewId } = tryExtractingTableAndViewId(tableOrViewId) const table = await sdk.tables.getTable(tableId) const { table: updatedTable, row } = await inputProcessing( userId, @@ -64,6 +65,7 @@ export async function save( row: await outputProcessing(table, row, { preserveLinks: true, squash: true, + fromViewId: viewId, }), } } else { diff --git a/packages/server/src/sdk/app/rows/internal.ts b/packages/server/src/sdk/app/rows/internal.ts index 2285ae6ed6..b5b3437e5e 100644 --- a/packages/server/src/sdk/app/rows/internal.ts +++ b/packages/server/src/sdk/app/rows/internal.ts @@ -13,10 +13,11 @@ import { getFullUser } from "../../../utilities/users" import { tryExtractingTableAndViewId } from "./utils" export async function save( - tableId: string, + tableOrViewId: string, inputs: Row, userId: string | undefined ) { + const { tableId, viewId } = tryExtractingTableAndViewId(tableOrViewId) inputs.tableId = tableId if (!inputs._rev && !inputs._id) { @@ -51,6 +52,7 @@ export async function save( return finaliseRow(table, row, { oldTable: dbTable, updateFormula: true, + fromViewId: viewId, }) } diff --git a/packages/server/src/sdk/app/rows/rows.ts b/packages/server/src/sdk/app/rows/rows.ts index 0bf9120f73..c61b8692ed 100644 --- a/packages/server/src/sdk/app/rows/rows.ts +++ b/packages/server/src/sdk/app/rows/rows.ts @@ -37,11 +37,11 @@ function pickApi(tableOrViewId: string) { } export async function save( - tableId: string, + tableOrViewId: string, row: Row, userId: string | undefined ) { - return pickApi(tableId).save(tableId, row, userId) + return pickApi(tableOrViewId).save(tableOrViewId, row, userId) } export async function find(tableOrViewId: string, rowId: string) {