Skip to content

Commit

Permalink
Update default reset form values based on whether the user can view o…
Browse files Browse the repository at this point in the history
…ther orgs or not
  • Loading branch information
Alejandro-Vega committed Oct 9, 2024
1 parent 03d3e6f commit 0874f96
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ describe("DataSubmissionListFilters Component", () => {
const organizationSelectInput = getByTestId("organization-select");

const button = within(organizationSelectInput).getByRole("button");
expect(button).toHaveAttribute("aria-disabled", "true");
expect(button).toHaveClass("Mui-readOnly");
});

it("resets all filters and clears URL searchParams when reset button is clicked", async () => {
Expand Down
25 changes: 15 additions & 10 deletions src/components/DataSubmissions/DataSubmissionListFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ const statusValues: SubmissionStatus[] = [
"Deleted",
];

const defaultValues: FilterForm = {
organization: "All",
status: "All",
dataCommons: "All",
name: "",
dbGaPID: "",
submitterName: "All",
};

type T = ListSubmissionsResp["listSubmissions"]["submissions"][0];

export type FilterForm = Pick<
Expand Down Expand Up @@ -129,14 +138,7 @@ const DataSubmissionListFilters = ({
const { activeOrganizations } = useOrganizationListContext();
const { searchParams, setSearchParams } = useSearchParamsContext();
const { control, register, watch, reset, setValue, getValues } = useForm<FilterForm>({
defaultValues: {
organization: "All",
status: "All",
dataCommons: "All",
name: "",
dbGaPID: "",
submitterName: "All",
},
defaultValues,
});
const [
statusFilter,
Expand Down Expand Up @@ -317,7 +319,10 @@ const DataSubmissionListFilters = ({
searchParams.delete("dbGaPID");
searchParams.delete("submitterName");
setSearchParams(newSearchParams);
reset();
reset({
...defaultValues,
organization: canViewOtherOrgs ? "All" : user?.organization?.orgID,
});
};

return (
Expand All @@ -340,7 +345,7 @@ const DataSubmissionListFilters = ({
"data-testid": "organization-select-input",
}}
data-testid="organization-select"
disabled={!canViewOtherOrgs}
readOnly={!canViewOtherOrgs}
onChange={(e) => {
field.onChange(e);
handleFilterChange("organization");
Expand Down

0 comments on commit 0874f96

Please sign in to comment.