Implement InlineSynthesis fronted + backend

This commit is contained in:
IRBorisov 2024-03-23 21:42:50 +03:00
parent 8bae771e29
commit f6cb4d7859
6 changed files with 51 additions and 6 deletions

View File

@ -16,7 +16,9 @@ import {
ICstSubstituteData,
ICstTarget,
ICstUpdateData,
IInlineSynthesisData,
IRSForm,
IRSFormData,
IRSFormUploadData
} from '@/models/rsform';
import {
@ -26,6 +28,7 @@ import {
getTRSFile,
patchConstituenta,
patchDeleteConstituenta,
patchInlineSynthesis,
patchLibraryItem,
patchMoveConstituenta,
patchProduceStructure,
@ -65,6 +68,7 @@ interface IRSFormContext {
resetAliases: (callback: () => void) => void;
produceStructure: (data: ICstTarget, callback?: DataCallback<ConstituentaID[]>) => void;
inlineSynthesis: (data: IInlineSynthesisData, callback?: DataCallback<IRSFormData>) => void;
cstCreate: (data: ICstCreateData, callback?: DataCallback<IConstituentaMeta>) => void;
cstRename: (data: ICstRenameData, callback?: DataCallback<IConstituentaMeta>) => void;
@ -464,6 +468,24 @@ export const RSFormState = ({ schemaID, versionID, children }: RSFormStateProps)
[setError, schema, setSchema]
);
const inlineSynthesis = useCallback(
(data: IInlineSynthesisData, callback?: DataCallback<IRSFormData>) => {
setError(undefined);
patchInlineSynthesis({
data: data,
showError: true,
setLoading: setProcessing,
onError: setError,
onSuccess: newData => {
setSchema(newData);
library.localUpdateTimestamp(Number(schemaID));
if (callback) callback(newData);
}
});
},
[setError, library, schemaID, setSchema]
);
return (
<RSFormContext.Provider
value={{
@ -482,6 +504,7 @@ export const RSFormState = ({ schemaID, versionID, children }: RSFormStateProps)
claim,
resetAliases,
produceStructure,
inlineSynthesis,
subscribe,
unsubscribe,
cstUpdate,

View File

@ -8,7 +8,7 @@ import Modal, { ModalProps } from '@/components/ui/Modal';
import TabLabel from '@/components/ui/TabLabel';
import useRSFormDetails from '@/hooks/useRSFormDetails';
import { LibraryItemID } from '@/models/library';
import { IRSForm, IRSFormInlineData, ISubstitution } from '@/models/rsform';
import { IInlineSynthesisData, IRSForm, ISubstitution } from '@/models/rsform';
import ConstituentsTab from './ConstituentsTab';
import SchemaTab from './SchemaTab';
@ -16,7 +16,7 @@ import SubstitutionsTab from './SubstitutionsTab';
interface DlgInlineSynthesisProps extends Pick<ModalProps, 'hideWindow'> {
receiver: IRSForm;
onInlineSynthesis: (data: IRSFormInlineData) => void;
onInlineSynthesis: (data: IInlineSynthesisData) => void;
}
export enum TabID {
@ -40,7 +40,7 @@ function DlgInlineSynthesis({ hideWindow, receiver, onInlineSynthesis }: DlgInli
if (!source.schema) {
return;
}
const data: IRSFormInlineData = {
const data: IInlineSynthesisData = {
source: source.schema?.id,
receiver: receiver.id,
items: selected,

View File

@ -247,7 +247,7 @@ export interface IVersionCreatedResponse {
/**
* Represents input data for inline synthesis.
*/
export interface IRSFormInlineData {
export interface IInlineSynthesisData {
receiver: LibraryItemID;
source: LibraryItemID;
items: ConstituentaID[];

View File

@ -38,6 +38,7 @@ import {
ICstSubstituteData,
ICstTarget,
ICstUpdateData,
IInlineSynthesisData,
IRSForm,
TermForm
} from '@/models/rsform';
@ -263,6 +264,19 @@ export const RSEditState = ({
[model]
);
const handleInlineSynthesis = useCallback(
(data: IInlineSynthesisData) => {
if (!model.schema) {
return;
}
const oldCount = model.schema.items.length;
model.inlineSynthesis(data, newSchema =>
toast.success(`Конституенты добавлены: ${newSchema['items'].length - oldCount}`)
);
},
[model]
);
const moveUp = useCallback(() => {
if (!model.schema?.items || selected.length === 0) {
return;
@ -557,7 +571,7 @@ export const RSEditState = ({
<DlgInlineSynthesis
receiver={model.schema}
hideWindow={() => setShowInlineSynthesis(false)}
onInlineSynthesis={() => toast('Testing')}
onInlineSynthesis={handleInlineSynthesis}
/>
) : null}
</AnimatePresence>

View File

@ -215,7 +215,7 @@ function RSTabsMenu({ onDestroy }: RSTabsMenuProps) {
onClick={handleTemplates}
/>
<DropdownButton
disabled={!controller.isContentEditable || !user.is_staff}
disabled={!controller.isContentEditable}
text='Применить конструкт'
title='Импортировать совокупность конституент из другой схемы'
icon={<LuBookCopy size='1rem' className='icon-green' />}

View File

@ -32,6 +32,7 @@ import {
ICstSubstituteData,
ICstTarget,
ICstUpdateData,
IInlineSynthesisData,
IProduceStructureResponse,
IRSFormCreateData,
IRSFormData,
@ -379,6 +380,13 @@ export function patchUploadTRS(target: string, request: FrontExchange<IRSFormUpl
}
});
}
export function patchInlineSynthesis(request: FrontExchange<IInlineSynthesisData, IRSFormData>) {
AxiosPatch({
title: 'Processing inline synthesis',
endpoint: `/api/operations/inline-synthesis`,
request: request
});
}
export function postResolveText(schema: string, request: FrontExchange<ITextRequest, IResolutionData>) {
AxiosPost({