-
Notifications
You must be signed in to change notification settings - Fork 4
ENG-1573: Merge sync functionality to both Duplicate node alert and suggestive mode checkboxes in admin panel. #929
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
Open
sid597
wants to merge
1
commit into
main
Choose a base branch
from
eng-1573-separate-sync-mode-flagtoggle-from-suggestive-mode
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,6 @@ | ||
| import React, { useState, useEffect, useMemo } from "react"; | ||
| import React, { useState, useEffect } from "react"; | ||
| import { | ||
| Button, | ||
| Checkbox, | ||
| HTMLTable, | ||
| Alert, | ||
| Intent, | ||
|
|
@@ -12,7 +11,6 @@ import { | |
| TabId, | ||
| Tabs, | ||
| } from "@blueprintjs/core"; | ||
| import Description from "roamjs-components/components/Description"; | ||
| import { Select } from "@blueprintjs/select"; | ||
| import { | ||
| getSupabaseContext, | ||
|
|
@@ -29,15 +27,13 @@ import { | |
| 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 { | ||
| setFeatureFlag, | ||
| getFeatureFlag, | ||
| isSyncEnabled, | ||
| } from "~/components/settings/utils/accessors"; | ||
| import { FeatureFlagPanel } from "./components/BlockPropSettingPanels"; | ||
| import type { FeatureFlags } from "./utils/zodSchema"; | ||
|
|
||
| const NodeRow = ({ node }: { node: PConceptFull }) => { | ||
| return ( | ||
|
|
@@ -258,106 +254,130 @@ const NodeListTab = (): React.ReactElement => { | |
| }; | ||
|
|
||
| const FeatureFlagsTab = (): React.ReactElement => { | ||
| const settings = useMemo(() => { | ||
| refreshConfigTree(); | ||
| return getFormattedConfigTree(); | ||
| }, []); | ||
|
|
||
| const [suggestiveModeEnabled, setSuggestiveModeEnabled] = useState( | ||
| settings.suggestiveModeEnabled.value || false, | ||
| const [isConsentAlertOpen, setIsConsentAlertOpen] = useState(false); | ||
| const [isInstructionAlertOpen, setIsInstructionAlertOpen] = useState(false); | ||
| const [isFirstSyncEnable, setIsFirstSyncEnable] = useState(false); | ||
| const [pendingFeatureKey, setPendingFeatureKey] = useState< | ||
| keyof FeatureFlags | null | ||
| >(null); | ||
| const [duplicateNodeAlertValue, setDuplicateNodeAlertValue] = useState( | ||
| getFeatureFlag("Duplicate node alert enabled"), | ||
| ); | ||
| const [suggestiveModeUid, setSuggestiveModeUid] = useState( | ||
| settings.suggestiveModeEnabled.uid, | ||
| const [suggestiveOverlayValue, setSuggestiveOverlayValue] = useState( | ||
| getFeatureFlag("Suggestive mode overlay enabled"), | ||
| ); | ||
| const [isAlertOpen, setIsAlertOpen] = useState(false); | ||
| const [isInstructionOpen, setIsInstructionOpen] = useState(false); | ||
|
|
||
| const syncAlreadyEnabled = duplicateNodeAlertValue || suggestiveOverlayValue; | ||
|
|
||
| const ensureSyncEnabled = ( | ||
| featureKey: keyof FeatureFlags, | ||
| ): Promise<boolean> => { | ||
| if (syncAlreadyEnabled) { | ||
| return Promise.resolve(true); | ||
| } | ||
| setPendingFeatureKey(featureKey); | ||
| setIsConsentAlertOpen(true); | ||
| return Promise.resolve(false); | ||
| }; | ||
|
|
||
| const handleFeatureToggled = ( | ||
| checked: boolean, | ||
| setter: (v: boolean) => void, | ||
| ) => { | ||
| setter(checked); | ||
| if (checked) { | ||
| setIsInstructionAlertOpen(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); | ||
| setFeatureFlag("Suggestive mode enabled", false); | ||
| } | ||
| }} | ||
| 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'" | ||
| } | ||
| /> | ||
| </> | ||
| <FeatureFlagPanel | ||
| title="Duplicate node alert" | ||
| description="Show possible duplicate nodes when viewing a discourse node page." | ||
| featureKey="Duplicate node alert enabled" | ||
| value={duplicateNodeAlertValue} | ||
| onBeforeEnable={() => ensureSyncEnabled("Duplicate node alert enabled")} | ||
| onAfterChange={(checked) => | ||
| handleFeatureToggled(checked, setDuplicateNodeAlertValue) | ||
| } | ||
| /> | ||
|
|
||
| <FeatureFlagPanel | ||
| title="Suggestive mode overlay" | ||
| description="Overlay suggestive mode button over discourse node references." | ||
| featureKey="Suggestive mode overlay enabled" | ||
| value={suggestiveOverlayValue} | ||
| onBeforeEnable={() => | ||
| ensureSyncEnabled("Suggestive mode overlay enabled") | ||
| } | ||
| onAfterChange={(checked) => | ||
| handleFeatureToggled(checked, setSuggestiveOverlayValue) | ||
| } | ||
| /> | ||
|
|
||
| <Alert | ||
| isOpen={isAlertOpen} | ||
| isOpen={isConsentAlertOpen} | ||
|
Member
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. nit: we could do this with a single multi step dialog: https://blueprintjs.com/docs/versions/3/#core/components/dialog.multistep-dialog |
||
| onConfirm={() => { | ||
| void createBlock({ | ||
| parentUid: settings.settingsUid, | ||
| node: { text: "(BETA) Suggestive Mode Enabled" }, | ||
| }).then((uid) => { | ||
| setSuggestiveModeUid(uid); | ||
| setSuggestiveModeEnabled(true); | ||
| setFeatureFlag("Suggestive mode enabled", true); | ||
| setIsAlertOpen(false); | ||
| setIsInstructionOpen(true); | ||
| }); | ||
| if (pendingFeatureKey) { | ||
| setFeatureFlag(pendingFeatureKey, true); | ||
| if (pendingFeatureKey === "Duplicate node alert enabled") { | ||
| setDuplicateNodeAlertValue(true); | ||
| } else if ( | ||
| pendingFeatureKey === "Suggestive mode overlay enabled" | ||
| ) { | ||
| setSuggestiveOverlayValue(true); | ||
| } | ||
| } | ||
| setIsConsentAlertOpen(false); | ||
| setIsFirstSyncEnable(true); | ||
| setIsInstructionAlertOpen(true); | ||
| }} | ||
| onCancel={() => { | ||
| setPendingFeatureKey(null); | ||
| setIsConsentAlertOpen(false); | ||
| }} | ||
| onCancel={() => setIsAlertOpen(false)} | ||
| canEscapeKeyCancel={true} | ||
| canOutsideClickCancel={true} | ||
| intent={Intent.PRIMARY} | ||
| confirmButtonText="Enable" | ||
| cancelButtonText="Cancel" | ||
| > | ||
| <p> | ||
| Enabling Suggestive Mode will send your data (nodes) to our servers | ||
| and OpenAI servers to generate embeddings and suggestions. | ||
| Enabling this feature will send your data (nodes) to our servers and | ||
| OpenAI servers to generate embeddings and suggestions. | ||
| </p> | ||
| <p>Are you sure you want to proceed?</p> | ||
| </Alert> | ||
|
|
||
| <Alert | ||
| isOpen={isInstructionOpen} | ||
| isOpen={isInstructionAlertOpen} | ||
| onConfirm={() => window.location.reload()} | ||
| onCancel={() => setIsInstructionOpen(false)} | ||
| onCancel={() => { | ||
| setIsInstructionAlertOpen(false); | ||
| setIsFirstSyncEnable(false); | ||
| }} | ||
| confirmButtonText="Reload Graph" | ||
| cancelButtonText="Later" | ||
| 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'"} | ||
| </p> | ||
| <p>Please reload the graph for this change to take effect.</p> | ||
| {isFirstSyncEnable && ( | ||
| <> | ||
| <p> | ||
| If this is the first time enabling sync, you will need to generate | ||
| and upload all node embeddings. | ||
| </p> | ||
| <p> | ||
| After reloading, go to Sync mode{" "} | ||
| { | ||
| "-> Sync config -> Click on 'Generate & Upload All Node Embeddings'" | ||
| } | ||
| </p> | ||
| </> | ||
| )} | ||
| </Alert> | ||
|
|
||
| <FeatureFlagPanel | ||
| title="Duplicate node alert" | ||
| description="Show possible duplicate nodes when viewing a discourse node page. Requires Suggestive mode to be enabled." | ||
| featureKey="Duplicate node alert enabled" | ||
| initialValue={getFeatureFlag("Duplicate node alert enabled")} | ||
| disabled={!suggestiveModeEnabled} | ||
| /> | ||
|
|
||
| <Button | ||
| className="w-96" | ||
| icon="send-message" | ||
|
|
@@ -379,10 +399,6 @@ const FeatureFlagsTab = (): React.ReactElement => { | |
|
|
||
| const AdminPanel = (): React.ReactElement => { | ||
| const [selectedTabId, setSelectedTabId] = useState<TabId>("admin"); | ||
| const settings = useMemo(() => { | ||
| refreshConfigTree(); | ||
| return getFormattedConfigTree(); | ||
| }, []); | ||
|
|
||
| return ( | ||
| <Tabs | ||
|
|
@@ -408,10 +424,10 @@ const AdminPanel = (): React.ReactElement => { | |
| </div> | ||
| } | ||
| /> | ||
| {settings.suggestiveModeEnabled.value && ( | ||
| {isSyncEnabled() && ( | ||
| <Tab | ||
| id="suggestive-mode-settings" | ||
| title="Suggestive mode" | ||
| id="sync-mode-settings" | ||
| title="Sync mode" | ||
| className="overflow-y-auto" | ||
| panel={<SuggestiveModeSettings />} | ||
| /> | ||
|
|
||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.