Skip to content

Commit

Permalink
fix: empty endpoints are shown as Pending (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleGedd authored Aug 7, 2024
1 parent d523a64 commit 08b96ad
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 13 deletions.
22 changes: 13 additions & 9 deletions ui/src/lib/components/Link/component.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
export let text: string
</script>

<a
{href}
{target}
on:click|stopPropagation
rel="noopener noreferrer"
class="font-medium text-blue-600 dark:text-blue-500 hover:underline pr-4"
>
{text}
</a>
{#if href}
<a
{href}
{target}
on:click|stopPropagation
rel="noopener noreferrer"
class="font-medium text-blue-600 dark:text-blue-500 hover:underline pr-4"
>
{text}
</a>
{:else}
<span class="dark:text-gray-400 mt-4 text-sm">{text}</span>
{/if}
4 changes: 2 additions & 2 deletions ui/src/lib/components/k8s/DataTable/component.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@
{/each}
</ul>
{:else if modifier === 'link-external'}
<Link href={value.href || value} text={value.text || value} target={'_blank'} />
<Link href={value.href || ''} text={value.text || ''} target={'_blank'} />
{:else if modifier === 'link-internal'}
<Link href={value.href || value} text={value.text || value} target={''} />
<Link href={value.href || ''} text={value.text || ''} target={''} />
{:else if key === 'namespace'}
<button
on:click|stopPropagation={() => namespace.set(value)}
Expand Down
66 changes: 65 additions & 1 deletion ui/src/lib/features/k8s/applications/endpoints/component.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2024-Present The UDS Authors

/* eslint-disable @typescript-eslint/no-explicit-any */
import { beforeEach, vi } from 'vitest'

import { testK8sTableWithCustomColumns, testK8sTableWithDefaults } from '$features/k8s/test-helper'
import type { ZarfPackage } from '$features/k8s/applications/packages/types'
import {
expectEqualIgnoringFields,
MockResourceStore,
testK8sTableWithCustomColumns,
testK8sTableWithDefaults,
} from '$features/k8s/test-helper'
import type { ResourceWithTable } from '$features/k8s/types'
import Component from './component.svelte'
import { createStore } from './store'

Expand All @@ -29,4 +37,60 @@ suite('StatefulsetTable Component', () => {
description,
disableRowClick: true,
})

vi.mock('../../store.ts', async (importOriginal) => {
const mockData = [
{
apiVersion: 'uds.dev/v1alpha1',
kind: 'Package',
metadata: {
creationTimestamp: '2021-09-29T20:00:00Z',
name: 'foo',
namespace: 'foo',
},
spec: {
network: {
expose: [
{
service: 'foo',
selector: {
' "app.kubernetes.io/name"': 'foo',
},
gateway: 'tenant',
host: 'foo',
port: 9898,
},
],
},
},
status: {
phase: 'Pending',
},
},
] as unknown as ZarfPackage[]

const original: Record<string, unknown> = await importOriginal()
return {
...original,
ResourceStore: vi.fn().mockImplementation((url, transform) => new MockResourceStore(url, transform, mockData)),
}
})

const expectedTables = [
{
name: 'foo',
url: {
href: '',
sort: '',
text: 'Pending',
},
namespace: 'foo',
status: 'Pending',
},
]

const store = createStore()
const start = store.start as unknown as () => ResourceWithTable<ZarfPackage, any>[]
expect(store.url).toEqual('/api/v1/resources/configs/uds-packages?dense=true')
expectEqualIgnoringFields(start()[0].table, expectedTables[0] as unknown, ['creationTimestamp'])
})
3 changes: 3 additions & 0 deletions ui/src/lib/features/k8s/applications/endpoints/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export function createStore(): ResourceStoreInterface<Resource, Row> {
const url = `/api/v1/resources/configs/uds-packages?dense=true`

const endpointBuilder = (r: Resource, e: Expose) => {
if (r.status?.phase === 'Pending') {
return { href: '', sort: '', text: 'Pending' }
}
const url = r.status?.endpoints?.find((ep) => ep.includes(`${e.host}.`)) ?? ''
return {
href: `https://${url}`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<!-- SPDX-License-Identifier: Apache-2.0 -->
<!-- SPDX-FileCopyrightText: 2024-Present The UDS Authors -->

<script lang="ts">
import { Link } from '$components'
Expand Down
2 changes: 1 addition & 1 deletion ui/src/lib/features/k8s/test-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function testK8sTableWithDefaults(Component: ComponentType, props: Record

render(Component)

// Ensure name and ooltip desc aren't empty
// Ensure name and tooltip desc aren't empty
const name: string = props.name as string
expect(name).toBeTruthy()
const description: string = props.description as string
Expand Down

0 comments on commit 08b96ad

Please sign in to comment.