Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ui] add tracking to launch all button #26411

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {showCustomAlert} from '../app/CustomAlertProvider';
import {PYTHON_ERROR_FRAGMENT} from '../app/PythonErrorFragment';
import {PythonErrorInfo} from '../app/PythonErrorInfo';
import {assertUnreachable} from '../app/Util';
import {useTrackEvent} from '../app/analytics';
import {TimeContext} from '../app/time/TimeContext';
import {timestampToString} from '../app/time/timestampToString';
import {PythonErrorFragment} from '../app/types/PythonErrorFragment.types';
Expand Down Expand Up @@ -77,6 +78,8 @@ export const EvaluateScheduleDialog = (props: Props) => {
};

const EvaluateSchedule = ({repoAddress, name, onClose, jobName}: Props) => {
const trackEvent = useTrackEvent();

const [selectedTimestamp, setSelectedTimestamp] = useState<{ts: number; label: string}>();
const scheduleSelector: ScheduleSelector = useMemo(
() => ({
Expand Down Expand Up @@ -181,6 +184,8 @@ const EvaluateSchedule = ({repoAddress, name, onClose, jobName}: Props) => {
if (!canLaunchAll) {
return;
}

trackEvent('launch-all-schedule');
setLaunching(true);

try {
Expand All @@ -193,7 +198,7 @@ const EvaluateSchedule = ({repoAddress, name, onClose, jobName}: Props) => {

setLaunching(false);
onClose();
}, [canLaunchAll, executionParamsList, launchMultipleRunsWithTelemetry, onClose]);
}, [canLaunchAll, executionParamsList, launchMultipleRunsWithTelemetry, onClose, trackEvent]);

const content = useMemo(() => {
// launching all runs state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {showSharedToaster} from '../app/DomUtils';
import {PYTHON_ERROR_FRAGMENT} from '../app/PythonErrorFragment';
import {PythonErrorInfo} from '../app/PythonErrorInfo';
import {assertUnreachable} from '../app/Util';
import {useTrackEvent} from '../app/analytics';
import {PythonErrorFragment} from '../app/types/PythonErrorFragment.types';
import {SensorSelector} from '../graphql/types';
import {useLaunchMultipleRunsWithTelemetry} from '../launchpad/useLaunchMultipleRunsWithTelemetry';
Expand Down Expand Up @@ -74,6 +75,8 @@ export const SensorDryRunDialog = (props: Props) => {
};

const SensorDryRun = ({repoAddress, name, currentCursor, onClose, jobName}: Props) => {
const trackEvent = useTrackEvent();

const [sensorDryRun] = useMutation<SensorDryRunMutation, SensorDryRunMutationVariables>(
EVALUATE_SENSOR_MUTATION,
);
Expand Down Expand Up @@ -187,6 +190,8 @@ const SensorDryRun = ({repoAddress, name, currentCursor, onClose, jobName}: Prop
if (!canLaunchAll) {
return;
}

trackEvent('launch-all-sensor');
setLaunching(true);

try {
Expand All @@ -206,6 +211,7 @@ const SensorDryRun = ({repoAddress, name, currentCursor, onClose, jobName}: Prop
launchMultipleRunsWithTelemetry,
onClose,
onCommitTickResult,
trackEvent,
]);

const leftButtons = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import userEvent from '@testing-library/user-event';
import {MemoryRouter, useHistory} from 'react-router-dom';

import {Resolvers} from '../../apollo-client';
import {useTrackEvent} from '../../app/analytics';
import {EvaluateScheduleDialog} from '../EvaluateScheduleDialog';
import {
GetScheduleQueryMock,
Expand All @@ -26,6 +27,11 @@ jest.mock('react-router-dom', () => ({
useHistory: jest.fn(),
}));

// Mocking useTrackEvent
jest.mock('../../app/analytics', () => ({
useTrackEvent: jest.fn(() => jest.fn()),
}));

const onCloseMock = jest.fn();

function Test({mocks, resolvers}: {mocks?: MockedResponse[]; resolvers?: Resolvers}) {
Expand Down Expand Up @@ -119,6 +125,8 @@ describe('EvaluateScheduleTest', () => {
createHref: createHrefSpy,
});

(useTrackEvent as jest.Mock).mockReturnValue(jest.fn());

render(
<MemoryRouter initialEntries={['/automation']}>
<Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import userEvent from '@testing-library/user-event';
import {MemoryRouter, useHistory} from 'react-router-dom';

import {Resolvers} from '../../apollo-client';
import {useTrackEvent} from '../../app/analytics';
import {SensorDryRunDialog} from '../SensorDryRunDialog';
import * as Mocks from '../__fixtures__/SensorDryRunDialog.fixtures';

Expand All @@ -20,6 +21,11 @@ jest.mock('react-router-dom', () => ({
useHistory: jest.fn(),
}));

// Mocking useTrackEvent
jest.mock('../../app/analytics', () => ({
useTrackEvent: jest.fn(() => jest.fn()),
}));

const onCloseMock = jest.fn();

function Test({mocks, resolvers}: {mocks?: MockedResponse[]; resolvers?: Resolvers}) {
Expand Down Expand Up @@ -98,6 +104,8 @@ describe('SensorDryRunTest', () => {
createHref: createHrefSpy,
});

(useTrackEvent as jest.Mock).mockReturnValue(jest.fn());

render(
<MemoryRouter initialEntries={['/automation']}>
<Test
Expand Down
Loading