Repository navigation
[PB-6491]:feat/usage advertisements #112
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
Merged
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
5a4e09b
fix: use npm publish instead of yarn publish in GitHub registry workflow
jaaaaavier 9a1ae99
feat: UsageWarningBanner
jaaaaavier 2d36f6b
add to the export files
jaaaaavier a61804e
feat: update sidenav storage component and add stories
jaaaaavier 9248e9f
Update publish-github.yml
jaaaaavier 0c22d9e
add test
jaaaaavier 8d80fdd
Update Sidenav.test.tsx.snap
jaaaaavier 103ae17
Update package.json
jaaaaavier 6323c4a
Merge branch 'master' into feat/usage-warning-banner
jaaaaavier 9aeb41a
update review
jaaaaavier 8f09771
refactor(usageBanner): make storage components presentational
jaaaaavier 039419b
feat: create & use Skeleton component
jaaaaavier 8a4fe17
feat: skeleton
jaaaaavier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/components/feedback/notifications/usageBanner/UsageWarningBanner.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import { CloudWarningIcon, XIcon } from '@phosphor-icons/react'; | ||
| import React, { ReactNode } from 'react'; | ||
| import { Button } from '../../../input/button'; | ||
|
|
||
| export interface UsageWarningBannerProps { | ||
| title: string; | ||
| description: ReactNode; | ||
| usage: string; | ||
| limit: string; | ||
| percentage: number; | ||
| upgradeLabel: string; | ||
| closeButtonLabel: string; | ||
| onUpgradeClick: () => void; | ||
| onCloseButtonClick: () => void; | ||
| barClassName?: string; | ||
| isLoading?: boolean; | ||
| } | ||
|
|
||
| const UsageWarningBanner: React.FC<UsageWarningBannerProps> = ({ | ||
| title, | ||
| description, | ||
| usage, | ||
| limit, | ||
| percentage, | ||
| upgradeLabel, | ||
| closeButtonLabel, | ||
| onUpgradeClick, | ||
| onCloseButtonClick, | ||
| barClassName = 'bg-yellow-60', | ||
| isLoading = false, | ||
| }) => ( | ||
| <div className="flex flex-col w-full px-4 py-3 rounded-xl bg-alert border-alert-dark border h-min"> | ||
| <div className="flex flex-col w-full gap-1"> | ||
| <div className="flex flex-row justify-between items-center"> | ||
| <span className="flex flex-row items-center gap-2"> | ||
| <CloudWarningIcon weight="fill" className="size-5 text-yellow-60" /> | ||
| <p className="text-sm font-semibold text-gray-80">{title}</p> | ||
| </span> | ||
| <button | ||
| type="button" | ||
| aria-label={closeButtonLabel} | ||
| onClick={onCloseButtonClick} | ||
| className="flex items-center justify-center" | ||
| > | ||
| <XIcon className="size-5 text-gray-53 cursor-pointer" /> | ||
| </button> | ||
| </div> | ||
| <div className="text-xs font-medium text-gray-52">{description}</div> | ||
| </div> | ||
| <div className="flex flex-row items-center gap-6 h-10"> | ||
| <div className="flex flex-1 flex-col gap-1"> | ||
| <div className="flex w-full h-1.5 bg-gray-10 rounded-full"> | ||
| <div className={`${barClassName} h-full rounded-full`} style={{ width: `${percentage}%` }} /> | ||
| </div> | ||
| {isLoading ? ( | ||
| <div className="flex flex-row items-center gap-2"> | ||
| <div className="h-3 w-8 rounded-lg bg-gray-5 animate-pulse" /> | ||
| <div className="h-3 w-2 rounded-lg bg-gray-5 animate-pulse" /> | ||
| <div className="h-3 w-8 rounded-lg bg-gray-5 animate-pulse" /> | ||
| </div> | ||
| ) : ( | ||
| <span className="flex flex-row gap-1"> | ||
| <p className="text-gray-60 text-xs">{usage}</p> | ||
| <p className="text-gray-60 text-xs">/</p> | ||
| <p className="text-gray-60 text-xs">{limit}</p> | ||
| </span> | ||
| )} | ||
| </div> | ||
| <Button variant="secondary" size="medium" onClick={onUpgradeClick}> | ||
| {upgradeLabel} | ||
| </Button> | ||
| </div> | ||
| </div> | ||
| ); | ||
|
|
||
| export default UsageWarningBanner; | ||
82 changes: 82 additions & 0 deletions
82
src/components/feedback/notifications/usageBanner/__test__/UsageWarningBanner.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import React from 'react'; | ||
| import { describe, expect, it, vi } from 'vitest'; | ||
| import { UsageWarningBanner, UsageWarningBannerProps } from '../'; | ||
|
|
||
| const renderBanner = (overrides: Partial<UsageWarningBannerProps> = {}) => { | ||
| const props: UsageWarningBannerProps = { | ||
| title: 'Storage almost full', | ||
| description: 'You are running out of space', | ||
| usage: '10 GB', | ||
| limit: '20 GB', | ||
| percentage: 50, | ||
| upgradeLabel: 'Upgrade now', | ||
| closeButtonLabel: 'Close', | ||
| onUpgradeClick: vi.fn(), | ||
| onCloseButtonClick: vi.fn(), | ||
| isLoading: false, | ||
| ...overrides, | ||
| }; | ||
|
|
||
| return { props, ...render(<UsageWarningBanner {...props} />) }; | ||
| }; | ||
|
|
||
| describe('UsageWarningBanner', () => { | ||
| it('colours the progress bar with the style chosen by the consumer', () => { | ||
| const { container } = renderBanner({ barClassName: 'bg-danger' }); | ||
|
|
||
| expect(container.querySelector('.bg-danger')).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('fills the bar in proportion to the storage used', () => { | ||
| const { container } = renderBanner({ barClassName: 'bg-yellow-60', percentage: 73 }); | ||
|
|
||
| const bar = container.querySelector<HTMLElement>('.bg-yellow-60'); | ||
| expect(bar?.style.width).toBe('73%'); | ||
| }); | ||
|
|
||
| it('renders the rich description provided by the consumer', () => { | ||
| renderBanner({ | ||
| description: ( | ||
| <p> | ||
| You have used <strong>90%</strong> of your storage | ||
| </p> | ||
| ), | ||
| }); | ||
|
|
||
| expect(screen.getByText('90%').tagName).toBe('STRONG'); | ||
| }); | ||
|
|
||
| it('shows a loading placeholder instead of the usage figures while data loads', () => { | ||
| const { container } = renderBanner({ isLoading: true }); | ||
|
|
||
| expect(container.querySelectorAll('.animate-pulse').length).toBeGreaterThan(0); | ||
| expect(screen.queryByText('10 GB')).toBeNull(); | ||
| expect(screen.queryByText('20 GB')).toBeNull(); | ||
| }); | ||
|
|
||
| it('shows the used and total storage once data has loaded', () => { | ||
| renderBanner({ isLoading: false }); | ||
|
|
||
| expect(screen.getByText('10 GB')).toBeTruthy(); | ||
| expect(screen.getByText('20 GB')).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('notifies the parent when the user chooses to upgrade', () => { | ||
| const onUpgradeClick = vi.fn(); | ||
| renderBanner({ onUpgradeClick }); | ||
|
|
||
| screen.getByRole('button', { name: 'Upgrade now' }).click(); | ||
|
|
||
| expect(onUpgradeClick).toHaveBeenCalledOnce(); | ||
| }); | ||
|
|
||
| it('notifies the parent when the user dismisses the banner', () => { | ||
| const onCloseButtonClick = vi.fn(); | ||
| renderBanner({ onCloseButtonClick, closeButtonLabel: 'Close' }); | ||
|
|
||
| screen.getByRole('button', { name: 'Close' }).click(); | ||
|
|
||
| expect(onCloseButtonClick).toHaveBeenCalledOnce(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export { default as UsageWarningBanner } from './UsageWarningBanner'; | ||
| export type { UsageWarningBannerProps } from './UsageWarningBanner'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,54 +1,49 @@ | ||
| interface SidenavStorageProps { | ||
| usage: string; | ||
| limit: string; | ||
| percentage: number; | ||
| onUpgradeClick: () => void; | ||
| upgradeLabel?: string; | ||
| isLoading?: boolean; | ||
| } | ||
| import { SidenavStorageProps } from './Sidenav'; | ||
|
|
||
| const SidenavStorage = ({ | ||
| usage, | ||
| limit, | ||
| percentage, | ||
| onUpgradeClick, | ||
| upgradeLabel, | ||
| isLoading = true, | ||
| }: SidenavStorageProps): JSX.Element => { | ||
| return ( | ||
| <div className="flex flex-col w-full gap-2.5 px-2 pb-5"> | ||
| <div className="flex flex-row w-full justify-between"> | ||
| <div className="flex flex-row items-center gap-2"> | ||
| {isLoading ? ( | ||
| <div className="flex flex-row items-center gap-2"> | ||
| <div className="h-3 w-8 rounded-lg bg-gray-5 animate-pulse" /> | ||
| <div className="h-3 w-2 rounded-lg bg-gray-5 animate-pulse" /> | ||
| <div className="h-3 w-8 rounded-lg bg-gray-5 animate-pulse" /> | ||
| </div> | ||
| ) : ( | ||
| <> | ||
| <p className="text-gray-60 text-sm font-semibold">{usage}</p> | ||
| <p className="text-gray-60 text-sm">/</p> | ||
| <p className="text-gray-60 text-sm">{limit}</p> | ||
| </> | ||
| )} | ||
| </div> | ||
| {upgradeLabel && ( | ||
| <button className="text-primary text-sm hover:text-primary-dark font-semibold" onClick={onUpgradeClick}> | ||
| {upgradeLabel} | ||
| </button> | ||
| isLoading = false, | ||
| barClassName = 'bg-gray-60', | ||
| containerClassName, | ||
| advertisement, | ||
| }: SidenavStorageProps): JSX.Element => ( | ||
| <div className={`flex flex-col w-full gap-2.5 p-3${containerClassName ? ` ${containerClassName}` : ''}`}> | ||
| {advertisement} | ||
| <div className="flex flex-row w-full justify-between"> | ||
| <div className="flex flex-row items-center gap-2"> | ||
| {isLoading ? ( | ||
| <div className="flex flex-row items-center gap-2"> | ||
| <div className="h-3 w-8 rounded-lg bg-gray-5 animate-pulse" /> | ||
| <div className="h-3 w-2 rounded-lg bg-gray-5 animate-pulse" /> | ||
| <div className="h-3 w-8 rounded-lg bg-gray-5 animate-pulse" /> | ||
| </div> | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use a Skeleton component |
||
| ) : ( | ||
| <> | ||
| <p className="text-gray-60 text-sm font-semibold">{usage}</p> | ||
| <p className="text-gray-60 text-sm">/</p> | ||
| <p className="text-gray-60 text-sm">{limit}</p> | ||
| </> | ||
| )} | ||
| </div> | ||
| <div className="flex w-full h-1.5 bg-gray-10 rounded-full"> | ||
| <div | ||
| className="bg-gray-60 rounded-full" | ||
| style={{ | ||
| width: `${percentage}%`, | ||
| }} | ||
| /> | ||
| </div> | ||
| {upgradeLabel && ( | ||
| <button className="text-primary text-sm hover:text-primary-dark font-semibold" onClick={onUpgradeClick}> | ||
| {upgradeLabel} | ||
| </button> | ||
| )} | ||
| </div> | ||
| <div className="flex w-full h-1.5 bg-gray-10 rounded-full"> | ||
| <div | ||
| className={`${barClassName} rounded-full`} | ||
| style={{ | ||
| width: `${percentage}%`, | ||
| }} | ||
| /> | ||
| </div> | ||
| ); | ||
| }; | ||
| </div> | ||
| ); | ||
|
|
||
| export default SidenavStorage; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extract this to a Skeleton component