Instantly share code, notes, and snippets.
Last active
December 21, 2015 18:37
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save joefiorini/41b3b02d23590baf4637 to your computer and use it in GitHub Desktop.
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
diff --git a/ops/client/src/toolkits-docviewer/index.js b/ops/client/src/toolkits-docviewer/index.js | |
index af11735..f3e3511 100644 | |
--- a/ops/client/src/toolkits-docviewer/index.js | |
+++ b/ops/client/src/toolkits-docviewer/index.js | |
@@ -163,7 +163,7 @@ class DocviewerContainer extends Component { | |
addAnnotation: this.addAnotation.bind(this), | |
removeAnnotation: this.removeAnnotation.bind(this)}}/> | |
{hasFields && | |
- <EntitiesForm {...{selectedField, annotations, onFocus: this.onFocus.bind(this)}}/> | |
+ <EntitiesForm {...{selectedField, annotations, onFocus: this.onFocus.bind(this)}} showSaveButton={true}/> | |
} | |
</section> | |
); | |
@@ -201,6 +201,7 @@ DocviewerContainer.propTypes = { | |
}; | |
const mapStateAndPropsToProps = (state, {documentId}) => { | |
+ const {toolkit} = state; | |
const {documentsMetadata, documentsHocr, selectedField, annotations: {current: annotations}} = selectDocviewerState(state); | |
const {fieldsMetadata, fieldRefsByInputName} = state.entities; | |
return { | |
@@ -212,6 +213,7 @@ const mapStateAndPropsToProps = (state, {documentId}) => { | |
annotations, | |
fieldsMetadata, | |
fieldRefsByInputName, | |
+ toolkit | |
}; | |
}; | |
diff --git a/ops/client/src/toolkits-entities/containers/Form.js b/ops/client/src/toolkits-entities/containers/Form.js | |
index 63043ee..3b64e5d 100644 | |
--- a/ops/client/src/toolkits-entities/containers/Form.js | |
+++ b/ops/client/src/toolkits-entities/containers/Form.js | |
@@ -3,10 +3,12 @@ import {findDOMNode} from 'react-dom'; | |
import {connect} from 'react-redux'; | |
import {reduxForm} from 'redux-form'; | |
import {scrollSpy, scroller} from 'react-scroll'; | |
+import {Button} from 'common-controls'; | |
import RecordGroup from '../components/RecordGroup'; | |
import {addRecord, removeRecord} from '../reducers'; | |
import {flattenFields} from '../util'; | |
+import * as entityActions from '../reducers'; | |
function hasVisibleFields(entity) { | |
return entity.fields ? | |
@@ -35,17 +37,25 @@ class Form extends Component { | |
); | |
} | |
+ renderSaveButton() { | |
+ const {is_completed: isCompleted, isSaving} = this.props.toolkit; | |
+ | |
+ return !isCompleted && | |
+ <Button name="commit" className="button--neutral" form="entities-form" spinOnBusy busy={isSaving}>Save</Button>; | |
+ } | |
+ | |
render() { | |
const { | |
- fields, | |
- selectedField, | |
- annotations, | |
- relations, | |
- handleSubmit, | |
- validationErrors, | |
- addRecord: handleAddRecord, | |
- removeRecord: handleRemoveRecord, | |
- ...passThrough, | |
+ fields, | |
+ selectedField, | |
+ annotations, | |
+ relations, | |
+ handleSubmit, | |
+ validationErrors, | |
+ addRecord: handleAddRecord, | |
+ removeRecord: handleRemoveRecord, | |
+ ...passThrough, | |
+ showSaveButton, | |
} = this.props; | |
return ( | |
@@ -60,6 +70,7 @@ class Form extends Component { | |
null | |
)) | |
} | |
+ {showSaveButton ? this.renderSaveButton() : null} | |
</form> | |
); | |
} | |
@@ -103,12 +114,12 @@ class FormWrapper extends Component { | |
} | |
} | |
-const mapStateToProps = ({entities: {relations, fieldsMetadata, validationErrors}, docviewer: {annotations: {current: annotations}, selectedField}}, ) => { | |
+const mapStateToProps = ({entities: {relations, fieldsMetadata, validationErrors}, docviewer: {annotations: {current: annotations}, selectedField}, toolkit}, ) => { | |
const fieldKeys = Object.values(fieldsMetadata).map(field => field.inputName); | |
- return {relations, fields: fieldKeys, validationErrors, annotations, selectedField}; | |
+ return {relations, fields: fieldKeys, validationErrors, annotations, selectedField, toolkit}; | |
}; | |
export default connect( | |
mapStateToProps, | |
- {addRecord, removeRecord} | |
+ {addRecord, removeRecord, onSubmit: entityActions.update} | |
)(FormWrapper); | |
diff --git a/ops/client/src/toolkits-main/containers/Toolkit.js b/ops/client/src/toolkits-main/containers/Toolkit.js | |
index 56308fe..d7c798c 100644 | |
--- a/ops/client/src/toolkits-main/containers/Toolkit.js | |
+++ b/ops/client/src/toolkits-main/containers/Toolkit.js | |
@@ -149,7 +149,8 @@ class Toolkit extends Component { | |
} | |
render() { | |
- const {isLoaded, isFinishing, checklistItem, signsOfLife} = this.props; | |
+ const {isFinishing, checklistItem, signsOfLife} = this.props; | |
+ const {isLoaded} = this.props.toolkit; | |
if (isLoaded) { | |
if (isFinishing) { | |
@@ -174,7 +175,7 @@ class Toolkit extends Component { | |
); | |
} | |
- return (<div></div>); | |
+ return (<div>Loading...</div>); | |
} | |
} | |
diff --git a/ops/client/src/toolkits-main/reducers/toolkitData.js b/ops/client/src/toolkits-main/reducers/toolkitData.js | |
index be56972..6b1353f 100644 | |
--- a/ops/client/src/toolkits-main/reducers/toolkitData.js | |
+++ b/ops/client/src/toolkits-main/reducers/toolkitData.js | |
@@ -13,7 +13,7 @@ export const SAVE_FAILURE = 'toolkits-main/toolkitData/SAVE_FAILURE'; | |
export const CLOSE = 'toolkits-main/toolkitData/CLOSE'; | |
export const RESET = 'toolkits-main/toolkitData/RESET'; | |
-const INITIAL_STATE = {}; | |
+const INITIAL_STATE = {isLoaded: false}; | |
/* TODO: Make this into a root reducer composed of reducers for the major relationships | |
@@ -52,6 +52,7 @@ export default (state = INITIAL_STATE, action = null) => { | |
case LOAD_SUCCESS: | |
return { | |
...action.result.toolkit, | |
+ isLoaded: true, | |
isSaving: false, | |
}; | |
case LOAD_FAILURE: | |
diff --git a/ops/client/src/toolkits-main/reducers/ui.js b/ops/client/src/toolkits-main/reducers/ui.js | |
index ecc0df7..0032764 100644 | |
--- a/ops/client/src/toolkits-main/reducers/ui.js | |
+++ b/ops/client/src/toolkits-main/reducers/ui.js | |
@@ -10,10 +10,6 @@ import * as ChecklistItem from './checklistItem'; | |
export default (state = {isLoaded: false}, action) => { | |
switch (action.type) { | |
- case LOAD_SUCCESS: | |
- return {...state, isLoaded: true}; | |
- case RESET: | |
- return {...state, isLoaded: false}; | |
case ChecklistItem.TRANSITION_REQUEST: | |
return {...state, isFinishing: action.newStatus === 'finished'}; | |
case ChecklistItem.TRANSITION_SUCCESS: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment