From 5142d1b4bc681af7e33b1acaf6b66eaafba221f8 Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Wed, 7 Apr 2021 19:58:29 +0200 Subject: [PATCH] can't move groups to the root level (#485) * can't move groups to the root level disabled "Move" button on root level * can now move groups to root * added move to root test --- cypress/integration/group_test.spec.ts | 15 +++++++++++++++ .../support/pages/admin_console/ListingPage.ts | 2 +- .../manage/groups/MoveGroupModal.ts | 5 +++++ src/groups/GroupTable.tsx | 10 ++++++++-- src/groups/MoveGroupDialog.tsx | 16 ++++++---------- src/groups/messages.json | 1 + 6 files changed, 36 insertions(+), 13 deletions(-) diff --git a/cypress/integration/group_test.spec.ts b/cypress/integration/group_test.spec.ts index 6b26e7ade9..db09692faa 100644 --- a/cypress/integration/group_test.spec.ts +++ b/cypress/integration/group_test.spec.ts @@ -94,6 +94,21 @@ describe("Group test", () => { sidebarPage.goToGroups(); listingPage.deleteItem(targetGroupName); }); + + it("Should move group to root", async () => { + const groups = ["group1", "group2"]; + await new AdminClient().createSubGroups(groups); + sidebarPage.goToGroups(); + listingPage.goToItemDetails(groups[0]); + cy.wait(2000); + listingPage.clickRowDetails(groups[1]).clickDetailMenu("Move to"); + + moveGroupModal.clickRoot().clickMove(); + sidebarPage.goToGroups(); + + new GroupDetailPage().checkListSubGroup(groups); + listingPage.deleteItem(groups[0]); + }); }); describe("Group details", () => { diff --git a/cypress/support/pages/admin_console/ListingPage.ts b/cypress/support/pages/admin_console/ListingPage.ts index fae51114fa..b5ba133d89 100644 --- a/cypress/support/pages/admin_console/ListingPage.ts +++ b/cypress/support/pages/admin_console/ListingPage.ts @@ -10,7 +10,7 @@ export default class ListingPage { constructor() { this.searchInput = '.pf-c-toolbar__item [type="search"]'; - this.itemsRows = ".pf-c-page__main-section table"; + this.itemsRows = "table"; this.itemRowDrpDwn = ".pf-c-dropdown > button"; this.exportBtn = '[role="menuitem"]:nth-child(1)'; this.deleteBtn = '[role="menuitem"]:nth-child(2)'; diff --git a/cypress/support/pages/admin_console/manage/groups/MoveGroupModal.ts b/cypress/support/pages/admin_console/manage/groups/MoveGroupModal.ts index 8ded506af7..c589c69664 100644 --- a/cypress/support/pages/admin_console/manage/groups/MoveGroupModal.ts +++ b/cypress/support/pages/admin_console/manage/groups/MoveGroupModal.ts @@ -7,6 +7,11 @@ export default class MoveGroupModal { return this; } + clickRoot() { + cy.get(".pf-c-breadcrumb__item > button").click(); + return this; + } + checkTitle(title: string) { cy.get(this.title).should("have.text", title); return this; diff --git a/src/groups/GroupTable.tsx b/src/groups/GroupTable.tsx index d122146950..9162e52596 100644 --- a/src/groups/GroupTable.tsx +++ b/src/groups/GroupTable.tsx @@ -171,7 +171,9 @@ export const GroupTable = () => { { title: t("common:delete"), onRowClick: async (group: GroupRepresentation) => { - return deleteGroup(group); + await deleteGroup(group); + refresh(); + return true; }, }, ]} @@ -214,7 +216,11 @@ export const GroupTable = () => { delete move.membersLength; try { try { - await adminClient.groups.setOrCreateChild({ id }, move); + if (id) { + await adminClient.groups.setOrCreateChild({ id }, move); + } else { + await adminClient.groups.create(move); + } } catch (error) { if (error.response) { throw error; diff --git a/src/groups/MoveGroupDialog.tsx b/src/groups/MoveGroupDialog.tsx index 0661d7504a..36cf8c526f 100644 --- a/src/groups/MoveGroupDialog.tsx +++ b/src/groups/MoveGroupDialog.tsx @@ -29,7 +29,7 @@ import { ListEmptyState } from "../components/list-empty-state/ListEmptyState"; type MoveGroupDialogProps = { group: GroupRepresentation; onClose: () => void; - onMove: (groupId: string) => void; + onMove: (groupId: string | undefined) => void; }; export const MoveGroupDialog = ({ @@ -73,14 +73,10 @@ export const MoveGroupDialog = ({ return ( onMove(currentGroup().id!)} + onClick={() => onMove(currentGroup()?.id)} > {t("moveHere")} , diff --git a/src/groups/messages.json b/src/groups/messages.json index e540b4e5a0..397d1d52d0 100644 --- a/src/groups/messages.json +++ b/src/groups/messages.json @@ -24,6 +24,7 @@ "path": "Path", "moveTo": "Move to", "moveToGroup": "Move {{group1}} to {{group2}}", + "root": "Root", "moveHere": "Move here", "moveGroupEmpty": "No sub groups", "moveGroupEmptyInstructions": "There are no sub groups, select 'Move here' to move the selected group as a subgroup of this group",