Skip to content

Commit

Permalink
Revert "fix facebook/react#14920"
Browse files Browse the repository at this point in the history
This reverts commit 68e5d8a.
  • Loading branch information
BobanL committed Dec 27, 2024
1 parent ca44b0a commit 817d84f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const EcrPaginationWrapper = ({
const search = current.toString();
const query = search ? `?${search}` : "";
router.push(`${pathname}${query}`);
}, [pathname, router, searchParams, userPreferences]);
}, [userPreferences]);

const totalPages =
totalCount > 0 ? Math.ceil(totalCount / userPreferences.itemsPerPage) : 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const EcrTableClient: React.FC<EcrTableClientProps> = ({
const search = current.toString();
const query = search ? `?${search}` : "";
router.push(`${pathname}${query}`);
}, [pathname, router, searchParams, sortPreferences]);
}, [sortPreferences]);

/**
* Updates the sort config from the server.
Expand Down
69 changes: 34 additions & 35 deletions containers/ecr-viewer/src/app/components/Filters.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import React, { useCallback, useEffect, useState } from "react";
import React, { useEffect, useState } from "react";
import { Icon } from "@trussworks/react-uswds";
import { useQueryParam, Filter } from "./BaseFilter";
import {
Expand Down Expand Up @@ -39,29 +39,6 @@ const FilterReportableConditions = () => {
const [filterConditions, setFilterConditions] = useState<{
[key: string]: boolean;
}>({});
const resetFilterConditions = useCallback(
(conditions: string[]) => {
const conditionParam = searchParams.get("condition");
const conditionsToTrue = new Set(conditionParam?.split("|") || []);

const conditionValue = (c: string) => {
if (conditionParam === null) {
return true;
} else {
return conditionsToTrue.has(c);
}
};
const prevFilterConditions = conditions.reduce(
(dict: { [key: string]: boolean }, condition: string) => {
dict[condition] = conditionValue(condition);
return dict;
},
{} as { [key: string]: boolean },
);
setFilterConditions(prevFilterConditions);
},
[searchParams],
);

useEffect(() => {
const fetchConditions = async () => {
Expand All @@ -78,7 +55,7 @@ const FilterReportableConditions = () => {
};

fetchConditions();
}, [resetFilterConditions]);
}, []);

// Build list of conditions to filter on
const handleCheckboxChange = (event: React.ChangeEvent<HTMLInputElement>) => {
Expand Down Expand Up @@ -107,6 +84,27 @@ const FilterReportableConditions = () => {
(val) => val === true,
);

const resetFilterConditions = (conditions: string[]) => {
const conditionParam = searchParams.get("condition");
const conditionsToTrue = new Set(conditionParam?.split("|") || []);

const conditionValue = (c: string) => {
if (conditionParam === null) {
return true;
} else {
return conditionsToTrue.has(c);
}
};
const prevFilterConditions = conditions.reduce(
(dict: { [key: string]: boolean }, condition: string) => {
dict[condition] = conditionValue(condition);
return dict;
},
{} as { [key: string]: boolean },
);
setFilterConditions(prevFilterConditions);
};

return (
<Filter
type="Reportable Condition"
Expand Down Expand Up @@ -179,18 +177,10 @@ const FilterReportableConditions = () => {
*/
const FilterByDate = () => {
const { searchParams, updateQueryParam } = useQueryParam();

const [filterDateOption, setFilterDateOption] = useState("");
const isFilterDateDefault = filterDateOption === DEFAULT_DATE_RANGE;

const resetFilterDate = useCallback(() => {
const queryDateRange = searchParams.get("dateRange");
if (!queryDateRange) {
setFilterDateOption(DEFAULT_DATE_RANGE);
} else if (queryDateRange !== filterDateOption) {
setFilterDateOption(queryDateRange);
}
}, [filterDateOption, searchParams]);

useEffect(() => {
const fetchDateRange = async () => {
try {
Expand All @@ -201,7 +191,7 @@ const FilterByDate = () => {
};

fetchDateRange();
}, [resetFilterDate]);
}, []);

const handleDateOptionChange = (
event: React.ChangeEvent<HTMLInputElement>,
Expand All @@ -211,6 +201,15 @@ const FilterByDate = () => {
setFilterDateOption(value);
};

const resetFilterDate = () => {
const queryDateRange = searchParams.get("dateRange");
if (!queryDateRange) {
setFilterDateOption(DEFAULT_DATE_RANGE);
} else if (queryDateRange !== filterDateOption) {
setFilterDateOption(queryDateRange);
}
};

return (
<Filter
type="Received Date"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ const FieldValue: React.FC<{
);
}
}
}, [children, cutField, hidden, id, valueLength]);
}, [hidden]);

return fieldValue;
};
Expand Down
2 changes: 1 addition & 1 deletion containers/ecr-viewer/src/app/view-data/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const ECRViewerPage: React.FC = () => {
}
};
fetchData();
}, [fhirId]);
}, []);

if (errors) {
if (errors.status === 404) {
Expand Down

0 comments on commit 817d84f

Please sign in to comment.