ENG-1272 Migrate all small global settings components#688
ENG-1272 Migrate all small global settings components#688
Conversation
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
This stack of pull requests is managed by Graphite. Learn more about stacking. |
29817b9 to
9cd0a2c
Compare
8f1c13c to
2d2bb77
Compare
2d2bb77 to
f9de2fd
Compare
d1b8faf to
9015611
Compare
23cedec to
496a3ba
Compare
16b26f7 to
dd2272b
Compare
0238148 to
8dbd24c
Compare
dd2272b to
92ea54b
Compare
8dbd24c to
4c71862
Compare
92ea54b to
5a165ac
Compare
4c71862 to
77d1c95
Compare
94e3904 to
fbede09
Compare
cf56730 to
2ac769a
Compare
apps/roam/src/components/settings/components/BlockPropSettingPanels.tsx
Outdated
Show resolved
Hide resolved
| }: BaseTextPanelProps) => { | ||
| const [value, setValue] = useState(() => getter(settingKeys) ?? defaultValue); | ||
| const [value, setValue] = useState( | ||
| () => defaultValue ?? getter(settingKeys) ?? "", |
There was a problem hiding this comment.
Here we are going with defaultValue i.e if there is a default value then use it instead of using the gette() the getter gets from the block props but we don't want to read from there. defaultValue is passed from the caller side (mentioned later) and these defaults use the existing block structure.
There was a problem hiding this comment.
I don't think this is a good pattern. That means we have to make sure that every time <BaseTextPanel> is called, it is using the default value. This is too error prone and requires manual checking of all callers.
Let's remove the getter() altogether. I'm not sure what purpose it is serving now anyway.
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.)
There was a problem hiding this comment.
Oh I see, you are using defaultValue as initialValue. Let's change it to initialValue
Initial Value = the initial value we are passing to another component which is handling that value's state going forward (not meant to change)
Default Value = if there no value, use this value (not meant to change)
Value = the value we care about to update the UI, the value we keep in state. (this is meant to change)
so generally something like this:
[value, setvValue] = useState(initialValue ?? defaultValue)
But the "let's remove the getter() comment still stands"
apps/roam/src/components/settings/components/BlockPropSettingPanels.tsx
Outdated
Show resolved
Hide resolved
apps/roam/src/components/settings/components/BlockPropSettingPanels.tsx
Outdated
Show resolved
Hide resolved
apps/roam/src/components/settings/components/BlockPropSettingPanels.tsx
Outdated
Show resolved
Hide resolved
apps/roam/src/components/settings/components/BlockPropSettingPanels.tsx
Outdated
Show resolved
Hide resolved
| title="remove special characters" | ||
| description="Whether or not to remove the special characters in a file name" | ||
| settingKeys={["Export", "Remove Special Characters"]} | ||
| defaultValue={exportSettings.removeSpecialCharacters.value} |
There was a problem hiding this comment.
We get the settings on line 11, 12, and use that to pass the default value from here.
mdroidian
left a comment
There was a problem hiding this comment.
I haven't had a change to review this yet, but please go through and remove any testing code not meant to merge and resolve any unresolved review comments.
|
I put them explicitly because I thought we were going to test them extensively before merging and these logs will help us do that. Should I remove them and after review merge the pr? |
|
As we discussed: re: new system to stop testing/unwanted code merging into production
|
| const newValue = e.target.value; | ||
| setValue(newValue); | ||
| setter(settingKeys, newValue); | ||
| syncToBlock?.(newValue); |
There was a problem hiding this comment.
For testing, add the following here
setTimeout(() => {
console.log(`[TextPanel] "${title}" after set, blockProp:`, getter(settingKeys));
}, 500);
same goes for all the other base panels, we should add this console.log to all the base panels for testing.
| } | ||
|
|
||
| // For testing purposes | ||
| // await initSchema(); |
There was a problem hiding this comment.
uncomment this for testing
| STREAMLINE_STYLING_KEY, | ||
| DISALLOW_DIAGNOSTICS, | ||
| } from "./data/userSettings"; | ||
| // import { initSchema } from "./components/settings/utils/init"; |
There was a problem hiding this comment.
uncomment this for testing
53f1015 to
0ef04ee
Compare
0ef04ee to
15f3a6b
Compare
mdroidian
left a comment
There was a problem hiding this comment.
So a few issues in this one:
- let's remove the getter() if we aren't using it yet, or put it behind a null/false flag that is intended to be used in the future
- changing
defaultValuetoinitialValue(this can be deferred, if it is, please link to the created task in which it will be completed) - clarify / simplify the logic for suggestive mode
- please format all files with prettier before tagging for review
- remove any code not intended to be merged
| }: BaseTextPanelProps) => { | ||
| const [value, setValue] = useState(() => getter(settingKeys) ?? defaultValue); | ||
| const [value, setValue] = useState( | ||
| () => defaultValue ?? getter(settingKeys) ?? "", |
There was a problem hiding this comment.
I don't think this is a good pattern. That means we have to make sure that every time <BaseTextPanel> is called, it is using the default value. This is too error prone and requires manual checking of all callers.
Let's remove the getter() altogether. I'm not sure what purpose it is serving now anyway.
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.)
| }: BaseFlagPanelProps) => { | ||
| const [value, setValue] = useState(() => getter(settingKeys) ?? defaultValue); | ||
| const [value, setValue] = useState( | ||
| () => defaultValue ?? getter(settingKeys) ?? false, |
| } | ||
| settingKeys={["Suggestive Mode", "Include Parent And Child Blocks"]} | ||
| defaultValue={settings.suggestiveMode.includeParentAndChildren.value} | ||
| overrideValue={includePageRelations ? true : undefined} |
There was a problem hiding this comment.
What is this called overrideValue and not just value? What value is it overriding?
Generally it's
defaultValue and value where we use defaultValue if there is no value defined.
| : "Include relations from parent and child blocks" | ||
| } | ||
| settingKeys={["Suggestive Mode", "Include Parent And Child Blocks"]} | ||
| defaultValue={settings.suggestiveMode.includeParentAndChildren.value} |
There was a problem hiding this comment.
From this panel alone this is confusing, can you walk me through the logic here?
Is it:
The value is from includeParentandChildren, but if includePageRelations is true then it is overriden? Overriden how?
Let's try to just use defaultValue/value and do the logic explicitly above so it's easy for anyone to follow how we derive defaultValue and value
| <div className="flex flex-col gap-4 p-1"> | ||
| <div className="sync-config-settings"> | ||
| <FlagPanel | ||
| <GlobalFlagPanel |
There was a problem hiding this comment.
Why is there no value prop on this component?
There was a problem hiding this comment.
Ah, it looks like you are using defaultValue like an initialValue. This is kind of confusing when defaultValue usually means
- this is an uncontrolled component
or - if there is no value, use
defaultValue
| }: BaseTextPanelProps) => { | ||
| const [value, setValue] = useState(() => getter(settingKeys) ?? defaultValue); | ||
| const [value, setValue] = useState( | ||
| () => defaultValue ?? getter(settingKeys) ?? "", |
There was a problem hiding this comment.
Oh I see, you are using defaultValue as initialValue. Let's change it to initialValue
Initial Value = the initial value we are passing to another component which is handling that value's state going forward (not meant to change)
Default Value = if there no value, use this value (not meant to change)
Value = the value we care about to update the UI, the value we keep in state. (this is meant to change)
so generally something like this:
[value, setvValue] = useState(initialValue ?? defaultValue)
But the "let's remove the getter() comment still stands"

https://www.loom.com/share/fcc05f0564e84a88baf41f535272523a