From 08c8c40526e61b42dcaa72e90b974ddae6f72a02 Mon Sep 17 00:00:00 2001 From: Billy Figueroa Date: Mon, 16 Sep 2024 12:13:38 -0400 Subject: [PATCH] fix(ui): fixing issue with table data being null (#320) --- .../components/k8s/DataTable/component.svelte | 104 ++++++++++-------- ui/src/lib/features/k8s/store.ts | 11 +- 2 files changed, 67 insertions(+), 48 deletions(-) diff --git a/ui/src/lib/components/k8s/DataTable/component.svelte b/ui/src/lib/components/k8s/DataTable/component.svelte index 26de4929..f9644ee1 100644 --- a/ui/src/lib/components/k8s/DataTable/component.svelte +++ b/ui/src/lib/components/k8s/DataTable/component.svelte @@ -241,53 +241,65 @@ - {#each $rows as row} - - !disableRowClick && row.resource.metadata?.uid && goto(`${baseURL}/${row.resource.metadata?.uid}`)} - class:active={row.resource.metadata?.uid && pathName.includes(row.resource.metadata?.uid ?? '')} - class:cursor-pointer={!disableRowClick} - > - {#each columns as [key, style, modifier], idx} - - {@const value = Object.hasOwn(row.table, key) ? row.table[key] : ''} - - {#if value.component} - - {:else if value.list} - - {:else if modifier === 'link-external'} - - {:else if modifier === 'link-internal'} - - {:else if key === 'namespace'} - - {:else if style?.includes('truncate')} - -
- {value} -
-
- {:else} - {value.text || (value === 0 ? '0' : value) || '-'} - {/if} - - {/each} + {#if $rows.length === 0 && isFiltering} + + No matching entries found - {/each} + {:else if $rows.length === 0} + + No resources found + + {:else} + {#each $rows as row} + + !disableRowClick && row.resource.metadata?.uid && goto(`${baseURL}/${row.resource.metadata?.uid}`)} + class:active={row.resource.metadata?.uid && pathName.includes(row.resource.metadata?.uid ?? '')} + class:cursor-pointer={!disableRowClick} + > + {#each columns as [key, style, modifier], idx} + + {@const value = Object.hasOwn(row.table, key) ? row.table[key] : ''} + + {#if value.component} + + {:else if value.list} +
    + {#each value.list as item} +
  • - {item}
  • + {/each} +
+ {:else if modifier === 'link-external'} + + {:else if modifier === 'link-internal'} + + {:else if key === 'namespace'} + + {:else if style?.includes('truncate')} + +
+ {value} +
+
+ {:else} + {value.text || (value === 0 ? '0' : value) || '-'} + {/if} + + {/each} + + {/each} + {/if} diff --git a/ui/src/lib/features/k8s/store.ts b/ui/src/lib/features/k8s/store.ts index f28b9c83..013ea9fa 100644 --- a/ui/src/lib/features/k8s/store.ts +++ b/ui/src/lib/features/k8s/store.ts @@ -236,9 +236,15 @@ export function transformResource Partial, ) { // Return a function to transform KubernetesObject resources - return (resources: T[]) => + + return (resources: T[]) => { + // If we don't have resoure return empty array to avoid 'Cannot read properties of null (reading 'map')' error + if (!resources) { + return [] + } + // Map the resources to the common table format - resources.map>((r) => { + return resources.map>((r) => { // Convert common KubernetesObject rows const commonRows = { name: r.metadata?.name ?? '', @@ -258,6 +264,7 @@ export function transformResource