2024-06-07 20:17:03 +03:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
import clsx from 'clsx';
|
|
|
|
|
2025-03-12 12:04:23 +03:00
|
|
|
import { SelectSingle } from '@/components/input';
|
2025-02-20 20:22:05 +03:00
|
|
|
import { type Styling } from '@/components/props';
|
2025-02-11 20:56:11 +03:00
|
|
|
|
2025-02-12 15:12:59 +03:00
|
|
|
import { labelVersion } from '../../rsform/labels';
|
2025-02-20 20:22:05 +03:00
|
|
|
import { type IVersionInfo } from '../backend/types';
|
|
|
|
import { type CurrentVersion } from '../models/library';
|
2024-06-07 20:17:03 +03:00
|
|
|
|
2025-02-20 20:22:05 +03:00
|
|
|
interface SelectVersionProps extends Styling {
|
2024-06-07 20:17:03 +03:00
|
|
|
id?: string;
|
2025-02-20 16:36:50 +03:00
|
|
|
value: CurrentVersion;
|
|
|
|
onChange: (newValue: CurrentVersion) => void;
|
2024-07-26 21:08:31 +03:00
|
|
|
|
2025-02-20 16:36:50 +03:00
|
|
|
items: IVersionInfo[];
|
2024-07-26 21:08:31 +03:00
|
|
|
placeholder?: string;
|
|
|
|
noBorder?: boolean;
|
2024-06-07 20:17:03 +03:00
|
|
|
}
|
|
|
|
|
2025-02-12 15:12:59 +03:00
|
|
|
export function SelectVersion({ id, className, items, value, onChange, ...restProps }: SelectVersionProps) {
|
2024-12-13 21:30:49 +03:00
|
|
|
const options = [
|
|
|
|
{
|
2025-02-20 16:36:50 +03:00
|
|
|
value: 'latest' as const,
|
|
|
|
label: labelVersion('latest', items)
|
2024-12-13 21:30:49 +03:00
|
|
|
},
|
|
|
|
...(items?.map(version => ({
|
|
|
|
value: version.id,
|
|
|
|
label: version.version
|
|
|
|
})) ?? [])
|
|
|
|
];
|
|
|
|
|
2024-06-07 20:17:03 +03:00
|
|
|
return (
|
|
|
|
<SelectSingle
|
|
|
|
id={id}
|
2025-03-10 16:01:40 +03:00
|
|
|
className={clsx('min-w-48 text-ellipsis', className)}
|
2024-06-07 20:17:03 +03:00
|
|
|
options={options}
|
2025-02-20 16:36:50 +03:00
|
|
|
value={{ value: value, label: labelVersion(value, items) }}
|
|
|
|
onChange={data => onChange(data?.value ?? 'latest')}
|
2024-06-07 20:17:03 +03:00
|
|
|
{...restProps}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|