Skip to content

Commit 3008b6b

Browse files
authored
ENG-1421: Derive TOP_LEVEL_BLOCK_PROP_KEYS from staticTopLevelEntries (#889)
* ENG-1421: Derive TOP_LEVEL_BLOCK_PROP_KEYS from staticTopLevelEntries * ENG-1421: Consolidate into single STATIC_TOP_LEVEL_ENTRIES export
1 parent eef3558 commit 3008b6b

3 files changed

Lines changed: 12 additions & 19 deletions

File tree

apps/roam/src/components/settings/utils/accessors.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { z } from "zod";
1111
import {
1212
DG_BLOCK_PROP_SETTINGS_PAGE_TITLE,
1313
DISCOURSE_NODE_PAGE_PREFIX,
14-
TOP_LEVEL_BLOCK_PROP_KEYS,
14+
STATIC_TOP_LEVEL_ENTRIES,
1515
FeatureFlagsSchema,
1616
GlobalSettingsSchema,
1717
PersonalSettingsSchema,
@@ -274,7 +274,7 @@ const setBlockPropBasedSettings = ({
274274

275275
export const getFeatureFlags = (): FeatureFlags => {
276276
const { blockProps } = getBlockPropBasedSettings({
277-
keys: [TOP_LEVEL_BLOCK_PROP_KEYS.featureFlags],
277+
keys: [STATIC_TOP_LEVEL_ENTRIES.featureFlags.key],
278278
});
279279

280280
return FeatureFlagsSchema.parse(blockProps || {});
@@ -292,14 +292,14 @@ export const setFeatureFlag = (
292292
const validatedValue = z.boolean().parse(value);
293293

294294
setBlockPropBasedSettings({
295-
keys: [TOP_LEVEL_BLOCK_PROP_KEYS.featureFlags, key],
295+
keys: [STATIC_TOP_LEVEL_ENTRIES.featureFlags.key, key],
296296
value: validatedValue,
297297
});
298298
};
299299

300300
export const getGlobalSettings = (): GlobalSettings => {
301301
const { blockProps } = getBlockPropBasedSettings({
302-
keys: [TOP_LEVEL_BLOCK_PROP_KEYS.global],
302+
keys: [STATIC_TOP_LEVEL_ENTRIES.global.key],
303303
});
304304

305305
return GlobalSettingsSchema.parse(blockProps || {});
@@ -337,7 +337,7 @@ export const setGlobalSetting = (keys: string[], value: json): void => {
337337
}
338338

339339
setBlockPropBasedSettings({
340-
keys: [TOP_LEVEL_BLOCK_PROP_KEYS.global, ...keys],
340+
keys: [STATIC_TOP_LEVEL_ENTRIES.global.key, ...keys],
341341
value,
342342
});
343343
};

apps/roam/src/components/settings/utils/pullWatchers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { type json, normalizeProps } from "~/utils/getBlockProps";
22
import type { AddPullWatch, PullBlock } from "roamjs-components/types";
33
import {
4-
TOP_LEVEL_BLOCK_PROP_KEYS,
4+
STATIC_TOP_LEVEL_ENTRIES,
55
getPersonalSettingsKey,
66
FeatureFlagsSchema,
77
GlobalSettingsSchema,
@@ -165,8 +165,8 @@ export const setupPullWatchOnSettingsPage = (
165165
const watches: Parameters<AddPullWatch>[] = [];
166166

167167
const featureFlagsBlockUid =
168-
blockUids[TOP_LEVEL_BLOCK_PROP_KEYS.featureFlags];
169-
const globalSettingsBlockUid = blockUids[TOP_LEVEL_BLOCK_PROP_KEYS.global];
168+
blockUids[STATIC_TOP_LEVEL_ENTRIES.featureFlags.key];
169+
const globalSettingsBlockUid = blockUids[STATIC_TOP_LEVEL_ENTRIES.global.key];
170170
const personalSettingsKey = getPersonalSettingsKey();
171171
const personalSettingsBlockUid = blockUids[personalSettingsKey];
172172

apps/roam/src/components/settings/utils/zodSchema.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -273,26 +273,19 @@ export const getPersonalSettingsKey = (): string => {
273273
return cachedPersonalSettingsKey;
274274
};
275275

276-
const staticTopLevelEntries = [
277-
{
278-
propKey: "featureFlags" as const,
276+
export const STATIC_TOP_LEVEL_ENTRIES = {
277+
featureFlags: {
279278
key: "Feature Flags",
280279
schema: FeatureFlagsSchema,
281280
},
282-
{
283-
propKey: "global" as const,
281+
global: {
284282
key: "Global",
285283
schema: GlobalSettingsSchema,
286284
},
287-
];
288-
289-
export const TOP_LEVEL_BLOCK_PROP_KEYS = {
290-
featureFlags: "Feature Flags",
291-
global: "Global",
292285
} as const;
293286

294287
export const getTopLevelBlockPropsConfig = () => [
295-
...staticTopLevelEntries,
288+
...Object.values(STATIC_TOP_LEVEL_ENTRIES),
296289
{ key: getPersonalSettingsKey(), schema: PersonalSettingsSchema },
297290
];
298291

0 commit comments

Comments
 (0)