Skip to content

Commit

Permalink
fix: fix review issues
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowusr committed Nov 16, 2024
1 parent ebd8b23 commit dbbf96b
Show file tree
Hide file tree
Showing 26 changed files with 135 additions and 134 deletions.
1 change: 1 addition & 0 deletions lib/static/icons/empty-report.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion lib/static/modules/reducers/static-image-accepter.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ export default (state, action) => {
const diff = set({}, ['staticImageAccepter', 'acceptableImages'], acceptableImagesDiff);
const imagesToCommitCount = get(state, ['staticImageAccepter', 'imagesToCommitCount']);

set(diff, ['staticImageAccepter', 'imagesToCommitCount'], imagesToCommitCount - action.payload.length);
for (const imageId of action.payload) {
set(acceptableImagesDiff, [imageId, 'commitStatus'], null);
set(diff, ['staticImageAccepter', 'imagesToCommitCount'], imagesToCommitCount - 1);
}

return applyStateUpdate(state, diff);
Expand Down
22 changes: 15 additions & 7 deletions lib/static/modules/reducers/tree/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ export default ((state, action) => {
const {tree, view} = state;
const imageIdsToUnstage = action.payload;

const failedBrowserIds = [];
const failedSuiteIds = [];
const imageIds = [];

for (const imageId of imageIdsToUnstage) {
const originalStatus = get(state, ['staticImageAccepter', 'acceptableImages', imageId, 'originalStatus']);

Expand All @@ -269,15 +273,19 @@ export default ((state, action) => {
changeImageStatus(tree, imageId, originalStatus, diff.tree);
changeNodeState(tree.results.byId, failedResultId, {status: FAIL}, diff.tree.results.byId);

failSuites(tree, failedSuiteId, diff.tree);
failedBrowserIds.push(failedBrowserId);
failedSuiteIds.push(failedSuiteId);
imageIds.push(imageId);
}

failSuites(tree, failedSuiteIds, diff.tree);

calcSuitesOpenness({tree, expand: view.expand, suiteIds: [failedSuiteId], diff: diff.tree});
calcBrowsersOpenness({tree, expand: view.expand, browserIds: [failedBrowserId], diff: diff.tree});
calcImagesOpenness({tree, expand: view.expand, imageIds: [imageId], diff: diff.tree});
calcSuitesOpenness({tree, expand: view.expand, suiteIds: failedSuiteIds, diff: diff.tree});
calcBrowsersOpenness({tree, expand: view.expand, browserIds: failedBrowserIds, diff: diff.tree});
calcImagesOpenness({tree, expand: view.expand, imageIds, diff: diff.tree});

calcBrowsersShowness({tree, view, browserIds: [failedBrowserId], diff: diff.tree});
calcSuitesShowness({tree, suiteIds: [failedSuiteId], diff: diff.tree});
}
calcBrowsersShowness({tree, view, browserIds: failedBrowserIds, diff: diff.tree});
calcSuitesShowness({tree, suiteIds: failedSuiteIds, diff: diff.tree});

return applyStateUpdate(state, diff);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/static/new-ui/components/AssertViewResult/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {ReactNode} from 'react';
import {connect} from 'react-redux';

import {ImageEntity, State} from '@/static/new-ui/types/store';
import {ImageEntity} from '@/static/new-ui/types/store';
import {DiffModeId, TestStatus} from '@/constants';
import {DiffViewer} from '../DiffViewer';
import {Screenshot} from '@/static/new-ui/components/Screenshot';
Expand Down Expand Up @@ -43,6 +43,6 @@ function AssertViewResultInternal({result, diffMode, style}: AssertViewResultPro
return null;
}

export const AssertViewResult = connect((state: State) => ({
export const AssertViewResult = connect(state => ({
diffMode: state.view.diffMode
}))(AssertViewResultInternal);
7 changes: 3 additions & 4 deletions lib/static/new-ui/components/AttemptPicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, {ReactNode} from 'react';
import {connect, useDispatch, useSelector} from 'react-redux';
import {ArrowRotateRight} from '@gravity-ui/icons';

import {State} from '@/static/new-ui/types/store';
import {AttemptPickerItem} from '@/static/new-ui/components/AttemptPickerItem';
import styles from './index.module.css';
import classNames from 'classnames';
Expand All @@ -26,9 +25,9 @@ function AttemptPickerInternal(props: AttemptPickerInternalProps): ReactNode {

const dispatch = useDispatch();
const currentBrowser = useSelector(getCurrentBrowser);
const isRunTestsAvailable = useSelector((state: State) => state.app.availableFeatures)
const isRunTestsAvailable = useSelector(state => state.app.availableFeatures)
.find(feature => feature.name === RunTestsFeature.name);
const isRunning = useSelector((state: State) => state.running);
const isRunning = useSelector(state => state.running);

const onAttemptPickHandler = (resultId: string, attemptIndex: number): void => {
if (!props.browserId || currentResultId === resultId) {
Expand Down Expand Up @@ -64,7 +63,7 @@ function AttemptPickerInternal(props: AttemptPickerInternalProps): ReactNode {
</div>;
}

export const AttemptPicker = connect((state: State) => {
export const AttemptPicker = connect(state => {
let resultIds: string[] = [];
let currentResultId = '';
const browserId = state.app.suitesPage.currentBrowserId;
Expand Down
3 changes: 1 addition & 2 deletions lib/static/new-ui/components/Card/AnimatedAppearCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import cardStyles from './index.module.css';
import styles from './AnimatedAppearCard.module.css';
import classNames from 'classnames';
import {useSelector} from 'react-redux';
import {State} from '@/static/new-ui/types/store';

export function AnimatedAppearCard(): ReactNode {
const isInitialized = useSelector((state: State) => state.app.isInitialized);
const isInitialized = useSelector(state => state.app.isInitialized);

return <div className={classNames(cardStyles.commonCard, styles.animatedAppearCard, {[styles.hidden]: isInitialized})}>
<div className={styles.backgroundOverlay}></div>
Expand Down
2 changes: 1 addition & 1 deletion lib/static/new-ui/components/Card/EmptyReportCard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {TextHintCard} from '@/static/new-ui/components/Card/TextHintCard';
import EmptyReport from '@/static/icons/empty-report.svg';
import EmptyReport from '../../../icons/empty-report.svg';
import classNames from 'classnames';
import {Icon} from '@gravity-ui/uikit';
import {Check} from '@gravity-ui/icons';
Expand Down
7 changes: 3 additions & 4 deletions lib/static/new-ui/components/CompactAttemptPicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import React, {ReactNode} from 'react';
import {useDispatch, useSelector} from 'react-redux';

import styles from './index.module.css';
import {State} from '@/static/new-ui/types/store';
import {getCurrentNamedImage} from '@/static/new-ui/features/visual-checks/selectors';
import {getIconByStatus} from '@/static/new-ui/utils';
import {changeTestRetry} from '@/static/modules/actions';
Expand All @@ -13,11 +12,11 @@ export function CompactAttemptPicker(): ReactNode {
const dispatch = useDispatch();
const currentImage = useSelector(getCurrentNamedImage);
const currentBrowserId = currentImage?.browserId;
const currentBrowser = useSelector((state: State) => currentBrowserId && state.tree.browsers.byId[currentBrowserId]);
const resultsById = useSelector((state: State) => state.tree.results.byId);
const currentBrowser = useSelector(state => currentBrowserId && state.tree.browsers.byId[currentBrowserId]);
const resultsById = useSelector(state => state.tree.results.byId);

const totalAttemptsCount = currentBrowser ? currentBrowser.resultIds.length : null;
const currentAttemptIndex = useSelector((state: State) => currentBrowser ? state.tree.browsers.stateById[currentBrowser.id].retryIndex : null);
const currentAttemptIndex = useSelector(state => currentBrowser ? state.tree.browsers.stateById[currentBrowser.id].retryIndex : null);

const onUpdate = ([value]: string[]): void => {
if (currentBrowserId) {
Expand Down
17 changes: 8 additions & 9 deletions lib/static/new-ui/components/GuiniToolbarOverlay/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {CloudArrowUpIn, TriangleExclamation} from '@gravity-ui/icons';
import styles from './index.module.css';
import classNames from 'classnames';
import {useDispatch, useSelector} from 'react-redux';
import {State} from '@/static/new-ui/types/store';
import {
CommitResult,
staticAccepterCommitScreenshot,
Expand All @@ -23,22 +22,22 @@ export function GuiniToolbarOverlay(): ReactNode {
const dispatch = useDispatch();
const toaster = useToaster();

const isInProgress = useSelector((state: State) => state.processing);
const allImagesById = useSelector((state: State) => state.tree.images.byId);
const acceptableImages = useSelector((state: State) => state.staticImageAccepter.acceptableImages);
const delayedImages = useSelector((state: State) => state.staticImageAccepter.accepterDelayedImages);
const isInProgress = useSelector(state => state.processing);
const allImagesById = useSelector(state => state.tree.images.byId);
const acceptableImages = useSelector(state => state.staticImageAccepter.acceptableImages);
const delayedImages = useSelector(state => state.staticImageAccepter.accepterDelayedImages);
const stagedImages = Object.values(acceptableImages)
.filter(image => image.commitStatus === TestStatus.STAGED);

const staticAccepterConfig = useSelector((state: State) => state.config.staticImageAccepter);
const pullRequestUrl = useSelector((state: State) => state.config.staticImageAccepter.pullRequestUrl);
const offset = useSelector((state: State) => state.ui.staticImageAccepterToolbar.offset);
const staticAccepterConfig = useSelector(state => state.config.staticImageAccepter);
const pullRequestUrl = useSelector(state => state.config.staticImageAccepter.pullRequestUrl);
const offset = useSelector(state => state.ui.staticImageAccepterToolbar.offset);
const location = useLocation();

const [isVisible, setIsVisible] = useState<boolean | null>(null);
const [isModalVisible, setIsModalVisible] = useState(false);

const commitMessage = useSelector((state: State) => state.app.staticImageAccepterModal.commitMessage);
const commitMessage = useSelector(state => state.app.staticImageAccepterModal.commitMessage);

useEffect(() => {
const newIsVisible = stagedImages.length > 0 &&
Expand Down
7 changes: 3 additions & 4 deletions lib/static/new-ui/components/LoadingBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ import React, {ReactNode, useEffect, useRef} from 'react';
import styles from './index.module.css';
import {useSelector} from 'react-redux';
import {getTotalLoadingProgress} from '@/static/new-ui/app/selectors';
import {State} from '@/static/new-ui/types/store';
import classNames from 'classnames';

export function LoadingBar(): ReactNode {
const isVisible = useSelector((state: State) => state.app.loading.isVisible);
const isInProgress = useSelector((state: State) => state.app.loading.isInProgress);
const isVisible = useSelector(state => state.app.loading.isVisible);
const isInProgress = useSelector(state => state.app.loading.isInProgress);
const isVisibleRef = useRef(isVisible);
const progress = useSelector(getTotalLoadingProgress);
const taskTitle = useSelector((state: State) => state.app.loading.taskTitle);
const taskTitle = useSelector(state => state.app.loading.taskTitle);

const [hidden, setHidden] = React.useState(true);

Expand Down
3 changes: 1 addition & 2 deletions lib/static/new-ui/components/MainLayout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {SettingsPanel} from '@/static/new-ui/components/SettingsPanel';
import TestplaneIcon from '../../../icons/testplane-mono.svg';
import styles from './index.module.css';
import {Footer} from './Footer';
import {State} from '@/static/new-ui/types/store';
import {EmptyReportCard} from '@/static/new-ui/components/Card/EmptyReportCard';

export enum PanelId {
Expand Down Expand Up @@ -41,7 +40,7 @@ export function MainLayout(props: MainLayoutProps): ReactNode {

const isInitialized = useSelector(getIsInitialized);

const browsersById = useSelector((state: State) => state.tree.browsers.byId);
const browsersById = useSelector(state => state.tree.browsers.byId);
const isReportEmpty = isInitialized && Object.keys(browsersById).length === 0;

const [visiblePanel, setVisiblePanel] = useState<PanelId | null>(null);
Expand Down
3 changes: 1 addition & 2 deletions lib/static/new-ui/components/SettingsPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import {useDispatch, useSelector} from 'react-redux';

import {LocalStorageKey, UiMode} from '@/constants/local-storage';
import * as actions from '@/static/modules/actions';
import {State} from '@/static/new-ui/types/store';
import useLocalStorage from '@/static/hooks/useLocalStorage';
import styles from './index.module.css';

export function SettingsPanel(): ReactNode {
const dispatch = useDispatch();

const baseHost = useSelector((state: State) => state.view.baseHost);
const baseHost = useSelector(state => state.view.baseHost);
const [, setUiMode] = useLocalStorage(LocalStorageKey.UIMode, UiMode.New);

const onBaseHostChange = (event: React.ChangeEvent<HTMLInputElement>): void => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {bindActionCreators} from 'redux';
import * as actions from '@/static/modules/actions';
import {BrowserIcon} from '@/static/new-ui/features/suites/components/BrowsersSelect/BrowserIcon';
import {getIsInitialized} from '@/static/new-ui/store/selectors';
import {State} from '@/static/new-ui/types/store';
import {BrowserItem} from '@/types';
import styles from './index.module.css';

Expand Down Expand Up @@ -175,7 +174,7 @@ function BrowsersSelectInternal({browsers, filteredBrowsers, actions}: BrowsersS
}

export const BrowsersSelect = connect(
(state: State) => ({
state => ({
filteredBrowsers: state.view.filteredBrowsers,
browsers: state.browsers
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, {ReactNode} from 'react';
import {useDispatch, useSelector} from 'react-redux';

import {AssertViewResult} from '@/static/new-ui/components/AssertViewResult';
import {ImageEntity, State} from '@/static/new-ui/types/store';
import {ImageEntity} from '@/static/new-ui/types/store';
import {DiffModeId, DiffModes, EditScreensFeature, TestStatus} from '@/constants';
import {
acceptTest,
Expand All @@ -25,13 +25,13 @@ interface ScreenshotsTreeViewItemProps {

export function ScreenshotsTreeViewItem(props: ScreenshotsTreeViewItemProps): ReactNode {
const dispatch = useDispatch();
const diffMode = useSelector((state: State) => state.view.diffMode);
const isEditScreensAvailable = useSelector((state: State) => state.app.availableFeatures)
const diffMode = useSelector(state => state.view.diffMode);
const isEditScreensAvailable = useSelector(state => state.app.availableFeatures)
.find(feature => feature.name === EditScreensFeature.name);
const isStaticImageAccepterEnabled = useSelector((state: State) => state.staticImageAccepter.enabled);
const isRunning = useSelector((state: State) => state.running);
const isProcessing = useSelector((state: State) => state.processing);
const isGui = useSelector((state: State) => state.gui);
const isStaticImageAccepterEnabled = useSelector(state => state.staticImageAccepter.enabled);
const isRunning = useSelector(state => state.running);
const isProcessing = useSelector(state => state.processing);
const isGui = useSelector(state => state.gui);

const isDiffModeSwitcherVisible = props.image.status === TestStatus.FAIL && props.image.diffImg;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import * as actions from '@/static/modules/actions';
import {CollapsibleSection} from '@/static/new-ui/features/suites/components/CollapsibleSection';
import {MetaInfo} from '@/static/new-ui/components/MetaInfo';
import {getIsInitialized} from '@/static/new-ui/store/selectors';
import {ResultEntity, State} from '@/static/new-ui/types/store';
import {ResultEntity} from '@/static/new-ui/types/store';
import {AttemptPicker} from '../../../../components/AttemptPicker';

import styles from './index.module.css';
Expand Down Expand Up @@ -86,7 +86,7 @@ function SuitesPageInternal({currentResult, actions, visibleBrowserIds}: SuitesP
}

export const SuitesPage = connect(
(state: State) => {
state => {
const currentResult = getCurrentResult(state);

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
} from '@/static/new-ui/features/suites/components/SuitesPage/types';
import {TreeViewItemTitle} from '@/static/new-ui/features/suites/components/TreeViewItemTitle';
import {TreeViewItemSubtitle} from '@/static/new-ui/features/suites/components/TreeViewItemSubtitle';
import {State} from '@/static/new-ui/types/store';
import {
getTreeViewExpandedById,
getTreeViewItems
Expand All @@ -39,10 +38,10 @@ export const SuitesTreeView = forwardRef<SuitesTreeViewHandle, SuitesTreeViewPro
const navigate = useNavigate();
const {suiteId} = useParams();

const isInitialized = useSelector((state: State) => state.app.isInitialized);
const currentBrowserId = useSelector((state: State) => state.app.suitesPage.currentBrowserId);
const treeViewItems = useSelector((state: State) => getTreeViewItems(state).tree);
const treeViewExpandedById = useSelector((state: State) => getTreeViewExpandedById(state));
const isInitialized = useSelector(state => state.app.isInitialized);
const currentBrowserId = useSelector(state => state.app.suitesPage.currentBrowserId);
const treeViewItems = useSelector(state => getTreeViewItems(state).tree);
const treeViewExpandedById = useSelector(state => getTreeViewExpandedById(state));

const list = useList({
items: treeViewItems,
Expand Down Expand Up @@ -84,6 +83,8 @@ export const SuitesTreeView = forwardRef<SuitesTreeViewHandle, SuitesTreeViewPro
let timeoutId: NodeJS.Timeout;
if (suiteId) {
dispatch(suitesPageSetCurrentSuite(suiteId));

// This tiny timeout helps when report contains thousands of items and scrolls to invalid position before they are done rendering.
timeoutId = setTimeout(() => {
virtualizer.scrollToIndex(list.structure.visibleFlattenIds.indexOf(suiteId), {align: 'center'});
}, 50);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {debounce} from 'lodash';
import {connect, useSelector} from 'react-redux';
import {bindActionCreators} from 'redux';
import * as actions from '@/static/modules/actions';
import {State} from '@/static/new-ui/types/store';
import {getIsInitialized} from '@/static/new-ui/store/selectors';

interface TestNameFilterProps {
Expand Down Expand Up @@ -32,6 +31,6 @@ function TestNameFilterInternal(props: TestNameFilterProps): ReactNode {
}

export const TestNameFilter = connect(
(state: State) => ({testNameFilter: state.view.testNameFilter}),
state => ({testNameFilter: state.view.testNameFilter}),
(dispatch) => ({actions: bindActionCreators(actions, dispatch)})
)(TestNameFilterInternal);
Loading

0 comments on commit dbbf96b

Please sign in to comment.