mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-06-28 15:21:54 +03:00
Some checks are pending
CI / AMD64 Build (push) Waiting to run
CI / ARM Build (push) Waiting to run
CI / Jetson Jetpack 6 (push) Waiting to run
CI / AMD64 Extra Build (push) Blocked by required conditions
CI / ARM Extra Build (push) Blocked by required conditions
CI / Synaptics Build (push) Blocked by required conditions
CI / Assemble and push default build (push) Blocked by required conditions
* attributes endpoint * event endpoints * add attributes to more filters * add to suggestions and query in explore * support attributes in search input * i18n * add object type filter to endpoint * add attributes to tracked object details pane * add generic multi select dialog * save object attributes endpoint * add group by param to fetch attributes endpoint * add attribute editing to tracked object details * docs * fix docs * update openapi spec to match python
97 lines
2.6 KiB
TypeScript
97 lines
2.6 KiB
TypeScript
import { Button } from "@/components/ui/button";
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogDescription,
|
|
DialogFooter,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
} from "@/components/ui/dialog";
|
|
import { cn } from "@/lib/utils";
|
|
import { useState } from "react";
|
|
import { isMobile } from "react-device-detect";
|
|
import { useTranslation } from "react-i18next";
|
|
import FilterSwitch from "@/components/filter/FilterSwitch";
|
|
|
|
type MultiSelectDialogProps = {
|
|
open: boolean;
|
|
title: string;
|
|
description?: string;
|
|
setOpen: (open: boolean) => void;
|
|
onSave: (selectedItems: string[]) => void;
|
|
selectedItems: string[];
|
|
availableItems: string[];
|
|
allowEmpty?: boolean;
|
|
};
|
|
|
|
export default function MultiSelectDialog({
|
|
open,
|
|
title,
|
|
description,
|
|
setOpen,
|
|
onSave,
|
|
selectedItems = [],
|
|
availableItems = [],
|
|
allowEmpty = false,
|
|
}: MultiSelectDialogProps) {
|
|
const { t } = useTranslation("common");
|
|
const [internalSelection, setInternalSelection] =
|
|
useState<string[]>(selectedItems);
|
|
|
|
// Reset internal selection when dialog opens
|
|
const handleOpenChange = (isOpen: boolean) => {
|
|
if (isOpen) {
|
|
setInternalSelection(selectedItems);
|
|
}
|
|
setOpen(isOpen);
|
|
};
|
|
|
|
const toggleItem = (item: string) => {
|
|
setInternalSelection((prev) =>
|
|
prev.includes(item) ? prev.filter((i) => i !== item) : [...prev, item],
|
|
);
|
|
};
|
|
|
|
const handleSave = () => {
|
|
if (!allowEmpty && internalSelection.length === 0) {
|
|
return;
|
|
}
|
|
onSave(internalSelection);
|
|
setOpen(false);
|
|
};
|
|
|
|
return (
|
|
<Dialog open={open} defaultOpen={false} onOpenChange={handleOpenChange}>
|
|
<DialogContent>
|
|
<DialogHeader>
|
|
<DialogTitle>{title}</DialogTitle>
|
|
{description && <DialogDescription>{description}</DialogDescription>}
|
|
</DialogHeader>
|
|
<div className="max-h-[80dvh] space-y-3 overflow-y-auto py-4">
|
|
{availableItems.map((item) => (
|
|
<FilterSwitch
|
|
key={item}
|
|
label={item}
|
|
isChecked={internalSelection.includes(item)}
|
|
onCheckedChange={() => toggleItem(item)}
|
|
/>
|
|
))}
|
|
</div>
|
|
<DialogFooter className={cn("pt-4", isMobile && "gap-2")}>
|
|
<Button type="button" onClick={() => setOpen(false)}>
|
|
{t("button.cancel")}
|
|
</Button>
|
|
<Button
|
|
variant="select"
|
|
type="button"
|
|
onClick={handleSave}
|
|
disabled={!allowEmpty && internalSelection.length === 0}
|
|
>
|
|
{t("button.save")}
|
|
</Button>
|
|
</DialogFooter>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
}
|