Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show All and Solo selection buttons for MultiSelect. #4723

Merged
merged 4 commits into from
Dec 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 29 additions & 14 deletions web/src/components/MultiSelect.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ import { useRef, useState } from 'preact/hooks';
import Menu from './Menu';
import { ArrowDropdown } from '../icons/ArrowDropdown';
import Heading from './Heading';
import Button from './Button';
import CameraIcon from '../icons/Camera';

export default function MultiSelect({ className, title, options, selection, onToggle }) {
export default function MultiSelect({ className, title, options, selection, onToggle, onShowAll, onSelectSingle }) {

const popupRef = useRef(null);

const [state, setState] = useState({
showMenu: false,
});


const isOptionSelected = (item) => { return selection == "all" || selection.split(',').indexOf(item) > -1; }

return (
<div className={`${className} p-2`} ref={popupRef}>
<div
Expand All @@ -23,21 +27,32 @@ export default function MultiSelect({ className, title, options, selection, onTo
</div>
{state.showMenu ? (
<Menu relativeTo={popupRef} onDismiss={() => setState({ showMenu: false })}>
<Heading className="p-4 justify-center" size="md">{title}</Heading>
<div className="flex flex-wrap justify-between items-center">
<Heading className="p-4 justify-center" size="md">{title}</Heading>
<Button tabindex="false" className="mx-4" onClick={() => onShowAll() }>
Show All
</Button>
</div>
{options.map((item) => (
<label
className={`flex flex-shrink space-x-2 p-1 my-1 min-w-[176px] hover:bg-gray-200 dark:hover:bg-gray-800 dark:hover:text-white cursor-pointer capitalize text-sm`}
key={item}>
<input
className="mx-4 m-0 align-middle"
type="checkbox"
checked={selection == "all" || selection.indexOf(item) > -1}
onChange={() => onToggle(item)} />
{item.replaceAll("_", " ")}
</label>
<div className="flex flex-grow" key={item}>
<label
className={`flex flex-shrink space-x-2 p-1 my-1 min-w-[176px] hover:bg-gray-200 dark:hover:bg-gray-800 dark:hover:text-white cursor-pointer capitalize text-sm`}>
<input
className="mx-4 m-0 align-middle"
type="checkbox"
checked={isOptionSelected(item)}
onChange={() => onToggle(item)} />
{item.replaceAll("_", " ")}
</label>
<div className="justify-right">
<Button color={isOptionSelected(item) ? "blue" : "black"} type="text" className="max-h-[35px] mx-2" onClick={() => onSelectSingle(item)}>
<CameraIcon />
</Button>
</div>
</div>
))}
</Menu>
): null}
</div>
);
}
}
8 changes: 8 additions & 0 deletions web/src/routes/Events.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -301,20 +301,26 @@ export default function Events({ path, ...props }) {
options={filterValues.cameras}
selection={searchParams.cameras}
onToggle={(item) => onToggleNamedFilter("cameras", item)}
onShowAll={() => onFilter("cameras", ["all"])}
onSelectSingle={(item) => onFilter("cameras", item)}
/>
<MultiSelect
className="basis-1/5 cursor-pointer rounded dark:bg-slate-800"
title="Labels"
options={filterValues.labels}
selection={searchParams.labels}
onToggle={(item) => onToggleNamedFilter("labels", item) }
onShowAll={() => onFilter("labels", ["all"])}
onSelectSingle={(item) => onFilter("labels", item)}
/>
<MultiSelect
className="basis-1/5 cursor-pointer rounded dark:bg-slate-800"
title="Zones"
options={filterValues.zones}
selection={searchParams.zones}
onToggle={(item) => onToggleNamedFilter("zones", item) }
onShowAll={() => onFilter("zones", ["all"])}
onSelectSingle={(item) => onFilter("zones", item)}
/>
{
filterValues.sub_labels.length > 0 && (
Expand All @@ -324,6 +330,8 @@ export default function Events({ path, ...props }) {
options={filterValues.sub_labels}
selection={searchParams.sub_labels}
onToggle={(item) => onToggleNamedFilter("sub_labels", item) }
onShowAll={() => onFilter("sub_labels", ["all"])}
onSelectSingle={(item) => onFilter("sub_labels", item)}
/>
)}
<div ref={datePicker} className="ml-auto">
Expand Down