Skip to content

Commit

Permalink
fix(vcd): fix veeam backup status (#13856)
Browse files Browse the repository at this point in the history
ref: MANAGER-15767

Signed-off-by: Paul Dickerson <[email protected]>
  • Loading branch information
pauldkn authored Nov 14, 2024
1 parent 17cf3e5 commit 0f77ae4
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<TTileProps>) {
const { t } = useTranslation('dashboard');

return (
Expand All @@ -21,7 +28,7 @@ export default function DataProtectionTile() {
{
id: 'backup',
label: DATA_PROTECTION_BACKUP_TITLE,
value: <BackupTileItem />,
value: <BackupTileItem vcdOrganization={vcdOrganization} />,
},
{
id: 'recovery',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -44,7 +45,7 @@ const renderComponent = () => {
<ShellContext.Provider
value={(shellContext as unknown) as ShellContextType}
>
<OrganizationDataProtectionTile />
<OrganizationDataProtectionTile vcdOrganization={organizationList[0]} />
</ShellContext.Provider>
</QueryClientProvider>,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<TTileProps>) {
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(
Expand All @@ -34,9 +39,10 @@ export default function BackupTileItem() {
.then((url: string) => setVeeamHref(url));
}, []);

if (isLoading) return <OsdsSkeleton data-testid="backupLoading" />;

return (
<div className="flex flex-col items-start">
{isLoading && <OsdsSkeleton data-testid="backupLoading" />}
<OsdsChip
inline
data-testid={badgeParams.testIdLabel}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export default function OrganizationGenerationInformationTile({
label: t('managed_vcd_dashboard_name'),
value: (
<EditableTileItem
label={vcdOrganization?.currentState?.fullName}
urn={vcdOrganization?.iam?.urn}
label={vcdOrganization.currentState?.fullName}
urn={vcdOrganization.iam?.urn}
iamActions={[
iamActions.vmwareCloudDirectorApiovhOrganizationEdit,
]}
Expand All @@ -55,8 +55,8 @@ export default function OrganizationGenerationInformationTile({
label: t('managed_vcd_dashboard_description'),
value: (
<EditableTileItem
label={vcdOrganization?.currentState?.description}
urn={vcdOrganization?.iam.urn}
label={vcdOrganization.currentState?.description}
urn={vcdOrganization.iam.urn}
iamActions={[
iamActions.vmwareCloudDirectorApiovhOrganizationEdit,
]}
Expand All @@ -76,7 +76,7 @@ export default function OrganizationGenerationInformationTile({
hue={ODS_THEME_COLOR_HUE._500}
>
<Region
name={vcdOrganization?.currentState?.region?.toLowerCase()}
name={vcdOrganization.currentState?.region?.toLowerCase()}
mode="region"
/>
</OsdsText>
Expand All @@ -93,7 +93,7 @@ export default function OrganizationGenerationInformationTile({
value: (
<Links
type={LinkType.external}
href={vcdOrganization?.currentState?.webInterfaceUrl}
href={vcdOrganization.currentState?.webInterfaceUrl}
label={t('managed_vcd_dashboard_management_interface_access')}
target={OdsHTMLAnchorElementTarget._blank}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ export const getVcdOrganization = async (
* Get VCD Backup
*/
export const getVcdOrganizationBackup = async (
organizationId: string,
backupId: string,
): Promise<ApiResponse<IVcdOrganizationBackup>> =>
apiClient.v2.get(
`/vmwareCloudDirector/backup/${organizationId}-veeam-backup`,
);
apiClient.v2.get(`/vmwareCloudDirector/backup/${backupId}`);

/**
* Edit VCD Organization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
getVcdOrganizationQueryKey,
getVcdOrganizationBackupQueryKey,
} from '@/utils/queryKeys';
import { getBackupIdFromOrganization } from '@/utils/veeamBackupId';

interface IUseManagedVcdOrganization
extends Pick<UseQueryOptions, 'refetchOnWindowFocus' | 'refetchInterval'> {
Expand All @@ -35,10 +36,13 @@ const useManagedVcdOrganization = ({
});
};

export const useManagedVcdOrganizationBackup = (id: string) => {
export const useManagedVcdOrganizationBackup = (
vcdOrganization: IVcdOrganization,
) => {
return useQuery<ApiResponse<IVcdOrganizationBackup>, ApiError>({
queryKey: getVcdOrganizationBackupQueryKey(id),
queryFn: () => getVcdOrganizationBackup(id),
queryKey: getVcdOrganizationBackupQueryKey(vcdOrganization.id),
queryFn: () =>
getVcdOrganizationBackup(getBackupIdFromOrganization(vcdOrganization)),
retry: false,
placeholderData: keepPreviousData,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ function GeneralInformation() {
return (
<div className="grid xs:grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-8 px-10">
<OrganizationGenerationInformationTile
vcdOrganization={vcdOrganization?.data}
vcdOrganization={vcdOrganization.data}
/>
<div className="flex flex-col gap-8">
<OrganizationOptionsTile
isLicenseActive={!!vcdOrganization?.data?.currentState?.spla}
isLicenseActive={!!vcdOrganization.data?.currentState?.spla}
/>
<DataProtectionTile />
<DataProtectionTile vcdOrganization={vcdOrganization.data} />
</div>
<div>
<BillingTile id={id} />
Expand Down
Original file line number Diff line number Diff line change
@@ -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`;

0 comments on commit 0f77ae4

Please sign in to comment.