Portal/rsconcept/frontend/src/features/rsform/dialogs/dlg-graph-params.tsx

106 lines
3.6 KiB
TypeScript
Raw Normal View History

2024-06-07 20:17:03 +03:00
'use client';
2025-02-08 17:09:51 +03:00
import { Controller, useForm } from 'react-hook-form';
2025-08-12 15:39:11 +03:00
import { MiniButton } from '@/components/control';
2025-03-12 12:04:23 +03:00
import { Checkbox } from '@/components/input';
import { ModalForm } from '@/components/modal';
2024-06-07 20:17:03 +03:00
2025-02-18 19:39:54 +03:00
import { CstType } from '../backend/types';
2025-08-12 15:39:11 +03:00
import { IconCstType } from '../components/icon-cst-type';
2025-02-11 20:56:11 +03:00
import { labelCstType } from '../labels';
2025-08-12 15:39:11 +03:00
import { cstTypeToFilterKey, type GraphFilterParams, useTermGraphStore } from '../stores/term-graph';
2025-02-19 23:29:45 +03:00
export function DlgGraphParams() {
2025-02-08 17:09:51 +03:00
const params = useTermGraphStore(state => state.filter);
const setParams = useTermGraphStore(state => state.setFilter);
const { handleSubmit, control } = useForm<GraphFilterParams>({
defaultValues: { ...params }
});
2024-06-07 20:17:03 +03:00
2025-02-08 17:09:51 +03:00
function onSubmit(data: GraphFilterParams) {
setParams(data);
2025-02-06 14:09:20 +03:00
}
2024-06-07 20:17:03 +03:00
return (
2025-02-06 20:27:56 +03:00
<ModalForm
2024-06-07 20:17:03 +03:00
header='Настройки графа термов'
2025-02-08 17:09:51 +03:00
onSubmit={event => void handleSubmit(onSubmit)(event)}
2024-06-07 20:17:03 +03:00
submitText='Применить'
2025-03-10 16:01:40 +03:00
className='flex gap-6 justify-between px-6 pb-3 w-120'
2024-06-07 20:17:03 +03:00
>
<div className='flex flex-col gap-1'>
<h1 className='mb-2'>Преобразования</h1>
2025-02-08 17:09:51 +03:00
<Controller
control={control}
name='noText'
render={({ field }) => <Checkbox {...field} label='Скрыть текст' title='Не отображать термины' />}
2024-06-07 20:17:03 +03:00
/>
2025-08-13 13:30:08 +03:00
<Controller
control={control}
name='foldDerived'
render={({ field }) => (
<Checkbox {...field} label='Скрыть порожденные' title='Не отображать порожденные понятия' />
)}
/>
2025-02-08 17:09:51 +03:00
<Controller
control={control}
name='noHermits'
render={({ field }) => <Checkbox {...field} label='Скрыть несвязанные' title='Неиспользуемые конституенты' />}
2024-06-07 20:17:03 +03:00
/>
2025-02-08 17:09:51 +03:00
<Controller
control={control}
name='noTemplates'
render={({ field }) => (
<Checkbox
{...field}
label='Скрыть шаблоны'
titleHtml='Терм-функции и предикат-функции <br/>с параметризованными аргументами'
/>
)}
2024-06-07 20:17:03 +03:00
/>
2025-02-08 17:09:51 +03:00
<Controller
control={control}
name='noTransitive'
render={({ field }) => (
<Checkbox
{...field}
label='Транзитивная редукция'
titleHtml='Удалить связи, образующие <br/>транзитивные пути в графе'
/>
)}
2024-06-07 20:17:03 +03:00
/>
</div>
<div className='flex flex-col gap-1'>
2025-08-12 15:39:11 +03:00
<h1 className='mb-1'>Типы конституент</h1>
<div>
{Object.values(CstType).map(cstType => {
const fieldName = cstTypeToFilterKey[cstType];
return (
<Controller
key={fieldName}
control={control}
name={fieldName}
render={({ field }) => (
<MiniButton
onClick={() => field.onChange(!field.value)}
title={labelCstType(cstType)}
icon={
<IconCstType
size='2rem'
value={cstType}
className={field.value ? 'text-constructive' : 'text-destructive'}
/>
}
/>
)}
/>
);
})}
</div>
2024-06-07 20:17:03 +03:00
</div>
2025-02-06 20:27:56 +03:00
</ModalForm>
2024-06-07 20:17:03 +03:00
);
}