Make update forms work with view V2s
This commit is contained in:
parent
917e837ffc
commit
3ae5216fd5
|
@ -63,7 +63,18 @@
|
|||
// ancestor that matches our datasource. This is for backwards compatibility
|
||||
// as previously we could use the "closest" context.
|
||||
for (let id of path.reverse().slice(1)) {
|
||||
if (context[id]?.tableId === dataSource.tableId) {
|
||||
// Check for matching view datasource
|
||||
if (
|
||||
dataSource.type === "viewV2" &&
|
||||
context[id]?._viewId === dataSource.id
|
||||
) {
|
||||
return context[id]
|
||||
}
|
||||
// Check for matching table datasource
|
||||
if (
|
||||
dataSource.type === "table" &&
|
||||
context[id]?.tableId === dataSource.tableId
|
||||
) {
|
||||
return context[id]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,20 +80,21 @@ const saveRowHandler = async (action, context) => {
|
|||
}
|
||||
}
|
||||
if (tableId) {
|
||||
payload.tableId = tableId
|
||||
if (tableId.startsWith("view")) {
|
||||
payload._viewId = tableId
|
||||
} else {
|
||||
payload.tableId = tableId
|
||||
}
|
||||
}
|
||||
try {
|
||||
const row = await API.saveRow(payload)
|
||||
|
||||
if (!notificationOverride) {
|
||||
notificationStore.actions.success("Row saved")
|
||||
}
|
||||
|
||||
// Refresh related datasources
|
||||
await dataSourceStore.actions.invalidateDataSource(tableId, {
|
||||
invalidateRelationships: true,
|
||||
})
|
||||
|
||||
return { row }
|
||||
} catch (error) {
|
||||
// Abort next actions
|
||||
|
@ -112,7 +113,11 @@ const duplicateRowHandler = async (action, context) => {
|
|||
}
|
||||
}
|
||||
if (tableId) {
|
||||
payload.tableId = tableId
|
||||
if (tableId.startsWith("view")) {
|
||||
payload._viewId = tableId
|
||||
} else {
|
||||
payload.tableId = tableId
|
||||
}
|
||||
}
|
||||
delete payload._id
|
||||
delete payload._rev
|
||||
|
@ -121,12 +126,10 @@ const duplicateRowHandler = async (action, context) => {
|
|||
if (!notificationOverride) {
|
||||
notificationStore.actions.success("Row saved")
|
||||
}
|
||||
|
||||
// Refresh related datasources
|
||||
await dataSourceStore.actions.invalidateDataSource(tableId, {
|
||||
invalidateRelationships: true,
|
||||
})
|
||||
|
||||
return { row }
|
||||
} catch (error) {
|
||||
// Abort next actions
|
||||
|
|
|
@ -19,11 +19,12 @@ export const buildRowEndpoints = API => ({
|
|||
* @param suppressErrors whether or not to suppress error notifications
|
||||
*/
|
||||
saveRow: async (row, suppressErrors = false) => {
|
||||
if (!row?.tableId) {
|
||||
const resourceId = row?._viewId || row?.tableId
|
||||
if (!resourceId) {
|
||||
return
|
||||
}
|
||||
return await API.post({
|
||||
url: `/api/${row._viewId || row.tableId}/rows`,
|
||||
url: `/api/${resourceId}/rows`,
|
||||
body: row,
|
||||
suppressErrors,
|
||||
})
|
||||
|
@ -35,11 +36,12 @@ export const buildRowEndpoints = API => ({
|
|||
* @param suppressErrors whether or not to suppress error notifications
|
||||
*/
|
||||
patchRow: async (row, suppressErrors = false) => {
|
||||
if (!row?.tableId && !row?._viewId) {
|
||||
const resourceId = row?._viewId || row?.tableId
|
||||
if (!resourceId) {
|
||||
return
|
||||
}
|
||||
return await API.patch({
|
||||
url: `/api/${row._viewId || row.tableId}/rows`,
|
||||
url: `/api/${resourceId}/rows`,
|
||||
body: row,
|
||||
suppressErrors,
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue