Simplify derived screenComponentErrors
This commit is contained in:
parent
84c8507bad
commit
c9feae9665
|
@ -11,7 +11,7 @@
|
||||||
selectedScreen,
|
selectedScreen,
|
||||||
hoverStore,
|
hoverStore,
|
||||||
componentTreeNodesStore,
|
componentTreeNodesStore,
|
||||||
screenComponentStore,
|
screenComponentErrors,
|
||||||
snippets,
|
snippets,
|
||||||
} from "@/stores/builder"
|
} from "@/stores/builder"
|
||||||
import ConfirmDialog from "@/components/common/ConfirmDialog.svelte"
|
import ConfirmDialog from "@/components/common/ConfirmDialog.svelte"
|
||||||
|
@ -69,7 +69,7 @@
|
||||||
port: window.location.port,
|
port: window.location.port,
|
||||||
},
|
},
|
||||||
snippets: $snippets,
|
snippets: $snippets,
|
||||||
componentErrors: $screenComponentStore.errors,
|
componentErrors: $screenComponentErrors,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh the preview when required
|
// Refresh the preview when required
|
||||||
|
|
|
@ -16,7 +16,7 @@ import { userStore, userSelectedResourceMap, isOnlyUser } from "./users.js"
|
||||||
import { deploymentStore } from "./deployments.js"
|
import { deploymentStore } from "./deployments.js"
|
||||||
import { contextMenuStore } from "./contextMenu.js"
|
import { contextMenuStore } from "./contextMenu.js"
|
||||||
import { snippets } from "./snippets"
|
import { snippets } from "./snippets"
|
||||||
import { screenComponentStore } from "./screenComponent"
|
import { screenComponentErrors } from "./screenComponent"
|
||||||
|
|
||||||
// Backend
|
// Backend
|
||||||
import { tables } from "./tables"
|
import { tables } from "./tables"
|
||||||
|
@ -68,7 +68,7 @@ export {
|
||||||
snippets,
|
snippets,
|
||||||
rowActions,
|
rowActions,
|
||||||
appPublished,
|
appPublished,
|
||||||
screenComponentStore,
|
screenComponentErrors,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const reset = () => {
|
export const reset = () => {
|
||||||
|
|
|
@ -2,39 +2,12 @@ import { derived } from "svelte/store"
|
||||||
import { tables } from "./tables"
|
import { tables } from "./tables"
|
||||||
import { selectedScreen } from "./screens"
|
import { selectedScreen } from "./screens"
|
||||||
import { viewsV2 } from "./viewsV2"
|
import { viewsV2 } from "./viewsV2"
|
||||||
import { DerivedBudiStore } from "../BudiStore"
|
|
||||||
import { findComponentsBySettingsType } from "@/helpers/screen"
|
import { findComponentsBySettingsType } from "@/helpers/screen"
|
||||||
import { Screen, Table, ViewV2 } from "@budibase/types"
|
import { Screen, Table, ViewV2 } from "@budibase/types"
|
||||||
|
|
||||||
interface BuilderScreenComponentStore {}
|
export const screenComponentErrors = derived(
|
||||||
|
|
||||||
interface DerivedScreenComponentStore extends BuilderScreenComponentStore {
|
|
||||||
errors: Record<string, string[]>
|
|
||||||
}
|
|
||||||
|
|
||||||
export class ScreenComponentStore extends DerivedBudiStore<
|
|
||||||
BuilderScreenComponentStore,
|
|
||||||
DerivedScreenComponentStore
|
|
||||||
> {
|
|
||||||
constructor() {
|
|
||||||
const makeDerivedStore = () => {
|
|
||||||
return derived(
|
|
||||||
[selectedScreen, tables, viewsV2],
|
[selectedScreen, tables, viewsV2],
|
||||||
([$selectedScreen, $tables, $viewsV2]): DerivedScreenComponentStore => {
|
([$selectedScreen, $tables, $viewsV2]): Record<string, string[]> => {
|
||||||
const datasources = flattenTablesAndViews($tables.list, $viewsV2.list)
|
|
||||||
return {
|
|
||||||
errors: getInvalidDatasources($selectedScreen, datasources),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
super({}, makeDerivedStore)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const screenComponentStore = new ScreenComponentStore()
|
|
||||||
|
|
||||||
function flattenTablesAndViews(tables: Table[], views: ViewV2[]) {
|
function flattenTablesAndViews(tables: Table[], views: ViewV2[]) {
|
||||||
return {
|
return {
|
||||||
...tables.reduce(
|
...tables.reduce(
|
||||||
|
@ -78,3 +51,8 @@ function getInvalidDatasources(
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const datasources = flattenTablesAndViews($tables.list, $viewsV2.list)
|
||||||
|
return getInvalidDatasources($selectedScreen, datasources)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue