ConceptPortal-public/rsconcept/frontend/src/components/select/SelectVersion.tsx
Ivan 609752a9d6
Some checks failed
Frontend CI / build (22.x) (push) Has been cancelled
R: Remove unused useMemo and useCallback
2024-12-13 21:31:09 +03:00

51 lines
1.2 KiB
TypeScript

'use client';
import clsx from 'clsx';
import { IVersionInfo, VersionID } from '@/models/library';
import { labelVersion } from '@/utils/labels';
import { CProps } from '../props';
import SelectSingle from '../ui/SelectSingle';
interface SelectVersionProps extends CProps.Styling {
id?: string;
items?: IVersionInfo[];
value?: VersionID;
onSelectValue: (newValue?: VersionID) => void;
placeholder?: string;
noBorder?: boolean;
}
function SelectVersion({ id, className, items, value, onSelectValue, ...restProps }: SelectVersionProps) {
const options = [
{
value: undefined,
label: labelVersion(undefined)
},
...(items?.map(version => ({
value: version.id,
label: version.version
})) ?? [])
];
const valueLabel = (() => {
const version = items?.find(ver => ver.id === value);
return version ? version.version : labelVersion(undefined);
})();
return (
<SelectSingle
id={id}
className={clsx('min-w-[12rem] text-ellipsis', className)}
options={options}
value={{ value: value, label: valueLabel }}
onChange={data => onSelectValue(data?.value)}
{...restProps}
/>
);
}
export default SelectVersion;