Refactor general review filter to only call the update function once (#14866)

This commit is contained in:
Josh Hawkins
2024-11-08 07:45:00 -06:00
committed by GitHub
parent 46ed520886
commit ae30ac6e3c
3 changed files with 117 additions and 117 deletions

View File

@@ -4,7 +4,7 @@ import { Button } from "../ui/button";
import { FaArrowDown, FaCalendarAlt, FaCog, FaFilter } from "react-icons/fa";
import { TimeRange } from "@/types/timeline";
import { ExportContent, ExportPreviewDialog } from "./ExportDialog";
import { ExportMode } from "@/types/filter";
import { ExportMode, GeneralFilter } from "@/types/filter";
import ReviewActivityCalendar from "./ReviewActivityCalendar";
import { SelectSeparator } from "../ui/select";
import { ReviewFilter, ReviewSeverity, ReviewSummary } from "@/types/review";
@@ -114,12 +114,12 @@ export default function MobileReviewSettingsDrawer({
// filters
const [currentLabels, setCurrentLabels] = useState<string[] | undefined>(
filter?.labels,
);
const [currentZones, setCurrentZones] = useState<string[] | undefined>(
filter?.zones,
);
const [currentFilter, setCurrentFilter] = useState<GeneralFilter>({
labels: filter?.labels,
zones: filter?.zones,
showAll: filter?.showAll,
...filter,
});
if (!isMobile) {
return;
@@ -260,23 +260,21 @@ export default function MobileReviewSettingsDrawer({
<GeneralFilterContent
allLabels={allLabels}
selectedLabels={filter?.labels}
currentLabels={currentLabels}
currentSeverity={currentSeverity}
showAll={filter?.showAll == true}
allZones={allZones}
filter={currentFilter}
selectedZones={filter?.zones}
currentZones={currentZones}
setCurrentZones={setCurrentZones}
updateZoneFilter={(newZones) =>
onUpdateFilter({ ...filter, zones: newZones })
}
setShowAll={(showAll) => {
onUpdateFilter({ ...filter, showAll });
onUpdateFilter={setCurrentFilter}
onApply={() => {
if (currentFilter !== filter) {
onUpdateFilter(currentFilter);
}
}}
onReset={() => {
const resetFilter: GeneralFilter = {};
setCurrentFilter(resetFilter);
onUpdateFilter(resetFilter);
}}
setCurrentLabels={setCurrentLabels}
updateLabelFilter={(newLabels) =>
onUpdateFilter({ ...filter, labels: newLabels })
}
onClose={() => setDrawerMode("select")}
/>
</div>