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