Skip to content

Commit b5b759c

Browse files
author
Mattia Franchetto
authored
Format status indicators according to guidelines (#167)
* Remove unused children from stack events statuses * Add formatStatus function * Use formatStatus in every status component * Add status indicator to custom images * Align clusters test
1 parent 4a71b32 commit b5b759c

File tree

5 files changed

+74
-16
lines changed

5 files changed

+74
-16
lines changed

frontend/src/components/Status.tsx

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ import {
1616
ComputeFleetStatus,
1717
} from '../types/clusters'
1818
import {InstanceState, Instance, EC2Instance} from '../types/instances'
19+
import {ImageBuildStatus} from '../types/images'
1920
import {StackEvent} from '../types/stackevents'
2021
import {JobStateCode} from '../types/jobs'
22+
import capitalize from 'lodash/capitalize'
2123
import React from 'react'
2224
import {
2325
StatusIndicator,
@@ -26,6 +28,10 @@ import {
2628

2729
export type StatusMap = Record<string, StatusIndicatorProps.Type>
2830

31+
export function formatStatus(status?: string): string {
32+
return capitalize(status?.replaceAll(/[_-]/g, ' '))
33+
}
34+
2935
function ClusterStatusIndicator({
3036
cluster,
3137
}: {
@@ -47,7 +53,7 @@ function ClusterStatusIndicator({
4753

4854
return (
4955
<StatusIndicator type={statusMap[clusterStatus]}>
50-
{clusterStatus.replaceAll('_', ' ')}
56+
{formatStatus(clusterStatus)}
5157
</StatusIndicator>
5258
)
5359
}
@@ -82,7 +88,7 @@ function JobStatusIndicator({status}: {status: JobStateCode}) {
8288

8389
return (
8490
<StatusIndicator type={statusMap[status]}>
85-
{status.replaceAll('_', ' ')}
91+
{formatStatus(status)}
8692
</StatusIndicator>
8793
)
8894
}
@@ -103,7 +109,7 @@ function ComputeFleetStatusIndicator({status}: {status: ComputeFleetStatus}) {
103109

104110
return (
105111
<StatusIndicator type={statusMap[status]}>
106-
{status.replaceAll('_', ' ')}
112+
{formatStatus(status)}
107113
</StatusIndicator>
108114
)
109115
}
@@ -124,18 +130,12 @@ function InstanceStatusIndicator({
124130

125131
return (
126132
<StatusIndicator type={statusMap[instance.state]}>
127-
{instance.state.replaceAll('-', ' ').toUpperCase()}
133+
{formatStatus(instance.state)}
128134
</StatusIndicator>
129135
)
130136
}
131137

132-
function StackEventStatusIndicator({
133-
stackEvent,
134-
children,
135-
}: {
136-
stackEvent: StackEvent
137-
children?: React.ReactNode
138-
}) {
138+
function StackEventStatusIndicator({stackEvent}: {stackEvent: StackEvent}) {
139139
const statusMap: Record<
140140
CloudFormationResourceStatus,
141141
StatusIndicatorProps.Type
@@ -159,8 +159,28 @@ function StackEventStatusIndicator({
159159
}
160160
return (
161161
<StatusIndicator type={statusMap[stackEvent.resourceStatus]}>
162-
{stackEvent.resourceStatus.replaceAll('_', ' ')}
163-
{children}
162+
{formatStatus(stackEvent.resourceStatus)}
163+
</StatusIndicator>
164+
)
165+
}
166+
167+
function CustomImageStatusIndicator({
168+
buildStatus,
169+
}: {
170+
buildStatus: ImageBuildStatus
171+
}) {
172+
const statusMap: Record<ImageBuildStatus, StatusIndicatorProps.Type> = {
173+
BUILD_COMPLETE: 'success',
174+
BUILD_FAILED: 'error',
175+
BUILD_IN_PROGRESS: 'in-progress',
176+
DELETE_COMPLETE: 'success',
177+
DELETE_IN_PROGRESS: 'in-progress',
178+
DELETE_FAILED: 'error',
179+
}
180+
181+
return (
182+
<StatusIndicator type={statusMap[buildStatus]}>
183+
{formatStatus(buildStatus)}
164184
</StatusIndicator>
165185
)
166186
}
@@ -171,4 +191,5 @@ export {
171191
InstanceStatusIndicator,
172192
JobStatusIndicator,
173193
StackEventStatusIndicator,
194+
CustomImageStatusIndicator,
174195
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import {formatStatus} from '../Status'
2+
3+
describe('Given a resource status', () => {
4+
describe('when the status has a dash', () => {
5+
it('should be removed', () => {
6+
expect(formatStatus('shutting-down')).toBe('Shutting down')
7+
})
8+
})
9+
10+
describe('when the status has an underscore', () => {
11+
it('should be removed', () => {
12+
expect(formatStatus('shutting_down')).toBe('Shutting down')
13+
})
14+
})
15+
16+
describe('when the status is lowercase', () => {
17+
it('should be capitalized', () => {
18+
expect(formatStatus('created')).toBe('Created')
19+
})
20+
})
21+
22+
describe('when the status is uppercase', () => {
23+
it('should be capitalized', () => {
24+
expect(formatStatus('CREATE_COMPLETE')).toBe('Create complete')
25+
})
26+
})
27+
28+
describe('when given an undefined string', () => {
29+
it('should return an empty string', () => {
30+
expect(formatStatus()).toBe('')
31+
})
32+
})
33+
})

frontend/src/old-pages/Clusters/__tests__/Clusters.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ describe('given a component to show the clusters list', () => {
6868
)
6969

7070
expect(getByText('test-cluster')).toBeTruthy()
71-
expect(getByText('CREATE COMPLETE')).toBeTruthy()
71+
expect(getByText('Create complete')).toBeTruthy()
7272
expect(getByText('3.1.4')).toBeTruthy()
7373
})
7474

frontend/src/old-pages/Images/CustomImages/CustomImageDetails.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import EmptyState from '../../../components/EmptyState'
3939
import {truncate} from 'lodash'
4040
import {ReadonlyConfigView} from '../../../components/ConfigView'
4141
import {extendCollectionsOptions} from '../../../shared/extendCollectionsOptions'
42+
import {CustomImageStatusIndicator} from '../../../components/Status'
4243

4344
const customImagesPath = ['app', 'customImages']
4445

@@ -135,7 +136,7 @@ function CustomImageProperties() {
135136
<ValueWithLabel
136137
label={t('customImages.imageDetails.properties.buildStatus')}
137138
>
138-
{image.imageBuildStatus}
139+
<CustomImageStatusIndicator buildStatus={image.imageBuildStatus} />
139140
</ValueWithLabel>
140141
<ValueWithLabel
141142
label={t('customImages.imageDetails.properties.amiId.label')}

frontend/src/old-pages/Images/CustomImages/CustomImages.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {TFunction, Trans, useTranslation} from 'react-i18next'
3838
import InfoLink from '../../../components/InfoLink'
3939
import TitleDescriptionHelpPanel from '../../../components/help-panel/TitleDescriptionHelpPanel'
4040
import {extendCollectionsOptions} from '../../../shared/extendCollectionsOptions'
41+
import {CustomImageStatusIndicator} from '../../../components/Status'
4142

4243
const imageBuildPath = ['app', 'customImages', 'imageBuild']
4344

@@ -167,7 +168,9 @@ function CustomImagesList() {
167168
{
168169
id: 'status',
169170
header: t('customImages.list.columns.status'),
170-
cell: image => image.imageBuildStatus || '-',
171+
cell: image => (
172+
<CustomImageStatusIndicator buildStatus={image.imageBuildStatus} />
173+
),
171174
sortingField: 'imageBuildStatus',
172175
},
173176
{

0 commit comments

Comments
 (0)