Skip to content

Commit

Permalink
fix link value selection (#5237)
Browse files Browse the repository at this point in the history
Co-authored-by: Patryk Andrzejewski <vox3r69@gmail.com>
Co-authored-by: M.Graczyk <michalina.graczyk@saleor.io>
  • Loading branch information
3 people committed Nov 7, 2024
1 parent 55988f0 commit a230369
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/twelve-mails-shave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": patch
---

Link value input in Navigation no longer overrides input value with cached value.
13 changes: 9 additions & 4 deletions src/navigation/components/MenuItemDialog/MenuItemDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,17 @@ const MenuItemDialog: React.FC<MenuItemDialogProps> = ({
onClose: () => {
reset(defaultInitial);
clearErrors();
onQueryChange("");
},
});

// Refresh initial display value if changed
React.useEffect(() => reset(initial), [initial]);
React.useEffect(() => {
// Form should be reset only when dialog is opened
// otherwise it will reset form on every render and when input is empty
reset(initial);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [open]);

const errors = useModalDialogErrors(apiErrors, open);
const mutationErrors = errors.filter(err => err.field === null);
Expand Down Expand Up @@ -187,7 +193,7 @@ const MenuItemDialog: React.FC<MenuItemDialogProps> = ({
onChange={onChange}
value={
// Show initial value with label in case initial options list from API does not contain it
initial && !formState.isDirty
initial && !formState.dirtyFields.linkValue
? {
value,
label: initialDisplayValue,
Expand All @@ -197,9 +203,8 @@ const MenuItemDialog: React.FC<MenuItemDialogProps> = ({
name="linkValue"
error={!!error}
helperText={error?.message}
fetchOptions={() => undefined}
fetchOptions={onQueryChange}
loading={loading}
onInputValueChange={onQueryChange}
data-test-id="menu-item-link-value-input"
/>
);
Expand Down

0 comments on commit a230369

Please sign in to comment.