Feature flags (#543)
* Re-organize a bit controllers * Added the featureflagcontroller * Implement feature flags in the front-end * Clean env files * Clean console.log messages * Fix feature flag test
This commit is contained in:
3
client/stores/app.js
vendored
3
client/stores/app.js
vendored
@@ -21,10 +21,7 @@ export const useAppStore = defineStore("app", {
|
||||
},
|
||||
}),
|
||||
getters: {
|
||||
paidPlansEnabled: () => useRuntimeConfig().public.paidPlansEnabled,
|
||||
featureBaseEnabled: () => useRuntimeConfig().public.featureBaseOrganization !== null,
|
||||
selfHosted: () => useRuntimeConfig().public.selfHosted,
|
||||
aiFeaturesEnabled: () => useRuntimeConfig().public.aiFeaturesEnabled,
|
||||
crispEnabled: () => useRuntimeConfig().public.crispWebsiteId !== null && useRuntimeConfig().public.crispWebsiteId !== '',
|
||||
},
|
||||
actions: {
|
||||
|
||||
24
client/stores/featureFlags.js
vendored
Normal file
24
client/stores/featureFlags.js
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
|
||||
export const useFeatureFlagsStore = defineStore('feature_flags', () => {
|
||||
const flags = ref({})
|
||||
|
||||
async function fetchFlags() {
|
||||
try {
|
||||
const { data } = await useOpnApi('/content/feature-flags')
|
||||
flags.value = data.value
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch feature flags:', error)
|
||||
}
|
||||
}
|
||||
|
||||
function getFlag(path, defaultValue = false) {
|
||||
return path.split('.').reduce((acc, part) => {
|
||||
if (acc === undefined) return defaultValue
|
||||
return acc && acc[part] !== undefined ? acc[part] : defaultValue
|
||||
}, flags.value)
|
||||
}
|
||||
|
||||
return { flags, fetchFlags, getFlag }
|
||||
})
|
||||
13
client/stores/form_integrations.js
vendored
13
client/stores/form_integrations.js
vendored
@@ -10,15 +10,18 @@ export const useFormIntegrationsStore = defineStore("form_integrations", () => {
|
||||
|
||||
const availableIntegrations = computed(() => {
|
||||
const user = useAuthStore().user
|
||||
const featureFlagsStore = useFeatureFlagsStore()
|
||||
if (!user) return integrations.value
|
||||
|
||||
const enrichedIntegrations = new Map()
|
||||
for (const [key, integration] of integrations.value.entries()) {
|
||||
enrichedIntegrations.set(key, {
|
||||
...integration,
|
||||
id: key,
|
||||
requires_subscription: !user.is_subscribed && integration.is_pro,
|
||||
})
|
||||
if (featureFlagsStore.getFlag(`integrations.${key}`, true)) {
|
||||
enrichedIntegrations.set(key, {
|
||||
...integration,
|
||||
id: key,
|
||||
requires_subscription: !user.is_subscribed && integration.is_pro,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return enrichedIntegrations
|
||||
|
||||
Reference in New Issue
Block a user