Screens and some slightly changes to Table API typing.

This commit is contained in:
mike12345567 2024-12-03 18:06:09 +00:00
parent ce6e1c5c22
commit 6494962c1a
9 changed files with 55 additions and 46 deletions

View File

@ -592,7 +592,10 @@ export class AccessController {
)
}
async checkScreensAccess(screens: Screen[], userRoleId: string) {
async checkScreensAccess(
screens: Screen[],
userRoleId: string
): Promise<Screen[]> {
let accessibleScreens = []
// don't want to handle this with Promise.all as this would mean all custom roles would be
// retrieved at same time, it is likely a custom role will be re-used and therefore want

View File

@ -10,13 +10,16 @@ import { updateAppPackage } from "./application"
import {
Plugin,
ScreenProps,
BBContext,
Screen,
UserCtx,
FetchScreenResponse,
SaveScreenRequest,
SaveScreenResponse,
DeleteScreenResponse,
} from "@budibase/types"
import { builderSocket } from "../../websockets"
export async function fetch(ctx: BBContext) {
export async function fetch(ctx: UserCtx<void, FetchScreenResponse>) {
const db = context.getAppDB()
const screens = (
@ -37,7 +40,9 @@ export async function fetch(ctx: BBContext) {
)
}
export async function save(ctx: UserCtx<Screen, Screen>) {
export async function save(
ctx: UserCtx<SaveScreenRequest, SaveScreenResponse>
) {
const db = context.getAppDB()
let screen = ctx.request.body
@ -107,7 +112,7 @@ export async function save(ctx: UserCtx<Screen, Screen>) {
builderSocket?.emitScreenUpdate(ctx, savedScreen)
}
export async function destroy(ctx: BBContext) {
export async function destroy(ctx: UserCtx<void, DeleteScreenResponse>) {
const db = context.getAppDB()
const id = ctx.params.screenId
const screen = await db.get<Screen>(id)

View File

@ -14,7 +14,3 @@ export async function execute(ctx: Ctx) {
throw err
}
}
export async function save(ctx: Ctx) {
ctx.throw(501, "Not currently implemented")
}

View File

@ -19,17 +19,18 @@ import {
EventType,
FetchTablesResponse,
FieldType,
MigrateRequest,
MigrateResponse,
MigrateTableRequest,
MigrateTableResponse,
SaveTableRequest,
SaveTableResponse,
Table,
TableResponse,
FindTableResponse,
TableSourceType,
UserCtx,
ValidateNewTableImportRequest,
ValidateTableImportRequest,
ValidateTableImportResponse,
DeleteTableResponse,
} from "@budibase/types"
import sdk from "../../../sdk"
import { jsonFromCsvString } from "../../../utilities/csv"
@ -94,7 +95,7 @@ export async function fetch(ctx: UserCtx<void, FetchTablesResponse>) {
ctx.body = result
}
export async function find(ctx: UserCtx<void, TableResponse>) {
export async function find(ctx: UserCtx<void, FindTableResponse>) {
const tableId = ctx.params.tableId
const table = await sdk.tables.getTable(tableId)
@ -137,7 +138,7 @@ export async function save(ctx: UserCtx<SaveTableRequest, SaveTableResponse>) {
builderSocket?.emitTableUpdate(ctx, cloneDeep(savedTable))
}
export async function destroy(ctx: UserCtx) {
export async function destroy(ctx: UserCtx<void, DeleteTableResponse>) {
const appId = ctx.appId
const tableId = ctx.params.tableId
await sdk.rowActions.deleteAll(tableId)
@ -223,7 +224,9 @@ export async function validateExistingTableImport(
}
}
export async function migrate(ctx: UserCtx<MigrateRequest, MigrateResponse>) {
export async function migrate(
ctx: UserCtx<MigrateTableRequest, MigrateTableResponse>
) {
const { oldColumn, newColumn } = ctx.request.body
let tableId = ctx.params.tableId as string
const table = await sdk.tables.getTable(tableId)

View File

@ -1,10 +0,0 @@
import Router from "@koa/router"
import * as controller from "../controllers/script"
import authorized from "../../middleware/authorized"
import { permissions } from "@budibase/backend-core"
const router: Router = new Router()
router.post("/api/script", authorized(permissions.BUILDER), controller.save)
export default router

View File

@ -9,7 +9,7 @@ import {
Database,
INTERNAL_TABLE_SOURCE_ID,
Table,
TableResponse,
FindTableResponse,
TableSourceType,
TableViewsResponse,
} from "@budibase/types"
@ -173,7 +173,9 @@ export async function getTables(tableIds: string[]): Promise<Table[]> {
return await processTables(tables)
}
export async function enrichViewSchemas(table: Table): Promise<TableResponse> {
export async function enrichViewSchemas(
table: Table
): Promise<FindTableResponse> {
const views = []
for (const view of Object.values(table.views ?? [])) {
if (sdk.views.isV2(view)) {

View File

@ -3,8 +3,8 @@ import {
BulkImportResponse,
CsvToJsonRequest,
CsvToJsonResponse,
MigrateRequest,
MigrateResponse,
MigrateTableRequest,
MigrateTableResponse,
SaveTableRequest,
SaveTableResponse,
Table,
@ -38,13 +38,16 @@ export class TableAPI extends TestAPI {
migrate = async (
tableId: string,
data: MigrateRequest,
data: MigrateTableRequest,
expectations?: Expectations
): Promise<MigrateResponse> => {
return await this._post<MigrateResponse>(`/api/tables/${tableId}/migrate`, {
): Promise<MigrateTableResponse> => {
return await this._post<MigrateTableResponse>(
`/api/tables/${tableId}/migrate`,
{
body: data,
expectations,
})
}
)
}
import = async (

View File

@ -1,4 +1,4 @@
import { ScreenRoutingJson } from "../../../documents"
import { ScreenRoutingJson, Screen } from "../../../documents"
export interface FetchScreenRoutingResponse {
routes: ScreenRoutingJson
@ -6,3 +6,12 @@ export interface FetchScreenRoutingResponse {
export interface FetchClientScreenRoutingResponse
extends FetchScreenRoutingResponse {}
export type FetchScreenResponse = Screen[]
export interface SaveScreenRequest extends Screen {}
export interface SaveScreenResponse extends Screen {}
export interface DeleteScreenResponse {
message: string
}

View File

@ -3,33 +3,30 @@ import { ViewV2Enriched } from "../../../sdk"
export type TableViewsResponse = { [key: string]: View | ViewV2Enriched }
export interface TableResponse extends Table {
export interface FindTableResponse extends Table {
views?: TableViewsResponse
}
export type FetchTablesResponse = TableResponse[]
export type FetchTablesResponse = FindTableResponse[]
export interface SaveTableRequest extends TableRequest {
rows?: Row[]
}
export type SaveTableResponse = Table
export interface BulkImportRequest {
rows: Row[]
identifierFields?: Array<string>
}
export interface BulkImportResponse {
message: string
}
export interface MigrateRequest {
export interface MigrateTableRequest {
oldColumn: string
newColumn: string
}
export interface MigrateResponse {
export interface MigrateTableResponse {
message: string
}
@ -37,12 +34,10 @@ export interface ValidateNewTableImportRequest {
rows: Row[]
schema: TableSchema
}
export interface ValidateTableImportRequest {
tableId?: string
rows: Row[]
}
export interface ValidateTableImportResponse {
schemaValidation: {
[field: string]: boolean
@ -55,5 +50,8 @@ export interface ValidateTableImportResponse {
export interface CsvToJsonRequest {
csvString: string
}
export type CsvToJsonResponse = any[]
export interface DeleteTableResponse {
message: string
}