From f54254bb564717d76bb390c5cfd30639278d5587 Mon Sep 17 00:00:00 2001
From: IRBorisov <8611739+IRBorisov@users.noreply.github.com>
Date: Sat, 30 Sep 2023 17:16:20 +0300
Subject: [PATCH] Improve reference editing
---
.../Help/HelpTerminologyControl.tsx | 2 +-
.../components/RefsInput/DlgEditReference.tsx | 104 +++++++++++-------
.../RefsInput/ReferenceTypeButton.tsx | 23 ++++
...{TermformButton.tsx => WordformButton.tsx} | 6 +-
.../src/components/RefsInput/index.tsx | 22 +++-
rsconcept/frontend/src/utils/codemirror.ts | 15 ++-
6 files changed, 122 insertions(+), 50 deletions(-)
create mode 100644 rsconcept/frontend/src/components/RefsInput/ReferenceTypeButton.tsx
rename rsconcept/frontend/src/components/RefsInput/{TermformButton.tsx => WordformButton.tsx} (75%)
diff --git a/rsconcept/frontend/src/components/Help/HelpTerminologyControl.tsx b/rsconcept/frontend/src/components/Help/HelpTerminologyControl.tsx
index 294dbcc1..9a5c3d7d 100644
--- a/rsconcept/frontend/src/components/Help/HelpTerminologyControl.tsx
+++ b/rsconcept/frontend/src/components/Help/HelpTerminologyControl.tsx
@@ -4,7 +4,7 @@ function HelpTerminologyControl() {
Терминологизация: Контроль терминологии
Портал позволяет контролировать употребление терминов, привязанных к сущностям в концептуальных схемах.
-
Для этого используется механизм текстовых отсылок: использование термина и синтаксическая связь.
+
Для этого используется механизм текстовых отсылок: использование термина и связывание слов.
При отсылке к термину указывается параметры словоформы так, обеспечивающие корректное согласование слов.
Граммема - минимальная единица грамматической информаци, например род, число, падеж.
Словоформа - грамматическая форма словосочетания, которая может меняться в зависимости от его грамматических характеристик.
diff --git a/rsconcept/frontend/src/components/RefsInput/DlgEditReference.tsx b/rsconcept/frontend/src/components/RefsInput/DlgEditReference.tsx
index 4ddd8fff..b6164568 100644
--- a/rsconcept/frontend/src/components/RefsInput/DlgEditReference.tsx
+++ b/rsconcept/frontend/src/components/RefsInput/DlgEditReference.tsx
@@ -8,33 +8,36 @@ import { IConstituenta, matchConstituenta } from '../../models/rsform';
import ConstituentaTooltip from '../../pages/RSFormPage/elements/ConstituentaTooltip';
import { colorfgCstStatus } from '../../utils/color';
import { prefixes } from '../../utils/constants';
-import { labelReferenceType } from '../../utils/labels';
-import { compareGrammemeOptions, IGrammemeOption, PremadeWordForms, SelectorGrammems, SelectorReferenceType } from '../../utils/selectors';
+import { compareGrammemeOptions, IGrammemeOption, PremadeWordForms, SelectorGrammems } from '../../utils/selectors';
import ConceptTooltip from '../Common/ConceptTooltip';
import Label from '../Common/Label';
import Modal from '../Common/Modal';
import SelectMulti from '../Common/SelectMulti';
-import SelectSingle from '../Common/SelectSingle';
import TextInput from '../Common/TextInput';
import DataTable, { IConditionalStyle } from '../DataTable';
import HelpTerminologyControl from '../Help/HelpTerminologyControl';
import { HelpIcon } from '../Icons';
-import TermformButton from './TermformButton';
+import ReferenceTypeButton from './ReferenceTypeButton';
+import WordformButton from './WordformButton';
+
+export interface IReferenceInputState {
+ type: ReferenceType
+ refRaw?: string
+ text?: string
+ mainRefs: string[]
+ basePosition: number
+}
interface DlgEditReferenceProps {
hideWindow: () => void
items: IConstituenta[]
-
- initialType: ReferenceType
- initialRef?: string
- initialText?: string
-
+ initial: IReferenceInputState
onSave: (newRef: string) => void
}
const constituentaHelper = createColumnHelper
();
-function DlgEditReference({ hideWindow, items, initialRef, initialText, initialType, onSave }: DlgEditReferenceProps) {
+function DlgEditReference({ hideWindow, items, initial, onSave }: DlgEditReferenceProps) {
const { colors } = useConceptTheme();
const [type, setType] = useState(ReferenceType.ENTITY);
@@ -49,6 +52,16 @@ function DlgEditReference({ hideWindow, items, initialRef, initialText, initialT
const [selectedGrams, setSelectedGrams] = useState([]);
const [gramOptions, setGramOptions] = useState([]);
+ const mainLink = useMemo(
+ () => {
+ const position = offset > 0 ? initial.basePosition + (offset - 1) : initial.basePosition + offset;
+ if (offset === 0 || position < 0 || position >= initial.mainRefs.length) {
+ return 'Некорректное значение смещения';
+ } else {
+ return initial.mainRefs[position];
+ }
+ }, [initial, offset]);
+
const isValid = useMemo(
() => {
if (type === ReferenceType.ENTITY) {
@@ -73,23 +86,23 @@ function DlgEditReference({ hideWindow, items, initialRef, initialText, initialT
// Initialization
useLayoutEffect(
() => {
- setType(initialType);
- if (initialRef) {
- if (initialType === ReferenceType.ENTITY) {
- const ref = parseEntityReference(initialRef);
+ setType(initial.type);
+ if (initial.refRaw) {
+ if (initial.type === ReferenceType.ENTITY) {
+ const ref = parseEntityReference(initial.refRaw);
setAlias(ref.entity);
const grams = parseGrammemes(ref.form);
setSelectedGrams(SelectorGrammems.filter(data => grams.includes(data.value)));
- } else if (initialType === ReferenceType.SYNTACTIC) {
- const ref = parseSyntacticReference(initialRef);
+ } else if (initial.type === ReferenceType.SYNTACTIC) {
+ const ref = parseSyntacticReference(initial.refRaw);
setOffset(ref.offset);
setNominal(ref.nominal);
}
- } else if (initialText) {
- setNominal(initialText ?? '');
- setFilter(initialText);
+ } else if (initial.text) {
+ setNominal(initial.text ?? '');
+ setFilter(initial.text);
}
- }, [initialRef, initialText, initialType, items]);
+ }, [initial, items]);
// Filter constituents
useEffect(
@@ -140,7 +153,7 @@ function DlgEditReference({ hideWindow, items, initialRef, initialText, initialT
{PremadeWordForms.slice(0, 6).map(
(data, index) =>
-
selectedGrams.find(item => item.value as Grammeme === gram))}
onSelectGrams={handleSelectGrams}
@@ -151,7 +164,7 @@ function DlgEditReference({ hideWindow, items, initialRef, initialText, initialT
{PremadeWordForms.slice(6, 12).map(
(data, index) =>
-
selectedGrams.find(item => item.value as Grammeme === gram))}
onSelectGrams={handleSelectGrams}
@@ -216,15 +229,17 @@ function DlgEditReference({ hideWindow, items, initialRef, initialText, initialT
canSubmit={isValid}
onSubmit={handleSubmit}
>
-
+
-
setType(data?.value ?? ReferenceType.ENTITY)}
+
+
@@ -238,20 +253,31 @@ function DlgEditReference({ hideWindow, items, initialRef, initialText, initialT
{type === ReferenceType.SYNTACTIC &&
-
-
setOffset(event.target.valueAsNumber)}
- />
+
+
+
setOffset(event.target.valueAsNumber)}
+ />
+
+ Основная ссылка:
+
+
+
setNominal(event.target.value)}
/>
diff --git a/rsconcept/frontend/src/components/RefsInput/ReferenceTypeButton.tsx b/rsconcept/frontend/src/components/RefsInput/ReferenceTypeButton.tsx
new file mode 100644
index 00000000..2a67d2d1
--- /dev/null
+++ b/rsconcept/frontend/src/components/RefsInput/ReferenceTypeButton.tsx
@@ -0,0 +1,23 @@
+import { ReferenceType } from '../../models/language';
+import { labelReferenceType } from '../../utils/labels';
+
+interface ReferenceTypeButtonProps {
+ id?: string
+ type: ReferenceType
+ isSelected?: boolean
+ onSelect: (type: ReferenceType) => void
+}
+
+function ReferenceTypeButton({ type, isSelected, onSelect, ...props }: ReferenceTypeButtonProps) {
+ return (
+
+ );
+}
+
+export default ReferenceTypeButton;
diff --git a/rsconcept/frontend/src/components/RefsInput/TermformButton.tsx b/rsconcept/frontend/src/components/RefsInput/WordformButton.tsx
similarity index 75%
rename from rsconcept/frontend/src/components/RefsInput/TermformButton.tsx
rename to rsconcept/frontend/src/components/RefsInput/WordformButton.tsx
index 607f7eed..1489bdd5 100644
--- a/rsconcept/frontend/src/components/RefsInput/TermformButton.tsx
+++ b/rsconcept/frontend/src/components/RefsInput/WordformButton.tsx
@@ -1,6 +1,6 @@
import { Grammeme } from '../../models/language';
-interface TermformButtonProps {
+interface WordformButtonProps {
id?: string
text: string
example: string
@@ -9,7 +9,7 @@ interface TermformButtonProps {
onSelectGrams: (grams: Grammeme[]) => void
}
-function TermformButton({ text, example, grams, onSelectGrams, isSelected, ...props }: TermformButtonProps) {
+function WordformButton({ text, example, grams, onSelectGrams, isSelected, ...props }: WordformButtonProps) {
return (