2024-08-21 17:33:51 +02:00
|
|
|
export const buildRowActionEndpoints = API => ({
|
|
|
|
/**
|
|
|
|
* Gets the available row actions for a table.
|
|
|
|
* @param tableId the ID of the table
|
|
|
|
*/
|
|
|
|
fetch: async tableId => {
|
|
|
|
const res = await API.get({
|
|
|
|
url: `/api/tables/${tableId}/actions`,
|
|
|
|
})
|
|
|
|
return res?.actions || {}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a row action.
|
|
|
|
* @param name the name of the row action
|
|
|
|
* @param tableId the ID of the table
|
|
|
|
*/
|
|
|
|
create: async ({ name, tableId }) => {
|
|
|
|
return await API.post({
|
|
|
|
url: `/api/tables/${tableId}/actions`,
|
|
|
|
body: {
|
|
|
|
name,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates a row action.
|
|
|
|
* @param name the new name of the row action
|
|
|
|
* @param tableId the ID of the table
|
|
|
|
* @param rowActionId the ID of the row action to update
|
|
|
|
*/
|
|
|
|
update: async ({ tableId, rowActionId, name }) => {
|
2024-09-03 16:05:13 +02:00
|
|
|
return await API.put({
|
2024-08-21 17:33:51 +02:00
|
|
|
url: `/api/tables/${tableId}/actions/${rowActionId}`,
|
|
|
|
body: {
|
|
|
|
name,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes a row action.
|
|
|
|
* @param tableId the ID of the table
|
|
|
|
* @param rowActionId the ID of the row action to delete
|
|
|
|
*/
|
|
|
|
delete: async ({ tableId, rowActionId }) => {
|
|
|
|
return await API.delete({
|
|
|
|
url: `/api/tables/${tableId}/actions/${rowActionId}`,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2024-09-03 11:09:07 +02:00
|
|
|
/**
|
|
|
|
* Enables a row action for a certain view
|
|
|
|
* @param tableId the ID of the parent table
|
|
|
|
* @param rowActionId the ID of the row action
|
|
|
|
* @param viewId the ID of the view
|
|
|
|
*/
|
|
|
|
enableView: async ({ tableId, rowActionId, viewId }) => {
|
|
|
|
return await API.post({
|
|
|
|
url: `/api/tables/${tableId}/actions/${rowActionId}/permissions/${viewId}`,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Disables a row action for a certain view
|
|
|
|
* @param tableId the ID of the parent table
|
|
|
|
* @param rowActionId the ID of the row action
|
|
|
|
* @param viewId the ID of the view
|
|
|
|
*/
|
|
|
|
disableView: async ({ tableId, rowActionId, viewId }) => {
|
|
|
|
return await API.delete({
|
|
|
|
url: `/api/tables/${tableId}/actions/${rowActionId}/permissions/${viewId}`,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2024-08-21 17:33:51 +02:00
|
|
|
/**
|
|
|
|
* Triggers a row action.
|
|
|
|
* @param tableId the ID of the table
|
|
|
|
* @param rowActionId the ID of the row action to trigger
|
|
|
|
*/
|
2024-09-03 11:09:07 +02:00
|
|
|
trigger: async ({ sourceId, rowActionId, rowId }) => {
|
2024-08-21 17:33:51 +02:00
|
|
|
return await API.post({
|
2024-09-03 11:09:07 +02:00
|
|
|
url: `/api/tables/${sourceId}/actions/${rowActionId}/trigger`,
|
2024-09-02 09:45:49 +02:00
|
|
|
body: {
|
|
|
|
rowId,
|
|
|
|
},
|
2024-08-21 17:33:51 +02:00
|
|
|
})
|
|
|
|
},
|
|
|
|
})
|