Skip to content

Commit ce471fa

Browse files
committed
address comments.
1 parent a9bc1c9 commit ce471fa

File tree

4 files changed

+18
-26
lines changed

4 files changed

+18
-26
lines changed

.github/workflows/publish.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ jobs:
117117
build-args: |
118118
"PUBLIC_CONSOLE_MODE=self-hosted"
119119
"PUBLIC_APPWRITE_MULTI_REGION=false"
120+
"PUBLIC_CONSOLE_FEATURE_FLAGS="sites,csv-import"
120121
"PUBLIC_GROWTH_ENDPOINT=${{ secrets.PUBLIC_GROWTH_ENDPOINT }}"
121122
122123
publish-cloud-no-regions:
@@ -154,5 +155,6 @@ jobs:
154155
build-args: |
155156
"PUBLIC_CONSOLE_MODE=cloud"
156157
"PUBLIC_APPWRITE_MULTI_REGION=false"
158+
"PUBLIC_CONSOLE_FEATURE_FLAGS="sites,csv-import"
157159
"PUBLIC_STRIPE_KEY=${{ secrets.PUBLIC_STRIPE_KEY_STAGE }}"
158160
"PUBLIC_GROWTH_ENDPOINT=${{ secrets.PUBLIC_GROWTH_ENDPOINT }}"

src/lib/flags.ts

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,24 @@
11
import { env } from '$env/dynamic/public';
2-
import type { Organization } from './stores/organization';
32
import type { Account } from './stores/user';
3+
import type { Organization } from './stores/organization';
44

5-
export const PUBLIC_CONSOLE_FEATURE_FLAGS = env.PUBLIC_CONSOLE_FEATURE_FLAGS ?? '';
6-
7-
function setupFlag(name: string, _description: string) {
8-
// TODO: Use flags library that provides visual component during development
9-
10-
return (user: Account, organization: Organization) => {
11-
if (PUBLIC_CONSOLE_FEATURE_FLAGS.includes(name)) {
12-
return true;
13-
}
14-
15-
const userPrefs = user?.prefs ?? {};
16-
const userFlag = userPrefs[`flags-${name}`] ?? null;
17-
if (userFlag) {
18-
return true;
19-
}
5+
// Parse feature flags from env as a string array (exact match only)
6+
const flagsRaw = (env.PUBLIC_CONSOLE_FEATURE_FLAGS ?? '').split(',');
207

21-
const organizationPrefs = organization?.prefs ?? {};
22-
const organizationFlag = organizationPrefs[`flags-${name}`] ?? null;
23-
if (organizationFlag) {
24-
return true;
25-
}
8+
function isFlagEnabled(name: string) {
9+
// loose generic to allow safe access while retaining type safety
10+
return <T extends { user?: Account; organization?: Organization }>(data: T) => {
11+
const { user, organization } = data;
2612

27-
return false;
13+
return !!(
14+
flagsRaw.includes(name) ||
15+
user?.prefs?.[`flags-${name}`] ||
16+
organization?.prefs?.[`flags-${name}`]
17+
);
2818
};
2919
}
3020

3121
export const flags = {
32-
showSites: setupFlag('sites', 'When disabled, sites view will show high demand'),
33-
showCsvImport: setupFlag('csv-import', 'When disabled, documents view will hide import button')
22+
showSites: isFlagEnabled('sites'),
23+
showCsvImport: isFlagEnabled('csv-import')
3424
};

src/routes/(console)/project-[region]-[project]/databases/database-[database]/collection-[collection]/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
analyticsSource="database_documents" />
101101
<Layout.Stack direction="row" alignItems="center" justifyContent="flex-end">
102102
<ViewSelector view={data.view} {columns} hideView />
103-
{#if flags.showCsvImport(data.account, data.organization)}
103+
{#if flags.showCsvImport(data)}
104104
<Button
105105
secondary
106106
event={Click.DatabaseImportCsv}

src/routes/(console)/project-[region]-[project]/sites/+page.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const load = async ({ url, depends, route, params, parent }) => {
1414
const offset = pageToOffset(page, limit);
1515
const view = getView(url, route, View.Grid, View.Grid);
1616

17-
if (!flags.showSites(data.account, data.organization)) {
17+
if (!flags.showSites(data)) {
1818
return {
1919
sitesLive: false,
2020
offset,

0 commit comments

Comments
 (0)