Skip to content

Commit 334f89a

Browse files
committed
Simple implementation of feature flags
1 parent 3b77754 commit 334f89a

File tree

8 files changed

+27
-17
lines changed

8 files changed

+27
-17
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
PUBLIC_CONSOLE_MODE=self-hosted
2+
PUBLIC_CONSOLE_FEATURE_FLAGS=
23
PUBLIC_APPWRITE_MULTI_REGION=false
34
PUBLIC_APPWRITE_ENDPOINT=http://localhost/v1
4-
55
PUBLIC_STRIPE_KEY=
66
PUBLIC_GROWTH_ENDPOINT=

.github/workflows/publish.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ jobs:
7878
labels: ${{ steps.meta.outputs.labels }}
7979
build-args: |
8080
"PUBLIC_CONSOLE_MODE=cloud"
81+
"PUBLIC_CONSOLE_FEATURE_FLAGS="sites,csv-import"
8182
"PUBLIC_APPWRITE_MULTI_REGION=true"
8283
"PUBLIC_GROWTH_ENDPOINT=${{ secrets.PUBLIC_GROWTH_ENDPOINT }}"
8384
"PUBLIC_STRIPE_KEY=${{ secrets.PUBLIC_STRIPE_KEY_STAGE }}"

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ ADD ./src /app/src
2121
ADD ./static /app/static
2222

2323
ARG PUBLIC_CONSOLE_MODE
24+
ARG PUBLIC_CONSOLE_FEATURE_FLAGS
2425
ARG PUBLIC_APPWRITE_MULTI_REGION
2526
ARG PUBLIC_APPWRITE_ENDPOINT
2627
ARG PUBLIC_GROWTH_ENDPOINT
@@ -31,6 +32,7 @@ ARG SENTRY_RELEASE
3132
ENV PUBLIC_APPWRITE_ENDPOINT=$PUBLIC_APPWRITE_ENDPOINT
3233
ENV PUBLIC_GROWTH_ENDPOINT=$PUBLIC_GROWTH_ENDPOINT
3334
ENV PUBLIC_CONSOLE_MODE=$PUBLIC_CONSOLE_MODE
35+
ENV PUBLIC_CONSOLE_FEATURE_FLAGS=$PUBLIC_CONSOLE_FEATURE_FLAGS
3436
ENV PUBLIC_APPWRITE_MULTI_REGION=$PUBLIC_APPWRITE_MULTI_REGION
3537
ENV PUBLIC_STRIPE_KEY=$PUBLIC_STRIPE_KEY
3638
ENV SENTRY_AUTH_TOKEN=$SENTRY_AUTH_TOKEN

build.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ async function main() {
2424
log(bold().magenta('APPWRITE CONSOLE'));
2525
log();
2626
logEnv('CONSOLE MODE', env?.PUBLIC_CONSOLE_MODE);
27+
logEnv('CONSOLE FEATURE FLAGS', env?.PUBLIC_CONSOLE_FEATURE_FLAGS);
2728
logEnv('MULTI REGION', env?.PUBLIC_APPWRITE_MULTI_REGION);
2829
logEnv('APPWRITE ENDPOINT', env?.PUBLIC_APPWRITE_ENDPOINT, 'relative');
2930
logEnv('GROWTH ENDPOINT', env?.PUBLIC_GROWTH_ENDPOINT);

compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ services:
55
context: .
66
args:
77
PUBLIC_CONSOLE_MODE: ${PUBLIC_CONSOLE_MODE}
8+
PUBLIC_CONSOLE_FEATURE_FLAGS: ${PUBLIC_CONSOLE_FEATURE_FLAGS}
89
PUBLIC_APPWRITE_MULTI_REGION: ${PUBLIC_APPWRITE_MULTI_REGION}
910
PUBLIC_APPWRITE_ENDPOINT: ${PUBLIC_APPWRITE_ENDPOINT}
1011
PUBLIC_GROWTH_ENDPOINT: ${PUBLIC_GROWTH_ENDPOINT}
@@ -21,6 +22,7 @@ services:
2122
- build/
2223
environment:
2324
- PUBLIC_CONSOLE_MODE
25+
- PUBLIC_CONSOLE_FEATURE_FLAGS
2426
- PUBLIC_APPWRITE_MULTI_REGION
2527
- PUBLIC_APPWRITE_ENDPOINT
2628
- PUBLIC_GROWTH_ENDPOINT

src/lib/flags.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { env } from '$env/dynamic/public';
2+
3+
export const PUBLIC_CONSOLE_FEATURE_FLAGS = env.PUBLIC_CONSOLE_FEATURE_FLAGS ?? '';
4+
5+
function setupFlag(name: string, _description: string) {
6+
// TODO: Use flags library that provides visual component
7+
return PUBLIC_CONSOLE_FEATURE_FLAGS.includes(name);
8+
}
9+
10+
export const flags = {
11+
showSites: setupFlag('sites', 'When disabled, sites view will show high demand'),
12+
showCsvImport: setupFlag('csv-import', 'When disabled, documents view will hide import button')
13+
};

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
import { base } from '$app/paths';
2525
import { IconPlus } from '@appwrite.io/pink-icons-svelte';
2626
import type { Models } from '@appwrite.io/console';
27-
import { organization } from '$lib/stores/organization';
28-
import { APPWRITE_OFFICIALS_ORG, isCloud } from '$lib/system';
27+
import { flags } from '$lib/flags';
2928
3029
export let data: PageData;
3130
@@ -88,14 +87,6 @@
8887
$isCsvImportInProgress = false;
8988
}
9089
}
91-
92-
/**
93-
* Controls visibility of CSV Imports feature:
94-
* - Shown if running on self-hosted
95-
* - Shown on cloud only if the organization is Appwrite's.
96-
* - Hidden on cloud for any non-Appwrite organization.
97-
*/
98-
$: showCsvImports = !isCloud || $organization.$id === APPWRITE_OFFICIALS_ORG;
9990
</script>
10091

10192
{#key page.params.collection}
@@ -109,7 +100,7 @@
109100
analyticsSource="database_documents" />
110101
<Layout.Stack direction="row" alignItems="center" justifyContent="flex-end">
111102
<ViewSelector view={data.view} {columns} hideView />
112-
{#if showCsvImports}
103+
{#if flags.showCsvImport}
113104
<Button
114105
secondary
115106
event={Click.DatabaseImportCsv}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Query, type Models } from '@appwrite.io/console';
22
import { sdk } from '$lib/stores/sdk';
33
import { getLimit, getPage, getSearch, getView, pageToOffset, View } from '$lib/helpers/load';
44
import { CARD_LIMIT, Dependencies } from '$lib/constants';
5+
import { flags } from '$lib/flags';
56

67
export const load = async ({ url, depends, route, params }) => {
78
depends(Dependencies.SITES);
@@ -11,11 +12,9 @@ export const load = async ({ url, depends, route, params }) => {
1112
const offset = pageToOffset(page, limit);
1213
const view = getView(url, route, View.Grid, View.Grid);
1314

14-
const sitesLive = false;
15-
16-
if (!sitesLive)
15+
if (!flags.showSites) {
1716
return {
18-
sitesLive,
17+
sitesLive: false,
1918
offset,
2019
limit,
2120
search,
@@ -25,6 +24,7 @@ export const load = async ({ url, depends, route, params }) => {
2524
sites: []
2625
} as Models.SiteList
2726
};
27+
}
2828

2929
const siteList = await sdk
3030
.forProject(params.region, params.project)
@@ -34,7 +34,7 @@ export const load = async ({ url, depends, route, params }) => {
3434
);
3535

3636
return {
37-
sitesLive,
37+
sitesLive: true,
3838
offset,
3939
limit,
4040
search,

0 commit comments

Comments
 (0)