Skip to content

Commit

Permalink
fix: pod status color (#176)
Browse files Browse the repository at this point in the history
Co-authored-by: UncleGedd <42304551+UncleGedd@users.noreply.github.com>
  • Loading branch information
TristanHoladay and UncleGedd authored Aug 8, 2024
1 parent 770c4a3 commit 2fe0c99
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
3 changes: 2 additions & 1 deletion ui/src/lib/features/k8s/workloads/pods/component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ suite('PodTable Component', () => {
},
restarts: 1,
controlled_by: 'DaemonSet',
status: 'Running',
status: { component: SvelteComponent, props: { status: 'Running' } },
node: '',
}

Expand All @@ -187,6 +187,7 @@ suite('PodTable Component', () => {
'creationTimestamp',
'containers.component',
'metrics.component',
'status.component',
])
vi.unstubAllGlobals()
})
19 changes: 19 additions & 0 deletions ui/src/lib/features/k8s/workloads/pods/status/component.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<script lang="ts">
export let status: string
const statusClasses = {
Running: 'text-green-400',
Stopped: 'text-red-400',
Pending: 'text-orange-300',
}
$: statusClass = statusClasses[status as keyof typeof statusClasses]
</script>

{#if status}
<span class={statusClass}>
{status}
</span>
{:else}
-
{/if}
17 changes: 17 additions & 0 deletions ui/src/lib/features/k8s/workloads/pods/status/component.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { render } from '@testing-library/svelte'
import Status from './component.svelte'

describe('Status component', () => {
test('renders text-green-400 for Running', () => {
const { container } = render(Status, { props: { status: 'Running' } })
expect(container.firstChild).toHaveClass('text-green-400')
})
test('renders text-red-400 for Running', () => {
const { container } = render(Status, { props: { status: 'Stopped' } })
expect(container.firstChild).toHaveClass('text-red-400')
})
test('renders text-yellow-500 for Running', () => {
const { container } = render(Status, { props: { status: 'Pending' } })
expect(container.firstChild).toHaveClass('text-orange-300')
})
})
5 changes: 3 additions & 2 deletions ui/src/lib/features/k8s/workloads/pods/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { type ColumnWrapper, type CommonRow, type ResourceStoreInterface } from
import ContainerStatus from './containers/component.svelte'
import PodMetrics from './metrics/component.svelte'
import { parseCPU } from './metrics/utils'
import Status from './status/component.svelte'

interface Row extends CommonRow {
containers: {
Expand All @@ -21,7 +22,7 @@ interface Row extends CommonRow {
restarts: number
controlled_by: string
node: string
status: string
status: { component: typeof Status; props: { status: string } }
metrics: {
component: typeof PodMetrics
sort: number
Expand Down Expand Up @@ -81,7 +82,7 @@ export function createStore(): ResourceStoreInterface<Resource, Row> {
},
restarts: r.status?.containerStatuses?.reduce((acc, curr) => acc + curr.restartCount, 0) ?? 0,
controlled_by: r.metadata?.ownerReferences?.at(0)?.kind ?? '',
status: r.status?.phase ?? '',
status: { component: Status, props: { status: r.status?.phase ?? '' } },
// @todo: This will not work due to using the default sparerResource stream
node: r.spec?.nodeName ?? '',
}))
Expand Down

0 comments on commit 2fe0c99

Please sign in to comment.