Skip to content

Commit

Permalink
fix link value selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Cloud11PL committed Nov 6, 2024
1 parent 5b6ed8c commit 6b51519
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 6b51519

Please sign in to comment.