Functions to get source type and usage endpoint for screens.
This commit is contained in:
parent
b8e5512f30
commit
1b8a229e85
|
@ -83,11 +83,15 @@ export function isViewId(id: string): boolean {
|
|||
/**
|
||||
* Check if a given ID is that of a datasource or datasource plus.
|
||||
*/
|
||||
export const isDatasourceId = (id: string): boolean => {
|
||||
export function isDatasourceId(id: string): boolean {
|
||||
// this covers both datasources and datasource plus
|
||||
return !!id && id.startsWith(`${DocumentType.DATASOURCE}${SEPARATOR}`)
|
||||
}
|
||||
|
||||
export function isQueryId(id: string): boolean {
|
||||
return !!id && id.startsWith(`${DocumentType.QUERY}${SEPARATOR}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets parameters for retrieving workspaces.
|
||||
*/
|
||||
|
|
|
@ -16,8 +16,10 @@ import {
|
|||
SaveScreenRequest,
|
||||
SaveScreenResponse,
|
||||
DeleteScreenResponse,
|
||||
UsageScreenResponse,
|
||||
} from "@budibase/types"
|
||||
import { builderSocket } from "../../websockets"
|
||||
import sdk from "../../sdk"
|
||||
|
||||
export async function fetch(ctx: UserCtx<void, FetchScreenResponse>) {
|
||||
const db = context.getAppDB()
|
||||
|
@ -140,3 +142,8 @@ function findPlugins(component: ScreenProps, foundPlugins: string[]) {
|
|||
}
|
||||
component._children.forEach(child => findPlugins(child, foundPlugins))
|
||||
}
|
||||
|
||||
export async function usage(ctx: UserCtx<void, UsageScreenResponse>) {
|
||||
const sourceId = ctx.params.sourceId
|
||||
const sourceType = sdk.common.getSourceType(sourceId)
|
||||
}
|
||||
|
|
|
@ -19,5 +19,10 @@ router
|
|||
authorized(permissions.BUILDER),
|
||||
controller.destroy
|
||||
)
|
||||
.post(
|
||||
"/api/screens/usage/:sourceId",
|
||||
authorized(permissions.BUILDER),
|
||||
controller.usage
|
||||
)
|
||||
|
||||
export default router
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
export * from "./utils"
|
|
@ -0,0 +1,15 @@
|
|||
import { SourceType } from "@budibase/types"
|
||||
import { docIds } from "@budibase/backend-core"
|
||||
|
||||
export function getSourceType(sourceId: string): SourceType {
|
||||
if (docIds.isTableId(sourceId)) {
|
||||
return SourceType.TABLE
|
||||
} else if (docIds.isViewId(sourceId)) {
|
||||
return SourceType.VIEW
|
||||
} else if (docIds.isDatasourceId(sourceId)) {
|
||||
return SourceType.DATASOURCE
|
||||
} else if (docIds.isQueryId(sourceId)) {
|
||||
return SourceType.QUERY
|
||||
}
|
||||
throw new Error("Unknown source type - cannot find document type")
|
||||
}
|
|
@ -11,6 +11,7 @@ import { default as plugins } from "./plugins"
|
|||
import * as views from "./app/views"
|
||||
import * as permissions from "./app/permissions"
|
||||
import * as rowActions from "./app/rowActions"
|
||||
import * as common from "./app/common"
|
||||
|
||||
const sdk = {
|
||||
backups,
|
||||
|
@ -26,6 +27,7 @@ const sdk = {
|
|||
permissions,
|
||||
links,
|
||||
rowActions,
|
||||
common,
|
||||
}
|
||||
|
||||
// default export for TS
|
||||
|
|
|
@ -15,3 +15,10 @@ export interface SaveScreenResponse extends Screen {}
|
|||
export interface DeleteScreenResponse {
|
||||
message: string
|
||||
}
|
||||
|
||||
export interface UsageScreenResponse {
|
||||
screens: {
|
||||
url: string
|
||||
_id: string
|
||||
}[]
|
||||
}
|
||||
|
|
|
@ -57,3 +57,10 @@ export interface RestConfig {
|
|||
}
|
||||
dynamicVariables?: DynamicVariable[]
|
||||
}
|
||||
|
||||
export enum SourceType {
|
||||
DATASOURCE = "datasource",
|
||||
QUERY = "query",
|
||||
TABLE = "table",
|
||||
VIEW = "view",
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue