Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
CR
Browse files Browse the repository at this point in the history
  • Loading branch information
SupaJoon committed Sep 14, 2023
1 parent 0a02503 commit fa9c488
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
2 changes: 2 additions & 0 deletions cypress/integration/nav_bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,13 @@ describe("Nav Bar", () => {
};
cy.overwriteGQL("User", userData);
cy.visit(SPRUCE_URLS.version);
cy.dataCy("user-dropdown-link").click();
cy.dataCy("admin-link").should("not.exist");
});

it("Should show Admin button to admins", () => {
cy.visit(SPRUCE_URLS.version);
cy.dataCy("user-dropdown-link").click();
cy.dataCy("admin-link")
.should("be.visible")
.should("have.attr", "href", LEGACY_URLS.admin);
Expand Down
1 change: 1 addition & 0 deletions src/analytics/navbar/useNavbarAnalytics.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useAnalyticsRoot } from "analytics/useAnalyticsRoot";

type Action =
| { name: "Click Admin Link" }
| { name: "Click Legacy UI Link" }
| { name: "Click Logo Link" }
| { name: "Click Waterfall Link" }
Expand Down
2 changes: 1 addition & 1 deletion src/components/Header/NavDropdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const NavDropdownMenuIcon: React.FC<{ open: boolean }> = ({ open }) => (
<Icon glyph={open ? "CaretUp" : "CaretDown"} role="presentation" />
);

interface MenuItemType {
export interface MenuItemType {
"data-cy"?: string;
text: string;
href?: string;
Expand Down
9 changes: 2 additions & 7 deletions src/components/Header/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Link, useParams } from "react-router-dom";
import { useNavbarAnalytics } from "analytics";
import Icon from "components/Icon";
import { CURRENT_PROJECT } from "constants/cookies";
import { adminSettingsURL, wikiUrl } from "constants/externalResources";
import { wikiUrl } from "constants/externalResources";
import { getCommitsRoute, getUserPatchesRoute, routes } from "constants/routes";
import { size } from "constants/tokens";
import { useAuthStateContext } from "context/auth";
Expand All @@ -27,7 +27,7 @@ export const Navbar: React.FC = () => {

const { data: userData } = useQuery<UserQuery>(GET_USER);
const { user } = userData || {};
const { permissions, userId } = user || {};
const { userId } = user || {};

const { projectIdentifier: projectFromUrl } = useParams<{
projectIdentifier: string;
Expand Down Expand Up @@ -82,11 +82,6 @@ export const Navbar: React.FC = () => {
>
My Hosts
</PrimaryLink>
{permissions?.canEditAdminSettings && (
<PrimaryLink data-cy="admin-link" to={adminSettingsURL}>
Admin
</PrimaryLink>
)}
<AuxiliaryDropdown projectIdentifier={projectIdentifier} />
</NavActionContainer>
<NavActionContainer>
Expand Down
16 changes: 12 additions & 4 deletions src/components/Header/UserDropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { useQuery } from "@apollo/client";
import { useNavbarAnalytics } from "analytics";
import { adminSettingsURL } from "constants/externalResources";
import { PreferencesTabRoutes, getPreferencesRoute } from "constants/routes";
import { useAuthDispatchContext } from "context/auth";
import { UserQuery } from "gql/generated/types";
import { GET_USER } from "gql/queries";
import { NavDropdown } from "./NavDropdown";
import { MenuItemType, NavDropdown } from "./NavDropdown";

export const UserDropdown = () => {
const { data } = useQuery<UserQuery>(GET_USER);
const { user } = data || {};
const { displayName } = user || {};
const { displayName, permissions } = user || {};

const { logoutAndRedirect } = useAuthDispatchContext();
const { sendEvent } = useNavbarAnalytics();

const menuItems = [
const menuItems: MenuItemType[] = [
{
text: "Preferences",
to: getPreferencesRoute(PreferencesTabRoutes.Profile),
Expand All @@ -31,7 +32,14 @@ export const UserDropdown = () => {
onClick: () => logoutAndRedirect(),
},
];

if (permissions?.canEditAdminSettings) {
menuItems.splice(1, 0, {
"data-cy": "admin-link",
text: "Admin",
href: adminSettingsURL,
onClick: () => sendEvent({ name: "Click Admin Link" }),
});
}
return (
<NavDropdown
dataCy="user-dropdown-link"
Expand Down

0 comments on commit fa9c488

Please sign in to comment.