Skip to content

Commit

Permalink
Feature/app components (#564)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sodik authored Sep 6, 2024
1 parent 32c7e8a commit fdd9d27
Show file tree
Hide file tree
Showing 109 changed files with 6,002 additions and 4,064 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.21.4",
"@storybook/source-loader": "^6.4.9",
"@types/jest": "^29.5.1",
"@types/jest": "^29.5.12",
"@typescript-eslint/eslint-plugin": "^5.7.0",
"@typescript-eslint/parser": "^5.7.0",
"babel-jest": "^29.5.0",
"babel-jest": "^29.7.0",
"chromatic": "^6.2.3",
"css-loader": "^6.5.1",
"doctoc": "^2.1.0",
Expand All @@ -24,8 +24,8 @@
"eslint-plugin-react-hooks": "^4.3.0",
"husky": "^7.0.4",
"identity-obj-proxy": "^3.0.0",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"lerna": "^6.6.1",
"lint-staged": "^13.1.2",
"patch-package": "^6.5.1",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
120 changes: 120 additions & 0 deletions packages/ui/__stories__/AppHeader.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import React, { useState } from 'react'

import { Button } from '../src/Button'
import { AppHeader as AppHeaderComponent } from '../src/AppHeader'

export default {
title: 'App/Header',
component: AppHeaderComponent,
}

export const Default = () => {
const [cluster, setCluster] = useState<string | null>(null)

return (
<AppHeaderComponent
name="Management Center"
logoProps={{
LinkComponent: ({ children, className }) => <span className={className}>{children}</span>,
}}
clusterSelectProps={{
clusterName: cluster,
clusterNames: ['Cluster-1', 'Cluster-2'],
clusterVersions: { 'Cluster-1': '5.5', 'Cluster-2': '6.0', 'Cluster-3': '3.1.2' },
onChange: setCluster,
}}
menuContent={() => (
<>
<span>Item</span>
</>
)}
/>
)
}

export const WithBadge = () => {
const [cluster, setCluster] = useState<string | null>(null)

return (
<AppHeaderComponent
name="Management Center"
clusterSelectProps={{
clusterName: cluster,
clusterNames: ['Cluster-1', 'Cluster-2'],
clusterVersions: { 'Cluster-1': '5.5', 'Cluster-2': '6.0', 'Cluster-3': '3.1.2' },
onChange: setCluster,
}}
menuContent={() => (
<>
<Button color="light" variant="text">
Item 1
</Button>
</>
)}
environment="production"
logoProps={{
LinkComponent: ({ children, className }) => <span className={className}>{children}</span>,
}}
/>
)
}

export const WithoutSelectCluster = () => (
<AppHeaderComponent
name="Management Center"
logoProps={{
LinkComponent: ({ children, className }) => <span className={className}>{children}</span>,
}}
menuContent={() => (
<>
<Button color="light" variant="text">
Item 1
</Button>
</>
)}
/>
)

export const DisabledSelectCluster = () => {
const [cluster, setCluster] = useState<string | null>(null)

return (
<AppHeaderComponent
name="Management Center"
clusterSelectProps={{
clusterNames: [],
clusterName: cluster,
onChange: setCluster,
}}
logoProps={{
LinkComponent: ({ children, className }) => <span className={className}>{children}</span>,
}}
menuContent={() => (
<>
<Button color="light" variant="text">
Item 1
</Button>
</>
)}
/>
)
}

export const WithoutMenu = () => {
const [cluster, setCluster] = useState<string | null>(null)

return (
<AppHeaderComponent
name="Management Center"
clusterSelectProps={{
clusterName: cluster,
clusterNames: ['Cluster-1', 'Cluster-2'],
clusterVersions: { 'Cluster-1': '5.5', 'Cluster-2': '6.0', 'Cluster-3': '3.1.2' },
onChange: setCluster,
}}
logoProps={{
LinkComponent: ({ children, className }) => <span className={className}>{children}</span>,
}}
/>
)
}
63 changes: 63 additions & 0 deletions packages/ui/__stories__/AppSidebar.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React from 'react'
import { Story } from '@storybook/react'
import { Disc, HardDrive, Wifi, Activity, Droplet, Airplay } from 'react-feather'

import {
AppSidebar,
AppSidebarSection,
AppSidebarMenuItemCounter,
AppSidebarItem,
AppSidebarProps,
AppSidebarFavorites,
} from '../src/AppSidebar'

export default {
title: 'App/Sidebar',
component: AppSidebar,
}

const Template: Story<Partial<AppSidebarProps>> = (props) => (
<AppSidebar footer={<span>24/08/14 01:49 PM Ver. 5.5.0</span>} {...props}>
<AppSidebarFavorites>{({ items }) => items.map((item) => <AppSidebarItem key={item} id={item} title={item} />)}</AppSidebarFavorites>
<AppSidebarSection active id="maps" title="Maps wan replication" ariaLabel="maps" icon={Disc}>
<AppSidebarItem id="1" title="Test" active wrapper={({ children }) => <a href="/">{children}</a>} />
<AppSidebarItem title="Wan healthcheck replication" />
<AppSidebarItem title="Test 2" />
</AppSidebarSection>
<AppSidebarSection active={false} id="cluster" title="Cluster" ariaLabel="cluster" icon={HardDrive}>
<AppSidebarItem id="2" title="Cluster-1" adornment={<AppSidebarMenuItemCounter>13</AppSidebarMenuItemCounter>} />
<AppSidebarItem title="Cluster-2" adornment={<AppSidebarMenuItemCounter>3</AppSidebarMenuItemCounter>} />
</AppSidebarSection>
<AppSidebarSection active={false} id="members" title="Memebers" ariaLabel="memebers" icon={Wifi}>
<AppSidebarItem title="Cluster-1" adornment={<AppSidebarMenuItemCounter>13</AppSidebarMenuItemCounter>} />
<AppSidebarItem title="Cluster-2" adornment={<AppSidebarMenuItemCounter>3</AppSidebarMenuItemCounter>} />
</AppSidebarSection>
<AppSidebarSection active={false} id="storage" title="Storage" ariaLabel="storage" icon={Activity}>
<AppSidebarItem title="Cluster-1" adornment={<AppSidebarMenuItemCounter>13</AppSidebarMenuItemCounter>} />
</AppSidebarSection>
<AppSidebarSection title="TOOLS">
<AppSidebarItem title="SQL" icon={Airplay} iconAriaLabel="SQL" onClick={console.log} />
<AppSidebarItem title="Flow" color="authPrimary" icon={Droplet} iconAriaLabel="Flow" available={false} onClick={console.log} />
</AppSidebarSection>
</AppSidebar>
)

export const Default = () => <Template open />

export const WithScroll = () => {
return (
<div style={{ height: 200, overflow: 'hidden' }}>
<Template open />
</div>
)
}

export const Collapsed = () => <Template open={false} />

export const CollapsedWithScroll = () => {
return (
<div style={{ height: 200, overflow: 'hidden' }}>
<Template open={false} />
</div>
)
}
17 changes: 15 additions & 2 deletions packages/ui/__stories__/Button.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { ReactNode } from 'react'
import { ComponentMeta, ComponentStory } from '@storybook/react'
import { Info, ChevronDown } from 'react-feather'
import cn from 'classnames'
Expand All @@ -22,6 +22,10 @@ export default {
},
} as ComponentMeta<typeof Button>

const DarkBackground = ({ children }: { children: ReactNode }) => (
<span style={{ display: 'inline-block', background: '#000', padding: 4 }}>{children}</span>
)

const Template: ComponentStory<typeof Button> = ({ className, ...args }) => {
const props = {
...args,
Expand Down Expand Up @@ -68,6 +72,15 @@ const Template: ComponentStory<typeof Button> = ({ className, ...args }) => {
<Button {...props} color="authSecondary" disabled size="medium" />
<Button {...props} variant="outlined" color="authSecondary" size="medium" />
<Button {...props} variant="text" color="authSecondary" size="medium" />
<DarkBackground>
<Button {...props} color="light" />
</DarkBackground>
<DarkBackground>
<Button {...props} variant="outlined" color="light" />
</DarkBackground>
<DarkBackground>
<Button {...props} variant="text" color="light" />
</DarkBackground>
</div>
</div>
)
Expand All @@ -87,7 +100,7 @@ Focused.args = {

export const Active = Template.bind({})
Active.args = {
className: styles.active,
active: true,
}

export const Disabled = Template.bind({})
Expand Down
9 changes: 8 additions & 1 deletion packages/ui/__stories__/Tooltip.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,21 @@ export default {
} as Meta<TooltipProps>

const Template: Story<TooltipProps> = (args) => (
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', height: 320 }}>
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 380, height: 320 }}>
<Tooltip {...args}>
{(ref) => (
<Button ref={ref} aria-labelledby={args.id} style={{ height: 80 }}>
This button has a tooltip
</Button>
)}
</Tooltip>
<Tooltip color="dark" {...args}>
{(ref) => (
<Button ref={ref} aria-labelledby={args.id} style={{ height: 80 }}>
This button has a tooltip
</Button>
)}
</Tooltip>
</div>
)

Expand Down
51 changes: 51 additions & 0 deletions packages/ui/__tests__/AppHeader/AppHeader.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React, { ComponentType } from 'react'
import { act } from 'react-dom/test-utils'
import { userEvent } from '@testing-library/user-event'
import { screen, render } from '@testing-library/react'
import { DataTestProp } from '@hazelcast/helpers'

import { AppHeader } from '../../src/AppHeader'

const LinkComponent: ComponentType<DataTestProp> = ({ children, 'data-test': dataTest }) => <div data-test={dataTest}>{children}</div>

describe('AppHeader', () => {
it('renders basic version', () => {
render(<AppHeader name="Test App" logoProps={{ LinkComponent }} />)

expect(screen.queryByText('Test App')).toBeInTheDocument()
expect(screen.queryByTestId('logo-link')).toBeInTheDocument()
expect(screen.queryByTestId('environment-badge')).not.toBeInTheDocument()
expect(screen.queryByTestId('select-cluster')).not.toBeInTheDocument()
expect(screen.queryByTestId('app-header-menu-toggle')).not.toBeInTheDocument()
})

it('renders menu content', async () => {
render(<AppHeader name="Test App" logoProps={{ LinkComponent }} menuContent={() => <span>Menu content</span>} />)

expect(screen.queryByTestId('app-header-menu-toggle')).toBeInTheDocument()
expect(screen.queryByText('Menu content')).not.toBeInTheDocument()

await act(async () => {
await userEvent.click(screen.getByTestId('app-header-menu-toggle'))
})

expect(screen.queryByText('Menu content')).toBeInTheDocument()
})

it('renders select cluster', () => {
render(
<AppHeader
name="Test App"
logoProps={{ LinkComponent }}
clusterSelectProps={{
clusterName: 'Cluster-1',
clusterNames: ['Cluster-1', 'Cluster-2'],
clusterVersions: { 'Cluster-1': '5.5', 'Cluster-2': '6.0', 'Cluster-3': '3.1.2' },
onChange: jest.fn(),
}}
/>,
)

expect(screen.queryByTestId('select-cluster')).toBeInTheDocument()
})
})
Loading

0 comments on commit fdd9d27

Please sign in to comment.