From 0f77ae4f3a039fed1f2abb0b6e58d9de986411d2 Mon Sep 17 00:00:00 2001 From: pauldkn <58977722+pauldkn@users.noreply.github.com> Date: Thu, 14 Nov 2024 17:39:33 +0100 Subject: [PATCH] fix(vcd): fix veeam backup status (#13856) ref: MANAGER-15767 Signed-off-by: Paul Dickerson --- ...rganizationDataProtectionTile.component.tsx | 11 +++++++++-- .../OrganizationDataProtectionTile.spec.tsx | 3 ++- .../BackupTileItem.component.tsx | 18 ++++++++++++------ ...izationGeneralInformationTile.component.tsx | 12 ++++++------ .../src/data/api/hpc-vmware-managed-vcd.ts | 6 ++---- .../data/hooks/useManagedVcdOrganization.ts | 10 +++++++--- .../OrganizationGeneralInformation.page.tsx | 6 +++--- .../{getBackupBadge.ts => veeamBackupBadge.ts} | 0 .../src/utils/veeamBackupId.ts | 9 +++++++++ 9 files changed, 50 insertions(+), 25 deletions(-) rename packages/manager/apps/hpc-vmware-managed-vcd/src/utils/{getBackupBadge.ts => veeamBackupBadge.ts} (100%) create mode 100644 packages/manager/apps/hpc-vmware-managed-vcd/src/utils/veeamBackupId.ts diff --git a/packages/manager/apps/hpc-vmware-managed-vcd/src/components/tiles/organization-data-tile/OrganizationDataProtectionTile.component.tsx b/packages/manager/apps/hpc-vmware-managed-vcd/src/components/tiles/organization-data-tile/OrganizationDataProtectionTile.component.tsx index 8d984f1c6b4e..4d227fcd0a1e 100644 --- a/packages/manager/apps/hpc-vmware-managed-vcd/src/components/tiles/organization-data-tile/OrganizationDataProtectionTile.component.tsx +++ b/packages/manager/apps/hpc-vmware-managed-vcd/src/components/tiles/organization-data-tile/OrganizationDataProtectionTile.component.tsx @@ -9,8 +9,15 @@ import { DATA_PROTECTION_RECOVERY_TITLE, } from '@/pages/dashboard/organization/OrganizationDashboard.constants'; import BackupTileItem from './backup-tile-item/BackupTileItem.component'; +import IVcdOrganization from '@/types/vcd-organization.interface'; -export default function DataProtectionTile() { +type TTileProps = { + vcdOrganization: IVcdOrganization; +}; + +export default function DataProtectionTile({ + vcdOrganization, +}: Readonly) { const { t } = useTranslation('dashboard'); return ( @@ -21,7 +28,7 @@ export default function DataProtectionTile() { { id: 'backup', label: DATA_PROTECTION_BACKUP_TITLE, - value: , + value: , }, { id: 'recovery', diff --git a/packages/manager/apps/hpc-vmware-managed-vcd/src/components/tiles/organization-data-tile/OrganizationDataProtectionTile.spec.tsx b/packages/manager/apps/hpc-vmware-managed-vcd/src/components/tiles/organization-data-tile/OrganizationDataProtectionTile.spec.tsx index 87a584ac98a9..28611525d56a 100644 --- a/packages/manager/apps/hpc-vmware-managed-vcd/src/components/tiles/organization-data-tile/OrganizationDataProtectionTile.spec.tsx +++ b/packages/manager/apps/hpc-vmware-managed-vcd/src/components/tiles/organization-data-tile/OrganizationDataProtectionTile.spec.tsx @@ -20,6 +20,7 @@ import { useManagedVcdOrganizationBackup } from '../../../data/hooks/useManagedV import IVcdOrganizationBackup, { BackupResourceStatus, } from '../../../types/vcd-organization-backup.interface'; +import { organizationList } from '../../../../mocks/vcd-organization/vcd-organization.mock'; vi.mock('../../../data/hooks/useManagedVcdOrganization', () => ({ useManagedVcdOrganizationBackup: vi.fn(), @@ -44,7 +45,7 @@ const renderComponent = () => { - + , ); diff --git a/packages/manager/apps/hpc-vmware-managed-vcd/src/components/tiles/organization-data-tile/backup-tile-item/BackupTileItem.component.tsx b/packages/manager/apps/hpc-vmware-managed-vcd/src/components/tiles/organization-data-tile/backup-tile-item/BackupTileItem.component.tsx index fc792de7b300..abb64b3ae58d 100644 --- a/packages/manager/apps/hpc-vmware-managed-vcd/src/components/tiles/organization-data-tile/backup-tile-item/BackupTileItem.component.tsx +++ b/packages/manager/apps/hpc-vmware-managed-vcd/src/components/tiles/organization-data-tile/backup-tile-item/BackupTileItem.component.tsx @@ -1,5 +1,4 @@ import React from 'react'; -import { useParams } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import { ShellContext } from '@ovh-ux/manager-react-shell-client'; import { Links, LinkType } from '@ovh-ux/manager-react-components'; @@ -11,14 +10,20 @@ import { BackupBadgeParams, getBackupBadgeParams, getBackupBadgeStatus, -} from '@/utils/getBackupBadge'; +} from '@/utils/veeamBackupBadge'; +import IVcdOrganization from '@/types/vcd-organization.interface'; -export default function BackupTileItem() { - const { id } = useParams(); +type TTileProps = { + vcdOrganization: IVcdOrganization; +}; + +export default function BackupTileItem({ + vcdOrganization, +}: Readonly) { const { t } = useTranslation('dashboard'); const { shell } = React.useContext(ShellContext); const { data: vcdBackup, isLoading, error } = useManagedVcdOrganizationBackup( - id, + vcdOrganization, ); const [veeamHref, setVeeamHref] = React.useState(''); const badgeParams: BackupBadgeParams = getBackupBadgeParams( @@ -34,9 +39,10 @@ export default function BackupTileItem() { .then((url: string) => setVeeamHref(url)); }, []); + if (isLoading) return ; + return (
- {isLoading && } @@ -93,7 +93,7 @@ export default function OrganizationGenerationInformationTile({ value: ( diff --git a/packages/manager/apps/hpc-vmware-managed-vcd/src/data/api/hpc-vmware-managed-vcd.ts b/packages/manager/apps/hpc-vmware-managed-vcd/src/data/api/hpc-vmware-managed-vcd.ts index 113cee5b6970..2f44ffc3466b 100644 --- a/packages/manager/apps/hpc-vmware-managed-vcd/src/data/api/hpc-vmware-managed-vcd.ts +++ b/packages/manager/apps/hpc-vmware-managed-vcd/src/data/api/hpc-vmware-managed-vcd.ts @@ -27,11 +27,9 @@ export const getVcdOrganization = async ( * Get VCD Backup */ export const getVcdOrganizationBackup = async ( - organizationId: string, + backupId: string, ): Promise> => - apiClient.v2.get( - `/vmwareCloudDirector/backup/${organizationId}-veeam-backup`, - ); + apiClient.v2.get(`/vmwareCloudDirector/backup/${backupId}`); /** * Edit VCD Organization diff --git a/packages/manager/apps/hpc-vmware-managed-vcd/src/data/hooks/useManagedVcdOrganization.ts b/packages/manager/apps/hpc-vmware-managed-vcd/src/data/hooks/useManagedVcdOrganization.ts index 2d008866546d..4e12d4df9cbb 100644 --- a/packages/manager/apps/hpc-vmware-managed-vcd/src/data/hooks/useManagedVcdOrganization.ts +++ b/packages/manager/apps/hpc-vmware-managed-vcd/src/data/hooks/useManagedVcdOrganization.ts @@ -14,6 +14,7 @@ import { getVcdOrganizationQueryKey, getVcdOrganizationBackupQueryKey, } from '@/utils/queryKeys'; +import { getBackupIdFromOrganization } from '@/utils/veeamBackupId'; interface IUseManagedVcdOrganization extends Pick { @@ -35,10 +36,13 @@ const useManagedVcdOrganization = ({ }); }; -export const useManagedVcdOrganizationBackup = (id: string) => { +export const useManagedVcdOrganizationBackup = ( + vcdOrganization: IVcdOrganization, +) => { return useQuery, ApiError>({ - queryKey: getVcdOrganizationBackupQueryKey(id), - queryFn: () => getVcdOrganizationBackup(id), + queryKey: getVcdOrganizationBackupQueryKey(vcdOrganization.id), + queryFn: () => + getVcdOrganizationBackup(getBackupIdFromOrganization(vcdOrganization)), retry: false, placeholderData: keepPreviousData, }); diff --git a/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/organization/general-information/OrganizationGeneralInformation.page.tsx b/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/organization/general-information/OrganizationGeneralInformation.page.tsx index cbceeb0cabb0..aa3ce4744966 100644 --- a/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/organization/general-information/OrganizationGeneralInformation.page.tsx +++ b/packages/manager/apps/hpc-vmware-managed-vcd/src/pages/dashboard/organization/general-information/OrganizationGeneralInformation.page.tsx @@ -37,13 +37,13 @@ function GeneralInformation() { return (
- +
diff --git a/packages/manager/apps/hpc-vmware-managed-vcd/src/utils/getBackupBadge.ts b/packages/manager/apps/hpc-vmware-managed-vcd/src/utils/veeamBackupBadge.ts similarity index 100% rename from packages/manager/apps/hpc-vmware-managed-vcd/src/utils/getBackupBadge.ts rename to packages/manager/apps/hpc-vmware-managed-vcd/src/utils/veeamBackupBadge.ts diff --git a/packages/manager/apps/hpc-vmware-managed-vcd/src/utils/veeamBackupId.ts b/packages/manager/apps/hpc-vmware-managed-vcd/src/utils/veeamBackupId.ts new file mode 100644 index 000000000000..9de7359dd19f --- /dev/null +++ b/packages/manager/apps/hpc-vmware-managed-vcd/src/utils/veeamBackupId.ts @@ -0,0 +1,9 @@ +import IVcdOrganization from '@/types/vcd-organization.interface'; + +const getOrganizationUuid = (organization: IVcdOrganization) => + organization.id.split( + `${organization.currentState.region.toLowerCase()}-`, + )[1]; + +export const getBackupIdFromOrganization = (organization: IVcdOrganization) => + `${getOrganizationUuid(organization)}-veeam-backup`;