Merge branch 'master' into screen-store-ts-conversion
This commit is contained in:
commit
2868ca1fac
|
@ -2,19 +2,24 @@ import { get } from "svelte/store"
|
||||||
import { BudiStore } from "../BudiStore"
|
import { BudiStore } from "../BudiStore"
|
||||||
import { previewStore } from "@/stores/builder"
|
import { previewStore } from "@/stores/builder"
|
||||||
|
|
||||||
|
interface BuilderHoverStore {
|
||||||
|
hoverTimeout?: NodeJS.Timeout
|
||||||
|
componentId: string | null
|
||||||
|
}
|
||||||
|
|
||||||
export const INITIAL_HOVER_STATE = {
|
export const INITIAL_HOVER_STATE = {
|
||||||
componentId: null,
|
componentId: null,
|
||||||
}
|
}
|
||||||
|
|
||||||
export class HoverStore extends BudiStore {
|
export class HoverStore extends BudiStore<BuilderHoverStore> {
|
||||||
hoverTimeout
|
hoverTimeout?: NodeJS.Timeout
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super({ ...INITIAL_HOVER_STATE })
|
super({ ...INITIAL_HOVER_STATE })
|
||||||
this.hover = this.hover.bind(this)
|
this.hover = this.hover.bind(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
hover(componentId, notifyClient = true) {
|
hover(componentId: string, notifyClient = true) {
|
||||||
clearTimeout(this.hoverTimeout)
|
clearTimeout(this.hoverTimeout)
|
||||||
if (componentId) {
|
if (componentId) {
|
||||||
this.processHover(componentId, notifyClient)
|
this.processHover(componentId, notifyClient)
|
||||||
|
@ -25,7 +30,7 @@ export class HoverStore extends BudiStore {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
processHover(componentId, notifyClient) {
|
processHover(componentId: string, notifyClient?: boolean) {
|
||||||
if (componentId === get(this.store).componentId) {
|
if (componentId === get(this.store).componentId) {
|
||||||
return
|
return
|
||||||
}
|
}
|
|
@ -2,27 +2,22 @@ import { get } from "svelte/store"
|
||||||
import { API } from "@/api"
|
import { API } from "@/api"
|
||||||
import { appStore } from "@/stores/builder"
|
import { appStore } from "@/stores/builder"
|
||||||
import { BudiStore } from "../BudiStore"
|
import { BudiStore } from "../BudiStore"
|
||||||
|
import { AppNavigation, AppNavigationLink, UIObject } from "@budibase/types"
|
||||||
|
|
||||||
|
interface BuilderNavigationStore extends AppNavigation {}
|
||||||
|
|
||||||
export const INITIAL_NAVIGATION_STATE = {
|
export const INITIAL_NAVIGATION_STATE = {
|
||||||
navigation: "Top",
|
navigation: "Top",
|
||||||
links: [],
|
links: [],
|
||||||
title: null,
|
|
||||||
sticky: null,
|
|
||||||
hideLogo: null,
|
|
||||||
logoUrl: null,
|
|
||||||
hideTitle: null,
|
|
||||||
textAlign: "Left",
|
textAlign: "Left",
|
||||||
navBackground: null,
|
|
||||||
navWidth: null,
|
|
||||||
navTextColor: null,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class NavigationStore extends BudiStore {
|
export class NavigationStore extends BudiStore<BuilderNavigationStore> {
|
||||||
constructor() {
|
constructor() {
|
||||||
super(INITIAL_NAVIGATION_STATE)
|
super(INITIAL_NAVIGATION_STATE)
|
||||||
}
|
}
|
||||||
|
|
||||||
syncAppNavigation(nav) {
|
syncAppNavigation(nav: AppNavigation) {
|
||||||
this.update(state => ({
|
this.update(state => ({
|
||||||
...state,
|
...state,
|
||||||
...nav,
|
...nav,
|
||||||
|
@ -33,15 +28,17 @@ export class NavigationStore extends BudiStore {
|
||||||
this.store.set({ ...INITIAL_NAVIGATION_STATE })
|
this.store.set({ ...INITIAL_NAVIGATION_STATE })
|
||||||
}
|
}
|
||||||
|
|
||||||
async save(navigation) {
|
async save(navigation: AppNavigation) {
|
||||||
const appId = get(appStore).appId
|
const appId = get(appStore).appId
|
||||||
const app = await API.saveAppMetadata(appId, { navigation })
|
const app = await API.saveAppMetadata(appId, { navigation })
|
||||||
|
if (app.navigation) {
|
||||||
this.syncAppNavigation(app.navigation)
|
this.syncAppNavigation(app.navigation)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async saveLink(url, title, roleId) {
|
async saveLink(url: string, title: string, roleId: string) {
|
||||||
const navigation = get(this.store)
|
const navigation = get(this.store)
|
||||||
let links = [...(navigation?.links ?? [])]
|
let links: AppNavigationLink[] = [...(navigation?.links ?? [])]
|
||||||
|
|
||||||
// Skip if we have an identical link
|
// Skip if we have an identical link
|
||||||
if (links.find(link => link.url === url && link.text === title)) {
|
if (links.find(link => link.url === url && link.text === title)) {
|
||||||
|
@ -60,7 +57,7 @@ export class NavigationStore extends BudiStore {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteLink(urls) {
|
async deleteLink(urls: string[] | string) {
|
||||||
const navigation = get(this.store)
|
const navigation = get(this.store)
|
||||||
let links = navigation?.links
|
let links = navigation?.links
|
||||||
if (!links?.length) {
|
if (!links?.length) {
|
||||||
|
@ -86,7 +83,7 @@ export class NavigationStore extends BudiStore {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
syncMetadata(metadata) {
|
syncMetadata(metadata: UIObject) {
|
||||||
const { navigation } = metadata
|
const { navigation } = metadata
|
||||||
this.syncAppNavigation(navigation)
|
this.syncAppNavigation(navigation)
|
||||||
}
|
}
|
|
@ -4,14 +4,14 @@ import { admin } from "@/stores/portal"
|
||||||
import analytics from "@/analytics"
|
import analytics from "@/analytics"
|
||||||
import { BudiStore } from "@/stores/BudiStore"
|
import { BudiStore } from "@/stores/BudiStore"
|
||||||
import {
|
import {
|
||||||
|
GetGlobalSelfResponse,
|
||||||
isSSOUser,
|
isSSOUser,
|
||||||
SetInitInfoRequest,
|
SetInitInfoRequest,
|
||||||
UpdateSelfRequest,
|
UpdateSelfRequest,
|
||||||
User,
|
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
|
|
||||||
interface PortalAuthStore {
|
interface PortalAuthStore {
|
||||||
user?: User
|
user?: GetGlobalSelfResponse
|
||||||
initInfo?: Record<string, any>
|
initInfo?: Record<string, any>
|
||||||
accountPortalAccess: boolean
|
accountPortalAccess: boolean
|
||||||
loaded: boolean
|
loaded: boolean
|
||||||
|
@ -33,7 +33,7 @@ class AuthStore extends BudiStore<PortalAuthStore> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
setUser(user?: User) {
|
setUser(user?: GetGlobalSelfResponse) {
|
||||||
this.set({
|
this.set({
|
||||||
loaded: true,
|
loaded: true,
|
||||||
user: user,
|
user: user,
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
import { derived } from "svelte/store"
|
|
||||||
import { auth } from "@/stores/portal"
|
|
||||||
|
|
||||||
export const INITIAL_FEATUREFLAG_STATE = {
|
|
||||||
SQS: false,
|
|
||||||
DEFAULT_VALUES: false,
|
|
||||||
BUDIBASE_AI: false,
|
|
||||||
AI_CUSTOM_CONFIGS: false,
|
|
||||||
}
|
|
||||||
|
|
||||||
export const featureFlags = derived([auth], ([$auth]) => {
|
|
||||||
return {
|
|
||||||
...INITIAL_FEATUREFLAG_STATE,
|
|
||||||
...($auth?.user?.flags || {}),
|
|
||||||
}
|
|
||||||
})
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
import { derived, Readable } from "svelte/store"
|
||||||
|
import { auth } from "@/stores/portal"
|
||||||
|
import { FeatureFlags, FeatureFlagDefaults } from "@budibase/types"
|
||||||
|
|
||||||
|
export const featureFlags: Readable<FeatureFlags> = derived(auth, $auth => ({
|
||||||
|
...FeatureFlagDefaults,
|
||||||
|
...($auth?.user?.flags || {}),
|
||||||
|
}))
|
|
@ -37,8 +37,8 @@ export interface AppInstance {
|
||||||
|
|
||||||
export interface AppNavigation {
|
export interface AppNavigation {
|
||||||
navigation: string
|
navigation: string
|
||||||
title: string
|
title?: string
|
||||||
navWidth: string
|
navWidth?: string
|
||||||
sticky?: boolean
|
sticky?: boolean
|
||||||
hideLogo?: boolean
|
hideLogo?: boolean
|
||||||
logoUrl?: string
|
logoUrl?: string
|
||||||
|
@ -46,6 +46,7 @@ export interface AppNavigation {
|
||||||
navBackground?: string
|
navBackground?: string
|
||||||
navTextColor?: string
|
navTextColor?: string
|
||||||
links?: AppNavigationLink[]
|
links?: AppNavigationLink[]
|
||||||
|
textAlign?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AppNavigationLink {
|
export interface AppNavigationLink {
|
||||||
|
@ -53,6 +54,8 @@ export interface AppNavigationLink {
|
||||||
url: string
|
url: string
|
||||||
id?: string
|
id?: string
|
||||||
roleId?: string
|
roleId?: string
|
||||||
|
type?: string
|
||||||
|
subLinks?: AppNavigationLink[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AppCustomTheme {
|
export interface AppCustomTheme {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
export * from "./integration"
|
export * from "./integration"
|
||||||
|
export * from "./misc"
|
||||||
export * from "./automations"
|
export * from "./automations"
|
||||||
export * from "./grid"
|
export * from "./grid"
|
||||||
export * from "./preview"
|
export * from "./preview"
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
// type purely to capture structures that the type is unknown, but maybe known later
|
||||||
|
export type UIObject = Record<string, any>
|
Loading…
Reference in New Issue