mirror of
https://github.com/IRBorisov/ConceptPortal.git
synced 2025-06-25 20:40:36 +03:00
F: Improve version selection
This commit is contained in:
parent
9c0315f049
commit
9d99179a40
|
@ -7,13 +7,14 @@ import { CProps } from '@/components/props';
|
|||
|
||||
import { labelVersion } from '../../rsform/labels';
|
||||
import { IVersionInfo } from '../backend/types';
|
||||
import { CurrentVersion } from '../models/library';
|
||||
|
||||
interface SelectVersionProps extends CProps.Styling {
|
||||
id?: string;
|
||||
value: number | undefined;
|
||||
onChange: (newValue: number | undefined) => void;
|
||||
value: CurrentVersion;
|
||||
onChange: (newValue: CurrentVersion) => void;
|
||||
|
||||
items?: IVersionInfo[];
|
||||
items: IVersionInfo[];
|
||||
placeholder?: string;
|
||||
noBorder?: boolean;
|
||||
}
|
||||
|
@ -21,8 +22,8 @@ interface SelectVersionProps extends CProps.Styling {
|
|||
export function SelectVersion({ id, className, items, value, onChange, ...restProps }: SelectVersionProps) {
|
||||
const options = [
|
||||
{
|
||||
value: undefined,
|
||||
label: labelVersion(undefined)
|
||||
value: 'latest' as const,
|
||||
label: labelVersion('latest', items)
|
||||
},
|
||||
...(items?.map(version => ({
|
||||
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 (
|
||||
<SelectSingle
|
||||
id={id}
|
||||
className={clsx('min-w-[12rem] text-ellipsis', className)}
|
||||
options={options}
|
||||
value={{ value: value, label: valueLabel }}
|
||||
onChange={data => onChange(data?.value)}
|
||||
value={{ value: value, label: labelVersion(value, items) }}
|
||||
onChange={data => onChange(data?.value ?? 'latest')}
|
||||
{...restProps}
|
||||
/>
|
||||
);
|
||||
|
|
|
@ -39,3 +39,6 @@ export interface ILibraryFilter {
|
|||
isEditor: boolean | null;
|
||||
filterUser: number | null;
|
||||
}
|
||||
|
||||
/** Represents current version */
|
||||
export type CurrentVersion = number | 'latest';
|
||||
|
|
|
@ -25,6 +25,7 @@ export class RSFormLoader {
|
|||
|
||||
constructor(input: IRSFormDTO) {
|
||||
this.schema = input as unknown as IRSForm;
|
||||
this.schema.version = input.version ?? 'latest';
|
||||
}
|
||||
|
||||
produceRSForm(): IRSForm {
|
||||
|
|
|
@ -5,9 +5,12 @@
|
|||
import { PARAMETER } from '@/utils/constants';
|
||||
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 { 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 { CstMatchMode, DependencyMode } from './stores/cstSearch';
|
||||
import { GraphColoring } from './stores/termGraph';
|
||||
|
@ -61,8 +64,8 @@ export function labelConstituenta(cst: IConstituenta) {
|
|||
/**
|
||||
* Generates label for {@link IVersionInfo} of {@link IRSForm}.
|
||||
*/
|
||||
export function labelVersion(schema: IRSForm | undefined) {
|
||||
const version = schema?.versions.find(ver => ver.id === schema?.version);
|
||||
export function labelVersion(value: CurrentVersion, items: IVersionInfo[]) {
|
||||
const version = items.find(ver => ver.id === value);
|
||||
return version ? version.version : 'актуальная';
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*/
|
||||
|
||||
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';
|
||||
|
||||
|
@ -139,7 +139,7 @@ export interface IInheritanceInfo {
|
|||
* Represents formal explication for set of concepts.
|
||||
*/
|
||||
export interface IRSForm extends ILibraryItemData {
|
||||
version?: number;
|
||||
version: CurrentVersion;
|
||||
versions: IVersionInfo[];
|
||||
|
||||
items: IConstituenta[];
|
||||
|
|
|
@ -9,6 +9,7 @@ import clsx from 'clsx';
|
|||
import { urls, useConceptNavigation } from '@/app';
|
||||
import { LibraryItemType, SelectVersion, ToolbarItemAccess, useUpdateItem } from '@/features/library';
|
||||
import { IUpdateLibraryItemDTO, schemaUpdateLibraryItem } from '@/features/library/backend/types';
|
||||
import { CurrentVersion } from '@/features/library/models/library';
|
||||
|
||||
import { SubmitButton } from '@/components/Control';
|
||||
import { IconSave } from '@/components/Icons';
|
||||
|
@ -54,8 +55,8 @@ export function FormRSForm() {
|
|||
setIsModified(isDirty);
|
||||
}, [isDirty, setIsModified]);
|
||||
|
||||
function handleSelectVersion(version?: number) {
|
||||
router.push(urls.schema(schema.id, version));
|
||||
function handleSelectVersion(version: CurrentVersion) {
|
||||
router.push(urls.schema(schema.id, version === 'latest' ? undefined : version));
|
||||
}
|
||||
|
||||
function onSubmit(data: IUpdateLibraryItemDTO) {
|
||||
|
|
|
@ -27,7 +27,7 @@ export function ToolbarVersioning({ blockReload }: ToolbarVersioningProps) {
|
|||
const showEditVersions = useDialogsStore(state => state.showEditVersions);
|
||||
|
||||
function handleRestoreVersion() {
|
||||
if (!schema.version || !window.confirm(promptText.restoreArchive)) {
|
||||
if (schema.version === 'latest' || !window.confirm(promptText.restoreArchive)) {
|
||||
return;
|
||||
}
|
||||
void versionRestore({ versionID: schema.version }).then(() => navigateVersion());
|
||||
|
|
|
@ -115,7 +115,7 @@ export function MenuRSTabs() {
|
|||
const fileName = (schema.alias ?? 'Schema') + EXTEOR_TRS_FILE;
|
||||
void download({
|
||||
itemID: schema.id,
|
||||
version: schema.version
|
||||
version: schema.version === 'latest' ? undefined : schema.version
|
||||
}).then((data: Blob) => {
|
||||
try {
|
||||
fileDownload(data, fileName);
|
||||
|
|
|
@ -86,7 +86,10 @@ export function RSTabs({ activeID, activeTab }: RSTabsProps) {
|
|||
>
|
||||
<MenuRSTabs />
|
||||
|
||||
<TabLabel label='Карточка' titleHtml={`${schema.title ?? ''}<br />Версия: ${labelVersion(schema)}`} />
|
||||
<TabLabel
|
||||
label='Карточка'
|
||||
titleHtml={`${schema.title ?? ''}<br />Версия: ${labelVersion(schema.version, schema.versions)}`}
|
||||
/>
|
||||
<TabLabel
|
||||
label='Содержание'
|
||||
titleHtml={`Конституент: ${schema.stats?.count_all ?? 0}<br />Ошибок: ${schema.stats?.count_errors ?? 0}`}
|
||||
|
|
Loading…
Reference in New Issue
Block a user