-
Notifications
You must be signed in to change notification settings - Fork 4
Eng 1616 add getconfigtree equivalent for block pros on init #944
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: eng-1470-test-dual-read-with-flag-on-and-fix-gapsv2
Are you sure you want to change the base?
Changes from all commits
343dc11
4d5c720
b13d401
4140f5c
aea086d
24e521b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -863,8 +863,10 @@ export const setGlobalSetting = (keys: string[], value: json): void => { | |
| }); | ||
| }; | ||
|
|
||
| export const getAllRelations = (): DiscourseRelation[] => { | ||
| const settings = getGlobalSettings(); | ||
| export const getAllRelations = ( | ||
| snapshot?: SettingsSnapshot, | ||
| ): DiscourseRelation[] => { | ||
| const settings = snapshot ? snapshot.globalSettings : getGlobalSettings(); | ||
|
|
||
| return Object.entries(settings.Relations).flatMap(([id, relation]) => | ||
| relation.ifConditions.map((ifCondition) => ({ | ||
|
|
@@ -909,6 +911,63 @@ export const getPersonalSetting = <T = unknown>( | |
| return blockPropsValue as T | undefined; | ||
| }; | ||
|
|
||
| export type SettingsSnapshot = { | ||
| featureFlags: FeatureFlags; | ||
| globalSettings: GlobalSettings; | ||
| personalSettings: PersonalSettings; | ||
| }; | ||
|
|
||
| export const bulkReadSettings = (): SettingsSnapshot => { | ||
| const pageResult = window.roamAlphaAPI.pull( | ||
| "[{:block/children [:block/string :block/props]}]", | ||
| [":node/title", DG_BLOCK_PROP_SETTINGS_PAGE_TITLE], | ||
| ) as Record<string, json> | null; | ||
|
|
||
| const children = (pageResult?.[":block/children"] ?? []) as Record< | ||
| string, | ||
| json | ||
| >[]; | ||
| const personalKey = getPersonalSettingsKey(); | ||
| let featureFlagsProps: json = {}; | ||
| let globalProps: json = {}; | ||
| let personalProps: json = {}; | ||
|
|
||
| for (const child of children) { | ||
| const text = child[":block/string"]; | ||
| if (typeof text !== "string") continue; | ||
| const rawBlockProps = child[":block/props"]; | ||
| const blockProps = | ||
| rawBlockProps && typeof rawBlockProps === "object" | ||
| ? normalizeProps(rawBlockProps) | ||
| : {}; | ||
| if (text === TOP_LEVEL_BLOCK_PROP_KEYS.featureFlags) { | ||
| featureFlagsProps = blockProps; | ||
| } else if (text === TOP_LEVEL_BLOCK_PROP_KEYS.global) { | ||
| globalProps = blockProps; | ||
| } else if (text === personalKey) { | ||
| personalProps = blockProps; | ||
| } | ||
| } | ||
|
|
||
| const featureFlags = FeatureFlagsSchema.parse(featureFlagsProps || {}); | ||
|
|
||
| if (!featureFlags["Use new settings store"]) { | ||
| return { | ||
| featureFlags, | ||
| globalSettings: GlobalSettingsSchema.parse(readAllLegacyGlobalSettings()), | ||
| personalSettings: PersonalSettingsSchema.parse( | ||
| readAllLegacyPersonalSettings(), | ||
| ), | ||
| }; | ||
|
Comment on lines
+954
to
+961
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 bulkReadSettings applies strict zod parse to legacy data that old code paths returned raw When the new settings store is disabled (the default), Affected code path in bulkReadSettingsThe legacy fallback at The migration code ( Prompt for agentsWas this helpful? React with 👍 or 👎 to provide feedback. |
||
| } | ||
|
|
||
| return { | ||
| featureFlags, | ||
| globalSettings: GlobalSettingsSchema.parse(globalProps || {}), | ||
| personalSettings: PersonalSettingsSchema.parse(personalProps || {}), | ||
| }; | ||
| }; | ||
|
|
||
| export const setPersonalSetting = (keys: string[], value: json): void => { | ||
| if (keys.length === 0) { | ||
| internalError({ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe
getPersonalSettingwas checking ifisNewSettingsStoreEnabled, but it doesn't look likebulkReadSettingsis doing this anymore.Specifically example would be:
const disallowDiagnostics = settingsSnapshot.personalSettings[PERSONAL_KEYS.disableProductDiagnostics];If the new store settings aren't enabled, would the migration have happened yet?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added the check, I missed it.