Skip to content

Commit 007bb5e

Browse files
author
rocketraccoon
committed
refactor(new-ui): Change url format
1 parent 8401fe8 commit 007bb5e

File tree

16 files changed

+125
-60
lines changed

16 files changed

+125
-60
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, {Component, Fragment} from 'react';
22
import {GlobalHotKeys} from 'react-hotkeys';
33
import PropTypes from 'prop-types';
4-
import {uniqBy, pick} from 'lodash';
4+
import {uniqBy} from 'lodash';
55

66
import ProgressBar from '../../progress-bar';
77
import ControlButton from '../../controls/control-button';

lib/static/modules/actions/visual-checks-page.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ import actionNames from '@/static/modules/action-names';
22
import {Action} from '@/static/modules/actions/types';
33
import {DiffModeId, TwoUpFitMode} from '@/constants';
44

5-
export type VisualChecksPageSetCurrentNamedImageAction = Action<typeof actionNames.VISUAL_CHECKS_PAGE_SET_CURRENT_NAMED_IMAGE, {
6-
namedImageId: string;
7-
}>;
5+
export type VisualChecksPageSetCurrentNamedImageData = {
6+
suiteId?: string;
7+
stateName?: string;
8+
};
9+
10+
export type VisualChecksPageSetCurrentNamedImageAction = Action<typeof actionNames.VISUAL_CHECKS_PAGE_SET_CURRENT_NAMED_IMAGE, VisualChecksPageSetCurrentNamedImageData>;
811

9-
export const visualChecksPageSetCurrentNamedImage = (namedImageId: string): VisualChecksPageSetCurrentNamedImageAction => {
10-
return {type: actionNames.VISUAL_CHECKS_PAGE_SET_CURRENT_NAMED_IMAGE, payload: {namedImageId}};
12+
export const visualChecksPageSetCurrentNamedImage = (data: VisualChecksPageSetCurrentNamedImageData): VisualChecksPageSetCurrentNamedImageAction => {
13+
return {type: actionNames.VISUAL_CHECKS_PAGE_SET_CURRENT_NAMED_IMAGE, payload: data};
1114
};
1215

1316
export type Toggle2UpDiffVisibilityAction = Action<typeof actionNames.VISUAL_CHECKS_TOGGLE_2UP_DIFF_VISIBILITY, {

lib/static/modules/default-state.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ export default Object.assign({config: configDefaults}, {
113113
filteredBrowsers: []
114114
},
115115
[Page.visualChecksPage]: {
116-
currentNamedImageId: null,
116+
suiteId: null,
117+
stateName: null,
117118

118119
viewMode: ViewMode.ALL,
119120
nameFilter: '',

lib/static/modules/reducers/visual-checks-page.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {TWO_UP_DIFF_VISIBILITY_KEY, TWO_UP_FIT_MODE_KEY} from '@/constants/local
88
export default (state: State, action: VisualChecksPageAction): State => {
99
switch (action.type) {
1010
case actionNames.VISUAL_CHECKS_PAGE_SET_CURRENT_NAMED_IMAGE:
11-
return applyStateUpdate(state, {app: {visualChecksPage: {currentNamedImageId: action.payload.namedImageId}}}) as State;
11+
return applyStateUpdate(state, {app: {visualChecksPage: action.payload}}) as State;
1212
case actionNames.VISUAL_CHECKS_TOGGLE_2UP_DIFF_VISIBILITY:
1313
localStorageWrapper.setItem(TWO_UP_DIFF_VISIBILITY_KEY, action.payload.isVisible);
1414
return applyStateUpdate(state, {

lib/static/new-ui/app/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ export function App(): ReactNode {
2929
url: '/suites',
3030
icon: ListCheck,
3131
element: <SuitesPage/>,
32-
children: [<Route key={'suite'} path='/suites/:suiteId?/:stateName?/:attempt?' element={<SuitesPage/>} />]
32+
children: [<Route key={'suite'} path='/suites/:suiteId?/:attempt?/:stateName?' element={<SuitesPage/>} />]
3333
},
3434
{
3535
title: 'Visual Checks',
3636
url: '/visual-checks',
3737
icon: Eye,
3838
element: <VisualChecksPage/>,
39-
children: [<Route key={'image'} path='/visual-checks/:imageId?/:attempt?' element={<VisualChecksPage/>} />]
39+
children: [<Route key={'image'} path='/visual-checks/:suiteId?/:attempt?/:stateName?' element={<VisualChecksPage/>} />]
4040
}
4141
];
4242

lib/static/new-ui/features/suites/components/ScreenshotsTreeViewItem/index.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React, {ReactNode, createRef, useEffect, useRef} from 'react';
44
import {useDispatch, useSelector} from 'react-redux';
55

66
import {AssertViewResult} from '@/static/new-ui/components/AssertViewResult';
7-
import {ImageEntity} from '@/static/new-ui/types/store';
7+
import {ImageEntity, Page} from '@/static/new-ui/types/store';
88
import {DiffModeId, EditScreensFeature, TestStatus} from '@/constants';
99
import {getAvailableDiffModes} from '@/static/new-ui/utils/diffModes';
1010
import {
@@ -20,6 +20,7 @@ import {thunkAcceptImages, thunkRevertImages} from '@/static/modules/actions/scr
2020
import {useAnalytics} from '@/static/new-ui/hooks/useAnalytics';
2121
import {ErrorHandler} from '../../../error-handling/components/ErrorHandling';
2222
import {useNavigate, useParams} from 'react-router-dom';
23+
import {getUrl} from '@/static/new-ui/utils/getUrl';
2324

2425
interface ScreenshotsTreeViewItemProps {
2526
image: ImageEntity;
@@ -87,7 +88,12 @@ export function ScreenshotsTreeViewItem(props: ScreenshotsTreeViewItemProps): Re
8788
const imageId = `${currentResult?.parentId} ${props.image.stateName}`;
8889

8990
const onVisualChecks = (): void => {
90-
navigate(`/visual-checks/${encodeURIComponent(imageId)}/${currentResult?.attempt}`);
91+
navigate(getUrl({
92+
page: Page.visualChecksPage,
93+
suiteId: suiteId,
94+
stateName: props.image.stateName,
95+
attempt: currentResult?.attempt
96+
}));
9197
};
9298

9399
useEffect(() => {

lib/static/new-ui/features/suites/components/SuitesPage/index.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import classNames from 'classnames';
22
import React, {ReactNode, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState} from 'react';
33
import {useDispatch, useSelector} from 'react-redux';
44
import {useNavigate, useParams} from 'react-router-dom';
5-
65
import {UiCard} from '@/static/new-ui/components/Card/UiCard';
76
import {getAttempt, getCurrentResult, getCurrentResultImages} from '@/static/new-ui/features/suites/selectors';
87
import {SplitViewLayout} from '@/static/new-ui/components/SplitViewLayout';
@@ -31,6 +30,7 @@ import {getIconByStatus} from '@/static/new-ui/utils';
3130
import {Page} from '@/static/new-ui/types/store';
3231
import {usePage} from '@/static/new-ui/hooks/usePage';
3332
import {changeTestRetry, setCurrentTreeNode, setStrictMatchFilter} from '@/static/modules/actions';
33+
import {getUrl} from '@/static/new-ui/utils/getUrl';
3434

3535
export function SuitesPage(): ReactNode {
3636
const page = usePage();
@@ -59,13 +59,13 @@ export function SuitesPage(): ReactNode {
5959
}, [page]);
6060

6161
useEffect(() => {
62-
if (currentResult?.parentId && attempt !== null && resultImages.length) {
63-
navigate('/' + [
64-
'suites',
65-
currentResult.parentId as string,
66-
params.stateName !== undefined ? params.stateName : resultImages[0].stateName as string,
67-
attempt?.toString() as string
68-
].map(encodeURIComponent).join('/'));
62+
if (currentResult?.parentId && attempt !== null) {
63+
navigate(getUrl({
64+
page: Page.suitesPage,
65+
attempt,
66+
suiteId: currentResult.parentId,
67+
stateName: resultImages.length ? resultImages[0].stateName : undefined
68+
}));
6969
}
7070
}, [currentResult, attempt]);
7171

lib/static/new-ui/features/suites/components/SuitesPage/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export interface TreeViewItemData {
2020
images?: ImageEntity[];
2121
parentData?: TreeViewItemData;
2222
skipReason?: string;
23+
suiteId?: string;
24+
stateName?: string;
2325
}
2426

2527
export interface TreeRoot {

lib/static/new-ui/features/suites/components/TestSteps/index.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import {ErrorHandler} from '../../../error-handling/components/ErrorHandling';
2727
import {goToTimeInSnapshotsPlayer, setCurrentPlayerHighlightTime} from '@/static/modules/actions/snapshots';
2828
import {setCurrentStep} from '@/static/modules/actions';
2929
import {useNavigate} from 'react-router-dom';
30+
import {getUrl} from '@/static/new-ui/utils/getUrl';
31+
import {Page} from '@/static/new-ui/types/store';
3032

3133
type TestStepClickHandler = (item: {id: string}) => void
3234

@@ -171,13 +173,13 @@ function TestStepsInternal(props: TestStepsProps): ReactNode {
171173
expandedById: Object.assign({}, props.stepsExpandedById, {[id]: !props.stepsExpandedById[id]})
172174
});
173175

174-
if (step.type === StepType.Action) {
175-
navigate('/' + [
176-
'suites',
177-
currentResult?.parentId as string,
178-
step.args[0] as string,
179-
currentResult?.attempt?.toString() as string
180-
].map(encodeURIComponent).join('/'));
176+
if (step.type === StepType.Action && step.title === 'assertView') {
177+
navigate(getUrl({
178+
page: Page.suitesPage,
179+
suiteId: currentResult?.parentId,
180+
attempt: currentResult?.attempt,
181+
stateName: step.args[0]
182+
}));
181183
}
182184
}, [items, props.actions, props.stepsExpandedById]);
183185

lib/static/new-ui/features/visual-checks/components/VisualChecksPage/VisualChecksStickyHeader.tsx

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,15 @@ import {preloadImageEntity} from '../../../../../modules/utils/imageEntity';
3131
import {useNavigate} from 'react-router-dom';
3232
import {RunTestButton} from '../../../../components/RunTest';
3333
import {IconButton} from '../../../../components/IconButton';
34+
import {getUrl} from '@/static/new-ui/utils/getUrl';
35+
import {Page} from '@/static/new-ui/types/store';
36+
import {TreeViewData} from '@/static/new-ui/components/TreeView';
37+
import {TreeViewItemData} from '@/static/new-ui/features/suites/components/SuitesPage/types';
3438

3539
interface VisualChecksStickyHeaderProps {
3640
currentNamedImage: NamedImageEntity | null;
37-
visibleNamedImageIds: string[];
38-
onImageChange: (id: string) => void;
41+
treeData: TreeViewData;
42+
onImageChange: (item: TreeViewItemData) => void;
3943
}
4044

4145
export const PRELOAD_IMAGES_COUNT = 3;
@@ -63,16 +67,17 @@ const usePreloadImages = (
6367
}, []);
6468
};
6569

66-
export function VisualChecksStickyHeader({currentNamedImage, visibleNamedImageIds, onImageChange}: VisualChecksStickyHeaderProps): ReactNode {
70+
export function VisualChecksStickyHeader({currentNamedImage, treeData, onImageChange}: VisualChecksStickyHeaderProps): ReactNode {
71+
const visibleNamedImageIds = treeData.allTreeNodeIds;
6772
const dispatch = useDispatch();
6873
const analytics = useAnalytics();
6974
const currentImage = useSelector(getCurrentImage);
7075
const attempt = useSelector(getAttempt);
7176
const navigate = useNavigate();
7277

7378
const currentNamedImageIndex = visibleNamedImageIds.indexOf(currentNamedImage?.id as string);
74-
const onPreviousImageHandler = (): void => onImageChange(visibleNamedImageIds[currentNamedImageIndex - 1]);
75-
const onNextImageHandler = (): void => onImageChange(visibleNamedImageIds[currentNamedImageIndex + 1]);
79+
const onPreviousImageHandler = (): void => onImageChange(treeData.tree[currentNamedImageIndex - 1].data);
80+
const onNextImageHandler = (): void => onImageChange(treeData.tree[currentNamedImageIndex + 1].data);
7681

7782
usePreloadImages(currentNamedImageIndex, visibleNamedImageIds);
7883

@@ -134,12 +139,12 @@ export function VisualChecksStickyHeader({currentNamedImage, visibleNamedImageId
134139

135140
const onSuites = (): void => {
136141
if (currentNamedImage) {
137-
navigate('/' + [
138-
'suites',
139-
currentNamedImage?.browserId as string,
140-
currentNamedImage?.stateName as string,
141-
attempt?.toString() as string
142-
].map(encodeURIComponent).join('/'));
142+
navigate(getUrl({
143+
page: Page.suitesPage,
144+
suiteId: currentNamedImage?.browserId,
145+
attempt,
146+
stateName: currentNamedImage?.stateName
147+
}));
143148
}
144149
};
145150

0 commit comments

Comments
 (0)