address comments.

This commit is contained in:
Darshan
2025-06-06 17:17:42 +05:30
parent a9bc1c9dcc
commit ce471faa68
4 changed files with 18 additions and 26 deletions
+14 -24
View File
@@ -1,34 +1,24 @@
import { env } from '$env/dynamic/public';
import type { Organization } from './stores/organization';
import type { Account } from './stores/user';
import type { Organization } from './stores/organization';
export const PUBLIC_CONSOLE_FEATURE_FLAGS = env.PUBLIC_CONSOLE_FEATURE_FLAGS ?? '';
// Parse feature flags from env as a string array (exact match only)
const flagsRaw = (env.PUBLIC_CONSOLE_FEATURE_FLAGS ?? '').split(',');
function setupFlag(name: string, _description: string) {
// TODO: Use flags library that provides visual component during development
function isFlagEnabled(name: string) {
// loose generic to allow safe access while retaining type safety
return <T extends { user?: Account; organization?: Organization }>(data: T) => {
const { user, organization } = data;
return (user: Account, organization: Organization) => {
if (PUBLIC_CONSOLE_FEATURE_FLAGS.includes(name)) {
return true;
}
const userPrefs = user?.prefs ?? {};
const userFlag = userPrefs[`flags-${name}`] ?? null;
if (userFlag) {
return true;
}
const organizationPrefs = organization?.prefs ?? {};
const organizationFlag = organizationPrefs[`flags-${name}`] ?? null;
if (organizationFlag) {
return true;
}
return false;
return !!(
flagsRaw.includes(name) ||
user?.prefs?.[`flags-${name}`] ||
organization?.prefs?.[`flags-${name}`]
);
};
}
export const flags = {
showSites: setupFlag('sites', 'When disabled, sites view will show high demand'),
showCsvImport: setupFlag('csv-import', 'When disabled, documents view will hide import button')
showSites: isFlagEnabled('sites'),
showCsvImport: isFlagEnabled('csv-import')
};
@@ -100,7 +100,7 @@
analyticsSource="database_documents" />
<Layout.Stack direction="row" alignItems="center" justifyContent="flex-end">
<ViewSelector view={data.view} {columns} hideView />
{#if flags.showCsvImport(data.account, data.organization)}
{#if flags.showCsvImport(data)}
<Button
secondary
event={Click.DatabaseImportCsv}
@@ -14,7 +14,7 @@ export const load = async ({ url, depends, route, params, parent }) => {
const offset = pageToOffset(page, limit);
const view = getView(url, route, View.Grid, View.Grid);
if (!flags.showSites(data.account, data.organization)) {
if (!flags.showSites(data)) {
return {
sitesLive: false,
offset,