Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui: add breadcrumbs for teams page (PROJQUAY-6442) #2504

Merged
merged 3 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 37 additions & 0 deletions web/cypress/e2e/breadcrumbs.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,41 @@ describe('Tests for Breadcrumbs', () => {
});
});
});

it('Teams page', () => {
cy.visit('/organization/projectquay/teams/owners?tab=Teamsandmembership');
cy.get('nav[test-id="page-breadcrumbs-list"]').within(() => {
cy.get('li')
.each(($el, index) => {
switch (index) {
case 0:
cy.wrap($el).should('have.text', 'Organization');
cy.wrap($el)
.children('a')
.should('have.attr', 'href', '/organization');
break;
case 1:
cy.wrap($el).should('have.text', 'projectquay');
cy.wrap($el)
.children('a')
.should('have.attr', 'href', '/organization/projectquay');
break;
case 2:
cy.wrap($el).should('have.text', 'owners');
cy.wrap($el).children('a').should('have.class', 'disabled-link');
cy.wrap($el)
.children('a')
.should(
'have.attr',
'href',
'/organization/projectquay/teams/owners',
);
break;
}
})
.then(($lis) => {
expect($lis).to.have.length(3);
});
});
});
});
32 changes: 24 additions & 8 deletions web/src/components/breadcrumb/Breadcrumb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
BreadcrumbItem,
PageBreadcrumb,
} from '@patternfly/react-core';
import {getNavigationRoutes} from 'src/routes/NavigationPath';
import {getNavigationRoutes, NavigationPath} from 'src/routes/NavigationPath';
import {Link, useParams, useLocation} from 'react-router-dom';
import React, {useEffect, useState} from 'react';
import useBreadcrumbs, {
Expand All @@ -13,6 +13,7 @@ import {
parseOrgNameFromUrl,
parseRepoNameFromUrl,
parseTagNameFromUrl,
parseTeamNameFromUrl,
titleCase,
} from 'src/libs/utils';

Expand All @@ -35,7 +36,11 @@ export function QuayBreadcrumb() {
setBreadcrumbItems([]);
};

const fetchBreadcrumb = (existingBreadcrumbs, nextBreadcrumb) => {
const fetchBreadcrumb = (
existingBreadcrumbs,
nextBreadcrumb,
routerBreadcrumb,
) => {
// existingBreadcrumbs is a list of breadcrumbs on the page
// first breadcrumb is either organization or repository
if (existingBreadcrumbs.length == 0) {
Expand All @@ -51,12 +56,23 @@ export function QuayBreadcrumb() {
'organization/' +
nextBreadcrumb['title'];
}
// third breadcrumb is repo name
// third breadcrumb is repo name or team name
// Eg: /organization/<orgname>/<reponame> or /organization/<orgname>/teams/quay?tab=Teamsandmembership
else if (existingBreadcrumbs.length == 2) {
nextBreadcrumb['title'] = parseRepoNameFromUrl(location.pathname);
nextBreadcrumb['pathname'] =
location.pathname.split(nextBreadcrumb['title'])[0] +
nextBreadcrumb['title'];
switch (routerBreadcrumb.match.route.path) {
case NavigationPath.repositoryDetail:
nextBreadcrumb['title'] = parseRepoNameFromUrl(location.pathname);
nextBreadcrumb['pathname'] =
location.pathname.split(nextBreadcrumb['title'])[0] +
nextBreadcrumb['title'];
break;
case NavigationPath.teamMember:
nextBreadcrumb['title'] = parseTeamNameFromUrl(location.pathname);
nextBreadcrumb['pathname'] =
location.pathname.split(nextBreadcrumb['title'])[0] +
nextBreadcrumb['title'];
break;
}
}
// fourth breadcrumb is tag name
else if (existingBreadcrumbs.length == 3) {
Expand Down Expand Up @@ -86,7 +102,7 @@ export function QuayBreadcrumb() {
if (object.key != '') {
newObj['title'] = object.key.replace(/\//, '');
}
newObj = fetchBreadcrumb(result, newObj);
newObj = fetchBreadcrumb(result, newObj, object);
result.push(newObj);
if (newObj['active']) {
break;
Expand Down
5 changes: 5 additions & 0 deletions web/src/routes/NavigationPath.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ export const getNavigationRoutes = () => {
element: <TagDetails />,
breadcrumb: Breadcrumb.manifestDigestBreadcrumb,
},
{
path: domainRoute(currentRoute, NavigationPath.teamMember),
element: <RepositoryDetails />,
breadcrumb: Breadcrumb.teamMemberBreadcrumb,
},
];
return NavigationRoutes;
};