Skip to content

Commit

Permalink
Some more cleanup from analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
apuntovanini committed Nov 9, 2024
1 parent 0c9c16e commit d42d883
Show file tree
Hide file tree
Showing 126 changed files with 213 additions and 6,140 deletions.
11 changes: 7 additions & 4 deletions packages/core/accordion/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ export type AccordionPropTypesBase = {
export type AccordionPropTypes = AccordionPropTypesBase & {
onChange?: (expanded: string[]) => void;
/** Handler to be called on click. */
onClick?: (
{ event, item }: { event: KeyboardEvent | MouseEvent; item: any },
AnalyticsEventInterface,
) => void;
onClick?: ({
event,
item,
}: {
event: KeyboardEvent | MouseEvent;
item: any;
}) => void;
};
1 change: 0 additions & 1 deletion packages/core/avatar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"types": "dist/uidu-avatar.cjs.d.ts",
"dependencies": {
"@babel/runtime": "^7.25.6",
"@uidu/analytics": "^0.12.4",
"@uidu/theme": "^0.12.4",
"@uidu/tooltip": "^0.11.4",
"styled-components": "^5.3.11",
Expand Down
35 changes: 2 additions & 33 deletions packages/core/avatar/src/components/Avatar.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import {
createAndFireEvent,
withAnalyticsContext,
withAnalyticsEvents,
} from '@uidu/analytics';
import Tooltip from '@uidu/tooltip';
import React, { Component, ReactNode } from 'react';
import { getProps, getStyledAvatar } from '../helpers';
Expand All @@ -17,7 +12,6 @@ import {
SizeType,
} from '../types';
import { omit } from '../utils';
import pkg from '../version.json';
import AvatarImage from './AvatarImage';
import { propsOmittedFromClickData } from './constants';
import Presence from './Presence';
Expand All @@ -40,25 +34,6 @@ class Avatar extends Component<AvatarPropTypes> {
size: 'medium' as SizeType,
};

createAndFireEventOnGuidu = createAndFireEvent('uidu');

clickAnalyticsCaller = () => {
const { createAnalyticsEvent } = this.props;

return createAnalyticsEvent
? this.createAndFireEventOnGuidu({
action: 'clicked',
actionSubject: 'avatar',

attributes: {
componentName: 'avatar',
packageName: pkg.name,
packageVersion: pkg.version,
},
})(createAnalyticsEvent)
: undefined;
};

// expose blur/focus to consumers via ref
blur = () => {
if (this.ref) this.ref.blur();
Expand All @@ -77,9 +52,7 @@ class Avatar extends Component<AvatarPropTypes> {

const item = omit(this.props, ...propsOmittedFromClickData);

const analyticsEvent = this.clickAnalyticsCaller();

onClick({ item, event }, analyticsEvent);
onClick({ item, event });
};

// enforce status / presence rules
Expand Down Expand Up @@ -211,8 +184,4 @@ export const AvatarWithoutAnalytics = mapProps<AvatarPropTypes>({
),
})(withPseudoState(Avatar));

export default withAnalyticsContext({
componentName: 'avatar',
packageName: pkg.name,
packageVersion: pkg.version,
})(withAnalyticsEvents()(AvatarWithoutAnalytics));
export default AvatarWithoutAnalytics;
13 changes: 5 additions & 8 deletions packages/core/avatar/src/types.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { AnalyticsEvent, WithAnalyticsEventsProps } from '@uidu/analytics';
import { ThemeProp } from '@uidu/theme/components';
import { ComponentType, ReactNode } from 'react';
import { WithPseudoStateProps } from './hoc/withPseudoState';
Expand All @@ -21,14 +20,12 @@ export type IndicatorSizeType = 'small' | 'medium' | 'large' | 'xlarge';
export type StatusType = ('approved' | 'declined' | 'locked') | ReactNode;
export type StyledComponentType = 'custom' | 'button' | 'link' | 'span';

export type AvatarClickType = (
event: { event: React.MouseEvent; item: Record<string, any> },
analyticsEvent?: AnalyticsEvent,
) => void;
export type AvatarClickType = (event: {
event: React.MouseEvent;
item: Record<string, any>;
}) => void;

export interface AvatarPropTypes
extends WithAnalyticsEventsProps,
WithPseudoStateProps {
export interface AvatarPropTypes extends WithPseudoStateProps {
/** Indicates the shape of the avatar. Most avatars are circular, but square avatars
can be used for 'container' objects. */
appearance?: AppearanceType;
Expand Down
3 changes: 0 additions & 3 deletions packages/core/blanket/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
"sideEffects": false,
"main": "dist/uidu-blanket.cjs.js",
"module": "dist/uidu-blanket.esm.js",
"dependencies": {
"@uidu/analytics": "0.12.4"
},
"devDependencies": {
"@uidu/button": "^1.9.4",
"@uidu/docs": "^0.11.4",
Expand Down
21 changes: 2 additions & 19 deletions packages/core/blanket/src/Blanket.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { usePlatformLeafEventHandler } from '@uidu/analytics';
import React, { forwardRef, memo, MouseEvent, useCallback } from 'react';
import styled from 'styled-components';
import tw, { theme } from 'twin.macro';
Expand All @@ -22,12 +21,6 @@ const Div = styled.div<{
const packageName = process.env._PACKAGE_NAME_ as string;
const packageVersion = process.env._PACKAGE_VERSION_ as string;

const analyticsAttributes = {
componentName: 'blanket',
packageName,
packageVersion,
};

function StatelessBlanket(
{
shouldAllowClickThrough = false,
Expand All @@ -37,23 +30,13 @@ function StatelessBlanket(
paddingRight = 0,
className = null,
children,
analyticsContext,
}: BlanketProps,
ref,
) {
const onBlanketClickedWithAnalytics = usePlatformLeafEventHandler({
fn: onBlanketClicked,
action: 'clicked',
analyticsData: analyticsContext,
...analyticsAttributes,
});

const blanketClickOutsideChildren = useCallback(
(e: MouseEvent<HTMLDivElement>) =>
e.currentTarget === e.target
? onBlanketClickedWithAnalytics(e)
: undefined,
[onBlanketClickedWithAnalytics],
e.currentTarget === e.target ? onBlanketClicked(e) : undefined,
[onBlanketClicked],
);

const onClick = shouldAllowClickThrough
Expand Down
10 changes: 1 addition & 9 deletions packages/core/blanket/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { UIAnalyticsEvent } from '@uidu/analytics';
import { ReactNode } from 'react';

export interface BlanketProps {
Expand All @@ -13,14 +12,7 @@ export interface BlanketProps {
/**
* Handler function to be called when the blanket is clicked.
*/
onBlanketClicked?: (
event: React.MouseEvent<HTMLDivElement>,
analyticsEvent: UIAnalyticsEvent,
) => void;
/**
* Additional information to be included in the `context` of analytics events.
*/
analyticsContext?: Record<string, any>;
onBlanketClicked?: (event: React.MouseEvent<HTMLDivElement>) => void;
/**
* A `testId` prop is provided for specified elements,
* which is a unique string that appears as a data attribute `data-testid` in the rendered code,
Expand Down
1 change: 0 additions & 1 deletion packages/core/button/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"module": "dist/uidu-button.esm.js",
"dependencies": {
"@babel/runtime": "^7.25.6",
"@uidu/analytics": "^0.12.4",
"@uidu/spinner": "^0.11.4",
"@uidu/theme": "^0.12.4",
"memoize-one": "^6.0.0",
Expand Down
7 changes: 1 addition & 6 deletions packages/core/button/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { UIAnalyticsEvent } from '@uidu/analytics';
import * as React from 'react';
import { LinkProps } from 'react-router-dom';

Expand Down Expand Up @@ -50,11 +49,7 @@ export type OnlyButtonProps = {
isSelected?: boolean;
/** Handler to be called on blur */
onBlur?: React.FocusEventHandler<HTMLElement>;
/** Handler to be called on click. The second argument can be used to track analytics data. See the tutorial in the analytics-next package for details */
onClick?: (
e: React.MouseEvent<HTMLElement>,
analyticsEvent: UIAnalyticsEvent,
) => void;
onClick?: (e: React.MouseEvent<HTMLElement>) => void;
onMouseDown?: React.MouseEventHandler<HTMLElement>;
onMouseEnter?: React.MouseEventHandler<HTMLElement>;
onMouseLeave?: React.MouseEventHandler<HTMLElement>;
Expand Down
1 change: 0 additions & 1 deletion packages/core/drawer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"types": "dist/uidu-drawer.cjs.d.ts",
"dependencies": {
"@babel/runtime": "^7.25.6",
"@uidu/analytics": "^0.12.4",
"@uidu/blanket": "^0.7.11",
"@uidu/docs": "^0.11.4",
"@uidu/item": "^0.11.4",
Expand Down
48 changes: 8 additions & 40 deletions packages/core/drawer/src/components/Drawer.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,14 @@
import {
createAndFireEvent,
withAnalyticsContext,
withAnalyticsEvents,
} from '@uidu/analytics';
import Blanket from '@uidu/blanket';
import { canUseDOM } from 'exenv';
import * as React from 'react';
import { createPortal } from 'react-dom';
import { TransitionGroup } from 'react-transition-group';
import { CloseTrigger, DrawerProps } from '../types';
import pkg from '../version.json';
import { DrawerProps } from '../types';
import DrawerPrimitive from './DrawerPrimitive';
import { Fade } from './transitions';

const OnlyChild = ({ children }) => React.Children.toArray(children)[0] || null;

const createAndFireEventOnGuidu = createAndFireEvent('uidu');

const createAndFireOnClick = (
createAnalyticsEvent: any,
trigger: CloseTrigger,
) =>
createAndFireEventOnGuidu({
action: 'dismissed',
actionSubject: 'drawer',
attributes: {
componentName: 'drawer',
packageName: pkg.name,
packageVersion: pkg.version,
trigger,
},
})(createAnalyticsEvent);

export class DrawerBase extends React.Component<DrawerProps> {
static defaultProps = {
width: 'narrow',
Expand Down Expand Up @@ -66,31 +43,26 @@ export class DrawerBase extends React.Component<DrawerProps> {
}

handleBlanketClick = (event: React.MouseEvent) => {
this.handleClose(event, 'blanket');
this.handleClose(event);
};

handleBackButtonClick = (event: React.MouseEvent) => {
this.handleClose(event, 'backButton');
this.handleClose(event);
};

handleClose = (
event: React.KeyboardEvent | React.MouseEvent,
trigger: CloseTrigger,
) => {
const { createAnalyticsEvent, onClose } = this.props;

const analyticsEvent = createAndFireOnClick(createAnalyticsEvent, trigger);
handleClose = (event: React.KeyboardEvent | React.MouseEvent) => {
const { onClose } = this.props;

if (onClose) {
onClose(event, analyticsEvent);
onClose(event);
}
};

handleKeyDown = (event: React.KeyboardEvent) => {
const { isOpen, onKeyDown } = this.props;

if (event.key === 'Escape' && isOpen) {
this.handleClose(event, 'escKey');
this.handleClose(event);
}
if (onKeyDown) {
onKeyDown(event);
Expand Down Expand Up @@ -145,8 +117,4 @@ export class DrawerBase extends React.Component<DrawerProps> {
}
}

export default withAnalyticsContext({
componentName: 'drawer',
packageName: pkg.name,
packageVersion: pkg.version,
})(withAnalyticsEvents()(DrawerBase));
export default DrawerBase;
29 changes: 12 additions & 17 deletions packages/core/drawer/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { WithAnalyticsEventsProps } from '@uidu/analytics';
import * as React from 'react';

export type DrawerSize = 'narrow' | 'medium' | 'wide' | 'extended' | 'full';
Expand Down Expand Up @@ -28,26 +27,22 @@ export type DrawerPrimitiveProps = BaseProps & {
shouldUnmountOnExit?: boolean;
};

export type DrawerProps = BaseProps &
WithAnalyticsEventsProps & {
/**
export type DrawerProps = BaseProps & {
/**
Callback function to be called when the drawer will be closed.
*/
onClose?: (
event: React.MouseEvent | React.KeyboardEvent,
analyticsEvent: any,
) => void;
/** A callback function that will be called when the drawer has finished its close transition. */
onCloseComplete?: () => void;
/**
onClose?: (event: React.MouseEvent | React.KeyboardEvent) => void;
/** A callback function that will be called when the drawer has finished its close transition. */
onCloseComplete?: () => void;
/**
Callback function that will be called when the drawer is displayed and `keydown` event is triggered.
*/
onKeyDown?: (event: React.KeyboardEvent) => void;
/** Controls if the drawer is open or close */
isOpen: boolean;
/** Boolean that controls if drawer should be retained/discarded */
shouldUnmountOnExit?: boolean;
};
onKeyDown?: (event: React.KeyboardEvent) => void;
/** Controls if the drawer is open or close */
isOpen: boolean;
/** Boolean that controls if drawer should be retained/discarded */
shouldUnmountOnExit?: boolean;
};

/**
Type of keyboard event that triggers which key will should close the drawer.
Expand Down
1 change: 0 additions & 1 deletion packages/core/dropdown-menu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"dependencies": {
"@atlaskit/icon": "^21.12.8",
"@babel/runtime": "^7.25.6",
"@uidu/analytics": "^0.12.4",
"@uidu/button": "^1.9.4",
"@uidu/droplist": "^0.11.4",
"@uidu/item": "^0.11.4",
Expand Down
Loading

0 comments on commit d42d883

Please sign in to comment.