F: Improve version selection

This commit is contained in:
Ivan 2025-02-20 16:37:56 +03:00
parent 9c0315f049
commit 9d99179a40
9 changed files with 29 additions and 22 deletions

View File

@ -7,13 +7,14 @@ import { CProps } from '@/components/props';
import { labelVersion } from '../../rsform/labels'; import { labelVersion } from '../../rsform/labels';
import { IVersionInfo } from '../backend/types'; import { IVersionInfo } from '../backend/types';
import { CurrentVersion } from '../models/library';
interface SelectVersionProps extends CProps.Styling { interface SelectVersionProps extends CProps.Styling {
id?: string; id?: string;
value: number | undefined; value: CurrentVersion;
onChange: (newValue: number | undefined) => void; onChange: (newValue: CurrentVersion) => void;
items?: IVersionInfo[]; items: IVersionInfo[];
placeholder?: string; placeholder?: string;
noBorder?: boolean; noBorder?: boolean;
} }
@ -21,8 +22,8 @@ interface SelectVersionProps extends CProps.Styling {
export function SelectVersion({ id, className, items, value, onChange, ...restProps }: SelectVersionProps) { export function SelectVersion({ id, className, items, value, onChange, ...restProps }: SelectVersionProps) {
const options = [ const options = [
{ {
value: undefined, value: 'latest' as const,
label: labelVersion(undefined) label: labelVersion('latest', items)
}, },
...(items?.map(version => ({ ...(items?.map(version => ({
value: version.id, value: version.id,
@ -30,18 +31,13 @@ export function SelectVersion({ id, className, items, value, onChange, ...restPr
})) ?? []) })) ?? [])
]; ];
const valueLabel = (() => {
const version = items?.find(ver => ver.id === value);
return version ? version.version : labelVersion(undefined);
})();
return ( return (
<SelectSingle <SelectSingle
id={id} id={id}
className={clsx('min-w-[12rem] text-ellipsis', className)} className={clsx('min-w-[12rem] text-ellipsis', className)}
options={options} options={options}
value={{ value: value, label: valueLabel }} value={{ value: value, label: labelVersion(value, items) }}
onChange={data => onChange(data?.value)} onChange={data => onChange(data?.value ?? 'latest')}
{...restProps} {...restProps}
/> />
); );

View File

@ -39,3 +39,6 @@ export interface ILibraryFilter {
isEditor: boolean | null; isEditor: boolean | null;
filterUser: number | null; filterUser: number | null;
} }
/** Represents current version */
export type CurrentVersion = number | 'latest';

View File

@ -25,6 +25,7 @@ export class RSFormLoader {
constructor(input: IRSFormDTO) { constructor(input: IRSFormDTO) {
this.schema = input as unknown as IRSForm; this.schema = input as unknown as IRSForm;
this.schema.version = input.version ?? 'latest';
} }
produceRSForm(): IRSForm { produceRSForm(): IRSForm {

View File

@ -5,9 +5,12 @@
import { PARAMETER } from '@/utils/constants'; import { PARAMETER } from '@/utils/constants';
import { prepareTooltip } from '@/utils/utils'; import { prepareTooltip } from '@/utils/utils';
import { IVersionInfo } from '../library';
import { CurrentVersion } from '../library/models/library';
import { CstType, IRSErrorDescription, ParsingStatus, RSErrorType, TokenID } from './backend/types'; import { CstType, IRSErrorDescription, ParsingStatus, RSErrorType, TokenID } from './backend/types';
import { GramData, Grammeme, ReferenceType } from './models/language'; import { GramData, Grammeme, ReferenceType } from './models/language';
import { CstClass, ExpressionStatus, IConstituenta, IRSForm } from './models/rsform'; import { CstClass, ExpressionStatus, IConstituenta } from './models/rsform';
import { IArgumentInfo, ISyntaxTreeNode } from './models/rslang'; import { IArgumentInfo, ISyntaxTreeNode } from './models/rslang';
import { CstMatchMode, DependencyMode } from './stores/cstSearch'; import { CstMatchMode, DependencyMode } from './stores/cstSearch';
import { GraphColoring } from './stores/termGraph'; import { GraphColoring } from './stores/termGraph';
@ -61,8 +64,8 @@ export function labelConstituenta(cst: IConstituenta) {
/** /**
* Generates label for {@link IVersionInfo} of {@link IRSForm}. * Generates label for {@link IVersionInfo} of {@link IRSForm}.
*/ */
export function labelVersion(schema: IRSForm | undefined) { export function labelVersion(value: CurrentVersion, items: IVersionInfo[]) {
const version = schema?.versions.find(ver => ver.id === schema?.version); const version = items.find(ver => ver.id === value);
return version ? version.version : 'актуальная'; return version ? version.version : 'актуальная';
} }

View File

@ -3,7 +3,7 @@
*/ */
import { ILibraryItemData, IVersionInfo } from '@/features/library/backend/types'; import { ILibraryItemData, IVersionInfo } from '@/features/library/backend/types';
import { ILibraryItemReference } from '@/features/library/models/library'; import { CurrentVersion, ILibraryItemReference } from '@/features/library/models/library';
import { Graph } from '@/models/Graph'; import { Graph } from '@/models/Graph';
@ -139,7 +139,7 @@ export interface IInheritanceInfo {
* Represents formal explication for set of concepts. * Represents formal explication for set of concepts.
*/ */
export interface IRSForm extends ILibraryItemData { export interface IRSForm extends ILibraryItemData {
version?: number; version: CurrentVersion;
versions: IVersionInfo[]; versions: IVersionInfo[];
items: IConstituenta[]; items: IConstituenta[];

View File

@ -9,6 +9,7 @@ import clsx from 'clsx';
import { urls, useConceptNavigation } from '@/app'; import { urls, useConceptNavigation } from '@/app';
import { LibraryItemType, SelectVersion, ToolbarItemAccess, useUpdateItem } from '@/features/library'; import { LibraryItemType, SelectVersion, ToolbarItemAccess, useUpdateItem } from '@/features/library';
import { IUpdateLibraryItemDTO, schemaUpdateLibraryItem } from '@/features/library/backend/types'; import { IUpdateLibraryItemDTO, schemaUpdateLibraryItem } from '@/features/library/backend/types';
import { CurrentVersion } from '@/features/library/models/library';
import { SubmitButton } from '@/components/Control'; import { SubmitButton } from '@/components/Control';
import { IconSave } from '@/components/Icons'; import { IconSave } from '@/components/Icons';
@ -54,8 +55,8 @@ export function FormRSForm() {
setIsModified(isDirty); setIsModified(isDirty);
}, [isDirty, setIsModified]); }, [isDirty, setIsModified]);
function handleSelectVersion(version?: number) { function handleSelectVersion(version: CurrentVersion) {
router.push(urls.schema(schema.id, version)); router.push(urls.schema(schema.id, version === 'latest' ? undefined : version));
} }
function onSubmit(data: IUpdateLibraryItemDTO) { function onSubmit(data: IUpdateLibraryItemDTO) {

View File

@ -27,7 +27,7 @@ export function ToolbarVersioning({ blockReload }: ToolbarVersioningProps) {
const showEditVersions = useDialogsStore(state => state.showEditVersions); const showEditVersions = useDialogsStore(state => state.showEditVersions);
function handleRestoreVersion() { function handleRestoreVersion() {
if (!schema.version || !window.confirm(promptText.restoreArchive)) { if (schema.version === 'latest' || !window.confirm(promptText.restoreArchive)) {
return; return;
} }
void versionRestore({ versionID: schema.version }).then(() => navigateVersion()); void versionRestore({ versionID: schema.version }).then(() => navigateVersion());

View File

@ -115,7 +115,7 @@ export function MenuRSTabs() {
const fileName = (schema.alias ?? 'Schema') + EXTEOR_TRS_FILE; const fileName = (schema.alias ?? 'Schema') + EXTEOR_TRS_FILE;
void download({ void download({
itemID: schema.id, itemID: schema.id,
version: schema.version version: schema.version === 'latest' ? undefined : schema.version
}).then((data: Blob) => { }).then((data: Blob) => {
try { try {
fileDownload(data, fileName); fileDownload(data, fileName);

View File

@ -86,7 +86,10 @@ export function RSTabs({ activeID, activeTab }: RSTabsProps) {
> >
<MenuRSTabs /> <MenuRSTabs />
<TabLabel label='Карточка' titleHtml={`${schema.title ?? ''}<br />Версия: ${labelVersion(schema)}`} /> <TabLabel
label='Карточка'
titleHtml={`${schema.title ?? ''}<br />Версия: ${labelVersion(schema.version, schema.versions)}`}
/>
<TabLabel <TabLabel
label='Содержание' label='Содержание'
titleHtml={`Конституент: ${schema.stats?.count_all ?? 0}<br />Ошибок: ${schema.stats?.count_errors ?? 0}`} titleHtml={`Конституент: ${schema.stats?.count_all ?? 0}<br />Ошибок: ${schema.stats?.count_errors ?? 0}`}