From 6e81c13be5b8555a85654c4e024f89e87f2a5326 Mon Sep 17 00:00:00 2001 From: IRBorisov <8611739+IRBorisov@users.noreply.github.com> Date: Sun, 6 Aug 2023 23:13:45 +0300 Subject: [PATCH] Embed arguments in typification update pyconcept to 1.3.0 --- rsconcept/backend/.env.dev | 6 +-- .../backend/apps/rsform/tests/t_imports.py | 1 + .../pages/RSFormPage/EditorConstituenta.tsx | 4 +- .../src/pages/RSFormPage/EditorItems.tsx | 4 +- .../pages/RSFormPage/EditorRSExpression.tsx | 8 +++- .../elements/ConstituentaTooltip.tsx | 4 +- rsconcept/frontend/src/utils/models.ts | 7 +++ rsconcept/frontend/src/utils/staticUI.ts | 44 ++++++++++++++----- 8 files changed, 55 insertions(+), 23 deletions(-) diff --git a/rsconcept/backend/.env.dev b/rsconcept/backend/.env.dev index 7adbeaed..175ac302 100644 --- a/rsconcept/backend/.env.dev +++ b/rsconcept/backend/.env.dev @@ -3,9 +3,9 @@ # Application settings SECRET_KEY=django-insecure-)rq@!&v7l2r%2%q#n!uq+zk@=&yc0^&ql^7%2!%9u)vt1x&j=d -ALLOWED_HOSTS=rs.acconcept.ru;localhost -CSRF_TRUSTED_ORIGINS=http://rs.acconcept.ru:3000;http://localhost:3000 -CORS_ALLOWED_ORIGINS=http://rs.acconcept.ru:3000;http://localhost:3000 +ALLOWED_HOSTS=rs.acconcept.ru;localhost;portal.acconcept.ru +CSRF_TRUSTED_ORIGINS=http://rs.acconcept.ru:3000;http://localhost:3000;http://portal.acconcept.ru:3000 +CORS_ALLOWED_ORIGINS=http://rs.acconcept.ru:3000;http://localhost:3000;http://portal.acconcept.ru:3000 # File locations diff --git a/rsconcept/backend/apps/rsform/tests/t_imports.py b/rsconcept/backend/apps/rsform/tests/t_imports.py index d33d46c2..da54f063 100644 --- a/rsconcept/backend/apps/rsform/tests/t_imports.py +++ b/rsconcept/backend/apps/rsform/tests/t_imports.py @@ -34,6 +34,7 @@ class TestIntegrations(TestCase): schema = self._default_schema() out1 = json.loads(pc.check_expression(schema, 'X1=X1')) self.assertTrue(out1['parseResult']) + self.assertEqual(len(out1['args']), 0) out2 = json.loads(pc.check_expression(schema, 'X1=X2')) self.assertFalse(out2['parseResult']) diff --git a/rsconcept/frontend/src/pages/RSFormPage/EditorConstituenta.tsx b/rsconcept/frontend/src/pages/RSFormPage/EditorConstituenta.tsx index b274dae8..646d3ad8 100644 --- a/rsconcept/frontend/src/pages/RSFormPage/EditorConstituenta.tsx +++ b/rsconcept/frontend/src/pages/RSFormPage/EditorConstituenta.tsx @@ -9,7 +9,7 @@ import TextArea from '../../components/Common/TextArea'; import { DumpBinIcon, HelpIcon, SaveIcon, SmallPlusIcon } from '../../components/Icons'; import { useRSForm } from '../../context/RSFormContext'; import { type CstType, EditMode, ICstUpdateData, SyntaxTree } from '../../utils/models'; -import { getCstTypeLabel, mapStatusInfo } from '../../utils/staticUI'; +import { getCstTypeLabel, getCstTypificationLabel, mapStatusInfo } from '../../utils/staticUI'; import EditorRSExpression from './EditorRSExpression'; import ViewSideConstituents from './elements/ViewSideConstituents'; @@ -64,7 +64,7 @@ function EditorConstituenta({ activeID, onShowAST, onCreateCst, onOpenEdit, onDe setTerm(activeCst.term?.raw ?? ''); setTextDefinition(activeCst.definition?.text?.raw ?? ''); setExpression(activeCst.definition?.formal ?? ''); - setTypification(activeCst?.parse?.typification || 'N/A'); + setTypification(activeCst ? getCstTypificationLabel(activeCst) : 'N/A'); } else if (schema && schema?.items.length > 0) { onOpenEdit(schema.items[0].id); } diff --git a/rsconcept/frontend/src/pages/RSFormPage/EditorItems.tsx b/rsconcept/frontend/src/pages/RSFormPage/EditorItems.tsx index 56a6be8b..a60e2bf9 100644 --- a/rsconcept/frontend/src/pages/RSFormPage/EditorItems.tsx +++ b/rsconcept/frontend/src/pages/RSFormPage/EditorItems.tsx @@ -10,7 +10,7 @@ import { useRSForm } from '../../context/RSFormContext'; import { useConceptTheme } from '../../context/ThemeContext'; import { prefixes } from '../../utils/constants'; import { CstType, IConstituenta, ICstMovetoData } from '../../utils/models' -import { getCstTypePrefix, getCstTypeShortcut, getTypeLabel, mapStatusInfo } from '../../utils/staticUI'; +import { getCstTypePrefix, getCstTypeShortcut, getCstTypificationLabel, mapStatusInfo } from '../../utils/staticUI'; interface EditorItemsProps { onOpenEdit: (cstID: number) => void @@ -192,7 +192,7 @@ function EditorItems({ onOpenEdit, onCreateCst, onDeleteCst }: EditorItemsProps) { name: 'Тип', id: 'type', - cell: (cst: IConstituenta) =>
Типизация: {getTypeLabel(data)}
+Типизация: {getCstTypificationLabel(data)}
Термин: {data.term.resolved || data.term.raw}
{data.definition.formal &&Выражение: {data.definition.formal}
} {data.definition.text.resolved &&Определение: {data.definition.text.resolved}
} diff --git a/rsconcept/frontend/src/utils/models.ts b/rsconcept/frontend/src/utils/models.ts index 0c1cb49d..1a718e2f 100644 --- a/rsconcept/frontend/src/utils/models.ts +++ b/rsconcept/frontend/src/utils/models.ts @@ -64,6 +64,11 @@ export interface ISyntaxTreeNode { } export type SyntaxTree = ISyntaxTreeNode[] +export interface IFunctionArg { + alias: string + typification: string +} + export interface IExpressionParse { parseResult: boolean syntax: Syntax @@ -72,6 +77,7 @@ export interface IExpressionParse { errors: IRSErrorDescription[] astText: string ast: SyntaxTree + args: IFunctionArg[] } export interface IRSExpression { @@ -113,6 +119,7 @@ export interface IConstituenta { valueClass: ValueClass typification: string syntaxTree: string + args: IFunctionArg[] } } diff --git a/rsconcept/frontend/src/utils/staticUI.ts b/rsconcept/frontend/src/utils/staticUI.ts index 20831121..ba884892 100644 --- a/rsconcept/frontend/src/utils/staticUI.ts +++ b/rsconcept/frontend/src/utils/staticUI.ts @@ -1,7 +1,10 @@ import { LayoutTypes } from 'reagraph'; import { resolveErrorClass,RSErrorClass, RSErrorType, TokenID } from './enums'; -import { CstMatchMode,CstType, DependencyMode,ExpressionStatus, type IConstituenta, IRSErrorDescription,type IRSForm, ISyntaxTreeNode,ParsingStatus, ValueClass } from './models'; +import { CstMatchMode, CstType, DependencyMode,ExpressionStatus, IConstituenta, + IFunctionArg,IRSErrorDescription, IRSForm, + ISyntaxTreeNode, ParsingStatus, ValueClass +} from './models'; export interface IRSButtonData { text: string @@ -14,16 +17,6 @@ export interface IStatusInfo { tooltip: string } -export function getTypeLabel(cst: IConstituenta): string { - if (cst.parse?.typification) { - return cst.parse.typification; - } - if (cst.parse?.status !== ParsingStatus.VERIFIED) { - return 'N/A'; - } - return 'Логический'; -} - export function getCstDescription(cst: IConstituenta): string { if (cst.cstType === CstType.STRUCTURED) { return ( @@ -381,7 +374,8 @@ export function getMockConstituenta(id: number, alias: string, type: CstType, co status: ParsingStatus.INCORRECT, valueClass: ValueClass.INVALID, typification: 'N/A', - syntaxTree: '' + syntaxTree: '', + args: [] } }; } @@ -394,6 +388,32 @@ export function getCloneTitle(schema: IRSForm): string { } } +export function getTypificationLabel({isValid, resultType, args}: { + isValid: boolean, + resultType: string, + args: IFunctionArg[] +}): string { + if (!isValid) { + return 'N/A'; + } + if (resultType === '') { + resultType = 'Логический' + } + if (args.length === 0) { + return resultType; + } + const argsText = args.map(arg => arg.typification).join(', '); + return `${resultType} 🠔 [${argsText}]`; +} + +export function getCstTypificationLabel(cst: IConstituenta): string { + return getTypificationLabel({ + isValid: cst.parse.status === ParsingStatus.VERIFIED, + resultType: cst.parse.typification, + args: cst.parse.args + }); +} + export function getRSErrorPrefix(error: IRSErrorDescription): string { const id = error.errorType.toString(16) switch(resolveErrorClass(error.errorType)) {