From e2282e2ccc9a225fbebc99a56cfd7bc740645f22 Mon Sep 17 00:00:00 2001 From: Dylan Wang <44744910+51wangping@users.noreply.github.com> Date: Wed, 10 Jul 2024 17:18:48 +0800 Subject: [PATCH] [Merged after v4.1.1] fix: cluster alias name (#3914) (#4147) * fix: cluster alias name * fix: add useGetClusterAliasName useGetProjectAliasName --- .../ClusterSetting/Gateway/Detail/index.tsx | 4 +-- .../CustomResources/Detail/index.tsx | 10 ++++-- .../containers/Projects/detail/index.tsx | 3 +- .../SystemComponents/Detail/index.tsx | 6 ++-- .../Workload/CronJobs/Detail/index.tsx | 6 ++-- .../Workload/DaemonSets/Detail/index.tsx | 6 ++-- .../Workload/Deployments/Detail/index.tsx | 6 ++-- .../containers/Workload/Jobs/Detail/index.tsx | 6 ++-- .../containers/Workload/Pods/Detail/index.tsx | 6 ++-- .../Workload/Routes/Detail/index.tsx | 6 ++-- .../Workload/Services/Detail/index.tsx | 6 ++-- .../Workload/StatefulSets/Detail/index.tsx | 6 ++-- .../Jobs/CronJob/Detail/index.tsx | 6 ++-- .../Jobs/Job/Detail/index.tsx | 6 ++-- .../Routes/Detail/index.tsx | 6 ++-- .../Services/Detail/index.tsx | 6 ++-- .../Workloads/DaemonSets/Detail/index.tsx | 6 ++-- .../Workloads/Deployments/Detail/index.tsx | 6 ++-- .../Workloads/StatefulSets/Detail/index.tsx | 6 ++-- .../Applications/DetailInfo/index.tsx | 6 ++-- .../Apps/Applications/DetailInfo/index.tsx | 13 +++---- .../Clusters/ClusterAliasName/index.tsx | 21 ++++++++++++ .../shared/src/components/Clusters/index.ts | 1 + .../Projects/ProjectAliasName/index.tsx | 26 ++++++++++++++ .../shared/src/components/Projects/index.ts | 1 + packages/shared/src/components/index.ts | 1 + packages/shared/src/utils/caches.ts | 34 +++++++++++++++++++ 27 files changed, 168 insertions(+), 48 deletions(-) create mode 100644 packages/shared/src/components/Clusters/ClusterAliasName/index.tsx create mode 100644 packages/shared/src/components/Projects/ProjectAliasName/index.tsx create mode 100644 packages/shared/src/components/Projects/index.ts diff --git a/packages/console/src/pages/clusters/containers/ClusterSetting/Gateway/Detail/index.tsx b/packages/console/src/pages/clusters/containers/ClusterSetting/Gateway/Detail/index.tsx index e8d87769d14..730fbaa9fcf 100644 --- a/packages/console/src/pages/clusters/containers/ClusterSetting/Gateway/Detail/index.tsx +++ b/packages/console/src/pages/clusters/containers/ClusterSetting/Gateway/Detail/index.tsx @@ -10,7 +10,7 @@ import { formatTime, gatewayStore, } from '@ks-console/shared'; -import { useCacheStore as useStore } from '@ks-console/shared'; +import { useCacheStore as useStore, ClusterAliasName } from '@ks-console/shared'; import { GatewayConfig } from '..'; import GatewaySetting from '../GatewaySetting'; @@ -83,7 +83,7 @@ const Detail = () => { return [ { label: t('CLUSTER'), - value: currentCluster || '', + value: , }, { label: t('CREATION_TIME'), diff --git a/packages/console/src/pages/clusters/containers/CustomResources/Detail/index.tsx b/packages/console/src/pages/clusters/containers/CustomResources/Detail/index.tsx index 5d403ffaeda..432cb561973 100644 --- a/packages/console/src/pages/clusters/containers/CustomResources/Detail/index.tsx +++ b/packages/console/src/pages/clusters/containers/CustomResources/Detail/index.tsx @@ -2,7 +2,13 @@ import React, { useRef } from 'react'; import { useParams } from 'react-router-dom'; import { Select } from '@kubed/icons'; import { isEmpty } from 'lodash'; -import { crdStore, DetailPage, FormattedCRD, formatTime } from '@ks-console/shared'; +import { + crdStore, + DetailPage, + FormattedCRD, + formatTime, + ClusterAliasName, +} from '@ks-console/shared'; const Detail = () => { const { cluster, name } = useParams(); @@ -16,7 +22,7 @@ const Detail = () => { return [ { label: t('CLUSTER'), - value: cluster || '', + value: , }, { label: t('SCOPE_TCAP'), diff --git a/packages/console/src/pages/clusters/containers/Projects/detail/index.tsx b/packages/console/src/pages/clusters/containers/Projects/detail/index.tsx index 70b4467a099..35cd1ceeaeb 100644 --- a/packages/console/src/pages/clusters/containers/Projects/detail/index.tsx +++ b/packages/console/src/pages/clusters/containers/Projects/detail/index.tsx @@ -8,6 +8,7 @@ import { useCommonActions, quotaStore, limitRangesStore, + ClusterAliasName, } from '@ks-console/shared'; import { notify } from '@kubed/components'; import { Pen, Project, Trash } from '@kubed/icons'; @@ -108,7 +109,7 @@ const ProjectDetail = () => { }, { label: t('CLUSTER'), - value: cluster!, + value: , }, { label: t('WORKSPACE'), diff --git a/packages/console/src/pages/clusters/containers/SystemComponents/Detail/index.tsx b/packages/console/src/pages/clusters/containers/SystemComponents/Detail/index.tsx index 9492a36c98c..63d31f1bb5e 100644 --- a/packages/console/src/pages/clusters/containers/SystemComponents/Detail/index.tsx +++ b/packages/console/src/pages/clusters/containers/SystemComponents/Detail/index.tsx @@ -7,6 +7,8 @@ import { getComponentStatus, StatusIndicator, SystemComponent, + ClusterAliasName, + ProjectAliasName, } from '@ks-console/shared'; import { Components } from '@kubed/icons'; @@ -27,11 +29,11 @@ function ServiceComponentDetail() { }, { label: t('CLUSTER'), - value: params.cluster, + value: , }, { label: t('PROJECT'), - value: data?.namespace, + value: , }, { label: t('REPLICA_COUNT'), diff --git a/packages/console/src/pages/clusters/containers/Workload/CronJobs/Detail/index.tsx b/packages/console/src/pages/clusters/containers/Workload/CronJobs/Detail/index.tsx index fe91acae2ba..3fa07fa27ae 100644 --- a/packages/console/src/pages/clusters/containers/Workload/CronJobs/Detail/index.tsx +++ b/packages/console/src/pages/clusters/containers/Workload/CronJobs/Detail/index.tsx @@ -2,7 +2,7 @@ import { isEmpty, get } from 'lodash'; import React, { useEffect, useMemo, useState } from 'react'; import { useNavigate, useParams } from 'react-router-dom'; import { Loading, notify } from '@kubed/components'; -import { useCacheStore as useStore } from '@ks-console/shared'; +import { useCacheStore as useStore, ClusterAliasName, ProjectAliasName } from '@ks-console/shared'; import { Icon, EditYamlModal, @@ -149,11 +149,11 @@ const DaemonSetDetail = () => { return [ { label: t('CLUSTER'), - value: cluster, + value: , }, { label: t('PROJECT'), - value: namespace, + value: , }, { label: t('STATUS'), diff --git a/packages/console/src/pages/clusters/containers/Workload/DaemonSets/Detail/index.tsx b/packages/console/src/pages/clusters/containers/Workload/DaemonSets/Detail/index.tsx index 483b72ad312..8209affa04b 100644 --- a/packages/console/src/pages/clusters/containers/Workload/DaemonSets/Detail/index.tsx +++ b/packages/console/src/pages/clusters/containers/Workload/DaemonSets/Detail/index.tsx @@ -13,6 +13,8 @@ import { getDisplayName, formatTime, yaml, + ClusterAliasName, + ProjectAliasName, } from '@ks-console/shared'; import { useRollbackModal, useBaseInfoModal } from '../../../../hooks/useModal'; import type { FormattedWorkload } from '@ks-console/shared'; @@ -175,11 +177,11 @@ const DaemonSetDetail = () => { return [ { label: t('CLUSTER'), - value: cluster, + value: , }, { label: t('PROJECT'), - value: namespace, + value: , }, { label: t('APP'), diff --git a/packages/console/src/pages/clusters/containers/Workload/Deployments/Detail/index.tsx b/packages/console/src/pages/clusters/containers/Workload/Deployments/Detail/index.tsx index e6ae09997bf..d812ae017d6 100644 --- a/packages/console/src/pages/clusters/containers/Workload/Deployments/Detail/index.tsx +++ b/packages/console/src/pages/clusters/containers/Workload/Deployments/Detail/index.tsx @@ -14,6 +14,8 @@ import { getDisplayName, formatTime, yaml, + ClusterAliasName, + ProjectAliasName, } from '@ks-console/shared'; import { useBaseInfoModal, @@ -211,11 +213,11 @@ const DeploymentDetail = () => { return [ { label: t('CLUSTER'), - value: cluster, + value: , }, { label: t('PROJECT'), - value: namespace, + value: , }, { label: t('APP'), diff --git a/packages/console/src/pages/clusters/containers/Workload/Jobs/Detail/index.tsx b/packages/console/src/pages/clusters/containers/Workload/Jobs/Detail/index.tsx index cbdd096d38e..d7eec112f2e 100644 --- a/packages/console/src/pages/clusters/containers/Workload/Jobs/Detail/index.tsx +++ b/packages/console/src/pages/clusters/containers/Workload/Jobs/Detail/index.tsx @@ -14,6 +14,8 @@ import { formatTime, yaml, getJobStatus, + ClusterAliasName, + ProjectAliasName, } from '@ks-console/shared'; import type { FormattedWorkload } from '@ks-console/shared'; import type { EditYamlConfig, ModalBaseConfig } from '../../../../types/workload'; @@ -147,11 +149,11 @@ const DaemonSetDetail = () => { return [ { label: t('CLUSTER'), - value: cluster, + value: , }, { label: t('PROJECT'), - value: namespace, + value: , }, { label: t('STATUS'), diff --git a/packages/console/src/pages/clusters/containers/Workload/Pods/Detail/index.tsx b/packages/console/src/pages/clusters/containers/Workload/Pods/Detail/index.tsx index f564fba9bcc..bcd21b650cc 100644 --- a/packages/console/src/pages/clusters/containers/Workload/Pods/Detail/index.tsx +++ b/packages/console/src/pages/clusters/containers/Workload/Pods/Detail/index.tsx @@ -12,6 +12,8 @@ import { getDisplayName, formatTime, yaml, + ClusterAliasName, + ProjectAliasName, } from '@ks-console/shared'; import type { FormattedPodDetail } from '@ks-console/shared'; import type { EditYamlConfig, ModalBaseConfig } from '../../../../types/workload'; @@ -100,11 +102,11 @@ const PodsDetail = () => { return [ { label: t('CLUSTER'), - value: cluster, + value: , }, { label: t('PROJECT'), - value: namespace, + value: , }, { label: t('APP'), diff --git a/packages/console/src/pages/clusters/containers/Workload/Routes/Detail/index.tsx b/packages/console/src/pages/clusters/containers/Workload/Routes/Detail/index.tsx index 28860c4a69f..ebb6c63a38e 100644 --- a/packages/console/src/pages/clusters/containers/Workload/Routes/Detail/index.tsx +++ b/packages/console/src/pages/clusters/containers/Workload/Routes/Detail/index.tsx @@ -13,6 +13,8 @@ import { formatTime, yaml, useBaseInfoModal, + ClusterAliasName, + ProjectAliasName, } from '@ks-console/shared'; import type { IngressDetail } from '@ks-console/shared'; import type { EditYamlConfig, ModalBaseConfig } from '../../../../types/workload'; @@ -125,11 +127,11 @@ const PodsDetail = () => { return [ { label: t('CLUSTER'), - value: cluster, + value: , }, { label: t('PROJECT'), - value: namespace, + value: , }, { label: t('APP'), diff --git a/packages/console/src/pages/clusters/containers/Workload/Services/Detail/index.tsx b/packages/console/src/pages/clusters/containers/Workload/Services/Detail/index.tsx index 0be7a287255..48e936fbaeb 100644 --- a/packages/console/src/pages/clusters/containers/Workload/Services/Detail/index.tsx +++ b/packages/console/src/pages/clusters/containers/Workload/Services/Detail/index.tsx @@ -15,6 +15,8 @@ import { joinSelector, IFormatEndPoint, useBaseInfoModal, + ClusterAliasName, + ProjectAliasName, } from '@ks-console/shared'; import type { IServiceDetail } from '@ks-console/shared'; import type { EditYamlConfig, ModalBaseConfig } from '../../../../types/workload'; @@ -174,11 +176,11 @@ const PodsDetail = () => { return [ { label: t('CLUSTER'), - value: cluster, + value: , }, { label: t('PROJECT'), - value: namespace, + value: , }, { label: t('TYPE'), diff --git a/packages/console/src/pages/clusters/containers/Workload/StatefulSets/Detail/index.tsx b/packages/console/src/pages/clusters/containers/Workload/StatefulSets/Detail/index.tsx index 63bfd1f2453..873785dc917 100644 --- a/packages/console/src/pages/clusters/containers/Workload/StatefulSets/Detail/index.tsx +++ b/packages/console/src/pages/clusters/containers/Workload/StatefulSets/Detail/index.tsx @@ -13,6 +13,8 @@ import { getDisplayName, formatTime, yaml, + ClusterAliasName, + ProjectAliasName, } from '@ks-console/shared'; import { useBaseInfoModal, useRollbackModal } from '../../../../hooks/useModal'; import type { FormattedWorkload } from '@ks-console/shared'; @@ -173,11 +175,11 @@ const DaemonSetDetail = () => { return [ { label: t('CLUSTER'), - value: cluster, + value: , }, { label: t('PROJECT'), - value: namespace, + value: , }, { label: t('APP'), diff --git a/packages/console/src/pages/projects/containers/ApplicationWorkloads/Jobs/CronJob/Detail/index.tsx b/packages/console/src/pages/projects/containers/ApplicationWorkloads/Jobs/CronJob/Detail/index.tsx index c0b5f0222ec..4ab36ad37d4 100644 --- a/packages/console/src/pages/projects/containers/ApplicationWorkloads/Jobs/CronJob/Detail/index.tsx +++ b/packages/console/src/pages/projects/containers/ApplicationWorkloads/Jobs/CronJob/Detail/index.tsx @@ -12,6 +12,8 @@ import { getCronJobStatus, useCommonActions, ClusterDetail, + ClusterAliasName, + ProjectAliasName, } from '@ks-console/shared'; const WORKLOAD_TYPE = 'CRONJOB'; @@ -103,11 +105,11 @@ const DaemonSetDetail = () => { return [ { label: t('CLUSTER'), - value: cluster, + value: , }, { label: t('PROJECT'), - value: namespace, + value: , }, { label: t('STATUS'), diff --git a/packages/console/src/pages/projects/containers/ApplicationWorkloads/Jobs/Job/Detail/index.tsx b/packages/console/src/pages/projects/containers/ApplicationWorkloads/Jobs/Job/Detail/index.tsx index bc11fa8352a..e2f39ae420a 100644 --- a/packages/console/src/pages/projects/containers/ApplicationWorkloads/Jobs/Job/Detail/index.tsx +++ b/packages/console/src/pages/projects/containers/ApplicationWorkloads/Jobs/Job/Detail/index.tsx @@ -12,6 +12,8 @@ import { formatTime, getJobStatus, useCommonActions, + ClusterAliasName, + ProjectAliasName, } from '@ks-console/shared'; const WORKLOAD_TYPE = 'JOB'; @@ -104,11 +106,11 @@ const DaemonSetDetail = () => { return [ { label: t('CLUSTER'), - value: cluster, + value: , }, { label: t('PROJECT'), - value: namespace, + value: , }, { label: t('STATUS'), diff --git a/packages/console/src/pages/projects/containers/ApplicationWorkloads/Routes/Detail/index.tsx b/packages/console/src/pages/projects/containers/ApplicationWorkloads/Routes/Detail/index.tsx index b15c95e6448..6223756c508 100644 --- a/packages/console/src/pages/projects/containers/ApplicationWorkloads/Routes/Detail/index.tsx +++ b/packages/console/src/pages/projects/containers/ApplicationWorkloads/Routes/Detail/index.tsx @@ -10,6 +10,8 @@ import { getDisplayName, formatTime, useCommonActions, + ClusterAliasName, + ProjectAliasName, } from '@ks-console/shared'; import type { IngressDetail } from '@ks-console/shared'; import useRoutesAnnotations from '../../../../../clusters/hooks/useRoutesAnnotations'; @@ -93,11 +95,11 @@ const IngressRoutesDetail = () => { return [ { label: t('CLUSTER'), - value: cluster, + value: , }, { label: t('PROJECT'), - value: namespace, + value: , }, { label: t('APP'), diff --git a/packages/console/src/pages/projects/containers/ApplicationWorkloads/Services/Detail/index.tsx b/packages/console/src/pages/projects/containers/ApplicationWorkloads/Services/Detail/index.tsx index 48b819dd669..82567e6dba1 100644 --- a/packages/console/src/pages/projects/containers/ApplicationWorkloads/Services/Detail/index.tsx +++ b/packages/console/src/pages/projects/containers/ApplicationWorkloads/Services/Detail/index.tsx @@ -12,6 +12,8 @@ import { joinSelector, IFormatEndPoint, useCommonActions, + ClusterAliasName, + ProjectAliasName, } from '@ks-console/shared'; import useServiceGateway from '../../../../../clusters/hooks/useServiceGateway'; import useServiceModal from '../../../../../clusters/hooks/useServiceModal'; @@ -138,11 +140,11 @@ const ServiceDetail = () => { return [ { label: t('CLUSTER'), - value: cluster, + value: , }, { label: t('PROJECT'), - value: namespace, + value: , }, { label: t('TYPE'), diff --git a/packages/console/src/pages/projects/containers/ApplicationWorkloads/Workloads/DaemonSets/Detail/index.tsx b/packages/console/src/pages/projects/containers/ApplicationWorkloads/Workloads/DaemonSets/Detail/index.tsx index d9778e03fbe..0d20de8eda8 100644 --- a/packages/console/src/pages/projects/containers/ApplicationWorkloads/Workloads/DaemonSets/Detail/index.tsx +++ b/packages/console/src/pages/projects/containers/ApplicationWorkloads/Workloads/DaemonSets/Detail/index.tsx @@ -15,6 +15,8 @@ import { getDisplayName, formatTime, useCommonActions, + ClusterAliasName, + ProjectAliasName, } from '@ks-console/shared'; import { useRollbackModal, useBaseInfoModal } from '../../../../../../clusters/hooks/useModal'; import type { FormattedWorkload } from '@ks-console/shared'; @@ -168,11 +170,11 @@ const DaemonSetDetail = () => { return [ { label: t('CLUSTER'), - value: cluster, + value: , }, { label: t('PROJECT'), - value: namespace, + value: , }, { label: t('APP'), diff --git a/packages/console/src/pages/projects/containers/ApplicationWorkloads/Workloads/Deployments/Detail/index.tsx b/packages/console/src/pages/projects/containers/ApplicationWorkloads/Workloads/Deployments/Detail/index.tsx index d2cb326a4b5..81202822e92 100644 --- a/packages/console/src/pages/projects/containers/ApplicationWorkloads/Workloads/Deployments/Detail/index.tsx +++ b/packages/console/src/pages/projects/containers/ApplicationWorkloads/Workloads/Deployments/Detail/index.tsx @@ -15,6 +15,8 @@ import { useCommonActions, useV3action, hasClusterModule, + ClusterAliasName, + ProjectAliasName, } from '@ks-console/shared'; import { useRollbackModal, useAutoScalingModal } from '../../../../../../clusters/hooks/useModal'; import type { FormattedWorkload } from '@ks-console/shared'; @@ -96,11 +98,11 @@ const DeploymentDetail = () => { return [ { label: t('CLUSTER'), - value: cluster, + value: , }, { label: t('PROJECT'), - value: namespace, + value: , }, { label: t('APP'), diff --git a/packages/console/src/pages/projects/containers/ApplicationWorkloads/Workloads/StatefulSets/Detail/index.tsx b/packages/console/src/pages/projects/containers/ApplicationWorkloads/Workloads/StatefulSets/Detail/index.tsx index 9624c950220..cd6b079dbad 100644 --- a/packages/console/src/pages/projects/containers/ApplicationWorkloads/Workloads/StatefulSets/Detail/index.tsx +++ b/packages/console/src/pages/projects/containers/ApplicationWorkloads/Workloads/StatefulSets/Detail/index.tsx @@ -16,6 +16,8 @@ import { useV3action, hasClusterModule, hpaStore, + ClusterAliasName, + ProjectAliasName, } from '@ks-console/shared'; import { useWorkloadService, @@ -197,11 +199,11 @@ const StatefulSetsDetail = () => { return [ { label: t('CLUSTER'), - value: cluster, + value: , }, { label: t('PROJECT'), - value: namespace, + value: , }, { label: t('APP'), diff --git a/packages/console/src/pages/projects/containers/Applications/DetailInfo/index.tsx b/packages/console/src/pages/projects/containers/Applications/DetailInfo/index.tsx index c0e3c61e817..58a2c171aa7 100644 --- a/packages/console/src/pages/projects/containers/Applications/DetailInfo/index.tsx +++ b/packages/console/src/pages/projects/containers/Applications/DetailInfo/index.tsx @@ -13,6 +13,8 @@ import { StatusIndicator, openpitrixStore, DeleteConfirmModal, + ClusterAliasName, + ProjectAliasName, } from '@ks-console/shared'; import { OPAppEditModal, OPTemplateEditModal } from '../../../components'; @@ -106,11 +108,11 @@ function DetailInfo(): JSX.Element { return [ { label: t('CLUSTER'), - value: cluster, + value: , }, { label: t('PROJECT'), - value: namespace, + value: , }, { label: t('STATUS'), diff --git a/packages/shared/src/components/Apps/Applications/DetailInfo/index.tsx b/packages/shared/src/components/Apps/Applications/DetailInfo/index.tsx index c0f23de8809..769c026373c 100644 --- a/packages/shared/src/components/Apps/Applications/DetailInfo/index.tsx +++ b/packages/shared/src/components/Apps/Applications/DetailInfo/index.tsx @@ -3,14 +3,14 @@ import { get, isEmpty, last } from 'lodash'; import { useQuery } from 'react-query'; import { Pen, Trash } from '@kubed/icons'; import { useNavigate, useParams } from 'react-router-dom'; -import { Loading, notify, Tooltip } from '@kubed/components'; +import { Loading, notify } from '@kubed/components'; +import { ClusterAliasName, ProjectAliasName } from '@ks-console/shared'; import { useCacheStore as useStore } from '../../../../index'; import Image from '../../../Image'; import { DetailPagee } from '../../../DetailPage'; import { DeleteConfirmModal } from '../../../Modals/DeleteConfirm'; import OPAppEditModal from '../AppTypeTable/OPAppTable/OPAppEditModal'; import OPTemplateEditModal from '../AppTypeTable/OPAppTable/OPTemplateEditModal'; -import { getProjectAliasName } from '../../../../utils/caches'; import { formatTime, getDisplayName, getAnnotationsName } from '../../../../utils'; import { openpitrixStore } from '../../../../stores'; import { DetailAction } from '../../../../hooks/useActions/utils'; @@ -48,10 +48,6 @@ function DetailInfo(): JSX.Element { cluster_id: detail.cluster_id, }; }, [detail]); - const project = getProjectAliasName( - namespace || detail?.labels?.['kubesphere.io/namespace'], - detail?.labels?.['kubesphere.io/workspace'], - ); const tabs = [ { @@ -107,16 +103,17 @@ function DetailInfo(): JSX.Element { if (isEmpty(detail)) { return; } + const fullCluster = cluster || detail.labels['kubesphere.io/cluster']; const appAliasName = detail?.metadata.annotations?.['application.kubesphere.io/app-alias-name']; return [ { label: t('CLUSTER'), - value: cluster || detail.labels['kubesphere.io/cluster'], + value: , }, { label: t('PROJECT'), - value: project, + value: , }, { label: t('STATUS'), diff --git a/packages/shared/src/components/Clusters/ClusterAliasName/index.tsx b/packages/shared/src/components/Clusters/ClusterAliasName/index.tsx new file mode 100644 index 00000000000..8e8de7c5909 --- /dev/null +++ b/packages/shared/src/components/Clusters/ClusterAliasName/index.tsx @@ -0,0 +1,21 @@ +import React from 'react'; +import { useGetClusterAliasName } from '../../../utils'; +export interface ClusterAliasNameProps { + cluster: string | undefined; + withTitle?: boolean; +} + +export default function ClusterAliasName({ cluster, withTitle = true }: ClusterAliasNameProps) { + if (!cluster) { + return null; + } + const fullName = useGetClusterAliasName(cluster); + + return withTitle ? ( + + {fullName || cluster} + + ) : ( + {fullName || cluster} + ); +} diff --git a/packages/shared/src/components/Clusters/index.ts b/packages/shared/src/components/Clusters/index.ts index f4661b5ab1f..6b816796edc 100644 --- a/packages/shared/src/components/Clusters/index.ts +++ b/packages/shared/src/components/Clusters/index.ts @@ -2,3 +2,4 @@ export { default as ClusterSelect } from './ClusterSelect'; export { default as ClusterWrapper } from './ClusterWrapper'; export { default as ClusterIcon } from './ClusterIcon'; export { default as ClusterTitle } from './ClusterTitle'; +export { default as ClusterAliasName } from './ClusterAliasName'; diff --git a/packages/shared/src/components/Projects/ProjectAliasName/index.tsx b/packages/shared/src/components/Projects/ProjectAliasName/index.tsx new file mode 100644 index 00000000000..f5bae412e1b --- /dev/null +++ b/packages/shared/src/components/Projects/ProjectAliasName/index.tsx @@ -0,0 +1,26 @@ +import React from 'react'; +import { useGetProjectAliasName } from '../../../utils'; +export interface ProjectAliasNameProps { + project: string | undefined; + workspace?: string | undefined; + withTitle?: boolean; +} + +export default function ProjectAliasName({ + project, + workspace, + withTitle = true, +}: ProjectAliasNameProps) { + if (!project) { + return null; + } + const fullName = useGetProjectAliasName(project, workspace); + + return withTitle ? ( + + {fullName || project} + + ) : ( + {fullName || project} + ); +} diff --git a/packages/shared/src/components/Projects/index.ts b/packages/shared/src/components/Projects/index.ts new file mode 100644 index 00000000000..b16a8b8d961 --- /dev/null +++ b/packages/shared/src/components/Projects/index.ts @@ -0,0 +1 @@ +export { default as ProjectAliasName } from './ProjectAliasName'; diff --git a/packages/shared/src/components/index.ts b/packages/shared/src/components/index.ts index bf294a00702..6db9edb4841 100644 --- a/packages/shared/src/components/index.ts +++ b/packages/shared/src/components/index.ts @@ -11,6 +11,7 @@ export * from './DetailPage'; export * from './InfiniteScroll'; export * from './Roles'; export * from './Clusters'; +export * from './Projects'; export * from './List'; export * from './Terminal'; export { default as Pagination } from './Pagination'; diff --git a/packages/shared/src/utils/caches.ts b/packages/shared/src/utils/caches.ts index 22e4cca436b..f3f7a8a432a 100644 --- a/packages/shared/src/utils/caches.ts +++ b/packages/shared/src/utils/caches.ts @@ -7,6 +7,13 @@ export function getWorkspacesAliasName(workspace: string) { export function getProjectAliasName(project: string, workspace?: string) { const [projectAliasName = {}] = useStore('projectAliasName'); + if (!workspace) { + let allprojectAliasName: any = {}; + Object.values(projectAliasName).forEach(obj => { + allprojectAliasName = Object.assign({}, allprojectAliasName, obj); + }); + return allprojectAliasName?.[project || ''] || project; + } return projectAliasName?.[workspace || '']?.[project] || project; } @@ -24,3 +31,30 @@ export function getPlatformRolesAliasName(role: string) { const [aliasName = {}] = useStore('platformRolesAliasName'); return aliasName?.[role || ''] || role; } + +export function useGetClusterAliasName(cluster: string) { + const [aliasName = {}] = useStore('clustersAliasName'); + return aliasName?.[cluster || ''] || cluster; +} + +export function useGetPlatformRolesAliasName(role: string) { + const [aliasName = {}] = useStore('platformRolesAliasName'); + return aliasName?.[role || ''] || role; +} + +export function useGetWorkspacesAliasName(workspace: string) { + const [workspacesAliasName] = useStore('workspaceAliasName'); + return workspacesAliasName?.[workspace] || workspace; +} + +export function useGetProjectAliasName(project: string, workspace?: string) { + const [projectAliasName = {}] = useStore('projectAliasName'); + if (!workspace) { + let allprojectAliasName: any = {}; + Object.values(projectAliasName).forEach(obj => { + allprojectAliasName = Object.assign({}, allprojectAliasName, obj); + }); + return allprojectAliasName?.[project || ''] || project; + } + return projectAliasName?.[workspace || '']?.[project] || project; +}