From 8a134557b63cd9bcc19f99c44b823043ee9a4a63 Mon Sep 17 00:00:00 2001 From: IRBorisov <8611739+IRBorisov@users.noreply.github.com> Date: Tue, 26 Mar 2024 22:55:53 +0300 Subject: [PATCH] Minor UI fixes --- .../DlgConstituentaTemplate/TemplateTab.tsx | 27 ++++++-------- .../frontend/src/models/miscellaneousAPI.ts | 1 - rsconcept/frontend/src/models/rsformAPI.ts | 2 +- .../EditorRSExpression/EditorRSExpression.tsx | 37 +++++++++++-------- .../EditorRSExpression/ParsingResult.tsx | 3 +- .../RSFormPage/EditorRSForm/FormRSForm.tsx | 4 +- .../RSFormPage/EditorRSForm/RSFormToolbar.tsx | 4 +- .../RSFormPage/EditorRSList/EditorRSList.tsx | 6 +-- rsconcept/frontend/src/styling/setup.css | 2 +- 9 files changed, 44 insertions(+), 42 deletions(-) diff --git a/rsconcept/frontend/src/dialogs/DlgConstituentaTemplate/TemplateTab.tsx b/rsconcept/frontend/src/dialogs/DlgConstituentaTemplate/TemplateTab.tsx index 05311868..9f45dd1d 100644 --- a/rsconcept/frontend/src/dialogs/DlgConstituentaTemplate/TemplateTab.tsx +++ b/rsconcept/frontend/src/dialogs/DlgConstituentaTemplate/TemplateTab.tsx @@ -23,7 +23,7 @@ interface TemplateTabProps { function TemplateTab({ state, partialUpdate }: TemplateTabProps) { const { templates, retrieveTemplate } = useLibrary(); - const [selectedSchema, setSelectedSchema] = useState(undefined); + const [category, setCategory] = useState(undefined); const [filteredData, setFilteredData] = useState([]); @@ -47,16 +47,16 @@ function TemplateTab({ state, partialUpdate }: TemplateTabProps) { ); const categorySelector = useMemo((): { value: number; label: string }[] => { - if (!selectedSchema) { + if (!category) { return []; } - return selectedSchema.items + return category.items .filter(cst => cst.cst_type === CATEGORY_CST_TYPE) .map(cst => ({ value: cst.id, label: cst.term_raw })); - }, [selectedSchema]); + }, [category]); useEffect(() => { if (templates.length > 0 && !state.templateID) { @@ -66,23 +66,22 @@ function TemplateTab({ state, partialUpdate }: TemplateTabProps) { useEffect(() => { if (!state.templateID) { - setSelectedSchema(undefined); + setCategory(undefined); } else { - retrieveTemplate(state.templateID, setSelectedSchema); + retrieveTemplate(state.templateID, setCategory); } }, [state.templateID, retrieveTemplate]); - // Filter constituents useEffect(() => { - if (!selectedSchema) { + if (!category) { return; } - let data = selectedSchema.items; + let data = category.items; if (state.filterCategory) { - data = applyFilterCategory(state.filterCategory, selectedSchema); + data = applyFilterCategory(state.filterCategory, category); } setFilteredData(data); - }, [state.filterCategory, selectedSchema]); + }, [state.filterCategory, category]); return ( <> @@ -92,16 +91,14 @@ function TemplateTab({ state, partialUpdate }: TemplateTabProps) { className='flex-grow border-none' options={categorySelector} value={ - state.filterCategory && selectedSchema + state.filterCategory && category ? { value: state.filterCategory.id, label: state.filterCategory.term_raw } : null } - onChange={data => - partialUpdate({ filterCategory: selectedSchema?.items.find(cst => cst.id === data?.value) }) - } + onChange={data => partialUpdate({ filterCategory: category?.items.find(cst => cst.id === data?.value) })} isClearable /> cst.order > start.order && cst.cst_type === CATEGORY_CST_TYPE); - return schema.items.filter(cst => cst.order > start.order && (!nextCategory || cst.order <= nextCategory.order)); + return schema.items.filter(cst => cst.order >= start.order && (!nextCategory || cst.order < nextCategory.order)); } /** diff --git a/rsconcept/frontend/src/pages/RSFormPage/EditorRSExpression/EditorRSExpression.tsx b/rsconcept/frontend/src/pages/RSFormPage/EditorRSExpression/EditorRSExpression.tsx index 38726a76..1edc26b9 100644 --- a/rsconcept/frontend/src/pages/RSFormPage/EditorRSExpression/EditorRSExpression.tsx +++ b/rsconcept/frontend/src/pages/RSFormPage/EditorRSExpression/EditorRSExpression.tsx @@ -56,11 +56,12 @@ function EditorRSExpression({ onToggleList, ...restProps }: EditorRSExpressionProps) { - const { schema } = useRSForm(); + const model = useRSForm(); const { mathFont, setMathFont } = useConceptTheme(); const [isModified, setIsModified] = useState(false); - const { parseData, checkExpression, resetParse, loading } = useCheckExpression({ schema }); + const parser = useCheckExpression({ schema: model.schema }); + const { resetParse } = parser; const rsInput = useRef(null); const [syntaxTree, setSyntaxTree] = useState([]); @@ -84,7 +85,7 @@ function EditorRSExpression({ } const prefix = getDefinitionPrefix(activeCst); const expression = prefix + value; - checkExpression(expression, activeCst, parse => { + parser.checkExpression(expression, activeCst, parse => { if (parse.errors.length > 0) { onShowError(parse.errors[0]); } else { @@ -163,15 +164,17 @@ function EditorRSExpression({ } onClick={toggleFont} + icon={} /> - setShowControls(prev => !prev)} - icon={} - /> + {!disabled || model.processing ? ( + setShowControls(prev => !prev)} + icon={} + /> + ) : null} handleCheckExpression()} /> @@ -207,11 +210,15 @@ function EditorRSExpression({ {...restProps} /> - + 0} - data={parseData} + isOpen={!!parser.parseData && parser.parseData.errors.length > 0} + data={parser.parseData} disabled={disabled} onShowError={onShowError} /> diff --git a/rsconcept/frontend/src/pages/RSFormPage/EditorRSExpression/ParsingResult.tsx b/rsconcept/frontend/src/pages/RSFormPage/EditorRSExpression/ParsingResult.tsx index 51ad3b71..af6cc1d7 100644 --- a/rsconcept/frontend/src/pages/RSFormPage/EditorRSExpression/ParsingResult.tsx +++ b/rsconcept/frontend/src/pages/RSFormPage/EditorRSExpression/ParsingResult.tsx @@ -1,4 +1,3 @@ -import clsx from 'clsx'; import { motion } from 'framer-motion'; import { IExpressionParse, IRSErrorDescription } from '@/models/rslang'; @@ -19,7 +18,7 @@ function ParsingResult({ isOpen, data, disabled, onShowError }: ParsingResultPro return (
- {controller.isMutable || controller.isProcessing ? ( + {controller.isMutable || (controller.isMutable && controller.isProcessing) ? ( <> setCanonical(value)} />
- {controller.isContentEditable || controller.isProcessing ? ( + {controller.isContentEditable || (controller.isMutable && controller.isProcessing) ? ( modified && controller.isMutable, [modified, controller.isMutable]); return ( - {controller.isContentEditable || controller.isProcessing ? ( + {controller.isContentEditable || (controller.isMutable && controller.isProcessing) ? ( ) : null} - {controller.isContentEditable || controller.isProcessing ? ( + {controller.isContentEditable || (controller.isMutable && controller.isProcessing) ? ( - {controller.isContentEditable || controller.isProcessing ? ( + {controller.isContentEditable || (controller.isMutable && controller.isProcessing) ? ( ) : null} - {controller.isContentEditable || controller.isProcessing ? ( + {controller.isContentEditable || (controller.isMutable && controller.isProcessing) ? ( ) : null}
p { +div:not(.dense) > p { @apply [&:not(:last-child)]:mb-2; }