-
Notifications
You must be signed in to change notification settings - Fork 4
ENG-1274: Migrate feature flags #684
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
08b3adf
new checkbox component for feature flag get and set in props, migrate…
sid597 219b066
use getFeatureFlag()
sid597 ba1773d
rerender left sidebar on enable/disable
sid597 c6b2937
fix component location
sid597 42bce3a
make feature flags fully reactive
sid597 1adcb4e
fix
sid597 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| type LeftSidebarLifecycle = { | ||
| mount: (() => Promise<void>) | null; | ||
| unmount: (() => void) | null; | ||
| }; | ||
|
|
||
| const lifecycle: LeftSidebarLifecycle = { | ||
| mount: null, | ||
| unmount: null, | ||
| }; | ||
|
|
||
| export const registerLeftSidebarLifecycle = (fns: { | ||
| mount: () => Promise<void>; | ||
| unmount: () => void; | ||
| }): void => { | ||
| lifecycle.mount = fns.mount; | ||
| lifecycle.unmount = fns.unmount; | ||
| }; | ||
|
|
||
| export const remountLeftSidebar = async (): Promise<void> => { | ||
| if (lifecycle.mount) { | ||
| await lifecycle.mount(); | ||
| } | ||
| }; | ||
|
|
||
| export const unmountLeftSidebar = (): void => { | ||
| if (lifecycle.unmount) { | ||
| lifecycle.unmount(); | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import React, { useState, useEffect, useMemo } from "react"; | ||
| import React, { useState, useEffect, useRef } from "react"; | ||
| import { | ||
| Button, | ||
| Checkbox, | ||
|
|
@@ -12,9 +12,7 @@ import { | |
| TabId, | ||
| Tabs, | ||
| } from "@blueprintjs/core"; | ||
| import Description from "roamjs-components/components/Description"; | ||
| import { Select } from "@blueprintjs/select"; | ||
| import { getSetting, setSetting } from "~/utils/extensionSettings"; | ||
| import { | ||
| getSupabaseContext, | ||
| getLoggedInClient, | ||
|
|
@@ -32,11 +30,8 @@ import { countReifiedRelations } from "~/utils/createReifiedBlock"; | |
| import type { DGSupabaseClient } from "@repo/database/lib/client"; | ||
| import internalError from "~/utils/internalError"; | ||
| import SuggestiveModeSettings from "./SuggestiveModeSettings"; | ||
| import { getFormattedConfigTree } from "~/utils/discourseConfigRef"; | ||
| import refreshConfigTree from "~/utils/refreshConfigTree"; | ||
| import createBlock from "roamjs-components/writes/createBlock"; | ||
| import deleteBlock from "roamjs-components/writes/deleteBlock"; | ||
| import { USE_REIFIED_RELATIONS } from "~/data/userSettings"; | ||
| import { FeatureFlagPanel } from "./components/BlockPropSettingPanels"; | ||
| import { useFeatureFlag } from "./utils/hooks"; | ||
|
|
||
| const NodeRow = ({ node }: { node: PConceptFull }) => { | ||
| return ( | ||
|
|
@@ -261,7 +256,7 @@ const MigrationTab = (): React.ReactElement => { | |
| const [useMigrationResults, setMigrationResults] = useState<string>(""); | ||
| const [useOngoing, setOngoing] = useState<boolean>(false); | ||
| const [useDryRun, setDryRun] = useState<boolean>(false); | ||
| const enabled = getSetting<boolean>(USE_REIFIED_RELATIONS, false); | ||
| const enabled = useFeatureFlag("Reified Relation Triples"); | ||
| const doMigrateRelations = async () => { | ||
| setOngoing(true); | ||
| try { | ||
|
|
@@ -331,64 +326,40 @@ const MigrationTab = (): React.ReactElement => { | |
| }; | ||
|
|
||
| const FeatureFlagsTab = (): React.ReactElement => { | ||
| const [useReifiedRelations, setUseReifiedRelations] = useState<boolean>( | ||
| getSetting<boolean>(USE_REIFIED_RELATIONS, false), | ||
| ); | ||
| const settings = useMemo(() => { | ||
| refreshConfigTree(); | ||
| return getFormattedConfigTree(); | ||
| }, []); | ||
|
|
||
| const [suggestiveModeEnabled, setSuggestiveModeEnabled] = useState( | ||
| settings.suggestiveModeEnabled.value || false, | ||
| ); | ||
| const [suggestiveModeUid, setSuggestiveModeUid] = useState( | ||
| settings.suggestiveModeEnabled.uid, | ||
| ); | ||
| const [isAlertOpen, setIsAlertOpen] = useState(false); | ||
| const [isInstructionOpen, setIsInstructionOpen] = useState(false); | ||
| const confirmResolverRef = useRef<((value: boolean) => void) | null>(null); | ||
|
|
||
| const handleSuggestiveModeBeforeEnable = (): Promise<boolean> => { | ||
| return new Promise((resolve) => { | ||
| confirmResolverRef.current = resolve; | ||
| setIsAlertOpen(true); | ||
| }); | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="flex flex-col gap-4 p-4"> | ||
| <Checkbox | ||
| checked={suggestiveModeEnabled} | ||
| onChange={(e) => { | ||
| const checked = (e.target as HTMLInputElement).checked; | ||
| if (checked) { | ||
| setIsAlertOpen(true); | ||
| } else { | ||
| if (suggestiveModeUid) { | ||
| void deleteBlock(suggestiveModeUid); | ||
| setSuggestiveModeUid(undefined); | ||
| } | ||
| setSuggestiveModeEnabled(false); | ||
| } | ||
| <FeatureFlagPanel | ||
| title="(BETA) Suggestive Mode Enabled" | ||
| description="Whether or not to enable the suggestive mode, if this is first time enabling it, you will need to generate and upload all node embeddings to supabase. Go to Suggestive Mode -> Sync Config -> Click on 'Generate & Upload All Node Embeddings'" | ||
| featureKey="Suggestive Mode Enabled" | ||
| onBeforeEnable={handleSuggestiveModeBeforeEnable} | ||
| onAfterChange={(checked) => { | ||
| if (checked) setIsInstructionOpen(true); | ||
| }} | ||
| labelElement={ | ||
| <> | ||
| (BETA) Suggestive Mode Enabled | ||
| <Description | ||
| description={ | ||
| "Whether or not to enable the suggestive mode, if this is first time enabling it, you will need to generate and upload all node embeddings to supabase. Go to Suggestive Mode -> Sync Config -> Click on 'Generate & Upload All Node Embeddings'" | ||
| } | ||
| /> | ||
| </> | ||
| } | ||
| /> | ||
| <Alert | ||
| isOpen={isAlertOpen} | ||
| onConfirm={() => { | ||
| void createBlock({ | ||
| parentUid: settings.settingsUid, | ||
| node: { text: "(BETA) Suggestive Mode Enabled" }, | ||
| }).then((uid) => { | ||
| setSuggestiveModeUid(uid); | ||
| setSuggestiveModeEnabled(true); | ||
| setIsAlertOpen(false); | ||
| setIsInstructionOpen(true); | ||
| }); | ||
| confirmResolverRef.current?.(true); | ||
| confirmResolverRef.current = null; | ||
| setIsAlertOpen(false); | ||
| }} | ||
| onCancel={() => { | ||
| confirmResolverRef.current?.(false); | ||
| confirmResolverRef.current = null; | ||
| setIsAlertOpen(false); | ||
| }} | ||
| onCancel={() => setIsAlertOpen(false)} | ||
| canEscapeKeyCancel={true} | ||
| canOutsideClickCancel={true} | ||
| intent={Intent.PRIMARY} | ||
|
|
@@ -404,45 +375,25 @@ const FeatureFlagsTab = (): React.ReactElement => { | |
|
|
||
| <Alert | ||
| isOpen={isInstructionOpen} | ||
| onConfirm={() => window.location.reload()} | ||
| onConfirm={() => setIsInstructionOpen(false)} | ||
| onCancel={() => setIsInstructionOpen(false)} | ||
| confirmButtonText="Reload Graph" | ||
| cancelButtonText="Later" | ||
| confirmButtonText="Got it" | ||
|
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. "Ok" |
||
| intent={Intent.PRIMARY} | ||
| > | ||
| <p> | ||
| If this is the first time enabling it, you will need to generate and | ||
| upload all node embeddings to supabase. | ||
| </p> | ||
| <p> | ||
| Please reload the graph to see the new 'Suggestive Mode' | ||
| tab. | ||
| </p> | ||
| <p> | ||
| Then go to Suggestive Mode{" "} | ||
| {"-> Sync Config -> Click on 'Generate & Upload All Node Embeddings'"} | ||
| Go to the new 'Suggestive Mode' tab, then Sync Config{" "} | ||
| {"-> Click on 'Generate & Upload All Node Embeddings'"} | ||
| </p> | ||
| </Alert> | ||
|
|
||
| <Checkbox | ||
| defaultChecked={useReifiedRelations} | ||
| onChange={(e) => { | ||
| const target = e.target as HTMLInputElement; | ||
| setUseReifiedRelations(target.checked); | ||
| void setSetting(USE_REIFIED_RELATIONS, target.checked).catch( | ||
| () => undefined, | ||
| ); | ||
| }} | ||
| labelElement={ | ||
| <> | ||
| Reified Relation Triples | ||
| <Description | ||
| description={ | ||
| "When ON, relations are read/written as reifiedRelationUid in [[roam/js/discourse-graph/relations]]." | ||
| } | ||
| /> | ||
| </> | ||
| } | ||
| <FeatureFlagPanel | ||
| title="Reified Relation Triples" | ||
| description="When ON, relations are read/written as reifiedRelationUid in [[roam/js/discourse-graph/relations]]." | ||
| featureKey="Reified Relation Triples" | ||
| /> | ||
|
|
||
| <Button | ||
|
|
@@ -466,10 +417,7 @@ const FeatureFlagsTab = (): React.ReactElement => { | |
|
|
||
| const AdminPanel = (): React.ReactElement => { | ||
| const [selectedTabId, setSelectedTabId] = useState<TabId>("admin"); | ||
| const settings = useMemo(() => { | ||
| refreshConfigTree(); | ||
| return getFormattedConfigTree(); | ||
| }, []); | ||
| const suggestiveModeEnabled = useFeatureFlag("Suggestive Mode Enabled"); | ||
|
|
||
| return ( | ||
| <Tabs | ||
|
|
@@ -504,7 +452,7 @@ const AdminPanel = (): React.ReactElement => { | |
| </div> | ||
| } | ||
| /> | ||
| {settings.suggestiveModeEnabled.value && ( | ||
| {suggestiveModeEnabled && ( | ||
| <Tab | ||
| id="suggestive-mode-settings" | ||
| title="Suggestive Mode" | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It looks like this is only calling blockProp based settings? I was under the assumption that we were going to run both at the same time while the migration was happening.