Skip to content

Commit 38cc81c

Browse files
committed
ref: extract defaultCreateButtonTracking
1 parent 633f26d commit 38cc81c

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

static/app/components/core/button/useButtonFunctionality.tsx

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,12 @@ import type {
66
DO_NOT_USE_LinkButtonProps as LinkButtonProps,
77
} from './types';
88

9-
export function useButtonFunctionality(props: ButtonProps | LinkButtonProps) {
10-
// Fallbacking aria-label to string children is not necessary as screen
11-
// readers natively understand that scenario. Leaving it here for a bunch of
12-
// our tests that query by aria-label.
13-
const accessibleLabel =
14-
props['aria-label'] ??
15-
(typeof props.children === 'string' ? props.children : undefined);
16-
17-
const useButtonTrackingLogger = () => {
18-
const hasAnalyticsDebug = window.localStorage?.getItem('DEBUG_ANALYTICS') === '1';
9+
const defaultCreateButtonTracking = (props: ButtonProps) => {
10+
const hasAnalyticsDebug = window.localStorage?.getItem('DEBUG_ANALYTICS') === '1';
11+
return () => {
1912
const hasCustomAnalytics =
2013
props.analyticsEventName || props.analyticsEventKey || props.analyticsParams;
21-
if (!hasCustomAnalytics || !hasAnalyticsDebug) {
22-
return () => {};
23-
}
24-
25-
return () => {
14+
if (hasCustomAnalytics && hasAnalyticsDebug) {
2615
// eslint-disable-next-line no-console
2716
console.log('buttonAnalyticsEvent', {
2817
eventKey: props.analyticsEventKey,
@@ -31,13 +20,22 @@ export function useButtonFunctionality(props: ButtonProps | LinkButtonProps) {
3120
href: 'href' in props ? props.href : undefined,
3221
...props.analyticsParams,
3322
});
34-
};
23+
}
3524
};
25+
};
26+
27+
export function useButtonFunctionality(props: ButtonProps | LinkButtonProps) {
28+
// Fallbacking aria-label to string children is not necessary as screen
29+
// readers natively understand that scenario. Leaving it here for a bunch of
30+
// our tests that query by aria-label.
31+
const accessibleLabel =
32+
props['aria-label'] ??
33+
(typeof props.children === 'string' ? props.children : undefined);
3634

37-
const useButtonTracking =
38-
HookStore.get('react-hook:use-button-tracking')[0] ?? useButtonTrackingLogger;
35+
const createButtonTracking =
36+
HookStore.get('react-hook:use-button-tracking')[0] ?? defaultCreateButtonTracking;
3937

40-
const buttonTracking = useButtonTracking({
38+
const buttonTracking = createButtonTracking({
4139
analyticsEventName: props.analyticsEventName,
4240
analyticsEventKey: props.analyticsEventKey,
4341
analyticsParams: {

0 commit comments

Comments
 (0)