refactor: remove drag and drop from the objects tree
Decided during manual testing: the legacy drop-inside zone had zero height, so drops only worked before/after a node and moves happened by accident. Sections are re-parented via Edit, as before. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,28 +1,26 @@
|
||||
import * as React from 'react';
|
||||
import { confirmModal } from '@tnsu/ui-kit';
|
||||
import { IObjectsRepository } from './objectsRepository';
|
||||
import { getChangedParentId, getDeleteConfirmMessage, getErrorText, resolveMove } from './objectsRules';
|
||||
import { DropPosition, IObjectModalTarget, ObjectNode, ObjectTree } from './objectsTypes';
|
||||
import { getChangedParentId, getDeleteConfirmMessage, getErrorText } from './objectsRules';
|
||||
import { IObjectModalTarget, ObjectNode } from './objectsTypes';
|
||||
import { OBJECTS_TEXTS } from './texts';
|
||||
|
||||
interface IActionsDeps {
|
||||
repository: IObjectsRepository;
|
||||
projectTitle: string | undefined;
|
||||
tree: ObjectTree;
|
||||
reload: () => void;
|
||||
}
|
||||
|
||||
export interface IObjectActions {
|
||||
/** Ошибка переноса или удаления (раньше — alert). */
|
||||
/** Ошибка удаления (раньше — alert). */
|
||||
actionError: string | undefined;
|
||||
/** Создание / правка из модалки. Ошибку бросает дальше — модалка покажет её у себя. */
|
||||
saveObject: (target: IObjectModalTarget, title: string, parentValue: string) => Promise<void>;
|
||||
moveObject: (dragId: number, targetId: number, position: DropPosition) => Promise<void>;
|
||||
deleteObject: (node: ObjectNode) => Promise<void>;
|
||||
}
|
||||
|
||||
/** Пишущие действия над деревом объектов. После каждого успешного действия дерево перечитывается. */
|
||||
export function useObjectActions({ repository, projectTitle, tree, reload }: IActionsDeps): IObjectActions {
|
||||
export function useObjectActions({ repository, projectTitle, reload }: IActionsDeps): IObjectActions {
|
||||
const [actionError, setActionError] = React.useState<string | undefined>(undefined);
|
||||
|
||||
const saveObject = async (target: IObjectModalTarget, title: string, parentValue: string): Promise<void> => {
|
||||
@@ -39,18 +37,6 @@ export function useObjectActions({ repository, projectTitle, tree, reload }: IAc
|
||||
reload();
|
||||
};
|
||||
|
||||
const moveObject = async (dragId: number, targetId: number, position: DropPosition): Promise<void> => {
|
||||
const move = resolveMove(tree, dragId, targetId, position);
|
||||
if (!move) return;
|
||||
setActionError(undefined);
|
||||
try {
|
||||
await repository.moveObject(dragId, move.parentId);
|
||||
reload();
|
||||
} catch (error) {
|
||||
setActionError(OBJECTS_TEXTS.moveError(getErrorText(error)));
|
||||
}
|
||||
};
|
||||
|
||||
const deleteObject = async (node: ObjectNode): Promise<void> => {
|
||||
const isConfirmed = await confirmModal({
|
||||
message: getDeleteConfirmMessage(node),
|
||||
@@ -67,5 +53,5 @@ export function useObjectActions({ repository, projectTitle, tree, reload }: IAc
|
||||
}
|
||||
};
|
||||
|
||||
return { actionError, saveObject, moveObject, deleteObject };
|
||||
return { actionError, saveObject, deleteObject };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user