Skip to content

Commit 3d04404

Browse files
authored
refactor: re-write actions to typescript and implement new analytics API (#626)
* refactor: re-write actions to typescript and implement new analytics API * fix: fix static accepter action naming
1 parent 5a3c821 commit 3d04404

File tree

75 files changed

+1293
-1255
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1293
-1255
lines changed

lib/common-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
COMMITED
1717
} from './constants';
1818

19-
import {CHECKED, INDETERMINATE, UNCHECKED} from './constants/checked-statuses';
19+
import {CHECKED, CheckStatus, INDETERMINATE, UNCHECKED} from './constants/checked-statuses';
2020
import {
2121
ImageBase64,
2222
ImageBuffer,
@@ -247,7 +247,7 @@ export const normalizeUrls = (urls: string[] = [], baseUrl: string): string[] =>
247247
export const isCheckboxChecked = (status: number): boolean => Number(status) === CHECKED;
248248
export const isCheckboxIndeterminate = (status: number): boolean => Number(status) === INDETERMINATE;
249249
export const isCheckboxUnchecked = (status: number): boolean => Number(status) === UNCHECKED;
250-
export const getToggledCheckboxState = (status: number): number => isCheckboxChecked(status) ? UNCHECKED : CHECKED;
250+
export const getToggledCheckboxState = (status: number): CheckStatus => isCheckboxChecked(status) ? UNCHECKED : CHECKED;
251251

252252
export function getDetailsFileName(testId: string, browserId: string, attempt: number): string {
253253
return `${testId}-${browserId}_${Number(attempt) + 1}_${Date.now()}.json`;

lib/static/components/controls/accept-opened-button.jsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ import PropTypes from 'prop-types';
55
import * as actions from '../../modules/actions';
66
import ControlButton from './control-button';
77
import {getAcceptableOpenedImageIds} from '../../modules/selectors/tree';
8+
import {AnalyticsContext} from '@/static/new-ui/providers/analytics';
89

910
class AcceptOpenedButton extends Component {
11+
static contextType = AnalyticsContext;
12+
1013
static propTypes = {
1114
isSuiteContol: PropTypes.bool,
1215
// from store
@@ -16,11 +19,14 @@ class AcceptOpenedButton extends Component {
1619
actions: PropTypes.object.isRequired
1720
};
1821

19-
_acceptOpened = () => {
22+
_acceptOpened = async () => {
23+
const analytics = this.context;
24+
await analytics?.trackOpenedScreenshotsAccept({acceptedImagesCount: this.props.acceptableOpenedImageIds.length});
25+
2026
if (this.props.isStaticImageAccepterEnabled) {
2127
this.props.actions.staticAccepterStageScreenshot(this.props.acceptableOpenedImageIds);
2228
} else {
23-
this.props.actions.acceptOpened(this.props.acceptableOpenedImageIds);
29+
this.props.actions.thunkAcceptImages({imageIds: this.props.acceptableOpenedImageIds});
2430
}
2531
};
2632

lib/static/components/controls/custom-gui-controls.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class CustomGuiControls extends PureComponent {
2929
const onClickHandler = (event, {value}) => {
3030
const controlIndex = controls.findIndex((control) => control.value === value);
3131

32-
actions.runCustomGuiAction({sectionName, groupIndex, controlIndex});
32+
actions.thunkRunCustomGuiAction({sectionName, groupIndex, controlIndex});
3333
};
3434

3535
return map(controls, ({label, value, active}, i) =>

lib/static/components/controls/find-same-diffs-button.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class FindSameDiffsButton extends Component {
2121
_findSameDiffs = () => {
2222
const {actions, imageId, failedOpenedImageIds, browserName} = this.props;
2323

24-
actions.findSameDiffs(imageId, failedOpenedImageIds, browserName);
24+
actions.thunkFindSameDiffs(imageId, failedOpenedImageIds, browserName);
2525
};
2626

2727
render() {

lib/static/components/controls/gui-controls.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class GuiControls extends Component {
3030
<ControlButton
3131
label="Stop tests"
3232
isDisabled={!running || stopping}
33-
handler={actions.stopTests}
33+
handler={actions.thunkStopTests}
3434
/>
3535
<AcceptOpenedButton />
3636
<CommonControls/>

lib/static/components/controls/run-button/index.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ const RunButton = ({actions, autoRun, isDisabled, isRunning, failedTests, checke
2929
const selectFailedTests = () => !shouldDisableFailed && setMode(RunMode.FAILED);
3030
const selectCheckedTests = () => !shouldDisableChecked && setMode(RunMode.CHECKED);
3131

32-
const runAllTests = () => actions.runAllTests();
33-
const runFailedTests = () => actions.runFailedTests(failedTests);
34-
const runCheckedTests = () => actions.retrySuite(checkedTests);
32+
const runAllTests = () => actions.thunkRunAllTests();
33+
const runFailedTests = () => actions.thunkRunFailedTests({tests: failedTests});
34+
const runCheckedTests = () => actions.thunkRunSuite({tests: checkedTests});
3535

3636
const handleRunClick = () => {
3737
const action = {

lib/static/components/gui.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import StickyHeader from './sticky-header/gui';
1010
import Loading from './loading';
1111
import ModalContainer from '../containers/modal';
1212
import MainTree from './main-tree';
13-
import CustomScripts from './custom-scripts';
13+
import {CustomScripts} from '../new-ui/components/CustomScripts';
1414
import {ClientEvents} from '../../gui/constants/client-events';
1515
import FaviconChanger from './favicon-changer';
1616
import ExtensionPoint from './extension-point';
@@ -60,7 +60,7 @@ class Gui extends Component {
6060
});
6161

6262
eventSource.addEventListener(ClientEvents.END, () => {
63-
actions.testsEnd();
63+
actions.thunkTestsEnd();
6464
});
6565
}
6666

lib/static/components/modals/screenshot-accepter/index.jsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ import {staticImageAccepterPropType} from '../../../modules/static-image-accepte
1313
import {preloadImage} from '../../../modules/utils';
1414

1515
import './style.css';
16+
import {AnalyticsContext} from '@/static/new-ui/providers/analytics';
1617

1718
const PRELOAD_IMAGE_COUNT = 3;
1819

1920
class ScreenshotAccepter extends Component {
21+
static contextType = AnalyticsContext;
22+
2023
static propTypes = {
2124
view: PropTypes.shape({
2225
diffMode: PropTypes.string.isRequired
@@ -58,6 +61,8 @@ class ScreenshotAccepter extends Component {
5861
for (let i = 1; i <= PRELOAD_IMAGE_COUNT; i++) {
5962
this._preloadAdjacentImages(activeImageIndex, stateNameImageIds, i);
6063
}
64+
65+
this.analytics = this.context;
6166
}
6267

6368
componentDidUpdate() {
@@ -138,7 +143,7 @@ class ScreenshotAccepter extends Component {
138143
if (this.props.staticImageAccepter.enabled) {
139144
this.props.actions.staticAccepterUndoDelayScreenshot();
140145
} else {
141-
await this.props.actions.undoAcceptImage(imageId, {skipTreeUpdate: true});
146+
await this.props.actions.thunkRevertImages({imageIds: [imageId], shouldCommitUpdatesToTree: false});
142147
this.delayedTestResults.pop();
143148
}
144149

@@ -164,7 +169,7 @@ class ScreenshotAccepter extends Component {
164169

165170
this.props.actions.staticAccepterStageScreenshot(imageIdsToStage);
166171
} else {
167-
this.props.actions.applyDelayedTestResults(this.delayedTestResults);
172+
this.props.actions.commitAcceptedImagesToTree(this.delayedTestResults);
168173
}
169174

170175
this.props.onClose();
@@ -184,7 +189,8 @@ class ScreenshotAccepter extends Component {
184189
}
185190

186191
async _acceptScreenshot(imageId, stateName) {
187-
const updatedData = await this.props.actions.screenshotAccepterAccept(imageId);
192+
const updatedData = await this.props.actions.thunkAcceptImages({imageIds: [imageId], shouldCommitUpdatesToTree: false});
193+
this.analytics?.trackScreenshotsAccept();
188194

189195
if (updatedData === null) {
190196
return null;

lib/static/components/report.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Loading from './loading';
1010
import StickyHeader from './sticky-header/report';
1111
import ModalContainer from '../containers/modal';
1212
import MainTree from './main-tree';
13-
import CustomScripts from './custom-scripts';
13+
import {CustomScripts} from '../new-ui/components/CustomScripts';
1414
import FaviconChanger from './favicon-changer';
1515
import ExtensionPoint from './extension-point';
1616
import BottomProgressBar from './bottom-progress-bar';

lib/static/components/section/body/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function Body(props) {
2727
const onTestRetry = () => {
2828
const {testName, browserName} = props;
2929

30-
props.actions.retryTest({testName, browserName});
30+
props.actions.thunkRunTest({test: {testName, browserName}});
3131
};
3232

3333
const addRetrySwitcher = () => {

0 commit comments

Comments
 (0)