Skip to content

Commit a423ac6

Browse files
committed
Add check
1 parent 8671d6a commit a423ac6

File tree

1 file changed

+88
-42
lines changed

1 file changed

+88
-42
lines changed

site/src/pages/WorkspacesPage/Filter.tsx

Lines changed: 88 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { useSearchParams } from "react-router-dom"
2121
import { useQuery } from "@tanstack/react-query"
2222
import { getUsers, getTemplates } from "api/api"
2323
import Skeleton, { SkeletonProps } from "@mui/material/Skeleton"
24+
import CheckOutlined from "@mui/icons-material/CheckOutlined"
2425

2526
/** Filter */
2627

@@ -431,32 +432,36 @@ const OwnerFilter = ({ autocomplete }: { autocomplete: UsersAutocomplete }) => {
431432
handleClose()
432433
}}
433434
>
434-
<UserOptionItem option={option} />
435+
<UserOptionItem
436+
option={option}
437+
isSelected={option.value === autocomplete.selectedOption?.value}
438+
/>
435439
</MenuItem>
436440
)}
437441
/>
438442
</div>
439443
)
440444
}
441445

442-
const UserOptionItem = ({ option }: { option: OwnerOption }) => {
446+
const UserOptionItem = ({
447+
option,
448+
isSelected,
449+
}: {
450+
option: OwnerOption
451+
isSelected?: boolean
452+
}) => {
443453
return (
444-
<Box
445-
display="flex"
446-
alignItems="center"
447-
gap={2}
448-
fontSize={14}
449-
overflow="hidden"
450-
>
451-
<UserAvatar
452-
username={option.label}
453-
avatarURL={option.avatarUrl}
454-
sx={{ width: 16, height: 16, fontSize: 8 }}
455-
/>
456-
<Box component="span" overflow="hidden" textOverflow="ellipsis">
457-
{option.label}
458-
</Box>
459-
</Box>
454+
<OptionItem
455+
option={option}
456+
isSelected={isSelected}
457+
left={
458+
<UserAvatar
459+
username={option.label}
460+
avatarURL={option.avatarUrl}
461+
sx={{ width: 16, height: 16, fontSize: 8 }}
462+
/>
463+
}
464+
/>
460465
)
461466
}
462467

@@ -502,32 +507,36 @@ const TemplatesFilter = ({
502507
handleClose()
503508
}}
504509
>
505-
<TemplateOptionItem option={option} />
510+
<TemplateOptionItem
511+
option={option}
512+
isSelected={option.value === autocomplete.selectedOption?.value}
513+
/>
506514
</MenuItem>
507515
)}
508516
/>
509517
</div>
510518
)
511519
}
512520

513-
const TemplateOptionItem = ({ option }: { option: TemplateOption }) => {
521+
const TemplateOptionItem = ({
522+
option,
523+
isSelected,
524+
}: {
525+
option: TemplateOption
526+
isSelected?: boolean
527+
}) => {
514528
return (
515-
<Box
516-
display="flex"
517-
alignItems="center"
518-
gap={2}
519-
fontSize={14}
520-
overflow="hidden"
521-
>
522-
<TemplateAvatar
523-
templateName={option.label}
524-
icon={option.icon}
525-
sx={{ width: 14, height: 14, fontSize: 8 }}
526-
/>
527-
<Box component="span" overflow="hidden" textOverflow="ellipsis">
528-
{option.label}
529-
</Box>
530-
</Box>
529+
<OptionItem
530+
option={option}
531+
isSelected={isSelected}
532+
left={
533+
<TemplateAvatar
534+
templateName={option.label}
535+
icon={option.icon}
536+
sx={{ width: 14, height: 14, fontSize: 8 }}
537+
/>
538+
}
539+
/>
531540
)
532541
}
533542

@@ -589,20 +598,30 @@ const StatusFilter = ({
589598
handleClose()
590599
}}
591600
>
592-
<StatusOptionItem option={option} />
601+
<StatusOptionItem
602+
option={option}
603+
isSelected={option.value === autocomplete.selectedOption?.value}
604+
/>
593605
</MenuItem>
594606
))}
595607
</Menu>
596608
</div>
597609
)
598610
}
599611

600-
const StatusOptionItem = ({ option }: { option: StatusOption }) => {
612+
const StatusOptionItem = ({
613+
option,
614+
isSelected,
615+
}: {
616+
option: StatusOption
617+
isSelected?: boolean
618+
}) => {
601619
return (
602-
<Box display="flex" alignItems="center" gap={2} fontSize={14}>
603-
<StatusIndicator option={option} />
604-
<span>{option.label}</span>
605-
</Box>
620+
<OptionItem
621+
option={option}
622+
left={<StatusIndicator option={option} />}
623+
isSelected={isSelected}
624+
/>
606625
)
607626
}
608627

@@ -620,6 +639,33 @@ const StatusIndicator: FC<{ option: StatusOption }> = ({ option }) => {
620639
)
621640
}
622641

642+
type OptionItemProps = {
643+
option: BaseOption
644+
left?: ReactNode
645+
isSelected?: boolean
646+
}
647+
648+
const OptionItem = ({ option, left, isSelected }: OptionItemProps) => {
649+
return (
650+
<Box
651+
display="flex"
652+
alignItems="center"
653+
gap={2}
654+
fontSize={14}
655+
overflow="hidden"
656+
width="100%"
657+
>
658+
{left}
659+
<Box component="span" overflow="hidden" textOverflow="ellipsis">
660+
{option.label}
661+
</Box>
662+
{isSelected && (
663+
<CheckOutlined sx={{ width: 16, height: 16, marginLeft: "auto" }} />
664+
)}
665+
</Box>
666+
)
667+
}
668+
623669
const MenuButton = forwardRef<HTMLButtonElement, ButtonProps>((props, ref) => {
624670
return (
625671
<Button

0 commit comments

Comments
 (0)