Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Связь для комментариев. #291

Merged
merged 41 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
b021449
Реализована связь для комментария.
XidFanSan May 14, 2024
c9e4427
Теперь связь создается без условий.
XidFanSan May 14, 2024
db32c01
Доработка комментариев.
XidFanSan May 14, 2024
9c74708
Убрана ошибка DiagramEditor.
XidFanSan May 20, 2024
197aa60
1) Исправлены замечания;
XidFanSan May 20, 2024
99a3de8
Удалены лишние console.log.
XidFanSan May 20, 2024
efc2a13
Исправление иерархии:
XidFanSan May 20, 2024
959cba5
Запрещаем создавать связь комментарию для самого себя.
XidFanSan May 20, 2024
180c143
Merge branch 'main' of github.com:XidFanSan/lapki-client into comment…
XidFanSan May 20, 2024
6950bb0
Внесены небольшие исправления.
XidFanSan May 29, 2024
3fba010
Merge branch 'main' of github.com:XidFanSan/lapki-client into comment…
XidFanSan May 29, 2024
03a2471
1) Переписан класс transition;
XidFanSan May 29, 2024
0cd467d
Изменено контекстное меню для отдельной связи.
XidFanSan May 29, 2024
bedba31
Внесены небольшие изменения.
XidFanSan May 29, 2024
ae27955
Исправлена ошибка отдельной связи.
XidFanSan May 29, 2024
f3298db
Добавлена связь комментария для начального состояния.
XidFanSan May 29, 2024
28ccb26
Убрано условие перехода.
XidFanSan May 29, 2024
4f63779
Merge branch 'main' of github.com:XidFanSan/lapki-client into comment…
XidFanSan May 31, 2024
c61c04d
Merge branch 'main' of github.com:XidFanSan/lapki-client into comment…
XidFanSan Jun 1, 2024
6d4c276
Возвращены одиночные связи.
XidFanSan Jun 1, 2024
f6ba38a
Merge branch 'main' of github.com:XidFanSan/lapki-client into comment…
XidFanSan Jun 3, 2024
1ba51b2
Удалены лишние типы.
XidFanSan Jun 4, 2024
119017b
Устранена ошибка typecheck.
XidFanSan Jun 4, 2024
8634049
Merge branch 'main' of github.com:XidFanSan/lapki-client into comment…
XidFanSan Jun 4, 2024
daa76f6
Добавлен запрет на перенос стрелки.
XidFanSan Jun 5, 2024
519c1a0
Убрано дублирования кода.
XidFanSan Jun 5, 2024
9f56f4d
Устранен баг.
XidFanSan Jun 5, 2024
5a740cf
Merge branch 'main' into comment-link
XidFanSan Jun 5, 2024
015bb97
Устранения конфликта.
XidFanSan Jun 5, 2024
513567e
Частично устранена проблема удаления комментария.
XidFanSan Jun 5, 2024
8ae915f
Устранена ошибка иерархии с удалением комментария.
XidFanSan Jun 5, 2024
1d40246
Добавлены TODO.
XidFanSan Jun 5, 2024
7f68664
1) Смена имени source и target;
XidFanSan Jun 10, 2024
9b7f215
Исправление ошибки sourceId и targetId.
XidFanSan Jun 10, 2024
df6ae3f
Merge branch 'main' of github.com:XidFanSan/lapki-client into comment…
XidFanSan Jun 10, 2024
9bb78e0
Исправление ширины нажатия на стрелку.
XidFanSan Jun 10, 2024
0822ec1
Merge branch 'main' into comment-link
XidFanSan Jun 10, 2024
68d1819
Merge branch 'main' of github.com:XidFanSan/lapki-client into comment…
XidFanSan Jun 10, 2024
dffd368
Исправление ошибки у модуля компилятора.
XidFanSan Jun 10, 2024
3feb486
Merge branch 'comment-link' of github.com:XidFanSan/lapki-client into…
XidFanSan Jun 10, 2024
d52e880
Merge branch 'main' of github.com:XidFanSan/lapki-client into comment…
XidFanSan Jun 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/renderer/src/components/DiagramEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ export const DiagramEditor: React.FC = () => {
};

// TODO(bryzZz) Нужно делить на две модалки
// Тут возникло много as any
// это потому что для состояния и перехода типы разные но модалка одна
// и приходится приводить к какому-то обшему типу
// Тут возникло много "as any"
// это потому что для состояния и перехода типы разные, но модалка одна
// и приходится приводить к какому-то общему типу
const handleCreateModalSubmit = (data: CreateModalResult) => {
if (data.key === 2) {
editor.controller.states.changeStateEvents({
Expand All @@ -170,8 +170,8 @@ export const DiagramEditor: React.FC = () => {
} else if (transition && data.key === 3) {
editor.controller.transitions.changeTransition({
id: transition.id,
source: transition.source.id,
target: transition.target.id,
sourceId: transition.source.id,
targetId: transition.target.id,
color: data.color ?? DEFAULT_TRANSITION_COLOR,
label: {
trigger: data.trigger,
Expand All @@ -181,8 +181,8 @@ export const DiagramEditor: React.FC = () => {
});
} else if (newTransitionData) {
editor.controller.transitions.createTransition({
source: newTransitionData.source.id,
target: newTransitionData.target.id,
sourceId: newTransitionData.source.id,
targetId: newTransitionData.target.id,
color: data.color ?? DEFAULT_TRANSITION_COLOR,
label: {
trigger: data.trigger,
Expand Down
51 changes: 44 additions & 7 deletions src/renderer/src/components/Hierarchy/Hierarchy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { twMerge } from 'tailwind-merge';

import './style-modern.css';
import { useSettings } from '@renderer/hooks';
import { State } from '@renderer/lib/drawable';
import { FinalState, State } from '@renderer/lib/drawable';
import { MyMouseEvent } from '@renderer/lib/types/mouse';
import { useEditorContext } from '@renderer/store/EditorContext';
import { escapeRegExp } from '@renderer/utils';
Expand All @@ -24,7 +24,7 @@ import { TitleRender } from './TitleRender';

export interface HierarchyItemData {
title: string;
type: 'state' | 'initialState' | 'finalState' | 'choiceState' | 'transition';
type: 'state' | 'initialState' | 'finalState' | 'choiceState' | 'transition' | 'note';
}

export const Hierarchy: React.FC = () => {
Expand All @@ -39,6 +39,7 @@ export const Hierarchy: React.FC = () => {
const finalStates = model.useData('elements.finalStates');
const choiceStates = model.useData('elements.choiceStates');
const transitions = model.useData('elements.transitions');
const notes = model.useData('elements.notes');

const [search, setSearch] = useState('');
const [focusedItem, setFocusedItem] = useState<TreeItemIndex>();
Expand Down Expand Up @@ -90,6 +91,20 @@ export const Hierarchy: React.FC = () => {
};
}

for (const noteId in notes) {
const note = notes[noteId];

data[noteId] = {
index: noteId,
isFolder: false,
//TODO: (XidFanSan) надо добавить название заметки (title)
data: { title: note.text ?? 'Комментарий', type: 'note' },
XidFanSan marked this conversation as resolved.
Show resolved Hide resolved
children: [],
canRename: false,
canMove: false,
};
}

for (const stateId in choiceStates) {
data[stateId] = {
index: stateId,
Expand All @@ -115,9 +130,13 @@ export const Hierarchy: React.FC = () => {
}
}

for (const [noteId] of [...Object.entries(notes)]) {
data.root.children?.push(noteId);
}

for (const transitionId in transitions) {
const transition = transitions[transitionId];
const targetName = data[transition.target]?.data?.title;
const targetName = data[transition.targetId]?.data?.title;

data[transitionId] = {
index: transitionId,
Expand All @@ -129,12 +148,12 @@ export const Hierarchy: React.FC = () => {
canRename: false,
canMove: false,
};
data[transition.source].children?.push(transitionId);
data[transition.source].isFolder = true;
data[transition.sourceId].children?.push(transitionId);
data[transition.sourceId].isFolder = true;
}

return data;
}, [choiceStates, finalStates, initialStates, states, transitions]);
}, [choiceStates, finalStates, initialStates, notes, states, transitions]);

// Синхронизация дерева и состояний
const handleFocusItem = (item: TreeItem<HierarchyItemData>) => setFocusedItem(item.index);
Expand Down Expand Up @@ -170,6 +189,7 @@ export const Hierarchy: React.FC = () => {

const onFocus = (item: TreeItem) => () => {
controller.selectState(item.index.toString());
controller.selectNote(item.index.toString());
controller.selectTransition(item.index.toString());
};

Expand Down Expand Up @@ -207,12 +227,23 @@ export const Hierarchy: React.FC = () => {
if (state && state instanceof State) {
return controller.states.handleContextMenu(state, { event: mouse });
}
if (state && state instanceof FinalState) {
return controller.states.handleFinalStateContextMenu(state, {
event: mouse,
});
}
const transition = controller.transitions.get(item.index.toString());
if (transition) {
return controller.transitions.handleContextMenu(transition, {
event: mouse,
});
}
const note = controller.notes.get(item.index.toString());
if (note) {
return controller.notes.handleContextMenu(note, {
event: mouse,
});
}
};

const onDragStart = (item: TreeItem, actions: TreeItemActions) => (e) => {
Expand Down Expand Up @@ -284,7 +315,13 @@ export const Hierarchy: React.FC = () => {
return setSelectedItems([transitionId]);
}
}
}, [states, transitions]);

for (const [noteId, note] of Object.entries(notes)) {
if (note?.selection) {
return setSelectedItems([noteId]);
}
}
}, [notes, states, transitions]);

return (
<div className={twMerge(theme !== 'light' && 'rct-dark')}>
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/src/components/Hierarchy/TitleRender.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ReactComponent as InitialStateIcon } from '@renderer/assets/icons/arrow_down_right.svg';
import { ReactComponent as ChoiceStateIcon } from '@renderer/assets/icons/choice_state.svg';
import { ReactComponent as FinalStateIcon } from '@renderer/assets/icons/final_state.svg';
import { ReactComponent as NoteIcon } from '@renderer/assets/icons/note.svg';
import { ReactComponent as StateIcon } from '@renderer/assets/icons/state.svg';
import { ReactComponent as TransitionIcon } from '@renderer/assets/icons/transition-alt.svg';

Expand All @@ -24,6 +25,7 @@ const icons: Record<
initialState: InitialStateIcon,
transition: TransitionIcon,
finalState: FinalStateIcon,
note: NoteIcon,
choiceState: ChoiceStateIcon,
};

Expand Down
8 changes: 4 additions & 4 deletions src/renderer/src/components/Modules/Compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ function actualizeTransitions(oldTransitions: { [key: string]: CompilerTransitio
for (const transitionId in oldTransitions) {
const oldTransition = oldTransitions[transitionId];
newTransitions[transitionId] = {
source: oldTransition.source,
target: oldTransition.target,
sourceId: oldTransition.source,
targetId: oldTransition.target,
color: oldTransition.color,
label: {
trigger: oldTransition.trigger,
Expand Down Expand Up @@ -70,8 +70,8 @@ function actualizeInitialState(
const initialId = generateId();
const transitionId = generateId();
const transition: Transition = {
source: initialId,
target: oldInitial.target,
sourceId: initialId,
targetId: oldInitial.target,
color: randomColor(),
};
const initial: InitialState = {
Expand Down
82 changes: 43 additions & 39 deletions src/renderer/src/hooks/useDiagramContextMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export const useDiagramContextMenu = () => {
editor.controller.transitions.changeTransition({
...transition.data,
id: transition.id,
source: state.id,
sourceId: state.id,
});
},
};
Expand All @@ -256,60 +256,64 @@ export const useDiagramContextMenu = () => {
editor.controller.transitions.changeTransition({
...transition.data,
id: transition.id,
target: state.id,
targetId: state.id,
});
},
};
};

const sourceArray = [
...Array.from(editor.controller.states.getStates()).filter(
(value) => transition.data.source !== value[0]
(value) => transition.data.sourceId !== value[0]
),
];

const targetArray = [
...Array.from(editor.controller.states.getStates()).filter(
(value) => transition.data.target !== value[0]
(value) => transition.data.targetId !== value[0]
),
];

handleEvent(position, [
{
label: 'Копировать',
type: 'copy',
action: () => {
editor?.controller.copySelected();
},
},
{
label: 'Выбрать исход(source)',
type: 'source',
isFolder: true,
children: [...sourceArray.map(([_id, value]) => source(value))],
// eslint-disable-next-line @typescript-eslint/no-empty-function
action: () => {},
},
{
label: 'Выбрать цель(target)',
type: 'target',
isFolder: true,
children: [...targetArray.map(([_id, value]) => target(value))],
// eslint-disable-next-line @typescript-eslint/no-empty-function
action: () => {},
},
{
label: 'Посмотреть код',
type: 'showCodeAll',
action: () => {
openTab({
type: 'transition',
name: transition.id,
code: editor.model.serializer.getTransition(transition.id) ?? '',
language: 'json',
});
},
},
...(transition.data.label
? [
{
label: 'Копировать',
type: 'copy',
action: () => {
editor?.controller.copySelected();
},
},
{
label: 'Выбрать исход(source)',
type: 'source',
isFolder: true,
children: [...sourceArray.map(([_id, value]) => source(value))],
// eslint-disable-next-line @typescript-eslint/no-empty-function
action: () => {},
},
{
label: 'Выбрать цель(target)',
type: 'target',
isFolder: true,
children: [...targetArray.map(([_id, value]) => target(value))],
// eslint-disable-next-line @typescript-eslint/no-empty-function
action: () => {},
},
{
label: 'Посмотреть код',
type: 'showCodeAll',
action: () => {
openTab({
type: 'transition',
name: transition.id,
code: editor.model.serializer.getTransition(transition.id) ?? '',
language: 'json',
});
},
},
]
: []),
{
label: 'Удалить',
type: 'delete',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,8 @@ export class EditorController {

this.removeSelection();

this.app.model.changeNoteSelection(id, true);

note.setIsSelected(true);
}

Expand Down Expand Up @@ -418,6 +420,7 @@ export class EditorController {

this.notes.forEach((note) => {
note.setIsSelected(false);
this.app.model.changeNoteSelection(note.id, false);
});

this.view.isDirty = true;
Expand Down
Loading
Loading