Skip to content

Commit a9bc1c9

Browse files
committed
More reliable user fetching
1 parent 9280f32 commit a9bc1c9

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
lines changed

src/lib/flags.ts

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
11
import { env } from '$env/dynamic/public';
2-
import { get } from 'svelte/store';
3-
import { user } from '$lib/stores/user';
4-
import { organization } from '$lib/stores/organization';
2+
import type { Organization } from './stores/organization';
3+
import type { Account } from './stores/user';
54

65
export const PUBLIC_CONSOLE_FEATURE_FLAGS = env.PUBLIC_CONSOLE_FEATURE_FLAGS ?? '';
76

87
function setupFlag(name: string, _description: string) {
98
// TODO: Use flags library that provides visual component during development
109

11-
if (PUBLIC_CONSOLE_FEATURE_FLAGS.includes(name)) {
12-
return true;
13-
}
10+
return (user: Account, organization: Organization) => {
11+
if (PUBLIC_CONSOLE_FEATURE_FLAGS.includes(name)) {
12+
return true;
13+
}
1414

15-
const userInstance = get(user);
16-
const userPrefs = userInstance?.prefs ?? {};
17-
const userFlag = userPrefs[`flags-${name}`] ?? null;
18-
if (userFlag) {
19-
return true;
20-
}
15+
const userPrefs = user?.prefs ?? {};
16+
const userFlag = userPrefs[`flags-${name}`] ?? null;
17+
if (userFlag) {
18+
return true;
19+
}
2120

22-
const organizationInstance = get(organization);
23-
const organizationPrefs = organizationInstance?.prefs ?? {};
24-
const organizationFlag = organizationPrefs[`flags-${name}`] ?? null;
25-
if (organizationFlag) {
26-
return true;
27-
}
21+
const organizationPrefs = organization?.prefs ?? {};
22+
const organizationFlag = organizationPrefs[`flags-${name}`] ?? null;
23+
if (organizationFlag) {
24+
return true;
25+
}
2826

29-
return false;
27+
return false;
28+
};
3029
}
3130

3231
export const flags = {

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}
103+
{#if flags.showCsvImport(data.account, data.organization)}
104104
<Button
105105
secondary
106106
event={Click.DatabaseImportCsv}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ import { getLimit, getPage, getSearch, getView, pageToOffset, View } from '$lib/
44
import { CARD_LIMIT, Dependencies } from '$lib/constants';
55
import { flags } from '$lib/flags';
66

7-
export const load = async ({ url, depends, route, params }) => {
7+
export const load = async ({ url, depends, route, params, parent }) => {
8+
const data = await parent();
9+
810
depends(Dependencies.SITES);
911
const page = getPage(url);
1012
const search = getSearch(url);
1113
const limit = getLimit(url, route, CARD_LIMIT);
1214
const offset = pageToOffset(page, limit);
1315
const view = getView(url, route, View.Grid, View.Grid);
1416

15-
if (!flags.showSites) {
17+
if (!flags.showSites(data.account, data.organization)) {
1618
return {
1719
sitesLive: false,
1820
offset,

0 commit comments

Comments
 (0)