Type row action endpoints
This commit is contained in:
parent
9926e8d15c
commit
ea84af782d
|
@ -39,9 +39,9 @@
|
|||
|
||||
const toggleAction = async (action, enabled) => {
|
||||
if (enabled) {
|
||||
await rowActions.enableView(tableId, viewId, action.id)
|
||||
await rowActions.enableView(tableId, action.id, viewId)
|
||||
} else {
|
||||
await rowActions.disableView(tableId, viewId, action.id)
|
||||
await rowActions.disableView(tableId, action.id, viewId)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -55,15 +55,12 @@ export class RowActionStore extends BudiStore {
|
|||
}
|
||||
|
||||
// Create the action
|
||||
const res = await API.rowActions.create({
|
||||
name,
|
||||
tableId,
|
||||
})
|
||||
const res = await API.rowActions.create(tableId, name)
|
||||
|
||||
// Enable action on this view if adding via a view
|
||||
if (viewId) {
|
||||
await Promise.all([
|
||||
this.enableView(tableId, viewId, res.id),
|
||||
this.enableView(tableId, res.id, viewId),
|
||||
automationStore.actions.fetch(),
|
||||
])
|
||||
} else {
|
||||
|
@ -76,21 +73,13 @@ export class RowActionStore extends BudiStore {
|
|||
return res
|
||||
}
|
||||
|
||||
enableView = async (tableId, viewId, rowActionId) => {
|
||||
await API.rowActions.enableView({
|
||||
tableId,
|
||||
viewId,
|
||||
rowActionId,
|
||||
})
|
||||
enableView = async (tableId, rowActionId, viewId) => {
|
||||
await API.rowActions.enableView(tableId, rowActionId, viewId)
|
||||
await this.refreshRowActions(tableId)
|
||||
}
|
||||
|
||||
disableView = async (tableId, viewId, rowActionId) => {
|
||||
await API.rowActions.disableView({
|
||||
tableId,
|
||||
viewId,
|
||||
rowActionId,
|
||||
})
|
||||
disableView = async (tableId, rowActionId, viewId) => {
|
||||
await API.rowActions.disableView(tableId, rowActionId, viewId)
|
||||
await this.refreshRowActions(tableId)
|
||||
}
|
||||
|
||||
|
@ -105,21 +94,14 @@ export class RowActionStore extends BudiStore {
|
|||
}
|
||||
|
||||
delete = async (tableId, rowActionId) => {
|
||||
await API.rowActions.delete({
|
||||
tableId,
|
||||
rowActionId,
|
||||
})
|
||||
await API.rowActions.delete(tableId, rowActionId)
|
||||
await this.refreshRowActions(tableId)
|
||||
// We don't need to refresh automations as we can only delete row actions
|
||||
// from the automations store, so we already handle the state update there
|
||||
}
|
||||
|
||||
trigger = async (sourceId, rowActionId, rowId) => {
|
||||
await API.rowActions.trigger({
|
||||
sourceId,
|
||||
rowActionId,
|
||||
rowId,
|
||||
})
|
||||
await API.rowActions.trigger(sourceId, rowActionId, rowId)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -487,11 +487,7 @@ const downloadFileHandler = async action => {
|
|||
|
||||
const rowActionHandler = async action => {
|
||||
const { resourceId, rowId, rowActionId } = action.parameters
|
||||
await API.rowActions.trigger({
|
||||
rowActionId,
|
||||
sourceId: resourceId,
|
||||
rowId,
|
||||
})
|
||||
await API.rowActions.trigger(resourceId, rowActionId, rowId)
|
||||
// Refresh related datasources
|
||||
await dataSourceStore.actions.invalidateDataSource(resourceId, {
|
||||
invalidateRelationships: true,
|
||||
|
|
|
@ -1,13 +1,46 @@
|
|||
export const buildRowActionEndpoints = API => ({
|
||||
import {
|
||||
RowActionsResponse,
|
||||
RowActionResponse,
|
||||
CreateRowActionRequest,
|
||||
RowActionPermissionsResponse,
|
||||
RowActionTriggerRequest,
|
||||
} from "@budibase/types"
|
||||
import { BaseAPIClient } from "./types"
|
||||
|
||||
export interface RowActionEndpoints {
|
||||
fetch: (tableId: string) => Promise<Record<string, RowActionResponse>>
|
||||
create: (tableId: string, name: string) => Promise<RowActionResponse>
|
||||
delete: (tableId: string, rowActionId: string) => Promise<void>
|
||||
enableView: (
|
||||
tableId: string,
|
||||
rowActionId: string,
|
||||
viewId: string
|
||||
) => Promise<RowActionPermissionsResponse>
|
||||
disableView: (
|
||||
tableId: string,
|
||||
rowActionId: string,
|
||||
viewId: string
|
||||
) => Promise<RowActionPermissionsResponse>
|
||||
trigger: (
|
||||
sourceId: string,
|
||||
rowActionId: string,
|
||||
rowId: string
|
||||
) => Promise<void>
|
||||
}
|
||||
|
||||
export const buildRowActionEndpoints = (
|
||||
API: BaseAPIClient
|
||||
): RowActionEndpoints => ({
|
||||
/**
|
||||
* 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 || {}
|
||||
return (
|
||||
await API.get<RowActionsResponse>({
|
||||
url: `/api/tables/${tableId}/actions`,
|
||||
})
|
||||
).actions
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -15,8 +48,8 @@ export const buildRowActionEndpoints = API => ({
|
|||
* @param name the name of the row action
|
||||
* @param tableId the ID of the table
|
||||
*/
|
||||
create: async ({ name, tableId }) => {
|
||||
return await API.post({
|
||||
create: async (tableId, name) => {
|
||||
return await API.post<CreateRowActionRequest, RowActionResponse>({
|
||||
url: `/api/tables/${tableId}/actions`,
|
||||
body: {
|
||||
name,
|
||||
|
@ -24,27 +57,12 @@ export const buildRowActionEndpoints = API => ({
|
|||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 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 }) => {
|
||||
return await API.put({
|
||||
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 }) => {
|
||||
delete: async (tableId, rowActionId) => {
|
||||
return await API.delete({
|
||||
url: `/api/tables/${tableId}/actions/${rowActionId}`,
|
||||
})
|
||||
|
@ -56,7 +74,7 @@ export const buildRowActionEndpoints = API => ({
|
|||
* @param rowActionId the ID of the row action
|
||||
* @param viewId the ID of the view
|
||||
*/
|
||||
enableView: async ({ tableId, rowActionId, viewId }) => {
|
||||
enableView: async (tableId, rowActionId, viewId) => {
|
||||
return await API.post({
|
||||
url: `/api/tables/${tableId}/actions/${rowActionId}/permissions/${viewId}`,
|
||||
})
|
||||
|
@ -68,7 +86,7 @@ export const buildRowActionEndpoints = API => ({
|
|||
* @param rowActionId the ID of the row action
|
||||
* @param viewId the ID of the view
|
||||
*/
|
||||
disableView: async ({ tableId, rowActionId, viewId }) => {
|
||||
disableView: async (tableId, rowActionId, viewId) => {
|
||||
return await API.delete({
|
||||
url: `/api/tables/${tableId}/actions/${rowActionId}/permissions/${viewId}`,
|
||||
})
|
||||
|
@ -79,8 +97,8 @@ export const buildRowActionEndpoints = API => ({
|
|||
* @param tableId the ID of the table
|
||||
* @param rowActionId the ID of the row action to trigger
|
||||
*/
|
||||
trigger: async ({ sourceId, rowActionId, rowId }) => {
|
||||
return await API.post({
|
||||
trigger: async (sourceId, rowActionId, rowId) => {
|
||||
return await API.post<RowActionTriggerRequest>({
|
||||
url: `/api/tables/${sourceId}/actions/${rowActionId}/trigger`,
|
||||
body: {
|
||||
rowId,
|
|
@ -23,6 +23,7 @@ import { QueryEndpoints } from "./queries"
|
|||
import { RelationshipEndpoints } from "./relationships"
|
||||
import { RoleEndpoints } from "./roles"
|
||||
import { RouteEndpoints } from "./routes"
|
||||
import { RowActionEndpoints } from "./rowActions"
|
||||
|
||||
export enum HTTPMethod {
|
||||
POST = "POST",
|
||||
|
@ -117,4 +118,4 @@ export type APIClient = BaseAPIClient &
|
|||
QueryEndpoints &
|
||||
RelationshipEndpoints &
|
||||
RoleEndpoints &
|
||||
RouteEndpoints & { [key: string]: any }
|
||||
RouteEndpoints & { rowActions: RowActionEndpoints; [key: string]: any }
|
||||
|
|
Loading…
Reference in New Issue