Create feature store
This commit is contained in:
parent
dd2ec5ed78
commit
d615e1daed
|
@ -0,0 +1,54 @@
|
|||
import { writable } from "svelte/store"
|
||||
import { API } from "api"
|
||||
import { licensing } from "./licensing"
|
||||
import { ConfigType } from "../../../../types/src/documents"
|
||||
|
||||
export const createFeatureStore = () => {
|
||||
const internalStore = writable({
|
||||
scim: {
|
||||
isFeatureFlagEnabled: false,
|
||||
isConfigFlagEnabled: false,
|
||||
},
|
||||
})
|
||||
|
||||
const store = writable({
|
||||
isScimEnabled: false,
|
||||
})
|
||||
|
||||
internalStore.subscribe(s => {
|
||||
store.update(state => ({
|
||||
...state,
|
||||
isScimEnabled: s.scim.isFeatureFlagEnabled && s.scim.isConfigFlagEnabled,
|
||||
}))
|
||||
})
|
||||
|
||||
licensing.subscribe(v => {
|
||||
internalStore.update(state => ({
|
||||
...state,
|
||||
scim: {
|
||||
...state.scim,
|
||||
isFeatureFlagEnabled: v.scimEnabled,
|
||||
},
|
||||
}))
|
||||
})
|
||||
|
||||
const actions = {
|
||||
init: async () => {
|
||||
const scimConfig = await API.getConfig(ConfigType.SCIM)
|
||||
internalStore.update(state => ({
|
||||
...state,
|
||||
scim: {
|
||||
...state.scim,
|
||||
isConfigFlagEnabled: scimConfig.enabled,
|
||||
},
|
||||
}))
|
||||
},
|
||||
}
|
||||
|
||||
return {
|
||||
subscribe: store.subscribe,
|
||||
...actions,
|
||||
}
|
||||
}
|
||||
|
||||
export const features = createFeatureStore()
|
|
@ -14,3 +14,4 @@ export { overview } from "./overview"
|
|||
export { environment } from "./environment"
|
||||
export { menu } from "./menu"
|
||||
export { auditLogs } from "./auditLogs"
|
||||
export { features } from "./features"
|
||||
|
|
Loading…
Reference in New Issue