Skip to content

Commit

Permalink
feat: add accept opened button
Browse files Browse the repository at this point in the history
  • Loading branch information
KuznetsovRoman committed Jul 16, 2024
1 parent 56dea1e commit 6b0ca64
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 42 deletions.
11 changes: 9 additions & 2 deletions lib/static/components/controls/accept-opened-button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ import {getAcceptableOpenedImageIds} from '../../modules/selectors/tree';

class AcceptOpenedButton extends Component {
static propTypes = {
isSuiteContol: PropTypes.bool,
// from store
processing: PropTypes.bool.isRequired,
acceptableOpenedImageIds: PropTypes.arrayOf(PropTypes.string).isRequired
};

_acceptOpened = () => {
this.props.actions.acceptOpened(this.props.acceptableOpenedImageIds);
if (this.props.isStaticImageAccepterEnabled) {
this.props.actions.staticAccepterStageScreenshot(this.props.acceptableOpenedImageIds);
} else {
this.props.actions.acceptOpened(this.props.acceptableOpenedImageIds);
}
};

render() {
Expand All @@ -24,6 +29,7 @@ class AcceptOpenedButton extends Component {
label="Accept opened"
isDisabled={!acceptableOpenedImageIds.length || processing}
handler={this._acceptOpened}
isSuiteControl={this.props.isSuiteContol}
/>;
}
}
Expand All @@ -32,7 +38,8 @@ export default connect(
(state) => {
return {
processing: state.processing,
acceptableOpenedImageIds: getAcceptableOpenedImageIds(state)
acceptableOpenedImageIds: getAcceptableOpenedImageIds(state),
isStaticImageAccepterEnabled: state.staticImageAccepter.enabled,
};
},
(dispatch) => ({actions: bindActionCreators(actions, dispatch)})
Expand Down
3 changes: 2 additions & 1 deletion lib/static/components/controls/common-filters.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import StrictMatchFilterInput from './strict-match-filter-input';
import ShowCheckboxesInput from './show-checkboxes-input';
import BrowserList from './browser-list';
import ControlButton from './control-button';
import AcceptOpenedButton from './accept-opened-button';

const CommonFilters = (props) => {
const onCommitChanges = () => {
Expand All @@ -24,12 +25,12 @@ const CommonFilters = (props) => {

return (
<div className='static-image-accepter'>
<AcceptOpenedButton isSuiteContol={true} />
<ControlButton
label={`Commit ${staticImageAccepter.imagesToCommitCount} images`}
title="Send request with imagesInfo to 'staticImageAccepter.serviceUrl'"
isDisabled={staticImageAccepter.imagesToCommitCount === 0}
isSuiteControl={true}
extendClassNames="static-image-accepter-commit"
handler={onCommitChanges}
/>
</div>
Expand Down
4 changes: 3 additions & 1 deletion lib/static/components/modals/screenshot-accepter/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ class ScreenshotAccepter extends Component {
}

if (this.props.staticImageAccepter.enabled) {
this.props.actions.staticAccepterStageScreenshot(this.props.staticImageAccepter.accepterDelayedImages);
const imageIdsToStage = this.props.staticImageAccepter.accepterDelayedImages.map(({imageId}) => imageId);

this.props.actions.staticAccepterStageScreenshot(imageIdsToStage);
} else {
this.props.actions.applyDelayedTestResults(this.delayedTestResults);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/static/components/state/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class State extends Component {

onTestAccept = () => {
if (this.props.isStaticImageAccepterEnabled) {
this.props.actions.staticAccepterStageScreenshot([{imageId: this.props.imageId, stateName: this.props.image.stateName}]);
this.props.actions.staticAccepterStageScreenshot([this.props.imageId]);
} else {
this.props.actions.acceptTest(this.props.imageId);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/static/modules/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,14 @@ export const staticAccepterCommitScreenshot = (imagesInfo, {repositoryUrl, pullR

const response = await axios.post(serviceUrl, payload, axiosRequestOptions);

const commitedImageIds = imagesInfo.map(imageInfo => imageInfo.id);
const commitedImages = imagesInfo.map(imageInfo => ({
imageId: imageInfo.id,
stateNameImageId: imageInfo.stateNameImageId
}));

if (response.status >= 200 && response.status < 400) {
dispatch({type: actionNames.STATIC_ACCEPTER_COMMIT_SCREENSHOT, payload: commitedImages});
dispatch({type: actionNames.STATIC_ACCEPTER_COMMIT_SCREENSHOT, payload: commitedImageIds});

storeCommitInLocalStorage(commitedImages);
} else {
Expand Down
6 changes: 3 additions & 3 deletions lib/static/modules/reducers/static-image-accepter.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ export default (state, action) => {
}

case actionNames.STATIC_ACCEPTER_STAGE_SCREENSHOT: {
const imagesToStage = action.payload;
const imageIdsToStage = action.payload;
const acceptableImages = state.staticImageAccepter.acceptableImages;
const acceptableImagesDiff = {};
const diff = set({}, ['staticImageAccepter', 'acceptableImages'], acceptableImagesDiff);

let imagesToCommitCountDiff = 0;

for (const {imageId} of imagesToStage) {
for (const imageId of imageIdsToStage) {
const stateImageIds = getStateImageIds(state.tree, imageId);
const stagedImageId = stateImageIds.find(imageId => acceptableImages[imageId].commitStatus === STAGED);

Expand Down Expand Up @@ -76,7 +76,7 @@ export default (state, action) => {
const acceptableImagesDiff = {};
const diff = set({}, ['staticImageAccepter', 'acceptableImages'], acceptableImagesDiff);

for (const {imageId} of action.payload) {
for (const imageId of action.payload) {
const stateImageIds = getStateImageIds(state.tree, imageId);
const commitedImageId = stateImageIds.find(imageId => acceptableImages[imageId].commitStatus === COMMITED);

Expand Down
4 changes: 2 additions & 2 deletions lib/static/modules/reducers/tree/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export default ((state, action) => {

case actionNames.STATIC_ACCEPTER_STAGE_SCREENSHOT: {
const {tree, view, staticImageAccepter} = state;
const imageIdsToStage = action.payload.map(({imageId}) => imageId);
const imageIdsToStage = action.payload;

const stateNameImages = getStaticAccepterStateNameImages(imageIdsToStage, staticImageAccepter);
const stagedImages = stateNameImages.filter(image => isStagedStatus(tree.images.byId[image.id].status));
Expand Down Expand Up @@ -268,7 +268,7 @@ export default ((state, action) => {

case actionNames.STATIC_ACCEPTER_COMMIT_SCREENSHOT: {
const {tree, view, staticImageAccepter} = state;
const imageIdsToCommit = action.payload.map(({imageId}) => imageId);
const imageIdsToCommit = action.payload;
const stateNameImageIds = imageIdsToCommit.map(imageId => staticImageAccepter.acceptableImages[imageId].stateNameImageId);
const relevantImages = Object.values(staticImageAccepter.acceptableImages).filter(image => stateNameImageIds.includes(image.stateNameImageId));
const commitedImages = relevantImages.filter(image => isCommitedStatus(tree.images.byId[image.id].status));
Expand Down
15 changes: 0 additions & 15 deletions lib/static/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -1017,20 +1017,5 @@ a:active {
.static-image-accepter {
display: flex;
flex-grow: 1;
}

.static-image-accepter .progress-bar {
margin-left: auto;
margin-right: 15px;
z-index: 999;
}

.static-image-accepter .progress-bar::after {
content: "Accepted: " attr(data-content);
font-size: 13px;
line-height: 18px;
}

.static-image-accepter .static-image-accepter-commit {
height: 25px;
}
10 changes: 5 additions & 5 deletions test/unit/lib/static/modules/reducers/static-image-accepter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('lib/static/modules/reducers/static-image-accepter', () => {

const state = {staticImageAccepter, tree};

const newState = reducer(state, {type: actionNames.STATIC_ACCEPTER_STAGE_SCREENSHOT, payload: [{imageId: 'imageId'}]});
const newState = reducer(state, {type: actionNames.STATIC_ACCEPTER_STAGE_SCREENSHOT, payload: ['imageId']});

assert.equal(newState.staticImageAccepter.acceptableImages['imageId'].commitStatus, STAGED);

Expand Down Expand Up @@ -97,7 +97,7 @@ describe('lib/static/modules/reducers/static-image-accepter', () => {

const state = {staticImageAccepter, tree};

const newState = reducer(state, {type: actionNames.STATIC_ACCEPTER_STAGE_SCREENSHOT, payload: [{imageId: 'imageId1'}]});
const newState = reducer(state, {type: actionNames.STATIC_ACCEPTER_STAGE_SCREENSHOT, payload: ['imageId1']});

assert.equal(newState.staticImageAccepter.acceptableImages['imageId1'].commitStatus, STAGED);
assert.equal(newState.staticImageAccepter.acceptableImages['imageId2'].commitStatus, null);
Expand All @@ -122,7 +122,7 @@ describe('lib/static/modules/reducers/static-image-accepter', () => {

const state = {staticImageAccepter, tree};

const newState = reducer(state, {type: actionNames.STATIC_ACCEPTER_STAGE_SCREENSHOT, payload: [{imageId: 'imageId1'}]});
const newState = reducer(state, {type: actionNames.STATIC_ACCEPTER_STAGE_SCREENSHOT, payload: ['imageId1']});

assert.equal(newState.staticImageAccepter.imagesToCommitCount, state.staticImageAccepter.imagesToCommitCount + 1);
});
Expand Down Expand Up @@ -180,7 +180,7 @@ describe('lib/static/modules/reducers/static-image-accepter', () => {

const state = {staticImageAccepter, tree};

const newState = reducer(state, {type: actionNames.STATIC_ACCEPTER_COMMIT_SCREENSHOT, payload: [{imageId: 'imageId'}]});
const newState = reducer(state, {type: actionNames.STATIC_ACCEPTER_COMMIT_SCREENSHOT, payload: ['imageId']});

assert.equal(newState.staticImageAccepter.acceptableImages['imageId'].commitStatus, COMMITED);

Expand All @@ -201,7 +201,7 @@ describe('lib/static/modules/reducers/static-image-accepter', () => {

const state = {staticImageAccepter, tree};

const newState = reducer(state, {type: actionNames.STATIC_ACCEPTER_COMMIT_SCREENSHOT, payload: [{imageId: 'imageId'}]});
const newState = reducer(state, {type: actionNames.STATIC_ACCEPTER_COMMIT_SCREENSHOT, payload: ['imageId']});

assert.equal(newState.staticImageAccepter.acceptableImages['imageId'].commitStatus, COMMITED);
});
Expand Down
22 changes: 11 additions & 11 deletions test/unit/lib/static/modules/reducers/tree/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1801,37 +1801,37 @@ describe('lib/static/modules/reducers/tree', () => {
].forEach(({actionName, newStatus}) => {
describe(`${actionName} action`, () => {
it('should change image status', () => {
const newState = reducer(state, {type: actionName, payload: [{imageId: 'i1'}]});
const newState = reducer(state, {type: actionName, payload: ['i1']});

assert.equal(newState.tree.images.byId['i1'].status, newStatus);
});

it('should not change result status', () => {
const newState = reducer(state, {type: actionName, payload: [{imageId: 'i1'}]});
const newState = reducer(state, {type: actionName, payload: ['i1']});

assert.equal(newState.tree.results.byId['r1'].status, FAIL);
});

it('should change result status', () => {
const newState = reducer(state, {type: actionName, payload: [{imageId: 'i1'}, {imageId: 'i2'}]});
const newState = reducer(state, {type: actionName, payload: ['i1', 'i2']});

assert.equal(newState.tree.results.byId['r1'].status, newStatus);
});

it('should not change suite status', () => {
const newState = reducer(state, {type: actionName, payload: [{imageId: 'i1'}, {imageId: 'i2'}]});
const newState = reducer(state, {type: actionName, payload: ['i1', 'i2']});

assert.equal(newState.tree.suites.byId['s2'].status, FAIL);
});

it('should change suite status', () => {
const newState = reducer(state, {type: actionName, payload: [{imageId: 'i1'}, {imageId: 'i2'}, {imageId: 'i3'}]});
const newState = reducer(state, {type: actionName, payload: ['i1', 'i2', 'i3']});

assert.equal(newState.tree.suites.byId['s2'].status, newStatus);
});

it('should change suite state', () => {
const newState = reducer(state, {type: actionName, payload: [{imageId: 'i1'}, {imageId: 'i2'}, {imageId: 'i3'}]});
const newState = reducer(state, {type: actionName, payload: ['i1', 'i2', 'i3']});

assert.equal(newState.tree.suites.stateById['s2'].shouldBeShown, false);
});
Expand All @@ -1840,27 +1840,27 @@ describe('lib/static/modules/reducers/tree', () => {

describe(`${actionNames.STATIC_ACCEPTER_STAGE_SCREENSHOT} action`, () => {
it('should unstage another staged image', () => {
const newState = reducer(state, {type: actionNames.STATIC_ACCEPTER_STAGE_SCREENSHOT, payload: [{imageId: 'i0'}]});
const newState = reducer(state, {type: actionNames.STATIC_ACCEPTER_STAGE_SCREENSHOT, payload: ['i0']});

assert.equal(newState.tree.images.byId['i0'].status, STAGED);

const nextState = reducer(newState, {type: actionNames.STATIC_ACCEPTER_STAGE_SCREENSHOT, payload: [{imageId: 'i1'}]});
const nextState = reducer(newState, {type: actionNames.STATIC_ACCEPTER_STAGE_SCREENSHOT, payload: ['i1']});

assert.equal(nextState.tree.images.byId['i0'].status, FAIL);
});
});

describe(`${actionNames.STATIC_ACCEPTER_UNSTAGE_SCREENSHOT} action`, () => {
it('should return original image status', () => {
const newState = reducer(state, {type: actionNames.STATIC_ACCEPTER_STAGE_SCREENSHOT, payload: [{imageId: 'i1'}]});
const newState = reducer(state, {type: actionNames.STATIC_ACCEPTER_STAGE_SCREENSHOT, payload: ['i1']});

const nextState = reducer(newState, {type: actionNames.STATIC_ACCEPTER_UNSTAGE_SCREENSHOT, payload: {imageId: 'i1'}});

assert.equal(nextState.tree.images.byId['i1'].status, FAIL);
});

it('should return original result status', () => {
const firstState = reducer(state, {type: actionNames.STATIC_ACCEPTER_STAGE_SCREENSHOT, payload: [{imageId: 'i1'}, {imageId: 'i2'}]});
const firstState = reducer(state, {type: actionNames.STATIC_ACCEPTER_STAGE_SCREENSHOT, payload: ['i1', 'i2']});

const secondState = reducer(firstState, {type: actionNames.STATIC_ACCEPTER_UNSTAGE_SCREENSHOT, payload: {imageId: 'i1'}});
const thirdState = reducer(secondState, {type: actionNames.STATIC_ACCEPTER_UNSTAGE_SCREENSHOT, payload: {imageId: 'i2'}});
Expand All @@ -1869,7 +1869,7 @@ describe('lib/static/modules/reducers/tree', () => {
});

it('should return original suite status', () => {
const firstState = reducer(state, {type: actionNames.STATIC_ACCEPTER_STAGE_SCREENSHOT, payload: [{imageId: 'i1'}, {imageId: 'i2'}, {imageId: 'i3'}]});
const firstState = reducer(state, {type: actionNames.STATIC_ACCEPTER_STAGE_SCREENSHOT, payload: ['i1', 'i2', 'i3']});

const secondState = reducer(firstState, {type: actionNames.STATIC_ACCEPTER_UNSTAGE_SCREENSHOT, payload: {imageId: 'i1'}});
const thirdState = reducer(secondState, {type: actionNames.STATIC_ACCEPTER_UNSTAGE_SCREENSHOT, payload: {imageId: 'i2'}});
Expand Down

0 comments on commit 6b0ca64

Please sign in to comment.