From 9b16849fe6bf0b534f9d8c3311f28887529b590e Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 3 Dec 2024 11:53:07 +0000 Subject: [PATCH] Type screen endpoints --- .../builder/src/stores/builder/screens.js | 7 +---- packages/frontend-core/src/api/screens.js | 23 -------------- packages/frontend-core/src/api/screens.ts | 31 +++++++++++++++++++ packages/frontend-core/src/api/types.ts | 4 ++- 4 files changed, 35 insertions(+), 30 deletions(-) delete mode 100644 packages/frontend-core/src/api/screens.js create mode 100644 packages/frontend-core/src/api/screens.ts diff --git a/packages/builder/src/stores/builder/screens.js b/packages/builder/src/stores/builder/screens.js index 10c4265e73..55fa3d5433 100644 --- a/packages/builder/src/stores/builder/screens.js +++ b/packages/builder/src/stores/builder/screens.js @@ -344,12 +344,7 @@ export class ScreenStore extends BudiStore { let deleteUrls = [] screensToDelete.forEach(screen => { // Delete the screen - promises.push( - API.deleteScreen({ - screenId: screen._id, - screenRev: screen._rev, - }) - ) + promises.push(API.deleteScreen(screen._id, screen._rev)) // Remove links to this screen deleteUrls.push(screen.routing.route) }) diff --git a/packages/frontend-core/src/api/screens.js b/packages/frontend-core/src/api/screens.js deleted file mode 100644 index 1daa79153b..0000000000 --- a/packages/frontend-core/src/api/screens.js +++ /dev/null @@ -1,23 +0,0 @@ -export const buildScreenEndpoints = API => ({ - /** - * Saves a screen definition - * @param screen the screen to save - */ - saveScreen: async screen => { - return await API.post({ - url: "/api/screens", - body: screen, - }) - }, - - /** - * Deletes a screen. - * @param screenId the ID of the screen to delete - * @param screenRev the rev of the screen to delete - */ - deleteScreen: async ({ screenId, screenRev }) => { - return await API.delete({ - url: `/api/screens/${screenId}/${screenRev}`, - }) - }, -}) diff --git a/packages/frontend-core/src/api/screens.ts b/packages/frontend-core/src/api/screens.ts new file mode 100644 index 0000000000..27b4dc482d --- /dev/null +++ b/packages/frontend-core/src/api/screens.ts @@ -0,0 +1,31 @@ +import { Screen } from "@budibase/types" +import { BaseAPIClient } from "./types" + +export interface ScreenEndpoints { + saveScreen: (screen: Screen) => Promise + deleteScreen: (id: string, rev: string) => Promise<{ message: string }> +} + +export const buildScreenEndpoints = (API: BaseAPIClient): ScreenEndpoints => ({ + /** + * Saves a screen definition + * @param screen the screen to save + */ + saveScreen: async screen => { + return await API.post({ + url: "/api/screens", + body: screen, + }) + }, + + /** + * Deletes a screen. + * @param id the ID of the screen to delete + * @param rev the rev of the screen to delete + */ + deleteScreen: async (id, rev) => { + return await API.delete({ + url: `/api/screens/${id}/${rev}`, + }) + }, +}) diff --git a/packages/frontend-core/src/api/types.ts b/packages/frontend-core/src/api/types.ts index 559bb6adfa..6b87fcd53e 100644 --- a/packages/frontend-core/src/api/types.ts +++ b/packages/frontend-core/src/api/types.ts @@ -25,6 +25,7 @@ import { RoleEndpoints } from "./roles" import { RouteEndpoints } from "./routes" import { RowActionEndpoints } from "./rowActions" import { RowEndpoints } from "./rows" +import { ScreenEndpoints } from "./screens" export enum HTTPMethod { POST = "POST", @@ -120,4 +121,5 @@ export type APIClient = BaseAPIClient & RelationshipEndpoints & RoleEndpoints & RouteEndpoints & - RowEndpoints & { rowActions: RowActionEndpoints; [key: string]: any } + RowEndpoints & + ScreenEndpoints & { rowActions: RowActionEndpoints; [key: string]: any }