From 6d0dc2854a5f04619369cc802291d0826c054af4 Mon Sep 17 00:00:00 2001 From: Evangelos Skopelitis Date: Tue, 5 Nov 2024 12:52:03 -0500 Subject: [PATCH] frontend: Home: Show the origin of each cluster This change introduces a new "Origin" column for the cluster list on the home page, displaying whether a cluster came from a kubeconfig, Headlamp, or a dynamic cluster, with references when available. Fixes: #1632 Signed-off-by: Evangelos Skopelitis --- frontend/src/components/App/Home/index.tsx | 25 +++++++++++++++++++ frontend/src/i18n/locales/de/translation.json | 5 +++- frontend/src/i18n/locales/en/translation.json | 5 +++- frontend/src/i18n/locales/es/translation.json | 5 +++- frontend/src/i18n/locales/fr/translation.json | 5 +++- frontend/src/i18n/locales/pt/translation.json | 5 +++- 6 files changed, 45 insertions(+), 5 deletions(-) diff --git a/frontend/src/components/App/Home/index.tsx b/frontend/src/components/App/Home/index.tsx index f3d9395bc4..2fed2e533c 100644 --- a/frontend/src/components/App/Home/index.tsx +++ b/frontend/src/components/App/Home/index.tsx @@ -236,6 +236,24 @@ function HomeComponent(props: HomeComponentProps) { .sort(); } + /** + * Gets the origin of a cluster. + * + * @param cluster + * @returns A description of where the cluster is picked up from: dynamic, in-cluster, or from a kubeconfig file. + */ + function getOrigin(cluster: Cluster): string { + if (cluster.meta_data?.source === 'kubeconfig') { + const kubeconfigPath = process.env.KUBECONFIG ?? '~/.kube/config'; + return t('translation|Kubeconfig') + ` (${kubeconfigPath})`; + } else if (cluster.meta_data?.source === 'dynamic_cluster') { + return t('translation|Dynamic cluster'); + } else if (cluster.meta_data?.source === 'in_cluster') { + return t('translation|In-cluster'); + } + return 'Unknown'; + } + const memoizedComponent = React.useMemo( () => ( @@ -264,6 +282,13 @@ function HomeComponent(props: HomeComponentProps) { ), }, + { + label: t('Origin'), + getValue: cluster => getOrigin(cluster), + render: ({ name }) => ( + {getOrigin(clusters[name])} + ), + }, { label: t('Status'), getValue: cluster => cluster.name, diff --git a/frontend/src/i18n/locales/de/translation.json b/frontend/src/i18n/locales/de/translation.json index 040764054c..73270aaa67 100644 --- a/frontend/src/i18n/locales/de/translation.json +++ b/frontend/src/i18n/locales/de/translation.json @@ -16,9 +16,13 @@ "Delete Cluster": "", "Are you sure you want to remove the cluster \"{{ clusterName }}\"?": "Sind Sie sicher, dass Sie den Cluster \"{{ clusterName }}\" entfernen möchten?", "Active": "Aktiv", + "Kubeconfig": "", + "Dynamic cluster": "", + "In-cluster": "", "Home": "Startseite", "All Clusters": "Alle Cluster", "Name": "Name", + "Origin": "", "Status": "Status", "Warnings": "", "Load cluster": "Cluster laden", @@ -40,7 +44,6 @@ "Visible": "Sichtbar", "Plugins": "Plugins", "Description": "Beschreibung", - "Origin": "", "Unknown": "", "Incompatible": "Inkompatibel", "Enabled": "", diff --git a/frontend/src/i18n/locales/en/translation.json b/frontend/src/i18n/locales/en/translation.json index 06eff75b14..f4beb9243e 100644 --- a/frontend/src/i18n/locales/en/translation.json +++ b/frontend/src/i18n/locales/en/translation.json @@ -16,9 +16,13 @@ "Delete Cluster": "Delete Cluster", "Are you sure you want to remove the cluster \"{{ clusterName }}\"?": "Are you sure you want to remove the cluster \"{{ clusterName }}\"?", "Active": "Active", + "Kubeconfig": "Kubeconfig", + "Dynamic cluster": "Dynamic cluster", + "In-cluster": "In-cluster", "Home": "Home", "All Clusters": "All Clusters", "Name": "Name", + "Origin": "Origin", "Status": "Status", "Warnings": "Warnings", "Load cluster": "Load cluster", @@ -40,7 +44,6 @@ "Visible": "Visible", "Plugins": "Plugins", "Description": "Description", - "Origin": "Origin", "Unknown": "Unknown", "Incompatible": "Incompatible", "Enabled": "Enabled", diff --git a/frontend/src/i18n/locales/es/translation.json b/frontend/src/i18n/locales/es/translation.json index 3534877151..f746435cf1 100644 --- a/frontend/src/i18n/locales/es/translation.json +++ b/frontend/src/i18n/locales/es/translation.json @@ -16,9 +16,13 @@ "Delete Cluster": "", "Are you sure you want to remove the cluster \"{{ clusterName }}\"?": "¿Está seguro de que desea eliminar el cluster \"{{ clusterName }}\"?", "Active": "Activo", + "Kubeconfig": "", + "Dynamic cluster": "", + "In-cluster": "", "Home": "Inicio", "All Clusters": "Todos los Clusters", "Name": "Nombre", + "Origin": "", "Status": "Estado", "Warnings": "", "Load cluster": "Cargar cluster", @@ -40,7 +44,6 @@ "Visible": "Visible", "Plugins": "Plugins", "Description": "Descripción", - "Origin": "", "Unknown": "", "Incompatible": "Incompatible", "Enabled": "", diff --git a/frontend/src/i18n/locales/fr/translation.json b/frontend/src/i18n/locales/fr/translation.json index 68db9c1c3c..921ccd5b8d 100644 --- a/frontend/src/i18n/locales/fr/translation.json +++ b/frontend/src/i18n/locales/fr/translation.json @@ -16,9 +16,13 @@ "Delete Cluster": "", "Are you sure you want to remove the cluster \"{{ clusterName }}\"?": "Voulez-vous vraiment supprimer le cluster \"{{ clusterName }}\"?", "Active": "Actif", + "Kubeconfig": "", + "Dynamic cluster": "", + "In-cluster": "", "Home": "Accueil", "All Clusters": "Tous les clusters", "Name": "Nom", + "Origin": "", "Status": "Statut", "Warnings": "", "Load cluster": "Charger cluster", @@ -40,7 +44,6 @@ "Visible": "Visible", "Plugins": "Plugins", "Description": "Description", - "Origin": "", "Unknown": "", "Incompatible": "Incompatible", "Enabled": "", diff --git a/frontend/src/i18n/locales/pt/translation.json b/frontend/src/i18n/locales/pt/translation.json index f7aa198d49..ebb483ecf9 100644 --- a/frontend/src/i18n/locales/pt/translation.json +++ b/frontend/src/i18n/locales/pt/translation.json @@ -16,9 +16,13 @@ "Delete Cluster": "", "Are you sure you want to remove the cluster \"{{ clusterName }}\"?": "Tem a certeza que quer remover o cluster \"{{ clusterName }}\"?", "Active": "Activo", + "Kubeconfig": "", + "Dynamic cluster": "", + "In-cluster": "", "Home": "Início", "All Clusters": "Todos os Clusters", "Name": "Nome", + "Origin": "", "Status": "Estado", "Warnings": "", "Load cluster": "Carregar cluster", @@ -40,7 +44,6 @@ "Visible": "Visível", "Plugins": "Plugins", "Description": "Descrição", - "Origin": "", "Unknown": "", "Incompatible": "Incompatível", "Enabled": "",