Fix measure breadcrumb category filter
When clicking a category name in the measure detail breadcrumb, users should be taken back to the measures list with that category filtered. Previously, the breadcrumb linked to a route that wasn't read by the measures page. Changed the breadcrumb to use a ?category search param instead of a route segment, and updated the measures page to initialize and sync its category filter from the URL. Removed the now-unused category/:categoryId route. Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
getMeasureStateLabel,
|
getMeasureStateLabel,
|
||||||
measureStates,
|
measureStates,
|
||||||
slugify,
|
|
||||||
sprintf,
|
sprintf,
|
||||||
} from "@probo/helpers";
|
} from "@probo/helpers";
|
||||||
import { useTranslate } from "@probo/i18n";
|
import { useTranslate } from "@probo/i18n";
|
||||||
@@ -148,7 +147,7 @@ export default function MeasureDetailPage(props: Props) {
|
|||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
label: measure.category,
|
label: measure.category,
|
||||||
to: `/organizations/${organizationId}/measures/category/${slugify(measure.category)}`,
|
to: `/organizations/${organizationId}/measures?category=${encodeURIComponent(measure.category)}`,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
: []),
|
: []),
|
||||||
|
|||||||
@@ -32,7 +32,8 @@ import {
|
|||||||
useToast,
|
useToast,
|
||||||
} from "@probo/ui";
|
} from "@probo/ui";
|
||||||
import { MeasureBadge } from "@probo/ui/src/Molecules/Badge/MeasureBadge";
|
import { MeasureBadge } from "@probo/ui/src/Molecules/Badge/MeasureBadge";
|
||||||
import { type ChangeEventHandler, useRef, useState, useTransition } from "react";
|
import { type ChangeEventHandler, useEffect, useRef, useState, useTransition } from "react";
|
||||||
|
import { useSearchParams } from "react-router";
|
||||||
import {
|
import {
|
||||||
ConnectionHandler,
|
ConnectionHandler,
|
||||||
graphql,
|
graphql,
|
||||||
@@ -164,10 +165,13 @@ export default function MeasuresPage({ queryRef }: MeasuresPageProps) {
|
|||||||
throw new Error("invalid node type");
|
throw new Error("invalid node type");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const [searchParams, setSearchParams] = useSearchParams();
|
||||||
|
const initialCategory = searchParams.get("category");
|
||||||
|
|
||||||
const [isPending, startTransition] = useTransition();
|
const [isPending, startTransition] = useTransition();
|
||||||
const [queryFilter, setQueryFilter] = useState<string | null>(null);
|
const [queryFilter, setQueryFilter] = useState<string | null>(null);
|
||||||
const [stateFilter, setStateFilter] = useState<MeasureState | null>(null);
|
const [stateFilter, setStateFilter] = useState<MeasureState | null>(null);
|
||||||
const [categoryFilter, setCategoryFilter] = useState<string | null>(null);
|
const [categoryFilter, setCategoryFilter] = useState<string | null>(initialCategory);
|
||||||
|
|
||||||
const { data, loadNext, hasNext, isLoadingNext, refetch }
|
const { data, loadNext, hasNext, isLoadingNext, refetch }
|
||||||
= usePaginationFragment<MeasuresPageRefetchQuery, MeasuresPageFragment$key>(
|
= usePaginationFragment<MeasuresPageRefetchQuery, MeasuresPageFragment$key>(
|
||||||
@@ -189,6 +193,13 @@ export default function MeasuresPage({ queryRef }: MeasuresPageProps) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (initialCategory) {
|
||||||
|
refetchFilters({ category: initialCategory });
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, []);
|
||||||
|
|
||||||
const handleQueryFilterChange = (value: string) => {
|
const handleQueryFilterChange = (value: string) => {
|
||||||
const newQuery = value === "" ? null : value;
|
const newQuery = value === "" ? null : value;
|
||||||
setQueryFilter(newQuery);
|
setQueryFilter(newQuery);
|
||||||
@@ -204,6 +215,15 @@ export default function MeasuresPage({ queryRef }: MeasuresPageProps) {
|
|||||||
const handleCategoryFilterChange = (value: string) => {
|
const handleCategoryFilterChange = (value: string) => {
|
||||||
const newCategory = value === "ALL" ? null : value;
|
const newCategory = value === "ALL" ? null : value;
|
||||||
setCategoryFilter(newCategory);
|
setCategoryFilter(newCategory);
|
||||||
|
setSearchParams(prev => {
|
||||||
|
const next = new URLSearchParams(prev);
|
||||||
|
if (newCategory) {
|
||||||
|
next.set("category", newCategory);
|
||||||
|
} else {
|
||||||
|
next.delete("category");
|
||||||
|
}
|
||||||
|
return next;
|
||||||
|
}, { replace: true });
|
||||||
refetchFilters({ category: newCategory });
|
refetchFilters({ category: newCategory });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -22,12 +22,6 @@ export const measureRoutes = [
|
|||||||
() =>
|
() =>
|
||||||
import("#/pages/organizations/measures/MeasuresPageLoader"),
|
import("#/pages/organizations/measures/MeasuresPageLoader"),
|
||||||
),
|
),
|
||||||
children: [
|
|
||||||
{
|
|
||||||
path: "category/:categoryId",
|
|
||||||
Component: Fragment,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "measures/:measureId",
|
path: "measures/:measureId",
|
||||||
|
|||||||
Reference in New Issue
Block a user