F: Implement crucial constituents UI
This commit is contained in:
parent
e3b20551d5
commit
18ad3f9f29
|
@ -12,6 +12,7 @@ from .basics import (
|
|||
WordFormSerializer
|
||||
)
|
||||
from .data_access import (
|
||||
CrucialUpdateSerializer,
|
||||
CstCreateSerializer,
|
||||
CstInfoSerializer,
|
||||
CstListSerializer,
|
||||
|
|
|
@ -72,6 +72,24 @@ class CstUpdateSerializer(StrictSerializer):
|
|||
return attrs
|
||||
|
||||
|
||||
class CrucialUpdateSerializer(StrictSerializer):
|
||||
''' Serializer: update crucial status. '''
|
||||
target = PKField(
|
||||
many=True,
|
||||
queryset=Constituenta.objects.all().only('crucial', 'schema_id')
|
||||
)
|
||||
value = serializers.BooleanField()
|
||||
|
||||
def validate(self, attrs):
|
||||
schema = cast(LibraryItem, self.context['schema'])
|
||||
for cst in attrs['target']:
|
||||
if schema and cst.schema_id != schema.pk:
|
||||
raise serializers.ValidationError({
|
||||
f'{cst.pk}': msg.constituentaNotInRSform(schema.title)
|
||||
})
|
||||
return attrs
|
||||
|
||||
|
||||
class CstDetailsSerializer(StrictModelSerializer):
|
||||
''' Serializer: Constituenta data including parse. '''
|
||||
parse = CstParseSerializer()
|
||||
|
|
|
@ -578,6 +578,19 @@ class TestConstituentaAPI(EndpointTester):
|
|||
self.assertEqual(self.cst3.definition_resolved, 'form1')
|
||||
self.assertEqual(self.cst3.term_forms, data['item_data']['term_forms'])
|
||||
|
||||
@decl_endpoint('/api/rsforms/{schema}/update-crucial', method='patch')
|
||||
def test_update_crucial(self):
|
||||
data = {'target': [self.cst1.pk], 'value': True}
|
||||
self.executeForbidden(data=data, schema=self.unowned_id)
|
||||
|
||||
self.logout()
|
||||
self.executeForbidden(data=data, schema=self.owned_id)
|
||||
|
||||
self.login()
|
||||
self.executeOK(data=data, schema=self.owned_id)
|
||||
self.cst1.refresh_from_db()
|
||||
self.assertEqual(self.cst1.crucial, True)
|
||||
|
||||
|
||||
class TestInlineSynthesis(EndpointTester):
|
||||
''' Testing Operations endpoints. '''
|
||||
|
|
|
@ -42,6 +42,7 @@ class RSFormViewSet(viewsets.GenericViewSet, generics.ListAPIView, generics.Retr
|
|||
'load_trs',
|
||||
'create_cst',
|
||||
'update_cst',
|
||||
'update_crucial',
|
||||
'move_cst',
|
||||
'delete_multiple_cst',
|
||||
'substitute',
|
||||
|
@ -137,6 +138,36 @@ class RSFormViewSet(viewsets.GenericViewSet, generics.ListAPIView, generics.Retr
|
|||
data=s.RSFormParseSerializer(schema.model).data
|
||||
)
|
||||
|
||||
@extend_schema(
|
||||
summary='update crucial attributes of a given list of constituents',
|
||||
tags=['RSForm'],
|
||||
request=s.CrucialUpdateSerializer,
|
||||
responses={
|
||||
c.HTTP_200_OK: s.RSFormParseSerializer,
|
||||
c.HTTP_400_BAD_REQUEST: None,
|
||||
c.HTTP_403_FORBIDDEN: None,
|
||||
c.HTTP_404_NOT_FOUND: None
|
||||
}
|
||||
)
|
||||
@action(detail=True, methods=['patch'], url_path='update-crucial')
|
||||
def update_crucial(self, request: Request, pk) -> HttpResponse:
|
||||
''' Update crucial attributes of a given list of constituents. '''
|
||||
model = self._get_item()
|
||||
serializer = s.CrucialUpdateSerializer(data=request.data, partial=True, context={'schema': model})
|
||||
serializer.is_valid(raise_exception=True)
|
||||
value: bool = serializer.validated_data['value']
|
||||
|
||||
with transaction.atomic():
|
||||
for cst in serializer.validated_data['target']:
|
||||
cst.crucial = value
|
||||
cst.save(update_fields=['crucial'])
|
||||
model.save(update_fields=['time_update'])
|
||||
|
||||
return Response(
|
||||
status=c.HTTP_200_OK,
|
||||
data=s.RSFormParseSerializer(model).data
|
||||
)
|
||||
|
||||
@extend_schema(
|
||||
summary='produce the structure of a given constituenta',
|
||||
tags=['RSForm'],
|
||||
|
|
|
@ -106,9 +106,9 @@ export { LuDatabase as IconDatabase } from 'react-icons/lu';
|
|||
export { LuView as IconDBStructure } from 'react-icons/lu';
|
||||
export { LuPlaneTakeoff as IconRESTapi } from 'react-icons/lu';
|
||||
export { LuImage as IconImage } from 'react-icons/lu';
|
||||
export { PiFediverseLogo as IconGraphSelection } from 'react-icons/pi';
|
||||
export { GoVersions as IconVersions } from 'react-icons/go';
|
||||
export { LuAtSign as IconTerm } from 'react-icons/lu';
|
||||
export { MdTaskAlt as IconCrucial } from 'react-icons/md';
|
||||
export { LuSubscript as IconAlias } from 'react-icons/lu';
|
||||
export { TbMathFunction as IconFormula } from 'react-icons/tb';
|
||||
export { BiFontFamily as IconText } from 'react-icons/bi';
|
||||
|
@ -150,9 +150,11 @@ export { GrConnect as IconConnect } from 'react-icons/gr';
|
|||
export { BiPlayCircle as IconExecute } from 'react-icons/bi';
|
||||
|
||||
// ======== Graph UI =======
|
||||
export { PiFediverseLogo as IconContextSelection } from 'react-icons/pi';
|
||||
export { ImMakeGroup as IconGroupSelection } from 'react-icons/im';
|
||||
export { BiCollapse as IconGraphCollapse } from 'react-icons/bi';
|
||||
export { BiExpand as IconGraphExpand } from 'react-icons/bi';
|
||||
export { LuMaximize as IconGraphMaximize } from 'react-icons/lu';
|
||||
export { TiArrowMaximise as IconGraphMaximize } from 'react-icons/ti';
|
||||
export { BiGitBranch as IconGraphInputs } from 'react-icons/bi';
|
||||
export { TbEarScan as IconGraphInverse } from 'react-icons/tb';
|
||||
export { BiGitMerge as IconGraphOutputs } from 'react-icons/bi';
|
||||
|
|
|
@ -40,12 +40,20 @@ export function generateSample(target: string): string {
|
|||
export function varSchema(schema: IRSForm): string {
|
||||
let result = `Название концептуальной схемы: ${schema.title}\n`;
|
||||
result += `[${schema.alias}] Описание: "${schema.description}"\n\n`;
|
||||
result += 'Понятия:\n';
|
||||
result += 'Конституенты:\n';
|
||||
schema.items.forEach(item => {
|
||||
result += `\n${item.alias} - "${labelCstTypification(item)}" - "${item.term_resolved}" - "${
|
||||
item.definition_formal
|
||||
}" - "${item.definition_resolved}" - "${item.convention}"`;
|
||||
});
|
||||
if (schema.stats.count_crucial > 0) {
|
||||
result +=
|
||||
'\nКлючевые конституенты: ' +
|
||||
schema.items
|
||||
.filter(cst => cst.crucial)
|
||||
.map(cst => cst.alias)
|
||||
.join(', ');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import {
|
||||
IconChild,
|
||||
IconConsolidation,
|
||||
IconCrucial,
|
||||
IconCstAxiom,
|
||||
IconCstBaseSet,
|
||||
IconCstConstSet,
|
||||
|
@ -91,6 +92,11 @@ export function HelpThesaurus() {
|
|||
родоструктурной экспликации являются Термин, Конвенция, Типизация (Структура), Формальное определение, Текстовое
|
||||
определение, Комментарий.
|
||||
</p>
|
||||
<p>
|
||||
<IconCrucial size='1rem' className='inline-icon' /> Ключевая конституента используется как маркер для
|
||||
обозначения содержательно значимых конституент. Ключевые конституенты выделяются визуально и используются при
|
||||
фильтрации.
|
||||
</p>
|
||||
|
||||
<br />
|
||||
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import {
|
||||
IconChild,
|
||||
IconClone,
|
||||
IconContextSelection,
|
||||
IconCrucial,
|
||||
IconDestroy,
|
||||
IconFilter,
|
||||
IconGraphSelection,
|
||||
IconKeyboard,
|
||||
IconLeftOpen,
|
||||
IconMoveDown,
|
||||
|
@ -26,6 +27,13 @@ export function HelpRSEditor() {
|
|||
return (
|
||||
<div className='dense'>
|
||||
<h1>Редактор конституенты</h1>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<IconCrucial className='inline-icon' /> статус ключевой конституенты
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div className='flex flex-col sm:flex-row sm:gap-3'>
|
||||
<div>
|
||||
<h2>Команды</h2>
|
||||
|
@ -68,7 +76,7 @@ export function HelpRSEditor() {
|
|||
<IconFilter className='inline-icon' /> фильтрация по атрибутам
|
||||
</li>
|
||||
<li>
|
||||
<IconGraphSelection className='inline-icon' /> фильтрация по графу термов
|
||||
<IconContextSelection className='inline-icon' /> фильтрация по графу термов
|
||||
</li>
|
||||
<li>
|
||||
<IconChild className='inline-icon' /> отображение наследованных
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
import { Divider } from '@/components/container';
|
||||
import {
|
||||
IconChild,
|
||||
IconClustering,
|
||||
IconContextSelection,
|
||||
IconCrucial,
|
||||
IconDestroy,
|
||||
IconEdit,
|
||||
IconFilter,
|
||||
|
@ -12,7 +15,7 @@ import {
|
|||
IconGraphInputs,
|
||||
IconGraphMaximize,
|
||||
IconGraphOutputs,
|
||||
IconGraphSelection,
|
||||
IconGroupSelection,
|
||||
IconNewItem,
|
||||
IconOSS,
|
||||
IconPredecessor,
|
||||
|
@ -103,7 +106,7 @@ export function HelpRSGraphTerm() {
|
|||
<h2>Выделение</h2>
|
||||
<ul>
|
||||
<li>
|
||||
<IconGraphSelection className='inline-icon' /> выделить связанные...
|
||||
<IconContextSelection className='inline-icon' /> выделить связанные...
|
||||
</li>
|
||||
<li>
|
||||
<IconGraphCollapse className='inline-icon' /> все влияющие
|
||||
|
@ -120,13 +123,23 @@ export function HelpRSGraphTerm() {
|
|||
<li>
|
||||
<IconGraphOutputs className='inline-icon' /> исходящие напрямую
|
||||
</li>
|
||||
<li>
|
||||
<IconGroupSelection className='inline-icon' /> выделить группы...
|
||||
</li>
|
||||
<li>
|
||||
<IconGraphCore className='inline-icon' /> выделить <LinkTopic text='Ядро' topic={HelpTopic.CC_SYSTEM} />
|
||||
</li>
|
||||
<li>
|
||||
<IconCrucial className='inline-icon' /> выделить ключевые
|
||||
</li>
|
||||
<li>
|
||||
<IconPredecessor className='inline-icon' /> выделить{' '}
|
||||
<LinkTopic text='собственные' topic={HelpTopic.CC_PROPAGATION} />
|
||||
</li>
|
||||
<li>
|
||||
<IconChild className='inline-icon' /> выделить{' '}
|
||||
<LinkTopic text='наследники' topic={HelpTopic.CC_PROPAGATION} />
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -17,6 +17,7 @@ import {
|
|||
type IRSFormUploadDTO,
|
||||
type ISubstitutionsDTO,
|
||||
type IUpdateConstituentaDTO,
|
||||
type IUpdateCrucialDTO,
|
||||
schemaConstituentaCreatedResponse,
|
||||
schemaExpressionParse,
|
||||
schemaProduceStructureResponse,
|
||||
|
@ -79,6 +80,15 @@ export const rsformsApi = {
|
|||
successMessage: infoMsg.changesSaved
|
||||
}
|
||||
}),
|
||||
updateCrucial: ({ itemID, data }: { itemID: number; data: IUpdateCrucialDTO }) =>
|
||||
axiosPatch<IUpdateCrucialDTO, IRSFormDTO>({
|
||||
schema: schemaRSForm,
|
||||
endpoint: `/api/rsforms/${itemID}/update-crucial`,
|
||||
request: {
|
||||
data: data,
|
||||
successMessage: infoMsg.changesSaved
|
||||
}
|
||||
}),
|
||||
deleteConstituents: ({ itemID, data }: { itemID: number; data: IConstituentaList }) =>
|
||||
axiosPatch<IConstituentaList, IRSFormDTO>({
|
||||
schema: schemaRSForm,
|
||||
|
|
|
@ -183,6 +183,7 @@ export class RSFormLoader {
|
|||
const items = this.schema.items;
|
||||
return {
|
||||
count_all: items.length,
|
||||
count_crucial: items.reduce((sum, cst) => sum + (cst.crucial ? 1 : 0), 0),
|
||||
count_errors: items.reduce((sum, cst) => sum + (cst.parse.status === ParsingStatus.INCORRECT ? 1 : 0), 0),
|
||||
count_property: items.reduce((sum, cst) => sum + (cst.parse.valueClass === ValueClass.PROPERTY ? 1 : 0), 0),
|
||||
count_incalculable: items.reduce(
|
||||
|
|
|
@ -65,6 +65,9 @@ export type IConstituentaCreatedResponse = z.infer<typeof schemaConstituentaCrea
|
|||
/** Represents data, used in updating persistent attributes in {@link IConstituenta}. */
|
||||
export type IUpdateConstituentaDTO = z.infer<typeof schemaUpdateConstituenta>;
|
||||
|
||||
/** Represents data, used in batch updating crucial attributes in {@link IConstituenta}. */
|
||||
export type IUpdateCrucialDTO = z.infer<typeof schemaUpdateCrucial>;
|
||||
|
||||
/** Represents data, used in ordering a list of {@link IConstituenta}. */
|
||||
export interface IMoveConstituentsDTO {
|
||||
items: number[];
|
||||
|
@ -360,6 +363,11 @@ export const schemaUpdateConstituenta = z.strictObject({
|
|||
})
|
||||
});
|
||||
|
||||
export const schemaUpdateCrucial = z.strictObject({
|
||||
target: z.array(z.number()),
|
||||
value: z.boolean()
|
||||
});
|
||||
|
||||
export const schemaProduceStructureResponse = z.strictObject({
|
||||
cst_list: z.array(z.number()),
|
||||
schema: schemaRSForm
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
|
||||
import { useUpdateTimestamp } from '@/features/library/backend/use-update-timestamp';
|
||||
|
||||
import { KEYS } from '@/backend/configuration';
|
||||
|
||||
import { rsformsApi } from './api';
|
||||
import { type IUpdateCrucialDTO } from './types';
|
||||
|
||||
export const useUpdateCrucial = () => {
|
||||
const client = useQueryClient();
|
||||
const { updateTimestamp } = useUpdateTimestamp();
|
||||
const mutation = useMutation({
|
||||
mutationKey: [KEYS.global_mutation, rsformsApi.baseKey, 'update-crucial'],
|
||||
mutationFn: rsformsApi.updateCrucial,
|
||||
onSuccess: data => {
|
||||
updateTimestamp(data.id, data.time_update);
|
||||
client.setQueryData(rsformsApi.getRSFormQueryOptions({ itemID: data.id }).queryKey, data);
|
||||
},
|
||||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
return {
|
||||
updateCrucial: (data: { itemID: number; data: IUpdateCrucialDTO }) => mutation.mutateAsync(data)
|
||||
};
|
||||
};
|
|
@ -26,6 +26,7 @@ export function BadgeConstituenta({ value, prefixID }: BadgeConstituentaProps) {
|
|||
className={clsx(
|
||||
'cc-badge-constituenta',
|
||||
value.is_inherited && 'border-dashed',
|
||||
value.crucial && 'cc-badge-inner-shadow',
|
||||
value.cst_class === CstClass.BASIC ? 'bg-accent-green25' : 'bg-input'
|
||||
)}
|
||||
style={{
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
import { type DomIconProps, IconCrucial } from '@/components/icons';
|
||||
import { cn } from '@/components/utils';
|
||||
|
||||
export function IconCrucialValue({ value, size = '1.25rem', className }: DomIconProps<boolean>) {
|
||||
if (value) {
|
||||
return <IconCrucial size={size} className={cn('text-primary', className)} />;
|
||||
} else {
|
||||
return <IconCrucial size={size} className={cn('text-muted-foreground', className)} />;
|
||||
}
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
import {
|
||||
type DomIconProps,
|
||||
IconContextSelection,
|
||||
IconGraphCollapse,
|
||||
IconGraphExpand,
|
||||
IconGraphInputs,
|
||||
IconGraphOutputs,
|
||||
IconGraphSelection
|
||||
IconGraphOutputs
|
||||
} from '@/components/icons';
|
||||
|
||||
import { DependencyMode } from '../stores/cst-search';
|
||||
|
@ -13,7 +13,7 @@ import { DependencyMode } from '../stores/cst-search';
|
|||
export function IconDependencyMode({ value, size = '1.25rem', className }: DomIconProps<DependencyMode>) {
|
||||
switch (value) {
|
||||
case DependencyMode.ALL:
|
||||
return <IconGraphSelection size={size} className={className} />;
|
||||
return <IconContextSelection size={size} className={className} />;
|
||||
case DependencyMode.OUTPUTS:
|
||||
return <IconGraphOutputs size={size} className={className ?? 'text-primary'} />;
|
||||
case DependencyMode.INPUTS:
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { IconChild } from '@/components/icons';
|
||||
import { IconChild, IconCrucial } from '@/components/icons';
|
||||
import { cn } from '@/components/utils';
|
||||
|
||||
import { labelCstTypification } from '../labels';
|
||||
|
@ -15,6 +15,7 @@ export function InfoConstituenta({ data, className, ...restProps }: InfoConstitu
|
|||
<h2 className='cursor-default' title={data.is_inherited ? ' наследник' : undefined}>
|
||||
{data.alias}
|
||||
{data.is_inherited ? <IconChild size='1rem' className='inline-icon align-middle ml-1 mt-1' /> : null}
|
||||
{data.crucial ? <IconCrucial size='1rem' className='inline-icon align-middle mt-1' /> : null}
|
||||
</h2>
|
||||
{data.term_resolved ? (
|
||||
<p>
|
||||
|
|
|
@ -116,7 +116,8 @@ export function PickMultiConstituenta({
|
|||
const cst = schema.cstByID.get(cstID);
|
||||
return !!cst && isBasicConcept(cst.cst_type);
|
||||
}}
|
||||
isOwned={cstID => !schema.cstByID.get(cstID)?.is_inherited}
|
||||
isCrucial={cstID => schema.cstByID.get(cstID)?.crucial ?? false}
|
||||
isInherited={cstID => schema.cstByID.get(cstID)?.is_inherited ?? false}
|
||||
value={value}
|
||||
onChange={onChange}
|
||||
className='w-fit'
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import {
|
||||
IconChild,
|
||||
IconConvention,
|
||||
IconCrucial,
|
||||
IconCstAxiom,
|
||||
IconCstBaseSet,
|
||||
IconCstConstSet,
|
||||
|
@ -113,6 +114,12 @@ export function RSFormStats({ className, stats }: RSFormStatsProps) {
|
|||
value={stats.count_theorem}
|
||||
/>
|
||||
|
||||
<ValueStats
|
||||
id='count_crucial'
|
||||
title='Ключевые'
|
||||
icon={<IconCrucial size='1.25rem' />}
|
||||
value={stats.count_crucial}
|
||||
/>
|
||||
<ValueStats
|
||||
id='count_text_term'
|
||||
title='Термины'
|
||||
|
|
|
@ -30,6 +30,7 @@ export function TGNode(node: TGNodeInternal) {
|
|||
<div
|
||||
className={clsx(
|
||||
'w-full h-full cursor-default flex items-center justify-center rounded-full',
|
||||
node.data.cst.crucial && 'text-primary',
|
||||
node.data.focused && 'border-[2px] border-selected',
|
||||
label.length > LABEL_THRESHOLD ? 'text-[12px]/[16px]' : 'text-[14px]/[20px]'
|
||||
)}
|
||||
|
@ -50,6 +51,7 @@ export function TGNode(node: TGNodeInternal) {
|
|||
{description ? (
|
||||
<div
|
||||
className={clsx(
|
||||
node.data.cst.crucial && 'text-primary',
|
||||
'mt-[4px] w-[150px] px-[4px] text-center translate-x-[calc(-50%+20px)]',
|
||||
'pointer-events-none',
|
||||
description.length > DESCRIPTION_THRESHOLD ? 'text-[10px]/[12px]' : 'text-[12px]/[16px]'
|
||||
|
@ -69,9 +71,11 @@ export function TGNode(node: TGNodeInternal) {
|
|||
|
||||
// ====== INTERNAL ======
|
||||
function describeCstNode(cst: IConstituenta) {
|
||||
return `${cst.alias}: ${cst.term_resolved}</br><b>Типизация:</b> ${labelCstTypification(
|
||||
cst
|
||||
)}</br><b>Содержание:</b> ${
|
||||
isBasicConcept(cst.cst_type) ? cst.convention : cst.definition_resolved || cst.definition_formal || cst.convention
|
||||
const contents = isBasicConcept(cst.cst_type)
|
||||
? cst.convention
|
||||
: cst.definition_resolved || cst.definition_formal || cst.convention;
|
||||
const typification = labelCstTypification(cst);
|
||||
return `${cst.alias}: ${cst.term_resolved}</br><b>Типизация:</b> ${typification}</br><b>Содержание:</b> ${
|
||||
contents ? contents : 'отсутствует'
|
||||
}`;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
import { MiniButton } from '@/components/control';
|
||||
import { Dropdown, DropdownButton, useDropdown } from '@/components/dropdown';
|
||||
import {
|
||||
IconChild,
|
||||
IconContextSelection,
|
||||
IconCrucial,
|
||||
IconGraphCollapse,
|
||||
IconGraphCore,
|
||||
IconGraphExpand,
|
||||
|
@ -8,7 +11,7 @@ import {
|
|||
IconGraphInverse,
|
||||
IconGraphMaximize,
|
||||
IconGraphOutputs,
|
||||
IconGraphSelection,
|
||||
IconGroupSelection,
|
||||
IconPredecessor,
|
||||
IconReset
|
||||
} from '@/components/icons';
|
||||
|
@ -21,7 +24,8 @@ interface ToolbarGraphSelectionProps extends Styling {
|
|||
onChange: (newSelection: number[]) => void;
|
||||
graph: Graph;
|
||||
isCore: (item: number) => boolean;
|
||||
isOwned?: (item: number) => boolean;
|
||||
isCrucial: (item: number) => boolean;
|
||||
isInherited: (item: number) => boolean;
|
||||
}
|
||||
|
||||
export function ToolbarGraphSelection({
|
||||
|
@ -29,20 +33,66 @@ export function ToolbarGraphSelection({
|
|||
graph,
|
||||
value: selected,
|
||||
isCore,
|
||||
isOwned,
|
||||
isInherited,
|
||||
isCrucial,
|
||||
onChange,
|
||||
...restProps
|
||||
}: ToolbarGraphSelectionProps) {
|
||||
const menu = useDropdown();
|
||||
const selectedMenu = useDropdown();
|
||||
const groupMenu = useDropdown();
|
||||
const emptySelection = selected.length === 0;
|
||||
|
||||
function handleSelectReset() {
|
||||
onChange([]);
|
||||
}
|
||||
|
||||
function handleSelectCore() {
|
||||
groupMenu.hide();
|
||||
const core = [...graph.nodes.keys()].filter(isCore);
|
||||
onChange([...core, ...graph.expandInputs(core)]);
|
||||
}
|
||||
|
||||
function handleSelectOwned() {
|
||||
if (isOwned) onChange([...graph.nodes.keys()].filter(isOwned));
|
||||
groupMenu.hide();
|
||||
onChange([...graph.nodes.keys()].filter((item: number) => !isInherited(item)));
|
||||
}
|
||||
|
||||
function handleSelectInherited() {
|
||||
groupMenu.hide();
|
||||
onChange([...graph.nodes.keys()].filter(isInherited));
|
||||
}
|
||||
|
||||
function handleSelectCrucial() {
|
||||
groupMenu.hide();
|
||||
onChange([...graph.nodes.keys()].filter(isCrucial));
|
||||
}
|
||||
|
||||
function handleExpandOutputs() {
|
||||
onChange([...selected, ...graph.expandOutputs(selected)]);
|
||||
}
|
||||
|
||||
function handleExpandInputs() {
|
||||
onChange([...selected, ...graph.expandInputs(selected)]);
|
||||
}
|
||||
|
||||
function handleSelectMaximize() {
|
||||
selectedMenu.hide();
|
||||
onChange(graph.maximizePart(selected));
|
||||
}
|
||||
|
||||
function handleSelectInvert() {
|
||||
selectedMenu.hide();
|
||||
onChange([...graph.nodes.keys()].filter(item => !selected.includes(item)));
|
||||
}
|
||||
|
||||
function handleSelectAllInputs() {
|
||||
selectedMenu.hide();
|
||||
onChange([...graph.expandInputs(selected)]);
|
||||
}
|
||||
|
||||
function handleSelectAllOutputs() {
|
||||
selectedMenu.hide();
|
||||
onChange([...graph.expandOutputs(selected)]);
|
||||
}
|
||||
|
||||
return (
|
||||
|
@ -50,73 +100,99 @@ export function ToolbarGraphSelection({
|
|||
<MiniButton
|
||||
title='Сбросить выделение'
|
||||
icon={<IconReset size='1.25rem' className='icon-primary' />}
|
||||
onClick={() => onChange([])}
|
||||
onClick={handleSelectReset}
|
||||
disabled={emptySelection}
|
||||
/>
|
||||
<div ref={menu.ref} onBlur={menu.handleBlur} className='flex items-center relative'>
|
||||
|
||||
<div ref={selectedMenu.ref} onBlur={selectedMenu.handleBlur} className='flex items-center relative'>
|
||||
<MiniButton
|
||||
title='Выделить...'
|
||||
hideTitle={menu.isOpen}
|
||||
icon={<IconGraphSelection size='1.25rem' className='icon-primary' />}
|
||||
onClick={menu.toggle}
|
||||
title='Выделить на основе выбранных...'
|
||||
hideTitle={selectedMenu.isOpen}
|
||||
icon={<IconContextSelection size='1.25rem' className='icon-primary' />}
|
||||
onClick={selectedMenu.toggle}
|
||||
disabled={emptySelection}
|
||||
/>
|
||||
<Dropdown isOpen={menu.isOpen} className='-translate-x-1/2'>
|
||||
<DropdownButton
|
||||
text='Влияющие'
|
||||
title='Выделить все влияющие'
|
||||
icon={<IconGraphCollapse size='1.25rem' className='icon-primary' />}
|
||||
onClick={() => onChange([...selected, ...graph.expandAllInputs(selected)])}
|
||||
disabled={emptySelection}
|
||||
/>
|
||||
<DropdownButton
|
||||
text='Зависимые'
|
||||
title='Выделить все зависимые'
|
||||
icon={<IconGraphExpand size='1.25rem' className='icon-primary' />}
|
||||
onClick={() => onChange([...selected, ...graph.expandAllOutputs(selected)])}
|
||||
disabled={emptySelection}
|
||||
/>
|
||||
|
||||
<Dropdown isOpen={selectedMenu.isOpen} className='-translate-x-1/2'>
|
||||
<DropdownButton
|
||||
text='Поставщики'
|
||||
title='Выделить поставщиков'
|
||||
icon={<IconGraphInputs size='1.25rem' className='icon-primary' />}
|
||||
onClick={() => onChange([...selected, ...graph.expandInputs(selected)])}
|
||||
onClick={handleExpandInputs}
|
||||
disabled={emptySelection}
|
||||
/>
|
||||
<DropdownButton
|
||||
text='Потребители'
|
||||
title='Выделить потребителей'
|
||||
icon={<IconGraphOutputs size='1.25rem' className='icon-primary' />}
|
||||
onClick={() => onChange([...selected, ...graph.expandOutputs(selected)])}
|
||||
onClick={handleExpandOutputs}
|
||||
disabled={emptySelection}
|
||||
/>
|
||||
|
||||
<DropdownButton
|
||||
text='Влияющие'
|
||||
title='Выделить все влияющие'
|
||||
icon={<IconGraphCollapse size='1.25rem' className='icon-primary' />}
|
||||
onClick={handleSelectAllInputs}
|
||||
disabled={emptySelection}
|
||||
/>
|
||||
<DropdownButton
|
||||
text='Зависимые'
|
||||
title='Выделить все зависимые'
|
||||
icon={<IconGraphExpand size='1.25rem' className='icon-primary' />}
|
||||
onClick={handleSelectAllOutputs}
|
||||
disabled={emptySelection}
|
||||
/>
|
||||
|
||||
<DropdownButton
|
||||
text='Максимизация'
|
||||
titleHtml='<b>Максимизация</b> <br/>дополнение выделения конституентами, <br/>зависимыми только от выделенных'
|
||||
aria-label='Максимизация - дополнение выделения конституентами, зависимыми только от выделенных'
|
||||
icon={<IconGraphMaximize size='1.25rem' className='icon-primary' />}
|
||||
onClick={() => onChange(graph.maximizePart(selected))}
|
||||
onClick={handleSelectMaximize}
|
||||
disabled={emptySelection}
|
||||
/>
|
||||
<DropdownButton
|
||||
text='Инвертировать'
|
||||
icon={<IconGraphInverse size='1.25rem' className='icon-primary' />}
|
||||
onClick={handleSelectInvert}
|
||||
/>
|
||||
</Dropdown>
|
||||
</div>
|
||||
|
||||
<MiniButton
|
||||
title='Выделить ядро'
|
||||
icon={<IconGraphCore size='1.25rem' className='icon-primary' />}
|
||||
onClick={handleSelectCore}
|
||||
/>
|
||||
<MiniButton
|
||||
title='Выделить собственные'
|
||||
icon={<IconPredecessor size='1.25rem' className='icon-primary' />}
|
||||
onClick={handleSelectOwned}
|
||||
/>
|
||||
<MiniButton
|
||||
title='Инвертировать'
|
||||
icon={<IconGraphInverse size='1.25rem' className='icon-primary' />}
|
||||
onClick={() => onChange([...graph.nodes.keys()].filter(item => !selected.includes(item)))}
|
||||
/>
|
||||
<div ref={groupMenu.ref} onBlur={groupMenu.handleBlur} className='flex items-center relative'>
|
||||
<MiniButton
|
||||
title='Выделить группу...'
|
||||
hideTitle={groupMenu.isOpen}
|
||||
icon={<IconGroupSelection size='1.25rem' className='icon-primary' />}
|
||||
onClick={groupMenu.toggle}
|
||||
/>
|
||||
<Dropdown isOpen={groupMenu.isOpen} className='-translate-x-1/2'>
|
||||
<DropdownButton
|
||||
text='ядро'
|
||||
title='Выделить ядро'
|
||||
icon={<IconGraphCore size='1.25rem' className='icon-primary' />}
|
||||
onClick={handleSelectCore}
|
||||
/>
|
||||
<DropdownButton
|
||||
text='ключевые'
|
||||
title='Выделить ключевые'
|
||||
icon={<IconCrucial size='1.25rem' className='icon-primary' />}
|
||||
onClick={handleSelectCrucial}
|
||||
/>
|
||||
<DropdownButton
|
||||
text='собственные'
|
||||
title='Выделить собственные'
|
||||
icon={<IconPredecessor size='1.25rem' className='icon-primary' />}
|
||||
onClick={handleSelectOwned}
|
||||
/>
|
||||
<DropdownButton
|
||||
text='наследники'
|
||||
title='Выделить наследников'
|
||||
icon={<IconChild size='1.25rem' className='icon-primary' />}
|
||||
onClick={handleSelectInherited}
|
||||
/>
|
||||
</Dropdown>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -6,9 +6,11 @@ import { Controller, useFormContext, useWatch } from 'react-hook-form';
|
|||
import { HelpTopic } from '@/features/help';
|
||||
import { BadgeHelp } from '@/features/help/components/badge-help';
|
||||
|
||||
import { MiniButton } from '@/components/control';
|
||||
import { TextArea, TextInput } from '@/components/input';
|
||||
|
||||
import { CstType, type ICreateConstituentaDTO } from '../../backend/types';
|
||||
import { IconCrucialValue } from '../../components/icon-crucial-value';
|
||||
import { RSInput } from '../../components/rs-input';
|
||||
import { SelectCstType } from '../../components/select-cst-type';
|
||||
import { getRSDefinitionPlaceholder } from '../../labels';
|
||||
|
@ -30,6 +32,7 @@ export function FormCreateCst({ schema }: FormCreateCstProps) {
|
|||
|
||||
const cst_type = useWatch({ control, name: 'cst_type' });
|
||||
const convention = useWatch({ control, name: 'convention' });
|
||||
const crucial = useWatch({ control, name: 'crucial' });
|
||||
const isBasic = isBasicConcept(cst_type);
|
||||
const isElementary = isBaseSet(cst_type);
|
||||
const isFunction = isFunctional(cst_type);
|
||||
|
@ -41,9 +44,18 @@ export function FormCreateCst({ schema }: FormCreateCstProps) {
|
|||
setForceComment(false);
|
||||
}
|
||||
|
||||
function handleToggleCrucial() {
|
||||
setValue('crucial', !crucial);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className='flex items-center self-center gap-3'>
|
||||
<MiniButton
|
||||
title='Ключевая конституента'
|
||||
icon={<IconCrucialValue size='1.25rem' value={crucial} />}
|
||||
onClick={handleToggleCrucial}
|
||||
/>
|
||||
<SelectCstType
|
||||
id='dlg_cst_type' //
|
||||
value={cst_type}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
import { useState } from 'react';
|
||||
import { Controller, useFormContext, useWatch } from 'react-hook-form';
|
||||
|
||||
import { MiniButton } from '@/components/control';
|
||||
import { TextArea, TextInput } from '@/components/input';
|
||||
|
||||
import { CstType, type IUpdateConstituentaDTO } from '../../backend/types';
|
||||
import { IconCrucialValue } from '../../components/icon-crucial-value';
|
||||
import { SelectCstType } from '../../components/select-cst-type';
|
||||
import { getRSDefinitionPlaceholder, labelCstTypification } from '../../labels';
|
||||
import { type IConstituenta, type IRSForm } from '../../models/rsform';
|
||||
|
@ -26,6 +28,7 @@ export function FormEditCst({ target, schema }: FormEditCstProps) {
|
|||
|
||||
const cst_type = useWatch({ control, name: 'item_data.cst_type' }) ?? CstType.BASE;
|
||||
const convention = useWatch({ control, name: 'item_data.convention' });
|
||||
const crucial = useWatch({ control, name: 'item_data.crucial' }) ?? false;
|
||||
const isBasic = isBasicConcept(cst_type);
|
||||
const isElementary = isBaseSet(cst_type);
|
||||
const isFunction = isFunctional(cst_type);
|
||||
|
@ -37,9 +40,18 @@ export function FormEditCst({ target, schema }: FormEditCstProps) {
|
|||
setForceComment(false);
|
||||
}
|
||||
|
||||
function handleToggleCrucial() {
|
||||
setValue('item_data.crucial', !crucial);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className='flex items-center self-center gap-3'>
|
||||
<MiniButton
|
||||
title='Ключевая конституента'
|
||||
icon={<IconCrucialValue size='1.25rem' value={crucial} />}
|
||||
onClick={handleToggleCrucial}
|
||||
/>
|
||||
<SelectCstType
|
||||
id='dlg_cst_type' //
|
||||
value={cst_type}
|
||||
|
|
|
@ -103,6 +103,8 @@ export interface IConstituenta {
|
|||
/** Represents {@link IRSForm} statistics. */
|
||||
export interface IRSFormStats {
|
||||
count_all: number;
|
||||
count_crucial: number;
|
||||
|
||||
count_errors: number;
|
||||
count_property: number;
|
||||
count_incalculable: number;
|
||||
|
|
|
@ -6,7 +6,10 @@ import { Controller, useForm } from 'react-hook-form';
|
|||
import { toast } from 'react-toastify';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
|
||||
import { SubmitButton } from '@/components/control';
|
||||
import { useUpdateCrucial } from '@/features/rsform/backend/use-update-crucial';
|
||||
import { IconCrucialValue } from '@/features/rsform/components/icon-crucial-value';
|
||||
|
||||
import { MiniButton, SubmitButton } from '@/components/control';
|
||||
import { TextButton } from '@/components/control/text-button';
|
||||
import { IconChild, IconPredecessor, IconSave } from '@/components/icons';
|
||||
import { TextArea } from '@/components/input';
|
||||
|
@ -47,7 +50,8 @@ export function FormConstituenta({ disabled, id, toggleReset, schema, activeCst,
|
|||
const setIsModified = useModificationStore(state => state.setIsModified);
|
||||
const isProcessing = useMutatingRSForm();
|
||||
|
||||
const { updateConstituenta: cstUpdate } = useUpdateConstituenta();
|
||||
const { updateConstituenta } = useUpdateConstituenta();
|
||||
const { updateCrucial } = useUpdateCrucial();
|
||||
const showTypification = useDialogsStore(state => state.showShowTypeGraph);
|
||||
const showEditTerm = useDialogsStore(state => state.showEditWordForms);
|
||||
const showRenameCst = useDialogsStore(state => state.showRenameCst);
|
||||
|
@ -129,7 +133,7 @@ export function FormConstituenta({ disabled, id, toggleReset, schema, activeCst,
|
|||
}
|
||||
|
||||
function onSubmit(data: IUpdateConstituentaDTO) {
|
||||
void cstUpdate({ itemID: schema.id, data }).then(() => {
|
||||
void updateConstituenta({ itemID: schema.id, data }).then(() => {
|
||||
setIsModified(false);
|
||||
reset({ ...data });
|
||||
});
|
||||
|
@ -159,6 +163,16 @@ export function FormConstituenta({ disabled, id, toggleReset, schema, activeCst,
|
|||
showRenameCst({ schema: schema, target: activeCst });
|
||||
}
|
||||
|
||||
function handleToggleCrucial() {
|
||||
void updateCrucial({
|
||||
itemID: schema.id,
|
||||
data: {
|
||||
target: [activeCst.id],
|
||||
value: !activeCst.crucial
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<form
|
||||
id={id}
|
||||
|
@ -173,15 +187,22 @@ export function FormConstituenta({ disabled, id, toggleReset, schema, activeCst,
|
|||
disabled={isModified || disabled}
|
||||
/>
|
||||
|
||||
<MiniButton
|
||||
title={activeCst.crucial ? 'Ключевая: да' : 'Ключевая: нет'}
|
||||
className='ml-6 mr-1 -mt-0.75'
|
||||
aria-label='Переключатель статуса ключевой конституенты'
|
||||
icon={<IconCrucialValue size='1rem' value={activeCst.crucial} />}
|
||||
onClick={handleToggleCrucial}
|
||||
disabled={disabled || isProcessing || isModified}
|
||||
/>
|
||||
|
||||
<TextButton
|
||||
text='Имя' //
|
||||
className='ml-6'
|
||||
title={disabled ? undefined : isModified ? tooltipText.unsaved : 'Переименовать конституенту'}
|
||||
onClick={handleRenameCst}
|
||||
disabled={isModified || disabled}
|
||||
/>
|
||||
|
||||
<div className='ml-2 text-sm font-medium min-w-16 whitespace-nowrap select-text cursor-default'>
|
||||
<div className='ml-2 text-sm font-medium whitespace-nowrap select-text cursor-default'>
|
||||
{activeCst?.alias ?? ''}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -3,11 +3,13 @@
|
|||
import { HelpTopic } from '@/features/help';
|
||||
import { BadgeHelp } from '@/features/help/components/badge-help';
|
||||
import { MiniSelectorOSS } from '@/features/library/components/mini-selector-oss';
|
||||
import { useUpdateCrucial } from '@/features/rsform/backend/use-update-crucial';
|
||||
|
||||
import { MiniButton } from '@/components/control';
|
||||
import { Dropdown, DropdownButton, useDropdown } from '@/components/dropdown';
|
||||
import {
|
||||
IconClone,
|
||||
IconCrucial,
|
||||
IconDestroy,
|
||||
IconMoveDown,
|
||||
IconMoveUp,
|
||||
|
@ -31,10 +33,12 @@ interface ToolbarRSListProps {
|
|||
|
||||
export function ToolbarRSList({ className }: ToolbarRSListProps) {
|
||||
const isProcessing = useMutatingRSForm();
|
||||
const { updateCrucial } = useUpdateCrucial();
|
||||
const menu = useDropdown();
|
||||
const {
|
||||
schema,
|
||||
selected,
|
||||
activeCst,
|
||||
navigateOss,
|
||||
deselectAll,
|
||||
createCst,
|
||||
|
@ -46,6 +50,19 @@ export function ToolbarRSList({ className }: ToolbarRSListProps) {
|
|||
moveDown
|
||||
} = useRSEdit();
|
||||
|
||||
function handleToggleCrucial() {
|
||||
if (!activeCst) {
|
||||
return;
|
||||
}
|
||||
void updateCrucial({
|
||||
itemID: schema.id,
|
||||
data: {
|
||||
target: selected,
|
||||
value: !activeCst.crucial
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={cn('cc-icons items-start outline-hidden', className)}>
|
||||
{schema.oss.length > 0 ? (
|
||||
|
@ -75,6 +92,13 @@ export function ToolbarRSList({ className }: ToolbarRSListProps) {
|
|||
onClick={moveDown}
|
||||
disabled={isProcessing || selected.length === 0 || selected.length === schema.items.length}
|
||||
/>
|
||||
<MiniButton
|
||||
title='Ключевая конституента'
|
||||
aria-label='Переключатель статуса ключевой конституенты'
|
||||
icon={<IconCrucial size='1.25rem' className='icon-primary' />}
|
||||
onClick={handleToggleCrucial}
|
||||
disabled={isProcessing || selected.length === 0}
|
||||
/>
|
||||
<div ref={menu.ref} onBlur={menu.handleBlur} className='relative'>
|
||||
<MiniButton
|
||||
title='Добавить пустую конституенту'
|
||||
|
|
|
@ -172,7 +172,8 @@ export function ToolbarTermGraph({ className }: ToolbarTermGraphProps) {
|
|||
const cst = schema.cstByID.get(cstID);
|
||||
return !!cst && isBasicConcept(cst.cst_type);
|
||||
}}
|
||||
isOwned={schema.inheritance.length > 0 ? cstID => !schema.cstByID.get(cstID)?.is_inherited : undefined}
|
||||
isCrucial={cstID => schema.cstByID.get(cstID)?.crucial ?? false}
|
||||
isInherited={cstID => schema.cstByID.get(cstID)?.is_inherited ?? false}
|
||||
value={selected}
|
||||
onChange={handleSetSelected}
|
||||
/>
|
||||
|
|
|
@ -80,6 +80,7 @@ export function ViewHidden({ items }: ViewHiddenProps) {
|
|||
type='button'
|
||||
className={clsx(
|
||||
'cc-view-hidden-item w-12 rounded-md text-center select-none',
|
||||
cst.crucial && 'text-primary',
|
||||
localSelected.includes(cstID) && 'selected',
|
||||
cst.is_inherited && 'inherited'
|
||||
)}
|
||||
|
|
|
@ -239,3 +239,7 @@
|
|||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
|
||||
@utility cc-badge-inner-shadow {
|
||||
box-shadow: inset 0 1px 3px 0, inset 0 -1px 3px 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user