Clean code
This commit is contained in:
parent
ec93037241
commit
f32910b033
|
@ -2,7 +2,7 @@ import { derived } from "svelte/store"
|
||||||
import { tables, selectedScreen, viewsV2 } from "@/stores/builder"
|
import { tables, selectedScreen, viewsV2 } from "@/stores/builder"
|
||||||
import { DerivedBudiStore } from "../BudiStore"
|
import { DerivedBudiStore } from "../BudiStore"
|
||||||
import { findComponentsBySettingsType } from "@/helpers/screen"
|
import { findComponentsBySettingsType } from "@/helpers/screen"
|
||||||
import { Screen } from "@budibase/types"
|
import { Screen, Table, ViewV2 } from "@budibase/types"
|
||||||
|
|
||||||
interface BuilderScreenComponentStore {}
|
interface BuilderScreenComponentStore {}
|
||||||
|
|
||||||
|
@ -20,22 +20,10 @@ export class ScreenComponentStore extends DerivedBudiStore<
|
||||||
[selectedScreen, tables, viewsV2],
|
[selectedScreen, tables, viewsV2],
|
||||||
([$selectedScreen, $tables, $viewsV2]): DerivedScreenComponentStore => {
|
([$selectedScreen, $tables, $viewsV2]): DerivedScreenComponentStore => {
|
||||||
function getErrors() {
|
function getErrors() {
|
||||||
const datasources = {
|
const datasources = flattenTablesAndViews(
|
||||||
...$tables.list.reduce(
|
$tables.list,
|
||||||
(list, table) => ({
|
$viewsV2.list
|
||||||
...list,
|
)
|
||||||
[table._id!]: table,
|
|
||||||
}),
|
|
||||||
{}
|
|
||||||
),
|
|
||||||
...$viewsV2.list.reduce(
|
|
||||||
(list, view) => ({
|
|
||||||
...list,
|
|
||||||
[view.id]: view,
|
|
||||||
}),
|
|
||||||
{}
|
|
||||||
),
|
|
||||||
}
|
|
||||||
return {
|
return {
|
||||||
...getInvalidDatasources($selectedScreen, datasources),
|
...getInvalidDatasources($selectedScreen, datasources),
|
||||||
}
|
}
|
||||||
|
@ -54,10 +42,35 @@ export class ScreenComponentStore extends DerivedBudiStore<
|
||||||
|
|
||||||
export const screenComponentStore = new ScreenComponentStore()
|
export const screenComponentStore = new ScreenComponentStore()
|
||||||
|
|
||||||
|
function flattenTablesAndViews(tables: Table[], views: ViewV2[]) {
|
||||||
|
return {
|
||||||
|
...tables.reduce(
|
||||||
|
(list, table) => ({
|
||||||
|
...list,
|
||||||
|
[table._id!]: table,
|
||||||
|
}),
|
||||||
|
{}
|
||||||
|
),
|
||||||
|
...views.reduce(
|
||||||
|
(list, view) => ({
|
||||||
|
...list,
|
||||||
|
[view.id]: view,
|
||||||
|
}),
|
||||||
|
{}
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function getInvalidDatasources(
|
function getInvalidDatasources(
|
||||||
screen: Screen,
|
screen: Screen,
|
||||||
datasources: Record<string, any>
|
datasources: Record<string, any>
|
||||||
) {
|
) {
|
||||||
|
const friendlyNameByType = {
|
||||||
|
table: "table",
|
||||||
|
view: "view",
|
||||||
|
viewV2: "view",
|
||||||
|
}
|
||||||
|
|
||||||
const result: Record<string, string[]> = {}
|
const result: Record<string, string[]> = {}
|
||||||
for (const component of findComponentsBySettingsType(screen, "table")) {
|
for (const component of findComponentsBySettingsType(screen, "table")) {
|
||||||
const { resourceId, type, label } = component.dataSource
|
const { resourceId, type, label } = component.dataSource
|
||||||
|
@ -72,9 +85,3 @@ function getInvalidDatasources(
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
const friendlyNameByType = {
|
|
||||||
table: "table",
|
|
||||||
view: "view",
|
|
||||||
viewV2: "view",
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue