-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tag-cluster-type): add component (#455)
- Loading branch information
1 parent
3234b46
commit 72cb4eb
Showing
6 changed files
with
124 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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 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
48 changes: 48 additions & 0 deletions
48
libs/shared/ui/src/lib/components/tag-cluster-type/tag-cluster-type.spec.tsx
This file contains 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,48 @@ | ||
import { render } from '__tests__/utils/setup-jest' | ||
import { CloudProviderEnum, KubernetesEnum } from 'qovery-typescript-axios' | ||
import TagClusterType, { TagClusterTypeProps } from './tag-cluster-type' | ||
|
||
describe('TagClusterType', () => { | ||
let props: TagClusterTypeProps = { | ||
cloudProvider: CloudProviderEnum.AWS, | ||
kubernetes: KubernetesEnum.MANAGED, | ||
} | ||
|
||
it('should render successfully', () => { | ||
const { baseElement } = render(<TagClusterType {...props} />) | ||
expect(baseElement).toBeTruthy() | ||
}) | ||
|
||
it('should render content for AWS and Managed', () => { | ||
const { baseElement } = render(<TagClusterType {...props} />) | ||
expect(baseElement.textContent).toBe('Managed (EKS)') | ||
}) | ||
|
||
it('should render content for AWS and K3S', () => { | ||
props = { | ||
cloudProvider: CloudProviderEnum.AWS, | ||
kubernetes: KubernetesEnum.K3_S, | ||
} | ||
|
||
const { baseElement } = render(<TagClusterType {...props} />) | ||
expect(baseElement.textContent).toBe('EC2 (K3S)') | ||
}) | ||
|
||
it('should render content for Scaleway', () => { | ||
props = { | ||
cloudProvider: CloudProviderEnum.SCW, | ||
} | ||
|
||
const { baseElement } = render(<TagClusterType {...props} />) | ||
expect(baseElement.textContent).toBe('Managed (Kapsule)') | ||
}) | ||
|
||
it('should render content for DO', () => { | ||
props = { | ||
cloudProvider: CloudProviderEnum.DO, | ||
} | ||
|
||
const { baseElement } = render(<TagClusterType {...props} />) | ||
expect(baseElement.textContent).toBe('Managed (DOKS)') | ||
}) | ||
}) |
18 changes: 18 additions & 0 deletions
18
libs/shared/ui/src/lib/components/tag-cluster-type/tag-cluster-type.stories.tsx
This file contains 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,18 @@ | ||
import { select } from '@storybook/addon-knobs' | ||
import { Meta, Story } from '@storybook/react' | ||
import { CloudProviderEnum, KubernetesEnum } from 'qovery-typescript-axios' | ||
import { TagClusterType, TagClusterTypeProps } from './tag-cluster-type' | ||
|
||
export default { | ||
component: TagClusterType, | ||
title: 'Tag/TagClusterType', | ||
} as Meta | ||
|
||
const Template: Story<TagClusterTypeProps> = (args) => <TagClusterType {...args} /> | ||
|
||
export const Primary = Template.bind({}) | ||
|
||
Primary.args = { | ||
cloud_provider: select('Cloud Provider', CloudProviderEnum, CloudProviderEnum.AWS), | ||
kubernetes: select('Kubernetes', KubernetesEnum, KubernetesEnum.MANAGED), | ||
} |
42 changes: 42 additions & 0 deletions
42
libs/shared/ui/src/lib/components/tag-cluster-type/tag-cluster-type.tsx
This file contains 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,42 @@ | ||
import { CloudProviderEnum, KubernetesEnum } from 'qovery-typescript-axios' | ||
import { Tag, TagSize } from '../tag/tag' | ||
|
||
export interface TagClusterTypeProps { | ||
cloudProvider?: CloudProviderEnum | ||
kubernetes?: KubernetesEnum | ||
size?: TagSize | ||
className?: string | ||
} | ||
|
||
export function TagClusterType(props: TagClusterTypeProps) { | ||
const { cloudProvider, kubernetes, size = TagSize.NORMAL, className = '' } = props | ||
|
||
const content = (cloudProvider?: CloudProviderEnum, kubernetes?: KubernetesEnum): string => { | ||
// AWS | ||
if (kubernetes === KubernetesEnum.K3_S && cloudProvider === CloudProviderEnum.AWS) { | ||
return 'EC2 (K3S)' | ||
} else if (kubernetes === KubernetesEnum.MANAGED && cloudProvider === CloudProviderEnum.AWS) { | ||
return 'Managed (EKS)' | ||
} | ||
|
||
// Digital Ocean | ||
if (cloudProvider === CloudProviderEnum.DO) { | ||
return 'Managed (DOKS)' | ||
} | ||
|
||
// Scaleway | ||
if (cloudProvider === CloudProviderEnum.SCW) { | ||
return 'Managed (Kapsule)' | ||
} | ||
|
||
return '' | ||
} | ||
|
||
return ( | ||
<Tag size={size} className={`border truncate ${className}`}> | ||
{content(cloudProvider, kubernetes)} | ||
</Tag> | ||
) | ||
} | ||
|
||
export default TagClusterType |