Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/forty-tables-yawn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@leafygreen-ui/mongo-nav': minor
---

Adds project status badge to ProjectNav
5 changes: 5 additions & 0 deletions .changeset/nervous-eyes-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@leafygreen-ui/menu': patch
---

Fixes SubMenuIcon padding to account for change in size of xlarge glyphs
4 changes: 2 additions & 2 deletions packages/menu/src/styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { uiColors } from '@leafygreen-ui/palette';

const indentation = 15;
const leftBar = 5;
export const svgWidth = 32;
export const svgWidth = 24;
export const menuItemPadding = 15;
export const paddingLeft = 60;
export const paddingLeft = 52;

export const menuItemContainerStyle = css`
display: flex;
Expand Down
1 change: 1 addition & 0 deletions packages/mongo-nav/src/MongoNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ function MongoNav({
mode={mode}
activeProduct={activeProduct}
activeNav={activeNav}
admin={admin}
current={data?.currentProject}
data={filteredProjects}
constructProjectURL={constructProjectURL}
Expand Down
1 change: 1 addition & 0 deletions packages/mongo-nav/src/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const dataFixtures = {
planType: 'atlas',
projectId: '020019e',
projectName: 'Test Project',
status: 'ACTIVE',
},
organizations: [
{
Expand Down
76 changes: 19 additions & 57 deletions packages/mongo-nav/src/helpers/Icons.tsx

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions packages/mongo-nav/src/helpers/ProjectStatusBadge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react';
import Badge, { Variant } from '@leafygreen-ui/badge';
import { css } from '@leafygreen-ui/emotion';
import { ProjectStatus } from '../types';

const projectStatusBadgeMargin = css`
margin-right: 20px;
`;

const projectStatusBadgeVariant = {
[ProjectStatus.Active]: Variant.Green,
[ProjectStatus.Closing]: Variant.Yellow,
[ProjectStatus.Closed]: Variant.Red,
[ProjectStatus.Dead]: Variant.Red,
};

interface ProjectStatusBadgeProps {
currentStatus: ProjectStatus;
}

export default function ProjectStatusBadge({
currentStatus,
}: ProjectStatusBadgeProps) {
return (
<Badge
variant={projectStatusBadgeVariant[currentStatus]}
data-testid="project-nav-project-status-badge"
className={projectStatusBadgeMargin}
>
{currentStatus}
</Badge>
);
}
9 changes: 5 additions & 4 deletions packages/mongo-nav/src/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import OrgNavLink from './OrgNavLink';
import InteractionRingWrapper from './InteractionRingWrapper';
import OnPremUserMenu from './OnPremUserMenu';
export { OrgNavLink, InteractionRingWrapper, OnPremUserMenu };
export { default as OrgNavLink } from './OrgNavLink';
export { default as InteractionRingWrapper } from './InteractionRingWrapper';
export { default as OnPremUserMenu } from './OnPremUserMenu';
export { default as ProjectStatusBadge } from './ProjectStatusBadge';
export { RealmIcon, AtlasIcon, ChartsIcon } from './Icons';
29 changes: 11 additions & 18 deletions packages/mongo-nav/src/org-nav/OrgNav.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import Tooltip from '@leafygreen-ui/tooltip';
import Badge from '@leafygreen-ui/badge';
import Badge, { Variant } from '@leafygreen-ui/badge';
import IconButton from '@leafygreen-ui/icon-button';
import Icon from '@leafygreen-ui/icon';
import UserMenu from '../user-menu';
Expand Down Expand Up @@ -78,27 +78,20 @@ const versionStyle = css`
})}
`;

export const Colors = {
Lightgray: 'lightgray',
Green: 'green',
Yellow: 'yellow',
Red: 'red',
} as const;

export type Colors = typeof Colors[keyof typeof Colors];

const paymentStatusMap: Record<Colors, ReadonlyArray<OrgPaymentLabel>> = {
[Colors.Lightgray]: [
const paymentStatusMap: {
[K in Partial<Variant>]?: ReadonlyArray<OrgPaymentLabel>;
} = {
[Variant.LightGray]: [
OrgPaymentLabel.Embargoed,
OrgPaymentLabel.EmbargoConfirmed,
],
[Colors.Green]: [OrgPaymentLabel.Ok],
[Colors.Yellow]: [
[Variant.Green]: [OrgPaymentLabel.Ok],
[Variant.Yellow]: [
OrgPaymentLabel.Warning,
OrgPaymentLabel.Suspended,
OrgPaymentLabel.Closing,
],
[Colors.Red]: [
[Variant.Red]: [
OrgPaymentLabel.Dead,
OrgPaymentLabel.AdminSuspended,
OrgPaymentLabel.Locked,
Expand Down Expand Up @@ -147,13 +140,13 @@ function OrgNav({
const isMobile = viewportWidth < breakpoints.small;
const disabled = activeNav === ActiveNavElement.UserSettings;

let paymentVariant: Colors | undefined;
let key: Colors;
let paymentVariant: Variant | undefined;
let key: Variant;

for (key in paymentStatusMap) {
const paymentStatus = current?.paymentStatus;

if (paymentStatus && paymentStatusMap[key].includes(paymentStatus)) {
if (paymentStatus && paymentStatusMap[key]?.includes(paymentStatus)) {
paymentVariant = key;
}
}
Expand Down
26 changes: 26 additions & 0 deletions packages/mongo-nav/src/project-nav/ProjectNav.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ describe('packages/mongo-nav/src/project-nav', () => {

const setExpectedElements = () => {
const { queryByTestId = () => null } = queries;
expectedElements.projectStatusBadge = queryByTestId(
'project-nav-project-status-badge',
);
expectedElements.atlas = queryByTestId('project-nav-atlas');
expectedElements.cloudManager = queryByTestId('project-nav-cloud-manager');
expectedElements.realm = queryByTestId('project-nav-realm');
Expand Down Expand Up @@ -144,6 +147,21 @@ describe('packages/mongo-nav/src/project-nav', () => {
});
};

const testForProjectStatusBadge = (isVisible: boolean) => {
it(`${
isVisible ? 'displays' : 'does not display'
} the project status badge in the nav`, () => {
const statusBadge = expectedElements.projectStatusBadge;

if (isVisible) {
expect(statusBadge).toBeInTheDocument();
expect((statusBadge as Element).innerHTML).toContain('ACTIVE');
} else {
expect(statusBadge).not.toBeInTheDocument();
}
});
};

describe('when rendered with default props', () => {
beforeEach(async () => {
fetchData = [];
Expand All @@ -158,6 +176,8 @@ describe('packages/mongo-nav/src/project-nav', () => {
testForNavLink(linkName, true),
);

testForProjectStatusBadge(false);

it('atlas tab shows the correct link', () => {
expect(expectedElements!.atlas!.getAttribute('href')).toEqual(
'https://cloud.mongodb.com/v2/020019e#',
Expand Down Expand Up @@ -238,6 +258,12 @@ describe('packages/mongo-nav/src/project-nav', () => {
});
});

describe('when admin is set to true', () => {
beforeEach(() => renderComponent({ admin: true, current: currentProject }));

testForProjectStatusBadge(true);
});

describe('when the date is before MongoDB World', () => {
const testDate = new Date('March 20, 2020 0:00:00');

Expand Down
20 changes: 17 additions & 3 deletions packages/mongo-nav/src/project-nav/ProjectNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ import {
NavElement,
Mode,
MongoNavInterface,
ProjectStatus,
} from '../types';
import { AtlasIcon, RealmIcon, ChartsIcon } from '../helpers/Icons';
import {
AtlasIcon,
RealmIcon,
ChartsIcon,
ProjectStatusBadge,
} from '../helpers';

const {
ProjectNavProjectDropdown,
Expand Down Expand Up @@ -70,7 +76,7 @@ const navContainerStyle = css`
const menuIconButtonStyle = css`
z-index: 1;
${facepaint({
marginRight: ['20px', '14px', '20px'],
marginRight: ['16px', '14px', '16px'],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering what this change is for?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To better align the two badges, as they are in the design spec

})}
`;

Expand Down Expand Up @@ -234,7 +240,7 @@ const secondTabName = displayProductName();

type ProjectNavProps = Pick<
MongoNavInterface,
'activeProduct' | 'activeNav' | 'onProjectChange' | 'mode'
'activeProduct' | 'activeNav' | 'onProjectChange' | 'admin' | 'mode'
> & {
current?: CurrentProjectInterface;
data?: Array<ProjectInterface>;
Expand All @@ -248,6 +254,7 @@ type ProjectNavProps = Pick<
};

export default function ProjectNav({
admin,
current,
data,
constructProjectURL,
Expand Down Expand Up @@ -378,6 +385,13 @@ export default function ProjectNav({
</MenuItem>
</Menu>

{!isMobile &&
admin &&
current?.status &&
Object.values(ProjectStatus).includes(current?.status) && (
<ProjectStatusBadge currentStatus={current.status} />
)}

<ul className={productListStyle}>
<li role="none" className={productTabStyle}>
<a
Expand Down
12 changes: 12 additions & 0 deletions packages/mongo-nav/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,17 @@ type OrgPaymentLabel = typeof OrgPaymentLabel[keyof typeof OrgPaymentLabel];

export { OrgPaymentLabel };

const ProjectStatus = {
Active: 'ACTIVE',
Dead: 'DEAD',
Closing: 'CLOSING',
Closed: 'CLOSED',
};

type ProjectStatus = typeof ProjectStatus[keyof typeof ProjectStatus];

export { ProjectStatus };

export interface AccountInterface {
email: string;
firstName: string;
Expand All @@ -163,6 +174,7 @@ export interface ProjectInterface {
export interface CurrentProjectInterface extends ProjectInterface {
alertsOpen: number;
chartsActivated: boolean;
status?: ProjectStatus;
}

export interface OrganizationInterface {
Expand Down