From 5d68f05b85611bf4ed34034bafff397a124e9ca2 Mon Sep 17 00:00:00 2001
From: Ivan <8611739+IRBorisov@users.noreply.github.com>
Date: Tue, 19 Nov 2024 21:56:26 +0300
Subject: [PATCH] M: Disable move buttons when all selected
---
.../EditorConstituenta/ToolbarConstituenta.tsx | 4 ++--
.../pages/RSFormPage/EditorRSList/ToolbarRSList.tsx | 12 ++++++++++--
.../RSFormPage/EditorTermGraph/EditorTermGraph.tsx | 2 +-
.../frontend/src/pages/RSFormPage/RSEditContext.tsx | 7 ++-----
4 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/rsconcept/frontend/src/pages/RSFormPage/EditorConstituenta/ToolbarConstituenta.tsx b/rsconcept/frontend/src/pages/RSFormPage/EditorConstituenta/ToolbarConstituenta.tsx
index a18c9dbe..8ca2c281 100644
--- a/rsconcept/frontend/src/pages/RSFormPage/EditorConstituenta/ToolbarConstituenta.tsx
+++ b/rsconcept/frontend/src/pages/RSFormPage/EditorConstituenta/ToolbarConstituenta.tsx
@@ -112,13 +112,13 @@ function ToolbarConstituenta({
}
- disabled={disabled || modified}
+ disabled={disabled || modified || (controller.schema && controller.schema?.items.length < 2)}
onClick={controller.moveUp}
/>
}
- disabled={disabled || modified}
+ disabled={disabled || modified || (controller.schema && controller.schema?.items.length < 2)}
onClick={controller.moveDown}
/>
>
diff --git a/rsconcept/frontend/src/pages/RSFormPage/EditorRSList/ToolbarRSList.tsx b/rsconcept/frontend/src/pages/RSFormPage/EditorRSList/ToolbarRSList.tsx
index e2132e1f..7fb4a0dc 100644
--- a/rsconcept/frontend/src/pages/RSFormPage/EditorRSList/ToolbarRSList.tsx
+++ b/rsconcept/frontend/src/pages/RSFormPage/EditorRSList/ToolbarRSList.tsx
@@ -46,13 +46,21 @@ function ToolbarRSList() {
}
- disabled={controller.isProcessing || controller.nothingSelected}
+ disabled={
+ controller.isProcessing ||
+ controller.selected.length === 0 ||
+ (controller.schema && controller.selected.length === controller.schema.items.length)
+ }
onClick={controller.moveUp}
/>
}
- disabled={controller.isProcessing || controller.nothingSelected}
+ disabled={
+ controller.isProcessing ||
+ controller.selected.length === 0 ||
+ (controller.schema && controller.selected.length === controller.schema.items.length)
+ }
onClick={controller.moveDown}
/>
diff --git a/rsconcept/frontend/src/pages/RSFormPage/EditorTermGraph/EditorTermGraph.tsx b/rsconcept/frontend/src/pages/RSFormPage/EditorTermGraph/EditorTermGraph.tsx
index f63d7a3a..5bf44f20 100644
--- a/rsconcept/frontend/src/pages/RSFormPage/EditorTermGraph/EditorTermGraph.tsx
+++ b/rsconcept/frontend/src/pages/RSFormPage/EditorTermGraph/EditorTermGraph.tsx
@@ -137,7 +137,7 @@ function EditorTermGraph({ onOpenEdit }: EditorTermGraphProps) {
return;
}
const definition = controller.selected.map(id => controller.schema!.cstByID.get(id)!.alias).join(' ');
- controller.createCst(controller.nothingSelected ? CstType.BASE : CstType.TERM, false, definition);
+ controller.createCst(controller.selected.length === 0 ? CstType.BASE : CstType.TERM, false, definition);
}
function handleDeleteCst() {
diff --git a/rsconcept/frontend/src/pages/RSFormPage/RSEditContext.tsx b/rsconcept/frontend/src/pages/RSFormPage/RSEditContext.tsx
index 390ae9db..f0c2850b 100644
--- a/rsconcept/frontend/src/pages/RSFormPage/RSEditContext.tsx
+++ b/rsconcept/frontend/src/pages/RSFormPage/RSEditContext.tsx
@@ -65,7 +65,6 @@ export interface IRSEditContext extends ILibraryItemEditor {
isProcessing: boolean;
isAttachedToOSS: boolean;
canProduceStructure: boolean;
- nothingSelected: boolean;
canDeleteSelected: boolean;
updateSchema: (data: ILibraryUpdateData) => void;
@@ -148,10 +147,9 @@ export const RSEditState = ({
[accessLevel, model.schema?.read_only]
);
const isContentEditable = useMemo(() => isMutable && !model.isArchive, [isMutable, model.isArchive]);
- const nothingSelected = useMemo(() => selected.length === 0, [selected]);
const canDeleteSelected = useMemo(
- () => !nothingSelected && selected.every(id => !model.schema?.cstByID.get(id)?.is_inherited),
- [selected, nothingSelected, model.schema]
+ () => selected.length > 0 && selected.every(id => !model.schema?.cstByID.get(id)?.is_inherited),
+ [selected, model.schema]
);
const isAttachedToOSS = useMemo(
() =>
@@ -625,7 +623,6 @@ export const RSEditState = ({
isProcessing: model.processing,
isAttachedToOSS,
canProduceStructure,
- nothingSelected,
canDeleteSelected,
setOwner,