-
Notifications
You must be signed in to change notification settings - Fork 4
ENG-1272 Migrate all small global settings components #688
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: main
Are you sure you want to change the base?
Changes from all commits
d06d8e7
224a20d
dcd3b6c
78b5481
d9aef91
6b5704f
30e4424
15f3a6b
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 |
|---|---|---|
|
|
@@ -2,13 +2,13 @@ | |
| import React, { useEffect, useState } from "react"; | ||
| import { Button, Intent, Tabs, Tab, TabId } from "@blueprintjs/core"; | ||
| import { getFormattedConfigTree } from "~/utils/discourseConfigRef"; | ||
| import FlagPanel from "roamjs-components/components/ConfigPanels/FlagPanel"; | ||
| import PageGroupsPanel from "./PageGroupPanel"; | ||
| import createBlock from "roamjs-components/writes/createBlock"; | ||
| import getPageUidByPageTitle from "roamjs-components/queries/getPageUidByPageTitle"; | ||
| import { DISCOURSE_CONFIG_PAGE_TITLE } from "~/utils/renderNodeConfigPage"; | ||
| import { createOrUpdateDiscourseEmbedding } from "~/utils/syncDgNodesToSupabase"; | ||
| import { render as renderToast } from "roamjs-components/components/Toast"; | ||
| import { GlobalFlagPanel } from "./components/BlockPropSettingPanels"; | ||
|
|
||
| const SuggestiveModeSettings = () => { | ||
| const settings = getFormattedConfigTree(); | ||
|
|
@@ -34,7 +34,7 @@ const SuggestiveModeSettings = () => { | |
| }, [suggestiveModeUid]); | ||
|
|
||
| const effectiveSuggestiveModeUid = | ||
| suggestiveModeUid || settings.suggestiveMode.parentUid; | ||
| suggestiveModeUid || settings.suggestiveMode.parentUid; | ||
|
|
||
| const [selectedTabId, setSelectedTabId] = useState<TabId>("page-groups"); | ||
|
|
||
|
|
@@ -64,35 +64,30 @@ const SuggestiveModeSettings = () => { | |
| panel={ | ||
| <div className="flex flex-col gap-4 p-1"> | ||
| <div className="sync-config-settings"> | ||
| <FlagPanel | ||
| <GlobalFlagPanel | ||
|
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. Why is there no
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. Ah, it looks like you are using
|
||
| title="Include Current Page Relations" | ||
| description="Include relations from pages referenced on the current page" | ||
| settingKeys={["Suggestive Mode", "Include Current Page Relations"]} | ||
| defaultValue={settings.suggestiveMode.includePageRelations.value} | ||
| order={0} | ||
| uid={settings.suggestiveMode.includePageRelations.uid} | ||
| parentUid={effectiveSuggestiveModeUid} | ||
| value={includePageRelations} | ||
| options={{ | ||
| onChange: (checked: boolean) => { | ||
| setIncludePageRelations(checked); | ||
| }, | ||
| }} | ||
| onChange={setIncludePageRelations} | ||
| /> | ||
|
|
||
| <FlagPanel | ||
| <GlobalFlagPanel | ||
| title="Include Parent And Child Blocks" | ||
| description={ | ||
| includePageRelations | ||
| ? "Include relations from parent and child blocks (automatically enabled when including page relations)" | ||
| : "Include relations from parent and child blocks" | ||
| } | ||
| settingKeys={["Suggestive Mode", "Include Parent And Child Blocks"]} | ||
| defaultValue={settings.suggestiveMode.includeParentAndChildren.value} | ||
|
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. From this panel alone this is confusing, can you walk me through the logic here? Is it: Let's try to just use |
||
| overrideValue={includePageRelations ? true : undefined} | ||
|
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. What is this called Generally it's |
||
| order={1} | ||
| uid={settings.suggestiveMode.includeParentAndChildren.uid} | ||
| parentUid={effectiveSuggestiveModeUid} | ||
| value={ | ||
| includePageRelations | ||
| ? true | ||
| : settings.suggestiveMode.includeParentAndChildren.value | ||
| } | ||
| disabled={includePageRelations} | ||
| /> | ||
| </div> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,6 +57,7 @@ type BaseFlagPanelProps = { | |
| getter: FlagGetter; | ||
| setter: FlagSetter; | ||
| defaultValue?: boolean; | ||
| overrideValue?: boolean; | ||
| disabled?: boolean; | ||
| onBeforeChange?: (checked: boolean) => Promise<boolean>; | ||
| onChange?: (checked: boolean) => void; | ||
|
|
@@ -98,20 +99,22 @@ const BaseTextPanel = ({ | |
| settingKeys, | ||
| getter, | ||
| setter, | ||
| defaultValue = "", | ||
| defaultValue, | ||
| placeholder, | ||
| parentUid, | ||
| uid, | ||
| order, | ||
| }: BaseTextPanelProps) => { | ||
| const [value, setValue] = useState(() => getter(settingKeys) ?? defaultValue); | ||
| const [value, setValue] = useState( | ||
| () => defaultValue ?? getter(settingKeys) ?? "", | ||
|
Collaborator
Author
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. Here we are going with
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. I don't think this is a good pattern. That means we have to make sure that every time Let's remove the If you want to have some code in here so you don't have to remember to put it back, code it as if we were using a flag to switch between blocks/props. But have the flag null or false (so that it always uses blocks until we add the mechanism to switch the flag to use props.)
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. Oh I see, you are using Initial Value = the initial value we are passing to another component which is handling that value's state going forward (not meant to change) so generally something like this:
|
||
| ); | ||
sid597 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const hasBlockSync = parentUid !== undefined && order !== undefined; | ||
| const { onChange: rawSyncToBlock } = useSingleChildValue({ | ||
| title, | ||
| parentUid: parentUid ?? "", | ||
| order: order ?? 0, | ||
| uid, | ||
| defaultValue, | ||
| defaultValue: defaultValue ?? "", | ||
| transform: (s: string) => s, | ||
| toStr: (s: string) => s, | ||
| }); | ||
|
|
@@ -143,15 +146,18 @@ const BaseFlagPanel = ({ | |
| settingKeys, | ||
| getter, | ||
| setter, | ||
| defaultValue = false, | ||
| defaultValue, | ||
| overrideValue, | ||
| disabled = false, | ||
| onBeforeChange, | ||
| onChange, | ||
| parentUid, | ||
| uid: initialBlockUid, | ||
| order, | ||
| }: BaseFlagPanelProps) => { | ||
| const [value, setValue] = useState(() => getter(settingKeys) ?? defaultValue); | ||
| const [value, setValue] = useState( | ||
| () => defaultValue ?? getter(settingKeys) ?? false, | ||
|
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. same as above comment |
||
| ); | ||
| const blockUidRef = useRef(initialBlockUid); | ||
|
|
||
| const syncFlagToBlock = useCallback( | ||
|
|
@@ -193,7 +199,7 @@ const BaseFlagPanel = ({ | |
|
|
||
| return ( | ||
| <Checkbox | ||
| checked={value} | ||
| checked={overrideValue ?? value} | ||
| onChange={(e) => void handleChange(e)} | ||
| disabled={disabled} | ||
| labelElement={ | ||
|
|
@@ -212,21 +218,23 @@ const BaseNumberPanel = ({ | |
| settingKeys, | ||
| getter, | ||
| setter, | ||
| defaultValue = 0, | ||
| defaultValue, | ||
| min, | ||
| max, | ||
| parentUid, | ||
| uid, | ||
| order, | ||
| }: BaseNumberPanelProps) => { | ||
| const [value, setValue] = useState(() => getter(settingKeys) ?? defaultValue); | ||
| const [value, setValue] = useState( | ||
| () => defaultValue ?? getter(settingKeys) ?? 0, | ||
| ); | ||
| const hasBlockSync = parentUid !== undefined && order !== undefined; | ||
| const { onChange: rawSyncToBlock } = useSingleChildValue({ | ||
| title, | ||
| parentUid: parentUid ?? "", | ||
| order: order ?? 0, | ||
| uid, | ||
| defaultValue, | ||
| defaultValue: defaultValue ?? 0, | ||
| transform: (s: string) => parseInt(s, 10), | ||
| toStr: (v: number) => `${v}`, | ||
| }); | ||
|
|
@@ -267,7 +275,7 @@ const BaseSelectPanel = ({ | |
| order, | ||
| }: BaseSelectPanelProps) => { | ||
| const [value, setValue] = useState( | ||
| () => getter(settingKeys) ?? defaultValue ?? options[0], | ||
| () => defaultValue ?? getter(settingKeys) ?? options[0], | ||
| ); | ||
| const hasBlockSync = parentUid !== undefined && order !== undefined; | ||
| const { onChange: rawSyncToBlock } = useSingleChildValue({ | ||
|
|
@@ -308,13 +316,13 @@ const BaseMultiTextPanel = ({ | |
| settingKeys, | ||
| getter, | ||
| setter, | ||
| defaultValue = [], | ||
| defaultValue, | ||
| parentUid, | ||
| uid: initialBlockUid, | ||
| order, | ||
| }: BaseMultiTextPanelProps) => { | ||
| const [values, setValues] = useState<string[]>( | ||
| () => getter(settingKeys) ?? defaultValue, | ||
| () => defaultValue ?? getter(settingKeys) ?? [], | ||
| ); | ||
| const [inputValue, setInputValue] = useState(""); | ||
| const hasBlockSync = parentUid !== undefined && order !== undefined; | ||
|
|
@@ -472,19 +480,23 @@ export const FeatureFlagPanel = ({ | |
| featureKey, | ||
| onBeforeEnable, | ||
| onAfterChange, | ||
| parentUid, | ||
| uid, | ||
| order, | ||
| }: { | ||
| title: string; | ||
| description: string; | ||
| featureKey: keyof FeatureFlags; | ||
| onBeforeEnable?: () => Promise<boolean>; | ||
| onAfterChange?: (checked: boolean) => void; | ||
| }) => { | ||
| } & RoamBlockSyncProps) => { | ||
| const handleBeforeChange: | ||
| | ((checked: boolean) => Promise<boolean>) | ||
| | undefined = onBeforeEnable | ||
| ? async (checked) => { | ||
| if (checked) { | ||
| return onBeforeEnable(); | ||
|
|
||
| } | ||
| return true; | ||
| } | ||
|
|
@@ -499,6 +511,9 @@ export const FeatureFlagPanel = ({ | |
| setter={featureFlagSetter} | ||
| onBeforeChange={handleBeforeChange} | ||
| onChange={onAfterChange} | ||
| parentUid={parentUid} | ||
| uid={uid} | ||
| order={order} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
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.
We get the settings on line 11, 12, and use that to pass the default value from here.