Validate queries
This commit is contained in:
parent
1f3c466028
commit
41b65a6b1d
|
@ -3,7 +3,8 @@ import { tables } from "./tables"
|
||||||
import { selectedScreen } from "./screens"
|
import { selectedScreen } from "./screens"
|
||||||
import { viewsV2 } from "./viewsV2"
|
import { viewsV2 } from "./viewsV2"
|
||||||
import { findComponentsBySettingsType } from "@/helpers/screen"
|
import { findComponentsBySettingsType } from "@/helpers/screen"
|
||||||
import { Screen } from "@budibase/types"
|
import { DatasourceType, Screen } from "@budibase/types"
|
||||||
|
import { queries } from "./queries"
|
||||||
|
|
||||||
function reduceBy<TItem extends {}, TKey extends keyof TItem>(
|
function reduceBy<TItem extends {}, TKey extends keyof TItem>(
|
||||||
key: TKey,
|
key: TKey,
|
||||||
|
@ -19,22 +20,39 @@ function reduceBy<TItem extends {}, TKey extends keyof TItem>(
|
||||||
}
|
}
|
||||||
|
|
||||||
export const screenComponentErrors = derived(
|
export const screenComponentErrors = derived(
|
||||||
[selectedScreen, tables, viewsV2],
|
[selectedScreen, tables, viewsV2, queries],
|
||||||
([$selectedScreen, $tables, $viewsV2]): Record<string, string[]> => {
|
([$selectedScreen, $tables, $viewsV2, $queries]): Record<
|
||||||
|
string,
|
||||||
|
string[]
|
||||||
|
> => {
|
||||||
function getInvalidDatasources(
|
function getInvalidDatasources(
|
||||||
screen: Screen,
|
screen: Screen,
|
||||||
datasources: Record<string, any>
|
datasources: Record<string, any>
|
||||||
) {
|
) {
|
||||||
const friendlyNameByType = {
|
const friendlyNameByType: Partial<Record<DatasourceType, string>> = {
|
||||||
viewV2: "view",
|
viewV2: "view",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const primaryKeyByType: Record<DatasourceType, string> = {
|
||||||
|
table: "resourceId",
|
||||||
|
view: "TODO",
|
||||||
|
viewV2: "resourceId",
|
||||||
|
query: "_id",
|
||||||
|
custom: "" as never,
|
||||||
|
}
|
||||||
|
|
||||||
const result: Record<string, string[]> = {}
|
const result: Record<string, string[]> = {}
|
||||||
for (const { component, setting } of findComponentsBySettingsType(
|
for (const { component, setting } of findComponentsBySettingsType(
|
||||||
screen,
|
screen,
|
||||||
["table", "dataSource"]
|
["table", "dataSource"]
|
||||||
)) {
|
)) {
|
||||||
const { resourceId, type, label } = component[setting.key]
|
const componentSettings = component[setting.key]
|
||||||
|
const { type, label } = componentSettings
|
||||||
|
if (type === "custom") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
const resourceId =
|
||||||
|
componentSettings[primaryKeyByType[type as DatasourceType]]
|
||||||
if (!datasources[resourceId]) {
|
if (!datasources[resourceId]) {
|
||||||
const friendlyTypeName =
|
const friendlyTypeName =
|
||||||
friendlyNameByType[type as keyof typeof friendlyNameByType] ?? type
|
friendlyNameByType[type as keyof typeof friendlyNameByType] ?? type
|
||||||
|
@ -50,6 +68,7 @@ export const screenComponentErrors = derived(
|
||||||
const datasources = {
|
const datasources = {
|
||||||
...reduceBy("_id", $tables.list),
|
...reduceBy("_id", $tables.list),
|
||||||
...reduceBy("id", $viewsV2.list),
|
...reduceBy("id", $viewsV2.list),
|
||||||
|
...reduceBy("_id", $queries.list),
|
||||||
}
|
}
|
||||||
|
|
||||||
return getInvalidDatasources($selectedScreen, datasources)
|
return getInvalidDatasources($selectedScreen, datasources)
|
||||||
|
|
|
@ -57,3 +57,5 @@ export interface RestConfig {
|
||||||
}
|
}
|
||||||
dynamicVariables?: DynamicVariable[]
|
dynamicVariables?: DynamicVariable[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type DatasourceType = "table" | "view" | "viewV2" | "query" | "custom"
|
||||||
|
|
Loading…
Reference in New Issue