|
| 1 | +import { FormMessage } from 'components/form/layout/layout' |
| 2 | +import { useCaptureSets } from 'data-services/hooks/capture-sets/useCaptureSets' |
| 3 | +import { ChevronRight, XIcon } from 'lucide-react' |
| 4 | +import { Button, Select } from 'nova-ui-kit' |
| 5 | +import { Link, useParams } from 'react-router-dom' |
| 6 | +import { APP_ROUTES } from 'utils/constants' |
| 7 | +import { STRING, translate } from 'utils/language' |
| 8 | + |
| 9 | +export const CaptureSetPicker = ({ |
| 10 | + clearable, |
| 11 | + value: _value, |
| 12 | + onValueChange, |
| 13 | +}: { |
| 14 | + clearable?: boolean |
| 15 | + value?: string |
| 16 | + onValueChange: (value?: string) => void |
| 17 | +}) => { |
| 18 | + const { projectId } = useParams() |
| 19 | + const { captureSets = [], isLoading } = useCaptureSets({ |
| 20 | + projectId: projectId as string, |
| 21 | + }) |
| 22 | + const captureSet = captureSets.find((c) => c.id === _value) |
| 23 | + const value = captureSet ? _value : '' |
| 24 | + |
| 25 | + return ( |
| 26 | + <div className="flex flex-col gap-4"> |
| 27 | + <div className="flex items-center justify-between gap-2"> |
| 28 | + <Select.Root |
| 29 | + key={value} |
| 30 | + disabled={isLoading || captureSets.length === 0} |
| 31 | + onValueChange={onValueChange} |
| 32 | + value={value} |
| 33 | + > |
| 34 | + <Select.Trigger loading={isLoading}> |
| 35 | + <Select.Value placeholder={translate(STRING.SELECT_PLACEHOLDER)} /> |
| 36 | + </Select.Trigger> |
| 37 | + <Select.Content className="max-h-72"> |
| 38 | + {captureSets.map((c) => ( |
| 39 | + <Select.Item key={c.id} value={c.id}> |
| 40 | + {c.name} |
| 41 | + </Select.Item> |
| 42 | + ))} |
| 43 | + </Select.Content> |
| 44 | + </Select.Root> |
| 45 | + {clearable && _value && ( |
| 46 | + <Button |
| 47 | + aria-label={translate(STRING.CLEAR)} |
| 48 | + className="shrink-0 text-muted-foreground" |
| 49 | + onClick={() => onValueChange()} |
| 50 | + size="icon" |
| 51 | + variant="ghost" |
| 52 | + > |
| 53 | + <XIcon className="w-4 h-4" /> |
| 54 | + </Button> |
| 55 | + )} |
| 56 | + </div> |
| 57 | + {captureSet?.numImages !== undefined ? ( |
| 58 | + captureSet.numImages === 0 ? ( |
| 59 | + <div className="flex flex-col gap-4"> |
| 60 | + <FormMessage |
| 61 | + className="flex justify-between gap-4" |
| 62 | + message={translate(STRING.MESSAGE_CAPTURE_SET_EMPTY)} |
| 63 | + theme="warning" |
| 64 | + withIcon |
| 65 | + > |
| 66 | + {captureSet.canPopulate ? ( |
| 67 | + <Link |
| 68 | + className="font-bold" |
| 69 | + to={APP_ROUTES.CAPTURE_SETS({ |
| 70 | + projectId: projectId as string, |
| 71 | + })} |
| 72 | + > |
| 73 | + <span>{translate(STRING.POPULATE)}</span> |
| 74 | + <ChevronRight className="inline w-4 h-4 ml-2" /> |
| 75 | + </Link> |
| 76 | + ) : null} |
| 77 | + </FormMessage> |
| 78 | + </div> |
| 79 | + ) : ( |
| 80 | + <FormMessage |
| 81 | + message={translate(STRING.MESSAGE_CAPTURE_SET_COUNT, { |
| 82 | + total: captureSet.numImages.toLocaleString(), |
| 83 | + })} |
| 84 | + withIcon |
| 85 | + /> |
| 86 | + ) |
| 87 | + ) : null} |
| 88 | + </div> |
| 89 | + ) |
| 90 | +} |
0 commit comments