Type layout endpoints

This commit is contained in:
Andrew Kingston 2024-12-02 16:06:12 +00:00
parent d36122b7bd
commit b2b2648798
No known key found for this signature in database
4 changed files with 35 additions and 28 deletions

View File

@ -59,10 +59,7 @@ export class LayoutStore extends BudiStore {
if (!layout?._id) {
return
}
await API.deleteLayout({
layoutId: layout._id,
layoutRev: layout._rev,
})
await API.deleteLayout(layout._id, layout._rev)
this.update(state => {
state.layouts = state.layouts.filter(x => x._id !== layout._id)
return state

View File

@ -1,23 +0,0 @@
export const buildLayoutEndpoints = API => ({
/**
* Saves a layout.
* @param layout the layout to save
*/
saveLayout: async layout => {
return await API.post({
url: "/api/layouts",
body: layout,
})
},
/**
* Deletes a layout.
* @param layoutId the ID of the layout to delete
* @param layoutRev the rev of the layout to delete
*/
deleteLayout: async ({ layoutId, layoutRev }) => {
return await API.delete({
url: `/api/layouts/${layoutId}/${layoutRev}`,
})
},
})

View File

@ -0,0 +1,31 @@
import { Layout, SaveLayoutRequest, SaveLayoutResponse } from "@budibase/types"
import { BaseAPIClient } from "./types"
export interface LayoutEndpoints {
saveLayout: (layout: Layout) => Promise<SaveLayoutResponse>
deleteLayout: (id: string, rev: string) => Promise<{ message: string }>
}
export const buildLayoutEndpoints = (API: BaseAPIClient): LayoutEndpoints => ({
/**
* Saves a layout.
* @param layout the layout to save
*/
saveLayout: async layout => {
return await API.post<SaveLayoutRequest, SaveLayoutResponse>({
url: "/api/layouts",
body: layout,
})
},
/**
* Deletes a layout.
* @param layoutId the ID of the layout to delete
* @param layoutRev the rev of the layout to delete
*/
deleteLayout: async (id: string, rev: string) => {
return await API.delete({
url: `/api/layouts/${id}/${rev}`,
})
},
})

View File

@ -12,6 +12,7 @@ import { EnvironmentVariableEndpoints } from "./environmentVariables"
import { EventEndpoints } from "./events"
import { FlagEndpoints } from "./flags"
import { GroupEndpoints } from "./groups"
import { LayoutEndpoints } from "./layouts"
export enum HTTPMethod {
POST = "POST",
@ -85,4 +86,5 @@ export type APIClient = BaseAPIClient &
EnvironmentVariableEndpoints &
EventEndpoints &
FlagEndpoints &
GroupEndpoints
GroupEndpoints &
LayoutEndpoints