Add vertical layout for constituent search

This commit is contained in:
IRBorisov 2024-03-15 14:35:06 +03:00
parent 1335a0f804
commit fd9b5d2728
4 changed files with 37 additions and 16 deletions

View File

@ -1,5 +1,6 @@
'use client'; 'use client';
import clsx from 'clsx';
import { AnimatePresence } from 'framer-motion'; import { AnimatePresence } from 'framer-motion';
import { useMemo, useState } from 'react'; import { useMemo, useState } from 'react';
@ -16,8 +17,8 @@ import FormConstituenta from './FormConstituenta';
// Max height of content for left editor pane. // Max height of content for left editor pane.
const UNFOLDED_HEIGHT = '59.1rem'; const UNFOLDED_HEIGHT = '59.1rem';
// Threshold window width to hide side constituents list. // Threshold window width to switch layout.
const SIDELIST_HIDE_THRESHOLD = 1100; // px const SIDELIST_LAYOUT_THRESHOLD = 1100; // px
interface EditorConstituentaProps { interface EditorConstituentaProps {
activeCst?: IConstituenta; activeCst?: IConstituenta;
@ -38,6 +39,8 @@ function EditorConstituenta({ activeCst, isModified, setIsModified, onOpenEdit }
[activeCst, controller.isContentEditable] [activeCst, controller.isContentEditable]
); );
const isNarrow = useMemo(() => !!windowSize.width && windowSize.width <= SIDELIST_LAYOUT_THRESHOLD, [windowSize]);
function handleInput(event: React.KeyboardEvent<HTMLDivElement>) { function handleInput(event: React.KeyboardEvent<HTMLDivElement>) {
if (disabled) { if (disabled) {
return; return;
@ -89,7 +92,15 @@ function EditorConstituenta({ activeCst, isModified, setIsModified, onOpenEdit }
onCreate={() => controller.createCst(activeCst?.cst_type, false)} onCreate={() => controller.createCst(activeCst?.cst_type, false)}
/> />
) : null} ) : null}
<div tabIndex={-1} className='flex max-w-[95rem]' onKeyDown={handleInput}> <div
tabIndex={-1}
className={clsx(
'max-w-[95rem]', // prettier: split lines
'flex',
{ 'flex-col items-center': isNarrow }
)}
onKeyDown={handleInput}
>
<FormConstituenta <FormConstituenta
isMutable={!disabled} isMutable={!disabled}
showList={showList} showList={showList}
@ -103,10 +114,11 @@ function EditorConstituenta({ activeCst, isModified, setIsModified, onOpenEdit }
onRename={controller.renameCst} onRename={controller.renameCst}
/> />
<AnimatePresence> <AnimatePresence>
{showList && windowSize.width && windowSize.width >= SIDELIST_HIDE_THRESHOLD ? ( {showList ? (
<ViewConstituents <ViewConstituents
schema={controller.schema} schema={controller.schema}
expression={activeCst?.definition_formal ?? ''} expression={activeCst?.definition_formal ?? ''}
isBottom={isNarrow}
baseHeight={UNFOLDED_HEIGHT} baseHeight={UNFOLDED_HEIGHT}
activeID={activeCst?.id} activeID={activeCst?.id}
onOpenEdit={onOpenEdit} onOpenEdit={onOpenEdit}

View File

@ -113,7 +113,7 @@ function FormConstituenta({
} }
return ( return (
<> <div>
<ControlsOverlay <ControlsOverlay
isMutable={isMutable} isMutable={isMutable}
processing={processing} processing={processing}
@ -189,7 +189,7 @@ function FormConstituenta({
/> />
) : null} ) : null}
</form> </form>
</> </div>
); );
} }

View File

@ -194,13 +194,6 @@ function RSTabsMenu({ onDestroy }: RSTabsMenuProps) {
onClick={editMenu.toggle} onClick={editMenu.toggle}
/> />
<Dropdown isOpen={editMenu.isOpen}> <Dropdown isOpen={editMenu.isOpen}>
<DropdownButton
disabled={!controller.isContentEditable}
text='Сброс имён'
title='Присвоить порядковые имена и обновить выражения'
icon={<BiAnalyse size='1rem' className='icon-primary' />}
onClick={handleReindex}
/>
<DropdownButton <DropdownButton
disabled={!controller.isContentEditable} disabled={!controller.isContentEditable}
text='Банк выражений' text='Банк выражений'
@ -208,6 +201,14 @@ function RSTabsMenu({ onDestroy }: RSTabsMenuProps) {
icon={<BiDiamond size='1rem' className='icon-green' />} icon={<BiDiamond size='1rem' className='icon-green' />}
onClick={handleTemplates} onClick={handleTemplates}
/> />
<DropdownButton
disabled={!controller.isContentEditable}
className='border-t-2'
text='Сброс имён'
title='Присвоить порядковые имена и обновить выражения'
icon={<BiAnalyse size='1rem' className='icon-primary' />}
onClick={handleReindex}
/>
<DropdownButton <DropdownButton
disabled={!controller.isContentEditable || !controller.canProduceStructure} disabled={!controller.isContentEditable || !controller.canProduceStructure}
text='Порождение структуры' text='Порождение структуры'

View File

@ -1,5 +1,6 @@
'use client'; 'use client';
import clsx from 'clsx';
import { motion } from 'framer-motion'; import { motion } from 'framer-motion';
import { useMemo, useState } from 'react'; import { useMemo, useState } from 'react';
@ -18,13 +19,14 @@ const COLUMN_EXPRESSION_HIDE_THRESHOLD = 1500;
interface ViewConstituentsProps { interface ViewConstituentsProps {
expression: string; expression: string;
isBottom?: boolean;
baseHeight: string; baseHeight: string;
activeID?: number; activeID?: number;
schema?: IRSForm; schema?: IRSForm;
onOpenEdit: (cstID: number) => void; onOpenEdit: (cstID: number) => void;
} }
function ViewConstituents({ expression, baseHeight, schema, activeID, onOpenEdit }: ViewConstituentsProps) { function ViewConstituents({ expression, schema, activeID, isBottom, baseHeight, onOpenEdit }: ViewConstituentsProps) {
const { noNavigation } = useConceptTheme(); const { noNavigation } = useConceptTheme();
const [filteredData, setFilteredData] = useState<IConstituenta[]>(schema?.items ?? []); const [filteredData, setFilteredData] = useState<IConstituenta[]>(schema?.items ?? []);
@ -38,7 +40,13 @@ function ViewConstituents({ expression, baseHeight, schema, activeID, onOpenEdit
return ( return (
<motion.div <motion.div
className='mt-[2.25rem] border' className={clsx(
'border', // prettier: split-lines
{
'mt-[2.25rem]': !isBottom, // prettier: split-lines
'mt-3 mx-6': isBottom
}
)}
initial={{ ...animateSideView.initial }} initial={{ ...animateSideView.initial }}
animate={{ ...animateSideView.animate }} animate={{ ...animateSideView.animate }}
exit={{ ...animateSideView.exit }} exit={{ ...animateSideView.exit }}
@ -50,7 +58,7 @@ function ViewConstituents({ expression, baseHeight, schema, activeID, onOpenEdit
setFiltered={setFilteredData} setFiltered={setFilteredData}
/> />
<ConstituentsTable <ConstituentsTable
maxHeight={maxHeight} maxHeight={isBottom ? '12rem' : maxHeight}
items={filteredData} items={filteredData}
activeID={activeID} activeID={activeID}
onOpenEdit={onOpenEdit} onOpenEdit={onOpenEdit}