Skip to content

Commit

Permalink
feat(generator): implemente useovhtracking hook
Browse files Browse the repository at this point in the history
ref: MANAGER-13929

Signed-off-by: Alex Boungnaseng <alex.boungnaseng.ext@corp.ovh.com>
  • Loading branch information
aboungnaseng-ovhcloud committed Apr 16, 2024
1 parent b512795 commit 43c1465
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 168 deletions.
5 changes: 1 addition & 4 deletions packages/components/ovh-at-internet/src/ovh-at-internet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { capitalize, isString, mapValues, trimEnd } from 'lodash-es';
import { capitalize, isString, mapValues } from 'lodash-es';
import { OvhAtInternetConfig } from './config';
import {
IOvhAtInternetTrack,
Expand All @@ -16,7 +16,6 @@ import { loadManagerTMS } from './manager-tms';
import { debug } from './utils';

import initMixCommander from './mix-commander';
import { toBeRequired } from '@testing-library/jest-dom/matchers';

function getPageTrackingData(
page: LegacyTrackingData,
Expand Down Expand Up @@ -108,7 +107,6 @@ export default class OvhAtInternet extends OvhAtInternetConfig {
}

canTrack(): boolean {
return true;
return this.isDefaultSet() && this.enabled && this.tag;
}

Expand All @@ -126,7 +124,6 @@ export default class OvhAtInternet extends OvhAtInternetConfig {
}

shouldUsePianoAnalytics() {
return true;
if (isTrackingDebug()) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,10 @@ export default function DashboardPage() {
title: serviceName,
};

const linkProps = {
label: t('manager_dashboard_back_link'),
href: '/',
target: OdsHTMLAnchorElementTarget._blank,
type: LinkType.back,
};

const onClickReturn = (href: string) => navigate(href);

return (
<div>
<DashboardLayout
header={header}
{{#if this.isPCI}}
{{else}}
linkProps={linkProps}
onClickReturn={() => onClickReturn(linkProps.href)}
{{/if}}
tabs={
<OsdsTabs panel={panel}>
<OsdsTabBar slot="top">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import { useTranslation } from "react-i18next";
import { Card, OnboardingLayout } from "@ovhcloud/manager-components";
import { useGuideUtils } from '@/hooks/useGuideUtils';
import useGuideUtils from '@/hooks/useGuideUtils';
import Breadcrumb from '@/components/Breadcrumb/Breadcrumb';
import onboardingImgSrc from "./onboarding-img.png";

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,16 @@ interface GuideLinkProps {
}

function useGuideUtils() {
const { subsidiary } = useAuthentication();
const [linkTabs, setLinkTabs] = useState<GuideLinkProps>({});

useEffect(() => {
setLinkTabs(getGuideListLink({ subsidiary: subsidiary as CountryCode }));
}, [subsidiary]);
try {
const { subsidiary } = useAuthentication();
useEffect(() => {
setLinkTabs(getGuideListLink({ subsidiary: subsidiary as CountryCode }));
}, [subsidiary]);
} catch (error) {
console.error('error: useGuideUtils : ', error);
}

return linkTabs;
}
Expand Down
13 changes: 12 additions & 1 deletion packages/manager/core/generator/app/templates/src/index.tsx.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,19 @@ import '@ovhcloud/ods-theme-blue-jeans/dist/index.css';
import './global.css';
import './vite-hmr';

import { UNIVERSE, SUB_UNIVERSE, APP_NAME, LEVEL2 } from './tracking.constant';

const trackingContext = {
chapter1: UNIVERSE,
chapter2: SUB_UNIVERSE,
chapter3: APP_NAME,
appName: APP_NAME,
level2: LEVEL2,
pageTheme: UNIVERSE,
};

const init = async (appName: string) => {
const context = await initShellContext(appName);
const context = await initShellContext(appName, trackingContext);

await initI18n({
context,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,32 @@
import React, { useEffect, useContext } from 'react';
import { defineCurrentPage } from '@ovh-ux/request-tagger';
import { Outlet, useLocation, useMatches } from 'react-router-dom';
import { useRouting } from '@ovh-ux/manager-react-shell-client';
import { ShellContext } from '@ovh-ux/manager-react-shell-client';

import {
useOvhCustomTracking,
} from '@/hooks/useCustomTracking';
useOvhTracking,
useRouteSynchro,
} from '@ovh-ux/manager-react-shell-client';

export default function Layout() {
const location = useLocation();
const routing = useRouting();
const { shell } = useContext(ShellContext);
const matches = useMatches();
const { trackClick } = useOvhCustomTracking();
const { trackCurrentPage } = useOvhTracking();
useRouteSynchro();

useEffect(() => {
const match = matches.slice(-1);
defineCurrentPage(`app.{{appName}}-${match[0]?.id}`);
}, [location]);

useEffect(() => {
trackPage();
trackCurrentPage();
}, [location]);

useEffect(() => {
shell.ux.hidePreloader();
}, []);

useEffect(() => {
routing.stopListenForHashChange();
}, []);

useEffect(() => {
routing.onHashChange();
}, [location]);

return <Outlet />;
}
50 changes: 37 additions & 13 deletions packages/manager/core/generator/app/templates/src/routes.tsx.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { RouteObject } from 'react-router-dom';
import NotFound from './pages/404';
import { PageType } from './hooks/useCustomTracking';
import { PageType } from '@ovh-ux/manager-react-shell-client';

const lazyRouteConfig = (importFn: CallableFunction): Partial<RouteObject> => {
return {
Expand All @@ -25,6 +25,12 @@ export const Routes: any = [
id: 'listing',
path: '',
...lazyRouteConfig(() => import('@/pages/listing')),
handle: {
tracking: {
pageName: 'listing',
pageType: PageType.listing,
},
},
},
{
path: ':serviceName',
Expand All @@ -34,18 +40,36 @@ export const Routes: any = [
id: 'dashboard',
path: '',
...lazyRouteConfig(() => import('@/pages/dashboard/index')),
handle: {
tracking: {
pageName: 'dashboard',
pageType: PageType.dashboard,
},
},
},
{
id: 'tab2',
path: 'Tab2',
...lazyRouteConfig(() => import('@/pages/dashboard/Tab2')),
handle: {
tracking: {
pageName: 'tab2',
pageType: PageType.dashboard,
},
},
},
],
},
{
id: 'onboarding',
path: 'onboarding',
...lazyRouteConfig(() => import('@/pages/onboarding')),
handle: {
tracking: {
pageName: 'onboarding',
pageType: PageType.onboarding,
},
},
},
],
},
Expand All @@ -65,9 +89,9 @@ export const Routes: any = [
path: '',
...lazyRouteConfig(() => import('@/pages/listing')),
handle: {
OvhTracking: {
name: 'listing',
type: PageType.listing,
tracking: {
pageName: 'listing',
pageType: PageType.listing,
},
},
},
Expand All @@ -81,9 +105,9 @@ export const Routes: any = [
...lazyRouteConfig(
() => import('@/pages/dashboard/index')),
handle: {
OvhTracking: {
name: 'dashboard',
type: PageType.dashboard,
tracking: {
pageName: 'dashboard',
pageType: PageType.dashboard,
},
},
},
Expand All @@ -93,9 +117,9 @@ export const Routes: any = [
...lazyRouteConfig(
() => import('@/pages/dashboard/Tab2')),
handle: {
OvhTracking: {
name: 'tab2',
type: PageType.dashboard,
tracking: {
pageName: 'tab2',
pageType: PageType.dashboard,
},
},
},
Expand All @@ -106,9 +130,9 @@ export const Routes: any = [
path: 'onboarding',
...lazyRouteConfig(() => import('@/pages/onboarding')),
handle: {
OvhTracking: {
name: 'tab2',
type: PageType.onboarding,
tracking: {
pageName: 'onboarding',
pageType: PageType.onboarding,
},
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export const LEVEL2 = '86';
export const UNIVERSE = '{{universe}}';
export const SUBUNIVERSE = '{{subuniverse}}';
export const SUB_UNIVERSE = '{{subuniverse}}';
export const APP_NAME = '{{appName}}'
export const PAGE_PREFIX = [UNIVERSE, SUBUNIVERSE, APP_NAME].join('::');
Loading

0 comments on commit 43c1465

Please sign in to comment.