mirror of
https://github.com/fosrl/pangolin.git
synced 2026-08-09 05:58:17 +02:00
reduce filter dropdown page size
This commit is contained in:
@@ -122,8 +122,8 @@ export const launcherFilterListQuerySchema = z.strictObject({
|
|||||||
.int()
|
.int()
|
||||||
.positive()
|
.positive()
|
||||||
.optional()
|
.optional()
|
||||||
.catch(500)
|
.catch(20)
|
||||||
.default(500),
|
.default(20),
|
||||||
page: z.coerce.number().int().min(1).optional().catch(1).default(1),
|
page: z.coerce.number().int().min(1).optional().catch(1).default(1),
|
||||||
query: z.string().optional().default("")
|
query: z.string().optional().default("")
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
import { launcherQueries, orgQueries } from "@app/lib/queries";
|
import { launcherQueries, orgQueries } from "@app/lib/queries";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import { useState } from "react";
|
import { useMemo, useState } from "react";
|
||||||
import { useDebounce } from "use-debounce";
|
import { useDebounce } from "use-debounce";
|
||||||
import { Checkbox } from "./ui/checkbox";
|
import { Checkbox } from "./ui/checkbox";
|
||||||
|
|
||||||
@@ -25,6 +25,7 @@ type LabelsFilterSelectorProps = {
|
|||||||
orgId: string;
|
orgId: string;
|
||||||
isSelected: (label: LabelFilterOption) => boolean;
|
isSelected: (label: LabelFilterOption) => boolean;
|
||||||
onToggle: (label: LabelFilterOption) => void;
|
onToggle: (label: LabelFilterOption) => void;
|
||||||
|
selectedLabels?: LabelFilterOption[];
|
||||||
onClear?: () => void;
|
onClear?: () => void;
|
||||||
showClear?: boolean;
|
showClear?: boolean;
|
||||||
scope?: "org" | "launcher";
|
scope?: "org" | "launcher";
|
||||||
@@ -34,6 +35,7 @@ export function LabelsFilterSelector({
|
|||||||
orgId,
|
orgId,
|
||||||
isSelected,
|
isSelected,
|
||||||
onToggle,
|
onToggle,
|
||||||
|
selectedLabels = [],
|
||||||
onClear,
|
onClear,
|
||||||
showClear = false,
|
showClear = false,
|
||||||
scope = "org"
|
scope = "org"
|
||||||
@@ -54,7 +56,7 @@ export function LabelsFilterSelector({
|
|||||||
...launcherQueries.labels({
|
...launcherQueries.labels({
|
||||||
orgId,
|
orgId,
|
||||||
query: debouncedQuery,
|
query: debouncedQuery,
|
||||||
perPage: 500
|
perPage: 20
|
||||||
}),
|
}),
|
||||||
enabled: scope === "launcher"
|
enabled: scope === "launcher"
|
||||||
});
|
});
|
||||||
@@ -63,6 +65,18 @@ export function LabelsFilterSelector({
|
|||||||
? (launcherLabelsQuery.data ?? [])
|
? (launcherLabelsQuery.data ?? [])
|
||||||
: (orgLabelsQuery.data ?? []);
|
: (orgLabelsQuery.data ?? []);
|
||||||
|
|
||||||
|
const labelsShown = useMemo(() => {
|
||||||
|
const base = [...labels];
|
||||||
|
if (debouncedQuery.trim().length === 0 && selectedLabels.length > 0) {
|
||||||
|
const selectedNotInBase = selectedLabels.filter(
|
||||||
|
(selected) =>
|
||||||
|
!base.some((label) => label.labelId === selected.labelId)
|
||||||
|
);
|
||||||
|
return [...selectedNotInBase, ...base];
|
||||||
|
}
|
||||||
|
return base;
|
||||||
|
}, [debouncedQuery, labels, selectedLabels]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Command shouldFilter={false}>
|
<Command shouldFilter={false}>
|
||||||
<CommandInput
|
<CommandInput
|
||||||
@@ -81,7 +95,7 @@ export function LabelsFilterSelector({
|
|||||||
{t("accessFilterClear")}
|
{t("accessFilterClear")}
|
||||||
</CommandItem>
|
</CommandItem>
|
||||||
)}
|
)}
|
||||||
{labels.map((label) => (
|
{labelsShown.map((label) => (
|
||||||
<CommandItem
|
<CommandItem
|
||||||
key={label.labelId}
|
key={label.labelId}
|
||||||
value={label.name}
|
value={label.name}
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ export function MultiSitesSelector({
|
|||||||
...launcherQueries.sites({
|
...launcherQueries.sites({
|
||||||
orgId,
|
orgId,
|
||||||
query: debouncedQuery,
|
query: debouncedQuery,
|
||||||
perPage: 500
|
perPage: 20
|
||||||
}),
|
}),
|
||||||
enabled: scope === "launcher"
|
enabled: scope === "launcher"
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -47,14 +47,14 @@ export function LauncherFilterPopover({
|
|||||||
const { data: labels = [] } = useQuery(
|
const { data: labels = [] } = useQuery(
|
||||||
launcherQueries.labels({
|
launcherQueries.labels({
|
||||||
orgId,
|
orgId,
|
||||||
perPage: 500
|
perPage: 20
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
const { data: sites = [] } = useQuery(
|
const { data: sites = [] } = useQuery(
|
||||||
launcherQueries.sites({
|
launcherQueries.sites({
|
||||||
orgId,
|
orgId,
|
||||||
perPage: 500
|
perPage: 20
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -195,6 +195,7 @@ export function LauncherFilterPopover({
|
|||||||
<LabelsFilterSelector
|
<LabelsFilterSelector
|
||||||
orgId={orgId}
|
orgId={orgId}
|
||||||
scope="launcher"
|
scope="launcher"
|
||||||
|
selectedLabels={resolvedSelectedLabels}
|
||||||
isSelected={(label) =>
|
isSelected={(label) =>
|
||||||
selectedLabelIds.has(label.labelId)
|
selectedLabelIds.has(label.labelId)
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1196,7 +1196,7 @@ export const launcherQueries = {
|
|||||||
sites: ({
|
sites: ({
|
||||||
orgId,
|
orgId,
|
||||||
query,
|
query,
|
||||||
perPage = 500
|
perPage = 20
|
||||||
}: {
|
}: {
|
||||||
orgId: string;
|
orgId: string;
|
||||||
query?: string;
|
query?: string;
|
||||||
@@ -1228,7 +1228,7 @@ export const launcherQueries = {
|
|||||||
labels: ({
|
labels: ({
|
||||||
orgId,
|
orgId,
|
||||||
query,
|
query,
|
||||||
perPage = 500
|
perPage = 20
|
||||||
}: {
|
}: {
|
||||||
orgId: string;
|
orgId: string;
|
||||||
query?: string;
|
query?: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user