Fix SearchDropdown clear button and URI search in Authorization tabs (#45407)

- Add defaultValues to useForm for proper form reset
- Call reset(defaultValues) in Clear button handler
- Fix form field name from 'uris' to 'uri' to match API parameter
- Add missing 'reset' dependency to useEffect

Closes #45406

Signed-off-by: erenkan <eren@keymate.io>
This commit is contained in:
Eren Kan 2026-01-28 17:01:04 +03:00 committed by GitHub
parent b0f93232e9
commit 5ad68321f6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -30,6 +30,15 @@ type SearchDropdownProps = {
type: "resource" | "policy" | "permission";
};
const defaultValues: SearchForm = {
name: "",
type: "",
uri: "",
owner: "",
scope: "",
resource: "",
};
export const SearchDropdown = ({
types,
search,
@ -37,7 +46,7 @@ export const SearchDropdown = ({
type,
}: SearchDropdownProps) => {
const { t } = useTranslation();
const form = useForm<SearchForm>({ mode: "onChange" });
const form = useForm<SearchForm>({ mode: "onChange", defaultValues });
const {
reset,
formState: { isDirty },
@ -51,7 +60,7 @@ export const SearchDropdown = ({
onSearch(form);
};
useEffect(() => reset(search), [search]);
useEffect(() => reset(search), [search, reset]);
return (
<Dropdown
@ -80,7 +89,7 @@ export const SearchDropdown = ({
{type === "resource" && (
<>
<TextControl name="type" label={t("type")} />
<TextControl name="uris" label={t("uris")} />
<TextControl name="uri" label={t("uris")} />
<TextControl name="owner" label={t("owner")} />
</>
)}
@ -116,7 +125,10 @@ export const SearchDropdown = ({
<Button
variant="link"
data-testid="revert-btn"
onClick={() => onSearch({})}
onClick={() => {
reset(defaultValues);
onSearch({});
}}
>
{t("clear")}
</Button>