Skip to content

Commit

Permalink
add application tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasneirynck committed Oct 18, 2021
1 parent ba350bc commit 99ab557
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 32 deletions.
23 changes: 13 additions & 10 deletions x-pack/plugins/fleet/public/applications/integrations/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,21 @@ export function renderApp(
{ element, appBasePath, history, setHeaderActionMenu }: AppMountParameters,
config: FleetConfigType,
kibanaVersion: string,
extensions: UIExtensionsStorage
extensions: UIExtensionsStorage,
UsageTracker: React.FC
) {
ReactDOM.render(
<IntegrationsApp
basepath={appBasePath}
startServices={startServices}
config={config}
history={history}
kibanaVersion={kibanaVersion}
extensions={extensions}
setHeaderActionMenu={setHeaderActionMenu}
/>,
<UsageTracker>
<IntegrationsApp
basepath={appBasePath}
startServices={startServices}
config={config}
history={history}
kibanaVersion={kibanaVersion}
extensions={extensions}
setHeaderActionMenu={setHeaderActionMenu}
/>
</UsageTracker>,
element
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import React from 'react';
import styled from 'styled-components';
import { EuiCard, EuiFlexItem, EuiBadge, EuiToolTip, EuiSpacer } from '@elastic/eui';

import { TrackApplicationView } from 'src/plugins/usage_collection/public';

import { CardIcon } from '../../../../../components/package_icon';
import type { IntegrationCardItem } from '../../../../../../common/types/models/epm';

Expand Down Expand Up @@ -50,26 +52,28 @@ export function PackageCard({

const testid = `integration-card:${id}`;
return (
<Card
data-test-subj={testid}
layout="horizontal"
title={title || ''}
titleSize="xs"
description={description}
hasBorder
icon={
<CardIcon
icons={icons}
packageName={name}
integrationName={integration}
version={version}
size="xl"
/>
}
href={url}
target={url.startsWith('http') || url.startsWith('https') ? '_blank' : undefined}
>
{releaseBadge}
</Card>
<TrackApplicationView viewId={testid}>
<Card
data-test-subj={testid}
layout="horizontal"
title={title || ''}
titleSize="xs"
description={description}
hasBorder
icon={
<CardIcon
icons={icons}
packageName={name}
integrationName={integration}
version={version}
size="xl"
/>
}
href={url}
target={url.startsWith('http') || url.startsWith('https') ? '_blank' : undefined}
>
{releaseBadge}
</Card>
</TrackApplicationView>
);
}
16 changes: 15 additions & 1 deletion x-pack/plugins/fleet/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import React from 'react';
import type {
AppMountParameters,
CoreSetup,
Expand All @@ -23,6 +24,8 @@ import type {

import type { SharePluginStart } from 'src/plugins/share/public';

import type { UsageCollectionSetup } from '../../../../src/plugins/usage_collection/public';

import { DEFAULT_APP_CATEGORIES, AppNavLinkStatus } from '../../../../src/core/public';

import type {
Expand Down Expand Up @@ -77,6 +80,7 @@ export interface FleetSetupDeps {
cloud?: CloudSetup;
globalSearch?: GlobalSearchPluginSetup;
customIntegrations: CustomIntegrationsSetup;
usageCollection?: UsageCollectionSetup;
}

export interface FleetStartDeps {
Expand Down Expand Up @@ -141,7 +145,17 @@ export class FleetPlugin implements Plugin<FleetSetup, FleetStart, FleetSetupDep
cloud: deps.cloud,
};
const { renderApp, teardownIntegrations } = await import('./applications/integrations');
const unmount = renderApp(startServices, params, config, kibanaVersion, extensions);

const Tracker =
deps.usageCollection?.components.ApplicationUsageTrackingProvider ?? React.Fragment;
const unmount = renderApp(
startServices,
params,
config,
kibanaVersion,
extensions,
Tracker
);

return () => {
unmount();
Expand Down

0 comments on commit 99ab557

Please sign in to comment.