-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(new-ui): implement screenshots display (#601)
* chore(new-ui): implement screenshots display * chore(new-ui): fix review issues
- Loading branch information
Showing
19 changed files
with
345 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
lib/static/new-ui/components/AssertViewResult/index.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.diff-viewer-container { | ||
display: flex; | ||
flex-direction: column; | ||
padding-left: calc(var(--indent) * 24px); | ||
padding-right: 1px | ||
} | ||
|
||
.diff-mode-switcher { | ||
--g-color-base-background: #fff; | ||
margin: 12px auto; | ||
} | ||
|
||
.screenshot { | ||
margin: 8px 0; | ||
padding-left: calc(var(--indent) * 24px); | ||
padding-right: 1px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React, {ReactNode} from 'react'; | ||
import {ImageEntity, State} from '@/static/new-ui/types/store'; | ||
import {DiffModeId, DiffModes, TestStatus} from '@/constants'; | ||
import {DiffViewer} from '../DiffViewer'; | ||
import {RadioButton} from '@gravity-ui/uikit'; | ||
import {connect} from 'react-redux'; | ||
import {bindActionCreators} from 'redux'; | ||
import * as actions from '@/static/modules/actions'; | ||
import styles from './index.module.css'; | ||
import {Screenshot} from '@/static/new-ui/components/Screenshot'; | ||
|
||
interface AssertViewResultProps { | ||
result: ImageEntity; | ||
style?: React.CSSProperties; | ||
actions: typeof actions; | ||
diffMode: DiffModeId; | ||
} | ||
|
||
function AssertViewResultInternal({result, actions, diffMode, style}: AssertViewResultProps): ReactNode { | ||
if (result.status === TestStatus.FAIL) { | ||
const onChangeHandler = (diffMode: DiffModeId): void => { | ||
actions.changeDiffMode(diffMode); | ||
}; | ||
|
||
return <div style={style} className={styles.diffViewerContainer}> | ||
<RadioButton onUpdate={onChangeHandler} value={diffMode} className={styles.diffModeSwitcher}> | ||
{Object.values(DiffModes).map(diffMode => | ||
<RadioButton.Option value={diffMode.id} content={diffMode.title} title={diffMode.description} key={diffMode.id}/> | ||
)} | ||
</RadioButton> | ||
<DiffViewer diffMode={diffMode} {...result} /> | ||
</div>; | ||
} else if (result.status === TestStatus.ERROR) { | ||
return <Screenshot containerStyle={style} containerClassName={styles.screenshot} image={result.actualImg} />; | ||
} else if (result.status === TestStatus.SUCCESS || result.status === TestStatus.UPDATED) { | ||
return <Screenshot containerStyle={style} containerClassName={styles.screenshot} image={result.expectedImg} />; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
export const AssertViewResult = connect((state: State) => ({ | ||
diffMode: state.view.diffMode | ||
}), (dispatch) => ({actions: bindActionCreators(actions, dispatch)}) | ||
)(AssertViewResultInternal); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
lib/static/new-ui/components/AttemptPickerItem/index.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
.attempt-picker-item { | ||
--g-button-padding: 8px; | ||
margin-right: 2px; | ||
} | ||
|
||
.attempt-picker-item--active { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.image-label, .image-label + div { | ||
margin-bottom: 8px; | ||
} | ||
|
||
.image-label-subtitle { | ||
color: var(--g-color-private-black-400); | ||
margin-left: 4px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import {ImageFile} from '@/types'; | ||
import {CoordBounds} from 'looks-same'; | ||
import {DiffModeId, DiffModes} from '@/constants'; | ||
import React, {ReactNode} from 'react'; | ||
import {OnlyDiffMode} from '@/static/new-ui/components/DiffViewer/OnlyDiffMode'; | ||
import {SwitchMode} from '@/static/new-ui/components/DiffViewer/SwitchMode'; | ||
import {SwipeMode} from '@/static/new-ui/components/DiffViewer/SwipeMode'; | ||
import {OnionSkinMode} from '@/static/new-ui/components/DiffViewer/OnionSkinMode'; | ||
import {SideBySideMode} from '@/static/new-ui/components/DiffViewer/SideBySideMode'; | ||
import {SideBySideToFitMode} from '@/static/new-ui/components/DiffViewer/SideBySideToFitMode'; | ||
import {ListMode} from '@/static/new-ui/components/DiffViewer/ListMode'; | ||
import {getDisplayedDiffPercentValue} from '@/static/new-ui/components/DiffViewer/utils'; | ||
|
||
import styles from './index.module.css'; | ||
|
||
interface DiffViewerProps { | ||
actualImg: ImageFile; | ||
expectedImg: ImageFile; | ||
diffImg: ImageFile; | ||
diffClusters: CoordBounds[]; | ||
diffMode: DiffModeId; | ||
/** For cosmetics, will be displayed in diff label. */ | ||
differentPixels?: number; | ||
/** For cosmetics, will be displayed in diff label. */ | ||
diffRatio?: number; | ||
/** | ||
* A valid CSS value assignable to height, e.g. `10px` or `calc(100vh - 50px)`. | ||
* Images will try to fit the `desiredHeight`, but will only shrink no more than 2 times. | ||
* */ | ||
desiredHeight?: string; | ||
} | ||
|
||
export function DiffViewer(props: DiffViewerProps): ReactNode { | ||
const getImageDisplayedSize = (image: ImageFile): string => `${image.size.width}×${image.size.height}`; | ||
const getImageLabel = (title: string, subtitle?: string): ReactNode => { | ||
return <div className={styles.imageLabel}> | ||
<span>{title}</span> | ||
{subtitle && <span className={styles.imageLabelSubtitle}>{subtitle}</span>} | ||
</div>; | ||
}; | ||
|
||
const expectedImg = Object.assign({}, props.expectedImg, { | ||
label: getImageLabel('Expected', getImageDisplayedSize(props.expectedImg)) | ||
}); | ||
const actualImg = Object.assign({}, props.actualImg, { | ||
label: getImageLabel('Actual', getImageDisplayedSize(props.actualImg)) | ||
}); | ||
let diffSubtitle: string | undefined; | ||
if (props.differentPixels !== undefined && props.diffRatio !== undefined) { | ||
diffSubtitle = `${props.differentPixels}px ⋅ ${getDisplayedDiffPercentValue(props.diffRatio)}%`; | ||
} | ||
const diffImg = Object.assign({}, props.diffImg, { | ||
label: getImageLabel('Diff', diffSubtitle), | ||
diffClusters: props.diffClusters | ||
}); | ||
|
||
switch (props.diffMode) { | ||
case DiffModes.ONLY_DIFF.id: | ||
return <OnlyDiffMode diff={diffImg} />; | ||
|
||
case DiffModes.SWITCH.id: | ||
return <SwitchMode expected={expectedImg} actual={actualImg} />; | ||
|
||
case DiffModes.SWIPE.id: | ||
return <SwipeMode expected={expectedImg} actual={actualImg} />; | ||
|
||
case DiffModes.ONION_SKIN.id: | ||
return <OnionSkinMode expected={expectedImg} actual={actualImg} />; | ||
|
||
case DiffModes.THREE_UP_SCALED.id: | ||
return <SideBySideMode expected={expectedImg} actual={actualImg} diff={diffImg} />; | ||
|
||
case DiffModes.THREE_UP_SCALED_TO_FIT.id: { | ||
const desiredHeight = props.desiredHeight ?? 'calc(100vh - 180px)'; | ||
|
||
return <SideBySideToFitMode desiredHeight={desiredHeight} expected={expectedImg} actual={actualImg} diff={diffImg} />; | ||
} | ||
case DiffModes.THREE_UP.id: | ||
default: | ||
return <ListMode expected={expectedImg} actual={actualImg} diff={diffImg} />; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,6 @@ | |
background-color: white; | ||
position: sticky; | ||
top: 0; | ||
z-index: 1; | ||
z-index: 10; | ||
padding-bottom: 4px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.