Skip to content

Commit

Permalink
feat(kms): add tracking batch 2 and 3
Browse files Browse the repository at this point in the history
ref: MANAGER-15195

Signed-off-by: Romain Jamet <[email protected]>
  • Loading branch information
Romain Jamet committed Nov 15, 2024
1 parent 8486ffa commit 78fb1db
Show file tree
Hide file tree
Showing 20 changed files with 528 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,18 @@ export const DatagridActionMenu = (props: OKMS) => {

export const DatagridServiceKeyCellName = (props: OkmsAllServiceKeys) => {
const navigate = useNavigate();
const { trackClick } = useOvhTracking();

return (
<div>
<Links
onClickReturn={() => {
trackClick({
location: PageLocation.datagrid,
buttonType: ButtonType.link,
actionType: 'navigation',
actions: ['details_encryption_key'],
});
navigate(`${props?.id}`);
}}
label={props?.name}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import {
Links,
} from '@ovh-ux/manager-react-components';
import { ODS_THEME_COLOR_INTENT } from '@ovhcloud/ods-common-theming';
import {
ButtonType,
PageLocation,
useOvhTracking,
} from '@ovh-ux/manager-react-shell-client';
import { OkmsCredential } from '@/types/okmsCredential.type';
import { useFormattedDate } from '@/hooks/useFormattedDate';
import { CredentialStatus } from '../credentialStatus/CredentialStatus.component';
Expand All @@ -19,10 +24,17 @@ import { kmsIamActions } from '@/utils/iam/iam.constants';

export const DatagridCredentialCellName = (credential: OkmsCredential) => {
const navigate = useNavigate();
const { trackClick } = useOvhTracking();
return (
<div>
<Links
onClickReturn={() => {
trackClick({
location: PageLocation.datagrid,
buttonType: ButtonType.link,
actionType: 'action',
actions: ['details_access_certificate'],
});
navigate(`${credential.id}`);
}}
label={credential.name}
Expand Down Expand Up @@ -86,7 +98,7 @@ export const DatagridCredentialCellActions = (credential: OkmsCredential) => {
const { t } = useTranslation('key-management-service/credential');
const okms = useContext(OkmsContext);
const navigate = useNavigate();

const { trackClick } = useOvhTracking();
const { filename, href, isDisabled } = getDownloadCredentialParameters(
credential,
);
Expand All @@ -98,15 +110,29 @@ export const DatagridCredentialCellActions = (credential: OkmsCredential) => {
href,
download: filename,
disabled: isDisabled,
onClick: () =>
trackClick({
location: PageLocation.datagrid,
buttonType: ButtonType.link,
actionType: 'action',
actions: ['download_access_certificate'],
}),
},
{
id: 2,
label: t('key_management_service_credential_delete'),
color: ODS_THEME_COLOR_INTENT.error,
iamActions: [kmsIamActions.credentialDelete],
urn: okms.iam.urn,
onClick: () =>
navigate(`${ROUTES_URLS.credentialDelete}/${credential.id}`),
onClick: () => {
trackClick({
location: PageLocation.datagrid,
buttonType: ButtonType.link,
actionType: 'action',
actions: ['delete_access_certificate'],
});
navigate(`${ROUTES_URLS.credentialDelete}/${credential.id}`);
},
},
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ import {
} from '@ovhcloud/ods-components';
import { ODS_THEME_COLOR_INTENT } from '@ovhcloud/ods-common-theming';
import { useNotifications } from '@ovh-ux/manager-react-components';
import {
ButtonType,
PageLocation,
PageType,
useOvhTracking,
} from '@ovh-ux/manager-react-shell-client';
import Modal from '@/components/Modal/Modal';

import { useUpdateOkmsServiceKey } from '@/data/hooks/useUpdateOkmsServiceKey';
Expand All @@ -41,7 +47,7 @@ export const ServiceKeyDeactivateModal = ({
const { addSuccess, clearNotifications } = useNotifications();
const { t } = useTranslation('key-management-service/serviceKeys');
const { t: tCommon } = useTranslation('key-management-service/common');

const { trackClick, trackPage } = useOvhTracking();
const navigate = useNavigate();

const closeModal = () => navigate('..');
Expand All @@ -55,9 +61,19 @@ export const ServiceKeyDeactivateModal = ({
t('key_management_service_service-keys_deactivation_success'),
true,
);
trackPage({
pageType: PageType.bannerSuccess,
pageName: 'deactivate_encryption_key',
});
closeModal();
},
onError: () => {
trackPage({
pageType: PageType.bannerError,
pageName: 'deactivate_encryption_key',
});
closeModal();
},
onError: closeModal,
});

const onUpdateServiceKeyStatus = () => {
Expand Down Expand Up @@ -140,6 +156,12 @@ export const ServiceKeyDeactivateModal = ({
variant={ODS_BUTTON_VARIANT.stroked}
color={ODS_THEME_COLOR_INTENT.primary}
onClick={() => {
trackClick({
location: PageLocation.popup,
buttonType: ButtonType.button,
actionType: 'action',
actions: ['cancel'],
});
navigate('..');
}}
>
Expand All @@ -149,7 +171,15 @@ export const ServiceKeyDeactivateModal = ({
disabled={!deactivationReason || isPending || undefined}
slot="actions"
color={ODS_THEME_COLOR_INTENT.primary}
onClick={onUpdateServiceKeyStatus}
onClick={() => {
trackClick({
location: PageLocation.popup,
buttonType: ButtonType.button,
actionType: 'action',
actions: ['confirm'],
});
onUpdateServiceKeyStatus();
}}
aria-label="edit-name-okms"
>
{t('key_management_service_service-keys_deactivation_button_confirm')}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
import { PageType, useOvhTracking } from '@ovh-ux/manager-react-shell-client';
import {
OsdsButton,
OsdsFormField,
Expand Down Expand Up @@ -40,6 +41,7 @@ export const ServiceKeyEditNameModal = ({
const { addSuccess, clearNotifications } = useNotifications();
const { t } = useTranslation('key-management-service/serviceKeys');
const { t: tCommon } = useTranslation('key-management-service/common');
const { trackPage } = useOvhTracking();

const navigate = useNavigate();

Expand All @@ -54,9 +56,19 @@ export const ServiceKeyEditNameModal = ({
t('key_management_service_service-keys_update_name_success'),
true,
);
trackPage({
pageType: PageType.bannerSuccess,
pageName: 'rename_encryption_key',
});
closeModal();
},
onError: () => {
trackPage({
pageType: PageType.bannerError,
pageName: 'rename_encryption_key',
});
closeModal();
},
onError: closeModal,
});

const getErrorMessage = (error: ServiceKeyNameErrorsType) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ vi.mock('react-router-dom', () => ({
useNavigate: vi.fn(() => vi.fn()),
}));

vi.mock('@ovh-ux/manager-react-shell-client', async (importOriginal) => {
const mod = await importOriginal<
typeof import('@ovh-ux/manager-react-shell-client')
>();

return {
...mod,
useOvhTracking: vi.fn(() => vi.fn()),
};
});

vi.mock('@/data/hooks/useDeleteOkmsServiceKey', () => ({
useDeleteOkmsServiceKey: vi.fn(() => ({
deleteKmsServiceKey: vi.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import {
import { ODS_THEME_COLOR_INTENT } from '@ovhcloud/ods-common-theming';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
import {
ButtonType,
PageLocation,
PageType,
useOvhTracking,
} from '@ovh-ux/manager-react-shell-client';
import { useDeleteOkmsServiceKey } from '@/data/hooks/useDeleteOkmsServiceKey';
import { useUpdateOkmsServiceKey } from '@/data/hooks/useUpdateOkmsServiceKey';
import { ROUTES_URLS } from '@/routes/routes.constants';
Expand All @@ -24,6 +30,9 @@ const useServiceKeyActionsList = (
const { t } = useTranslation('key-management-service/serviceKeys');
const { addSuccess, clearNotifications } = useNotifications();
const navigate = useNavigate();
const { trackClick, trackPage } = useOvhTracking();
const trackLocation = isListMode ? PageLocation.datagrid : PageLocation.page;

const {
deleteKmsServiceKey,
isPending: deleteIsPending,
Expand All @@ -32,8 +41,17 @@ const useServiceKeyActionsList = (
keyId: okmsKey?.id,
onSuccess: () => {
navigate(`/${okms.id}/${ROUTES_URLS.keys}`);
trackPage({
pageType: PageType.bannerSuccess,
pageName: 'delete_encryption_key',
});
},
onError: () => {
trackPage({
pageType: PageType.bannerError,
pageName: 'delete_encryption_key',
});
},
onError: () => {},
});

const {
Expand All @@ -48,8 +66,17 @@ const useServiceKeyActionsList = (
t('key_management_service_service-keys_reactivate_success'),
true,
);
trackPage({
pageType: PageType.bannerSuccess,
pageName: 'reactivate_encryption_key',
});
},
onError: () => {
trackPage({
pageType: PageType.bannerError,
pageName: 'reactivate_encryption_key',
});
},
onError: () => {},
});

const items: ActionMenuItem[] = [];
Expand All @@ -64,6 +91,14 @@ const useServiceKeyActionsList = (
JSON.stringify(okmsKey?.keys),
)}`,
download: `${okmsKey?.name}.jwk`,
onClick: () => {
trackClick({
location: trackLocation,
buttonType: ButtonType.button,
actionType: 'action',
actions: ['download_encryption_key'],
});
},
});
}
if (okmsKey?.state === OkmsServiceKeyState.active) {
Expand All @@ -72,6 +107,12 @@ const useServiceKeyActionsList = (
label: t('key_management_service_service-keys_link_deactivate_key'),
color: ODS_THEME_COLOR_INTENT.primary,
onClick: () => {
trackClick({
location: trackLocation,
buttonType: ButtonType.button,
actionType: 'action',
actions: ['deactivate_encryption_key'],
});
return isListMode
? navigate(`${ROUTES_URLS.serviceKeyDeactivate}/${okmsKey?.id}`)
: navigate(
Expand All @@ -94,12 +135,20 @@ const useServiceKeyActionsList = (
label: t('key_management_service_service-keys_link_reactivate_key'),
color: ODS_THEME_COLOR_INTENT.primary,
disabled: updateIsPending,
onClick: () => updateKmsServiceKey({ state: OkmsServiceKeyState.active }),
iamActions: [
kmsIamActions.serviceKeyUpdate,
kmsIamActions.serviceKeyActivate,
],
urn: okmsKey?.iam.urn,
onClick: () => {
trackClick({
location: trackLocation,
buttonType: ButtonType.button,
actionType: 'action',
actions: ['reactivate_encryption_key'],
});
updateKmsServiceKey({ state: OkmsServiceKeyState.active });
},
});
}
if (
Expand All @@ -112,9 +161,17 @@ const useServiceKeyActionsList = (
color: ODS_THEME_COLOR_INTENT.error,
disabled:
okmsKey?.state === OkmsServiceKeyState.active || deleteIsPending,
onClick: () => deleteKmsServiceKey(),
iamActions: [kmsIamActions.serviceKeyDelete],
urn: okmsKey?.iam.urn,
onClick: () => {
trackClick({
location: trackLocation,
buttonType: ButtonType.button,
actionType: 'action',
actions: ['delete_encryption_key'],
});
deleteKmsServiceKey();
},
});
}
return items;
Expand Down
Loading

0 comments on commit 78fb1db

Please sign in to comment.