[BUGFIX] Fix variable editing panel's custom all value text field to handle empty string#64
[BUGFIX] Fix variable editing panel's custom all value text field to handle empty string#64
Conversation
…dle empty string Signed-off-by: Jenny Zhu <jenny.a.zhu@gmail.com>
| } else { | ||
| field.onChange(event); | ||
| } | ||
| field.onChange(event.target.value); |
There was a problem hiding this comment.
We need something on UI side for defining custom all value to undefined then.
A switch?
If enabled: show textfield and handle empty string
If disabled: undefined
There was a problem hiding this comment.
Because I am pretty sure some datasources have different behaviors, if the value is empty or undefined
There was a problem hiding this comment.
I pushed another commit to handle the case _allAllValue is disabled then the customAllValue should be undefined.
if (!_allowAllValue && values.spec.customAllValue !== undefined) {
form.setValue('spec.customAllValue', undefined);
}
There was a problem hiding this comment.
To me we should handle the case where: _allowAllValue is true and customAllValue can be undefined or empty from the UI too
There was a problem hiding this comment.
To me we should handle the case where: _allowAllValue is true and customAllValue can be undefined or empty from the UI too
I took another approach with useState hooks to try to synchronize what the form displays with the value of customAllValue, which was the root of the issue. Now it should handle the case where "_allowAllValue is true and customAllValue can be undefined or empty from the UI too".
Screen.Recording.2026-02-23.at.4.45.12.PM.mov
…dle empty string and undefined Signed-off-by: Jenny Zhu <jenny.a.zhu@gmail.com>
Signed-off-by: Jenny Zhu <jenny.a.zhu@gmail.com>
| onChange={(event) => { | ||
| const newValue = event.target.value; | ||
| setCustomAllDisplayValue(newValue); | ||
| if (newValue === '') { |
There was a problem hiding this comment.
Now that we can set undefined with reset button, I would remove this check for allowing empty string to be set by UI users
| const [customAllDisplayValue, setCustomAllDisplayValue] = useState(_customAllValue ?? ''); | ||
| const [isCustomAllReset, setIsCustomAllReset] = useState(false); | ||
|
|
||
| useEffect(() => { |
There was a problem hiding this comment.
Arf, not fan of this useEffect, that why I think using a Switch component would be simpler, for enabling or not custom all value.
If switch is enable => show text field and default value is empty string.
If false => textfield hidden and value is undefined
There was a problem hiding this comment.
True, Switch is probably the simpler approach. Push another commit to update it to the Switch.
Screen.Recording.2026-02-24.at.4.46.26.PM.mov
There was a problem hiding this comment.
Looks better to me, I think useEffect can be removed, no? 🤔
…witch Signed-off-by: Jenny Zhu <jenny.a.zhu@gmail.com>
| const [customAllDisplayValue, setCustomAllDisplayValue] = useState(_customAllValue ?? ''); | ||
| const [isCustomAllReset, setIsCustomAllReset] = useState(false); | ||
|
|
||
| useEffect(() => { |
There was a problem hiding this comment.
Looks better to me, I think useEffect can be removed, no? 🤔
| onChange={(event) => { | ||
| if (action === 'read') return; | ||
| const isEnabled = event.target.checked; | ||
| setUseCustomAllValue(isEnabled); |
There was a problem hiding this comment.
We can remove the negation here
| setUseCustomAllValue(isEnabled); | |
| if (isEnabled) { | |
| form.setValue('spec.customAllValue', ''); | |
| } else { | |
| form.setValue('spec.customAllValue', undefined); | |
| } |
| <Typography variant="caption" sx={{ mt: -0.5 }}> | ||
| Enable to set a custom value when "All" is selected | ||
| </Typography> | ||
| {useCustomAllValue && ( |
There was a problem hiding this comment.
| {useCustomAllValue && ( | |
| {_customAllValue !== undefined && ( |
Description
Fix the editing variable panel so that the custom all value text field can handle an empty string. Previously, if you tried to delete the current string, the empty string would trigger a hook to repopulate the text field with the previous value.
Screenshots
BEFORE
https://github.com/user-attachments/assets/6eb92fc0-cd22-417c-8fea-e42b34e41fa8
AFTER
https://github.com/user-attachments/assets/c469a264-726a-4035-8bef-2e8583274e3a
Checklist
[<catalog_entry>] <commit message>naming convention using one of thefollowing
catalog_entryvalues:FEATURE,ENHANCEMENT,BUGFIX,BREAKINGCHANGE,DOC,IGNORE.UI Changes
See e2e docs for more details. Common issues include: