From 7ad85ed0bc0adce857180462e36e30593f9ea47f Mon Sep 17 00:00:00 2001 From: manu Date: Wed, 3 Jul 2024 12:15:43 +0200 Subject: [PATCH 1/2] Add 'deletable' option to fileType in PlaybookDropdownMenu This commit introduces a new 'deletable' option to the fileType attribute in the PlaybookDropdownMenu component. It also modifies the filtering of items based on the 'deletable' fileType. Additionally, a 'rootNode' attribute is added in TreeComponent and some unnecessary imports are removed. --- .../Playbooks/components/PlaybookDropdownMenu.tsx | 6 +++--- .../pages/Playbooks/components/TreeComponent.tsx | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/client/src/pages/Playbooks/components/PlaybookDropdownMenu.tsx b/client/src/pages/Playbooks/components/PlaybookDropdownMenu.tsx index 0a2b1f4d..302c2408 100644 --- a/client/src/pages/Playbooks/components/PlaybookDropdownMenu.tsx +++ b/client/src/pages/Playbooks/components/PlaybookDropdownMenu.tsx @@ -25,7 +25,7 @@ type PlaybookDropdownMenuType = { }; type PlaybookDrownMenuItemType = { - fileType: DirectoryTree.CONSTANTS | 'any'; + fileType: DirectoryTree.CONSTANTS | 'any' | 'deletable'; playbookQuickRef?: string; icon?: React.JSX.Element; label: string; @@ -49,7 +49,7 @@ const menuItems: PlaybookDrownMenuItemType[] = [ label: 'Delete', icon: , key: '3', - fileType: 'any', + fileType: 'deletable', }, ]; @@ -73,7 +73,7 @@ const PlaybookDropdownMenu: React.FC = (props) => { const items = menuItems .filter( (e) => - (e.fileType === 'any' && !props.cannotDelete) || + (e.fileType === 'deletable' && !props.cannotDelete) || e.fileType === props.type, ) .map((e) => { diff --git a/client/src/pages/Playbooks/components/TreeComponent.tsx b/client/src/pages/Playbooks/components/TreeComponent.tsx index d01f9afd..fff6e590 100644 --- a/client/src/pages/Playbooks/components/TreeComponent.tsx +++ b/client/src/pages/Playbooks/components/TreeComponent.tsx @@ -2,7 +2,6 @@ import { SimpleIconsGit, StreamlineLocalStorageFolderSolid, } from '@/components/Icons/CustomIcons'; -import { Typography } from 'antd'; import React, { ReactNode } from 'react'; import { API, @@ -10,7 +9,6 @@ import { DirectoryTree as DT, Playbooks, } from 'ssm-shared-lib'; -import PlaybookDropdownMenu from './PlaybookDropdownMenu'; export type ClientPlaybooksTrees = { isLeaf?: boolean; @@ -83,11 +81,21 @@ export function recursiveTreeTransform( key: child.path, _name: child.name, nodeType: child.type, + rootNode: false, playbookRepository: { basePath: playbookRepository.basePath, name: playbookRepository.name, uuid: playbookRepository.uuid, }, + // TODO ugly fix to prevent user breaking the system + custom: + (child as DirectoryTree.ExtendedTreeNode).custom === undefined && + !child.path.includes( + '/server/src/ansible/00000000-0000-0000-0000-000000000000/agent', + ) && + !child.path.includes( + '/server/src/ansible/00000000-0000-0000-0000-000000000000/device', + ), depth: depth, selectable: false, children: recursiveTreeTransform( @@ -102,6 +110,7 @@ export function recursiveTreeTransform( key: child.path, _name: child.name, nodeType: DirectoryTree.CONSTANTS.FILE, + rootNode: false, playbookRepository: { basePath: playbookRepository.basePath, name: playbookRepository.name, @@ -120,6 +129,7 @@ export function recursiveTreeTransform( newTree.push({ key: node.path, _name: node.name, + rootNode: false, nodeType: DirectoryTree.CONSTANTS.FILE, playbookRepository: { basePath: playbookRepository.basePath, From 8af79dec63c8526772a5de3c5c4e5803917962c6 Mon Sep 17 00:00:00 2001 From: manu Date: Wed, 3 Jul 2024 12:16:43 +0200 Subject: [PATCH 2/2] Implement restrictions on node deletion A condition has been added to prevent deletion of custom nodes or root nodes in DirectoryTreeView component of the Playbooks page. This helps to maintain the integrity of the tree structure and prevents accidental deletion of important nodes. --- client/src/pages/Playbooks/components/DirectoryTreeView.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/client/src/pages/Playbooks/components/DirectoryTreeView.tsx b/client/src/pages/Playbooks/components/DirectoryTreeView.tsx index f78a2528..19080d42 100644 --- a/client/src/pages/Playbooks/components/DirectoryTreeView.tsx +++ b/client/src/pages/Playbooks/components/DirectoryTreeView.tsx @@ -106,6 +106,7 @@ const DirectoryTreeView: React.FC = (props) => { }} callbacks={props.callbacks} remoteRootNode={node.remoteRootNode} + cannotDelete={!node.custom || node.rootNode} >