small fix that adds collapse icon based on count (#29996)

* small fix that adds collapse icon based on count

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>

* fixed test

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>

---------

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
This commit is contained in:
Erik Jan de Wit 2024-05-30 13:46:21 +02:00 committed by GitHub
parent 5949fd43d0
commit 1135f4f05f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 49 additions and 42 deletions

View file

@ -50,7 +50,13 @@ describe("Group test", () => {
); );
}); });
after(() => adminClient.deleteGroups()); after(
async () =>
await Promise.all([
adminClient.deleteGroups(),
...range(5).map((index) => adminClient.deleteUser(username + index)),
]),
);
beforeEach(() => { beforeEach(() => {
loginPage.logIn(); loginPage.logIn();
@ -154,7 +160,6 @@ describe("Group test", () => {
createdGroups[index % 3].id, createdGroups[index % 3].id,
); );
}), }),
adminClient.createUser({ username: "new", enabled: true }),
]); ]);
}); });
@ -198,13 +203,6 @@ describe("Group test", () => {
.goToGroupChildGroupsTab(predefinedGroups[0]) .goToGroupChildGroupsTab(predefinedGroups[0])
.assertGroupItemExist(predefinedGroups[1], true); .assertGroupItemExist(predefinedGroups[1], true);
}); });
it("Navigate to sub-group details", () => {
searchGroupPage
.searchGlobal(predefinedGroups[1])
.goToGroupChildGroupsFromTree(predefinedGroups[1])
.assertGroupItemExist(predefinedGroups[2], true);
});
}); });
it("Rename group", () => { it("Rename group", () => {
@ -321,9 +319,12 @@ describe("Group test", () => {
); );
}), }),
adminClient.createGroup(emptyGroup), adminClient.createGroup(emptyGroup),
adminClient.createUser({ username: "new", enabled: true }),
]); ]);
}); });
after(() => adminClient.deleteUser("new"));
beforeEach(() => { beforeEach(() => {
groupPage.goToGroupChildGroupsTab(predefinedGroups[0]); groupPage.goToGroupChildGroupsTab(predefinedGroups[0]);
childGroupsTab.goToMembersTab(); childGroupsTab.goToMembersTab();

View file

@ -1,10 +1,8 @@
import SidebarPage from "../../SidebarPage";
import GroupPage from "./GroupPage"; import GroupPage from "./GroupPage";
export class SearchGroupPage extends GroupPage { export class SearchGroupPage extends GroupPage {
#groupSearchField = "group-search"; #groupSearchField = "group-search";
#searchButton = "[data-testid='group-search'] button[type='submit']"; #searchButton = "[data-testid='group-search'] button[type='submit']";
#sidebarPage = new SidebarPage();
public searchGroup(groupName: string) { public searchGroup(groupName: string) {
this.typeSearchInput(groupName); this.typeSearchInput(groupName);
@ -18,12 +16,6 @@ export class SearchGroupPage extends GroupPage {
return this; return this;
} }
public goToGroupChildGroupsFromTree(item: string) {
cy.get(".pf-v5-c-tree-view__content").contains(item).click();
this.#sidebarPage.waitForPageLoad();
return this;
}
public typeSearchInput(value: string) { public typeSearchInput(value: string) {
cy.findByTestId(this.#groupSearchField).type(value); cy.findByTestId(this.#groupSearchField).type(value);
return this; return this;

View file

@ -5,6 +5,7 @@ import {
Checkbox, Checkbox,
InputGroup, InputGroup,
InputGroupItem, InputGroupItem,
Spinner,
Tooltip, Tooltip,
TreeView, TreeView,
TreeViewDataItem, TreeViewDataItem,
@ -190,10 +191,17 @@ export const GroupTree = ({
</Tooltip> </Tooltip>
), ),
access: group.access || {}, access: group.access || {},
children: children: group.subGroupCount
group.subGroups && group.subGroups.length > 0 ? [
? group.subGroups.map((g) => mapGroup(g, refresh)) {
: undefined, name: (
<>
<Spinner size="sm" /> {t("spinnerLoading")}
</>
),
},
]
: undefined,
action: (hasAccess("manage-users") || group.access?.manage) && ( action: (hasAccess("manage-users") || group.access?.manage) && (
<GroupTreeContextMenu group={group} refresh={refresh} /> <GroupTreeContextMenu group={group} refresh={refresh} />
), ),
@ -296,6 +304,29 @@ export const GroupTree = ({
return path; return path;
}; };
const nav = (item: TreeViewDataItem, data: ExtendedTreeViewDataItem[]) => {
if (item.id === "next") return;
setActiveItem(item);
const path = findGroup(data, item.id!, []);
if (!subGroups.every(({ id }) => path.find((t) => t.id === id))) clear();
if (
canViewDetails ||
path.at(-1)?.access?.view ||
subGroups.at(-1)?.access?.view
) {
navigate(
toGroups({
realm,
id: path.map((g) => g.id).join("/"),
}),
);
} else {
addAlert(t("noViewRights"), AlertVariant.warning);
navigate(toGroups({ realm }));
}
};
return data ? ( return data ? (
<PaginatingTableToolbar <PaginatingTableToolbar
count={count} count={count}
@ -337,28 +368,11 @@ export const GroupTree = ({
hasGuides hasGuides
hasSelectableNodes hasSelectableNodes
className="keycloak_groups_treeview" className="keycloak_groups_treeview"
onExpand={(_, item) => {
nav(item, data);
}}
onSelect={(_, item) => { onSelect={(_, item) => {
if (item.id === "next") return; nav(item, data);
setActiveItem(item);
const path = findGroup(data, item.id!, []);
if (!subGroups.every(({ id }) => path.find((t) => t.id === id)))
clear();
if (
canViewDetails ||
path.at(-1)?.access?.view ||
subGroups.at(-1)?.access?.view
) {
navigate(
toGroups({
realm,
id: path.map((g) => g.id).join("/"),
}),
);
} else {
addAlert(t("noViewRights"), AlertVariant.warning);
navigate(toGroups({ realm }));
}
}} }}
/> />
)} )}