mirror of
https://github.com/IRBorisov/ConceptPortal.git
synced 2025-06-26 13:00:39 +03:00
F: Rework edit wordforms dialog
This commit is contained in:
parent
6641d4b224
commit
e5b1bbb57a
|
@ -43,7 +43,7 @@ interface ModalFormProps extends ModalProps {
|
||||||
beforeSubmit?: () => boolean;
|
beforeSubmit?: () => boolean;
|
||||||
|
|
||||||
/** Callback to be called after submit. */
|
/** Callback to be called after submit. */
|
||||||
onSubmit: (event: React.FormEvent<HTMLFormElement>) => void | Promise<void>;
|
onSubmit: (event: React.FormEvent<HTMLFormElement>) => void;
|
||||||
|
|
||||||
/** Callback to be called when modal is canceled. */
|
/** Callback to be called when modal is canceled. */
|
||||||
onCancel?: () => void;
|
onCancel?: () => void;
|
||||||
|
@ -82,7 +82,8 @@ export function ModalForm({
|
||||||
if (beforeSubmit && !beforeSubmit()) {
|
if (beforeSubmit && !beforeSubmit()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
void Promise.resolve(onSubmit(event)).then(hideDialog);
|
onSubmit(event);
|
||||||
|
hideDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -13,7 +13,7 @@ interface BadgeWordFormProps {
|
||||||
/**
|
/**
|
||||||
* Displays a badge with grammemes of a word form.
|
* Displays a badge with grammemes of a word form.
|
||||||
*/
|
*/
|
||||||
function BadgeWordForm({ keyPrefix, form }: BadgeWordFormProps) {
|
export function BadgeWordForm({ keyPrefix, form }: BadgeWordFormProps) {
|
||||||
return (
|
return (
|
||||||
<div className='flex flex-wrap justify-start gap-1 select-none w-fit'>
|
<div className='flex flex-wrap justify-start gap-1 select-none w-fit'>
|
||||||
{form.grams.map(gram => (
|
{form.grams.map(gram => (
|
||||||
|
@ -22,5 +22,3 @@ function BadgeWordForm({ keyPrefix, form }: BadgeWordFormProps) {
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default BadgeWordForm;
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ interface SelectMultiGrammemeProps
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function SelectMultiGrammeme({ value, onChange, ...restProps }: SelectMultiGrammemeProps) {
|
export function SelectMultiGrammeme({ value, onChange, ...restProps }: SelectMultiGrammemeProps) {
|
||||||
const compatible = getCompatibleGrams(
|
const compatible = getCompatibleGrams(
|
||||||
value.filter(data => Object.values(Grammeme).includes(data.value as Grammeme)).map(data => data.value as Grammeme)
|
value.filter(data => Object.values(Grammeme).includes(data.value as Grammeme)).map(data => data.value as Grammeme)
|
||||||
);
|
);
|
||||||
|
@ -27,5 +27,3 @@ function SelectMultiGrammeme({ value, onChange, ...restProps }: SelectMultiGramm
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default SelectMultiGrammeme;
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ interface SelectWordFormProps extends CProps.Styling {
|
||||||
onChange: React.Dispatch<React.SetStateAction<IGrammemeOption[]>>;
|
onChange: React.Dispatch<React.SetStateAction<IGrammemeOption[]>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
function SelectWordForm({ value, onChange, className, ...restProps }: SelectWordFormProps) {
|
export function SelectWordForm({ value, onChange, className, ...restProps }: SelectWordFormProps) {
|
||||||
function handleSelect(grams: Grammeme[]) {
|
function handleSelect(grams: Grammeme[]) {
|
||||||
onChange(supportedGrammeOptions.filter(({ value }) => grams.includes(value as Grammeme)));
|
onChange(supportedGrammeOptions.filter(({ value }) => grams.includes(value as Grammeme)));
|
||||||
}
|
}
|
||||||
|
@ -53,5 +53,3 @@ function SelectWordForm({ value, onChange, className, ...restProps }: SelectWord
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default SelectWordForm;
|
|
||||||
|
|
|
@ -6,8 +6,8 @@ import { Label, TextInput } from '@/components/Input';
|
||||||
import { useDialogsStore } from '@/stores/dialogs';
|
import { useDialogsStore } from '@/stores/dialogs';
|
||||||
|
|
||||||
import { PickConstituenta } from '../../components/PickConstituenta';
|
import { PickConstituenta } from '../../components/PickConstituenta';
|
||||||
import SelectMultiGrammeme from '../../components/SelectMultiGrammeme';
|
import { SelectMultiGrammeme } from '../../components/SelectMultiGrammeme';
|
||||||
import SelectWordForm from '../../components/SelectWordForm';
|
import { SelectWordForm } from '../../components/SelectWordForm';
|
||||||
import { IConstituenta } from '../../models/rsform';
|
import { IConstituenta } from '../../models/rsform';
|
||||||
import { matchConstituenta } from '../../models/rsformAPI';
|
import { matchConstituenta } from '../../models/rsformAPI';
|
||||||
import { CstMatchMode } from '../../stores/cstSearch';
|
import { CstMatchMode } from '../../stores/cstSearch';
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useEffect, useState } from 'react';
|
import { useState } from 'react';
|
||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
|
|
||||||
import { HelpTopic } from '@/features/help';
|
import { HelpTopic } from '@/features/help';
|
||||||
|
@ -16,53 +16,51 @@ import { useGenerateLexeme } from '../../backend/cctext/useGenerateLexeme';
|
||||||
import { useInflectText } from '../../backend/cctext/useInflectText';
|
import { useInflectText } from '../../backend/cctext/useInflectText';
|
||||||
import { useIsProcessingCctext } from '../../backend/cctext/useIsProcessingCctext';
|
import { useIsProcessingCctext } from '../../backend/cctext/useIsProcessingCctext';
|
||||||
import { useParseText } from '../../backend/cctext/useParseText';
|
import { useParseText } from '../../backend/cctext/useParseText';
|
||||||
import SelectMultiGrammeme from '../../components/SelectMultiGrammeme';
|
import { useCstUpdate } from '../../backend/useCstUpdate';
|
||||||
|
import { SelectMultiGrammeme } from '../../components/SelectMultiGrammeme';
|
||||||
import { Grammeme, IGrammemeOption, IWordForm, supportedGrammemes } from '../../models/language';
|
import { Grammeme, IGrammemeOption, IWordForm, supportedGrammemes } from '../../models/language';
|
||||||
import { parseGrammemes, supportedGrammeOptions, wordFormEquals } from '../../models/languageAPI';
|
import { parseGrammemes, supportedGrammeOptions, wordFormEquals } from '../../models/languageAPI';
|
||||||
import { IConstituenta, TermForm } from '../../models/rsform';
|
import { IConstituenta } from '../../models/rsform';
|
||||||
|
|
||||||
import TableWordForms from './TableWordForms';
|
import { TableWordForms } from './TableWordForms';
|
||||||
|
|
||||||
export interface DlgEditWordFormsProps {
|
export interface DlgEditWordFormsProps {
|
||||||
|
itemID: number;
|
||||||
target: IConstituenta;
|
target: IConstituenta;
|
||||||
onSave: (data: TermForm[]) => void;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function DlgEditWordForms() {
|
function DlgEditWordForms() {
|
||||||
const { target, onSave } = useDialogsStore(state => state.props as DlgEditWordFormsProps);
|
const { itemID, target } = useDialogsStore(state => state.props as DlgEditWordFormsProps);
|
||||||
|
const { cstUpdate } = useCstUpdate();
|
||||||
|
|
||||||
const isProcessing = useIsProcessingCctext();
|
const isProcessing = useIsProcessingCctext();
|
||||||
const { inflectText } = useInflectText();
|
const { inflectText } = useInflectText();
|
||||||
const { parseText } = useParseText();
|
const { parseText } = useParseText();
|
||||||
const { generateLexeme } = useGenerateLexeme();
|
const { generateLexeme } = useGenerateLexeme();
|
||||||
|
|
||||||
const [term, setTerm] = useState('');
|
const [inputText, setInputText] = useState(target.term_resolved);
|
||||||
const [inputText, setInputText] = useState('');
|
|
||||||
const [inputGrams, setInputGrams] = useState<IGrammemeOption[]>([]);
|
const [inputGrams, setInputGrams] = useState<IGrammemeOption[]>([]);
|
||||||
const [forms, setForms] = useState<IWordForm[]>([]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
const [forms, setForms] = useState<IWordForm[]>(
|
||||||
const initForms: IWordForm[] = [];
|
target.term_forms.map(term => ({
|
||||||
target.term_forms.forEach(term =>
|
|
||||||
initForms.push({
|
|
||||||
text: term.text,
|
text: term.text,
|
||||||
grams: parseGrammemes(term.tags)
|
grams: parseGrammemes(term.tags)
|
||||||
})
|
}))
|
||||||
);
|
);
|
||||||
setForms(initForms);
|
|
||||||
setTerm(target.term_resolved);
|
|
||||||
setInputText(target.term_resolved);
|
|
||||||
setInputGrams([]);
|
|
||||||
}, [target]);
|
|
||||||
|
|
||||||
function handleSubmit() {
|
function handleSubmit() {
|
||||||
const result: TermForm[] = [];
|
void cstUpdate({
|
||||||
forms.forEach(({ text, grams }) =>
|
itemID: itemID,
|
||||||
result.push({
|
data: {
|
||||||
|
target: target.id,
|
||||||
|
item_data: {
|
||||||
|
term_forms: forms.map(({ text, grams }) => ({
|
||||||
text: text,
|
text: text,
|
||||||
tags: grams.join(',')
|
tags: grams.join(',')
|
||||||
})
|
}))
|
||||||
);
|
}
|
||||||
onSave(result);
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleAddForm() {
|
function handleAddForm() {
|
||||||
|
@ -80,7 +78,7 @@ function DlgEditWordForms() {
|
||||||
|
|
||||||
function handleInflect() {
|
function handleInflect() {
|
||||||
void inflectText({
|
void inflectText({
|
||||||
text: term,
|
text: target.term_resolved,
|
||||||
grams: inputGrams.map(gram => gram.value).join(',')
|
grams: inputGrams.map(gram => gram.value).join(',')
|
||||||
}).then(response => setInputText(response.result));
|
}).then(response => setInputText(response.result));
|
||||||
}
|
}
|
||||||
|
@ -134,7 +132,7 @@ function DlgEditWordForms() {
|
||||||
label='Начальная форма'
|
label='Начальная форма'
|
||||||
placeholder='Термин в начальной форме'
|
placeholder='Термин в начальной форме'
|
||||||
rows={1}
|
rows={1}
|
||||||
value={term}
|
value={target.term_resolved}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div className='mt-3 mb-2'>
|
<div className='mt-3 mb-2'>
|
||||||
|
|
|
@ -7,7 +7,7 @@ import DataTable, { createColumnHelper } from '@/components/DataTable';
|
||||||
import { IconRemove } from '@/components/Icons';
|
import { IconRemove } from '@/components/Icons';
|
||||||
import { NoData } from '@/components/View';
|
import { NoData } from '@/components/View';
|
||||||
|
|
||||||
import BadgeWordForm from '../../components/BadgeWordForm';
|
import { BadgeWordForm } from '../../components/BadgeWordForm';
|
||||||
import { IWordForm } from '../../models/language';
|
import { IWordForm } from '../../models/language';
|
||||||
|
|
||||||
interface TableWordFormsProps {
|
interface TableWordFormsProps {
|
||||||
|
@ -18,7 +18,7 @@ interface TableWordFormsProps {
|
||||||
|
|
||||||
const columnHelper = createColumnHelper<IWordForm>();
|
const columnHelper = createColumnHelper<IWordForm>();
|
||||||
|
|
||||||
function TableWordForms({ forms, setForms, onFormSelect }: TableWordFormsProps) {
|
export function TableWordForms({ forms, setForms, onFormSelect }: TableWordFormsProps) {
|
||||||
function handleDeleteRow(row: number) {
|
function handleDeleteRow(row: number) {
|
||||||
setForms(prev => {
|
setForms(prev => {
|
||||||
const newForms: IWordForm[] = [];
|
const newForms: IWordForm[] = [];
|
||||||
|
@ -80,5 +80,3 @@ function TableWordForms({ forms, setForms, onFormSelect }: TableWordFormsProps)
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default TableWordForms;
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ import { usePreferencesStore } from '@/stores/preferences';
|
||||||
import { globals } from '@/utils/constants';
|
import { globals } from '@/utils/constants';
|
||||||
import { promptUnsaved } from '@/utils/utils';
|
import { promptUnsaved } from '@/utils/utils';
|
||||||
|
|
||||||
import { useCstUpdate } from '../../../backend/useCstUpdate';
|
|
||||||
import { useMutatingRSForm } from '../../../backend/useMutatingRSForm';
|
import { useMutatingRSForm } from '../../../backend/useMutatingRSForm';
|
||||||
import { useRSEdit } from '../RSEditContext';
|
import { useRSEdit } from '../RSEditContext';
|
||||||
import { ViewConstituents } from '../ViewConstituents';
|
import { ViewConstituents } from '../ViewConstituents';
|
||||||
|
@ -30,7 +29,6 @@ function EditorConstituenta() {
|
||||||
|
|
||||||
const showList = usePreferencesStore(state => state.showCstSideList);
|
const showList = usePreferencesStore(state => state.showCstSideList);
|
||||||
const showEditTerm = useDialogsStore(state => state.showEditWordForms);
|
const showEditTerm = useDialogsStore(state => state.showEditWordForms);
|
||||||
const { cstUpdate } = useCstUpdate();
|
|
||||||
const { isModified } = useModificationStore();
|
const { isModified } = useModificationStore();
|
||||||
|
|
||||||
const [toggleReset, setToggleReset] = useState(false);
|
const [toggleReset, setToggleReset] = useState(false);
|
||||||
|
@ -66,17 +64,7 @@ function EditorConstituenta() {
|
||||||
if (isModified && !promptUnsaved()) {
|
if (isModified && !promptUnsaved()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
showEditTerm({
|
showEditTerm({ itemID: schema.id, target: activeCst });
|
||||||
target: activeCst,
|
|
||||||
onSave: forms =>
|
|
||||||
void cstUpdate({
|
|
||||||
itemID: schema.id,
|
|
||||||
data: {
|
|
||||||
target: activeCst.id,
|
|
||||||
item_data: { term_forms: forms }
|
|
||||||
}
|
|
||||||
})
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function initiateSubmit() {
|
function initiateSubmit() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user