-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
315 additions
and
35 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,31 @@ | ||
import actionNames from '../actionNames'; | ||
import Api from '../../helpers/Api'; | ||
import { sendMessageToBackend } from '../Error/errorActions'; | ||
|
||
const api = Api.getInstance(); | ||
|
||
export const setValidationResult = (result) => { | ||
return { | ||
type: actionNames.SET_VALIDATION_RESULT, | ||
payload: result | ||
} | ||
} | ||
|
||
export const validateFilenames = (formData) => { | ||
return (dispatch) => { | ||
api.post('/api//v1/package/files/validation', formData) | ||
.then(res => { | ||
dispatch(setValidationResult(res.data)); | ||
}) | ||
.catch(error => { | ||
console.log(error); | ||
dispatch(sendMessageToBackend(error)); | ||
}); | ||
} | ||
} | ||
|
||
export const clearValidationResult = () => { | ||
return { | ||
type: actionNames.CLEAR_VALIDATION_RESULT | ||
} | ||
} |
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,26 @@ | ||
import actionNames from '../actionNames'; | ||
import { setValidationResult, clearValidationResult } from './validationActions'; | ||
|
||
describe('setValidationResult', () => { | ||
it('should return the result in the correct structure', () => { | ||
let expectedResult = { | ||
type: actionNames.SET_VALIDATION_RESULT, | ||
payload: { 'key': 'value' } | ||
}; | ||
|
||
let result = setValidationResult({ 'key': 'value' }); | ||
|
||
expect(result).toEqual(expectedResult); | ||
}); | ||
}); | ||
describe('clearValidationResult', () => { | ||
it('should return the result in the correct structure', () => { | ||
let expectedResult = { | ||
type: actionNames.CLEAR_VALIDATION_RESULT | ||
}; | ||
|
||
let result = clearValidationResult(); | ||
|
||
expect(result).toEqual(expectedResult); | ||
}); | ||
}); |
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,7 +1,9 @@ | ||
const actionNames = { | ||
RESET_STATE: 'RESET_STATE', | ||
SET_PACKAGES: 'SET_PACKAGES', | ||
GET_PACKAGES: 'GET_PACKAGES' | ||
CLEAR_VALIDATION_RESULT: 'CLEAR_VALIDATION_RESULT', | ||
GET_PACKAGES: 'GET_PACKAGES', | ||
RESET_STATE: 'RESET_STATE', | ||
SET_PACKAGES: 'SET_PACKAGES', | ||
SET_VALIDATION_RESULT: 'SET_VALIDATION_RESULT' | ||
}; | ||
|
||
export default actionNames; |
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 |
---|---|---|
@@ -1,10 +1,18 @@ | ||
import { connect } from 'react-redux'; | ||
import FilenameValidationPage from './FilenameValidationPage'; | ||
import { validateFilenames, clearValidationResult } from '../../actions/Validation/validationActions'; | ||
|
||
const mapStateToProps = (state, props) => ({ | ||
validationResult: state.filenameValidation | ||
}); | ||
|
||
const mapDispatchToProps = (dispatch, props) => ({ | ||
validateFilenames(formData) { | ||
dispatch(validateFilenames(formData)); | ||
}, | ||
clearValidationResult() { | ||
dispatch(clearValidationResult()); | ||
} | ||
}); | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(FilenameValidationPage); |
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,23 @@ | ||
import React, { Component } from 'react'; | ||
import { Container, Row, Col, Button } from 'reactstrap'; | ||
|
||
class ValidationFailure extends Component { | ||
render() { | ||
return( | ||
<Container> | ||
<Row className='mt-3'> | ||
<Col sm={12}> | ||
<img | ||
src="img/fail-kidneys.jpg" | ||
alt="Filename mismatch" | ||
id="fail-kidneys" | ||
/> | ||
</Col> | ||
</Row> | ||
</Container> | ||
|
||
) | ||
} | ||
} | ||
|
||
export default ValidationFailure; |
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,95 @@ | ||
import React, { Component } from 'react'; | ||
import { Container, Row, Col, Button } from 'reactstrap'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
class ValidationSuccess extends Component { | ||
|
||
generateTableRows(filesProvided, filesFound) { | ||
let rows = []; | ||
for (let i=0; i< filesProvided.length; i++) { | ||
let fileProvided = filesProvided[i]; | ||
let fileFound = filesFound[i]; | ||
rows.push( | ||
<Row className='mt-3'> | ||
<Col sm={6}> | ||
{fileProvided} | ||
</Col> | ||
<Col sm={6}> | ||
{fileFound} | ||
</Col> | ||
</Row> | ||
); | ||
} | ||
return rows; | ||
} | ||
|
||
render() { | ||
let metadataFileName = ''; | ||
let filesProvided = this.props.result.filesFromMetadata.sort(); | ||
let filesFound = this.props.result.filesInGlobus.sort(); | ||
let metadataFileIndex = filesFound.findIndex((file) => file.startsWith('METADATA')); | ||
if (metadataFileIndex > -1) { | ||
metadataFileName = filesFound[metadataFileIndex]; | ||
filesFound.splice(metadataFileIndex, 1); | ||
} | ||
let rows = this.generateTableRows(filesProvided, filesFound); | ||
|
||
return ( | ||
<Container> | ||
<Row className='mt-3'> | ||
<Col sm={2} > | ||
<img | ||
src="img/happy-kidneys.jpg" | ||
alt="Filename match" | ||
id="happy-kidneys" | ||
className='validationImage' | ||
/> | ||
</Col> | ||
<Col sm={10}> | ||
<h3 className='validationMessage'>Validation Success!</h3> | ||
</Col> | ||
</Row> | ||
<Row className='mt-3'> | ||
<Col sm={12}> | ||
<span className='heavierText'>Package Id:</span> {this.props.result.packageId} | ||
</Col> | ||
</Row> | ||
|
||
<Row className='mt-3'> | ||
<Col sm={6} className='resultHeader'> | ||
Files Provided | ||
</Col> | ||
<Col sm={6} className='resultHeader'> | ||
Files Found | ||
</Col> | ||
</Row> | ||
{rows} | ||
{metadataFileName !== '' && | ||
<Row className='mt-3'> | ||
<Col sm={6}> | ||
|
||
</Col> | ||
<Col sm={6}> | ||
{metadataFileName} | ||
</Col> | ||
</Row> | ||
|
||
} | ||
<Row className='mt-6'> | ||
<Col sm={6}> | ||
<Link to='/filenameValidation'> | ||
<Button color="primary">Let's do it again!</Button> | ||
</Link> | ||
</Col> | ||
<Col sm={6}> | ||
<Link to='/'> | ||
<Button color="primary">Done for now</Button> | ||
</Link> | ||
</Col> | ||
</Row> | ||
</Container> | ||
); | ||
} | ||
} | ||
|
||
export default ValidationSuccess; |
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,15 @@ | ||
import actionNames from '../../actions/actionNames'; | ||
|
||
export const filenameValidation = (state = {}, action) => { | ||
let newState = {}; | ||
|
||
switch (action.type) { | ||
case actionNames.SET_VALIDATION_RESULT: | ||
newState = action.payload; | ||
return newState; | ||
case actionNames.CLEAR_VALIDATION_RESULT: | ||
return newState; | ||
default: | ||
return state; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/components/Validation/filenameValidationReducer.test.js
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,25 @@ | ||
import { filenameValidation } from './filenameValidationReducer'; | ||
import actionNames from '../../actions/actionNames'; | ||
|
||
describe('filenameValidation', () => { | ||
it('should return the given state if not known action', () => { | ||
let action = { | ||
type: 'UNKNOWN' | ||
}; | ||
expect(filenameValidation({}, action)).toEqual({}); | ||
}); | ||
|
||
it('should return the new state if SET_VALIDATION_RESULT', () => { | ||
let action = { | ||
type: actionNames.SET_VALIDATION_RESULT, | ||
payload: 'new stuff' | ||
}; | ||
expect(filenameValidation({}, action)).toEqual('new stuff'); | ||
}); | ||
it('should clear the state if CLEAR_VALIDATION_RESULT', () => { | ||
let action = { | ||
type: actionNames.CLEAR_VALIDATION_RESULT | ||
}; | ||
expect(filenameValidation({'key': 'value'}, action)).toEqual({}); | ||
}); | ||
}); |
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.