2022-02-24 15:14:55 +01:00
|
|
|
import { createLocalStorageStore } from "@budibase/frontend-core"
|
2021-11-26 14:25:02 +01:00
|
|
|
import { initialise } from "./initialise"
|
|
|
|
import { authStore } from "./auth"
|
2022-06-09 16:33:41 +02:00
|
|
|
import { API } from "../api"
|
2021-11-26 14:25:02 +01:00
|
|
|
|
|
|
|
const initialState = {
|
2022-06-09 16:03:43 +02:00
|
|
|
enabled: false,
|
2021-11-26 14:25:02 +01:00
|
|
|
visible: false,
|
|
|
|
allowSelection: false,
|
|
|
|
role: null,
|
|
|
|
}
|
|
|
|
|
|
|
|
const createDevToolStore = () => {
|
2022-06-09 16:55:59 +02:00
|
|
|
const store = createLocalStorageStore("bb-devtools", initialState)
|
2021-11-26 14:25:02 +01:00
|
|
|
|
2022-06-09 16:03:43 +02:00
|
|
|
const setEnabled = enabled => {
|
|
|
|
store.update(state => ({
|
|
|
|
...state,
|
|
|
|
enabled,
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
2021-11-26 14:25:02 +01:00
|
|
|
const setVisible = visible => {
|
|
|
|
store.update(state => ({
|
|
|
|
...state,
|
2022-06-09 16:03:43 +02:00
|
|
|
visible,
|
2021-11-26 14:25:02 +01:00
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
|
|
|
const setAllowSelection = allowSelection => {
|
|
|
|
store.update(state => ({
|
|
|
|
...state,
|
|
|
|
allowSelection,
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
|
|
|
const changeRole = async role => {
|
|
|
|
store.update(state => ({
|
|
|
|
...state,
|
|
|
|
role: role === "self" ? null : role,
|
|
|
|
}))
|
2022-06-09 16:33:41 +02:00
|
|
|
API.invalidateCache()
|
2021-11-26 14:25:02 +01:00
|
|
|
await authStore.actions.fetchUser()
|
|
|
|
await initialise()
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
subscribe: store.subscribe,
|
2022-06-09 16:03:43 +02:00
|
|
|
actions: { setEnabled, setVisible, setAllowSelection, changeRole },
|
2021-11-26 14:25:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const devToolsStore = createDevToolStore()
|