Handle view creation on new table requests
This commit is contained in:
parent
f1a75b84b4
commit
2c26b55a7c
|
@ -75,9 +75,10 @@ export async function save(ctx: UserCtx<SaveTableRequest, SaveTableResponse>) {
|
|||
const table = ctx.request.body
|
||||
const isImport = table.rows
|
||||
|
||||
const savedTable = await pickApi({ table }).save(ctx)
|
||||
let savedTable = await pickApi({ table }).save(ctx)
|
||||
if (!table._id) {
|
||||
await events.table.created(savedTable)
|
||||
savedTable = sdk.tables.enrichViewSchemas(savedTable)
|
||||
} else {
|
||||
await events.table.updated(savedTable)
|
||||
}
|
||||
|
|
|
@ -18,10 +18,11 @@ export async function save(ctx: UserCtx<SaveTableRequest, SaveTableResponse>) {
|
|||
_rename?: RenameColumn
|
||||
} = {
|
||||
_id: generateTableID(),
|
||||
...rest,
|
||||
type: "table",
|
||||
sourceType: TableSourceType.INTERNAL,
|
||||
views: {},
|
||||
...rest,
|
||||
// Ensure these fields are populated, even if not sent in the request
|
||||
type: rest.type || "table",
|
||||
sourceType: rest.sourceType || TableSourceType.INTERNAL,
|
||||
}
|
||||
const renaming = tableToSave._rename
|
||||
delete tableToSave._rename
|
||||
|
|
|
@ -5,6 +5,7 @@ import {
|
|||
FieldType,
|
||||
INTERNAL_TABLE_SOURCE_ID,
|
||||
InternalTable,
|
||||
NumberFieldMetadata,
|
||||
RelationshipType,
|
||||
Row,
|
||||
SaveTableRequest,
|
||||
|
@ -83,7 +84,7 @@ describe("/tables", () => {
|
|||
},
|
||||
},
|
||||
views: {
|
||||
view1: {
|
||||
"table view": {
|
||||
id: "viewId",
|
||||
version: 2,
|
||||
name: "table view",
|
||||
|
@ -96,9 +97,29 @@ describe("/tables", () => {
|
|||
const expected: Table = {
|
||||
...tableData,
|
||||
type: "table",
|
||||
views: {
|
||||
"table view": {
|
||||
...tableData.views!["table view"],
|
||||
schema: {
|
||||
autoId: {
|
||||
autocolumn: true,
|
||||
constraints: {
|
||||
presence: false,
|
||||
type: "number",
|
||||
},
|
||||
name: "id",
|
||||
type: FieldType.NUMBER,
|
||||
subtype: AutoFieldSubType.AUTO_ID,
|
||||
visible: false,
|
||||
} as NumberFieldMetadata,
|
||||
},
|
||||
},
|
||||
},
|
||||
sourceType: TableSourceType.INTERNAL,
|
||||
sourceId: expect.any(String),
|
||||
_rev: expect.stringMatching(/^1-.+/),
|
||||
_id: expect.any(String),
|
||||
createdAt: mocks.date.MOCK_DATE.toISOString(),
|
||||
updatedAt: mocks.date.MOCK_DATE.toISOString(),
|
||||
}
|
||||
expect(testTable).toEqual(expected)
|
||||
|
|
|
@ -75,11 +75,13 @@ export async function save(
|
|||
if (!tableView) continue
|
||||
|
||||
if (viewsSdk.isV2(tableView)) {
|
||||
if (oldTable?.views && oldTable.views[view]) {
|
||||
table.views[view] = viewsSdk.syncSchema(
|
||||
oldTable!.views![view] as ViewV2,
|
||||
oldTable.views[view] as ViewV2,
|
||||
table.schema,
|
||||
renaming
|
||||
)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue