Skip to content

Commit

Permalink
add onDiscard without confirm #58
Browse files Browse the repository at this point in the history
  • Loading branch information
mydu committed Jul 2, 2019
1 parent c3f4159 commit 0ff1a3b
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 6 deletions.
10 changes: 8 additions & 2 deletions importApp/src/components/FieldInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,16 @@ class FieldInput extends React.Component {
}

componentDidUpdate (prevProps) {
const {fieldDescriptor, fieldValue} = this.props;
if (fieldDescriptor.name === 'slug' && fieldValue !== prevProps.fieldValue ) {
const {fieldDescriptor, fieldValue, fixedValue} = this.props;
if (fieldDescriptor.name === 'slug' && fieldValue !== prevProps.fieldValue) {
this.validateField(fieldValue)
}
if (fixedValue !== prevProps.fixedValue && !fixedValue) {
const state = this.getStateFromProps();
this.setState({
...state
})
}
}

getStateFromProps = () => {
Expand Down
27 changes: 24 additions & 3 deletions importApp/src/components/ForeignkeyCorrection.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,21 @@ class ForeignKeyCorrection extends React.Component {
})
}

handleDiscard = () => {
const {modificationItem} = this.props;
this.props.onTouch(false);
const fixedValues = this.initFixedValues();
this.setState({
fixedValues,
showSolving: modificationItem.fixed ? false : true,
showNewForm: false,
newResource: null,
newReference: null,
newRefReference: null
});
this.props.onDiscard()
}

renderFixed() {
const {modificationItem} = this.props;
const {field, fixedValues, fixedReferenceTable, unchangable}= modificationItem;
Expand Down Expand Up @@ -229,6 +244,7 @@ class ForeignKeyCorrection extends React.Component {
foreignKeys={schema.foreignKeys}
fieldDescriptor={fieldDescriptor}
referenceTables={referenceTables}
fixedValue={this.state.fixedValues[modificationItem.field]}
fieldValue={this.state.fixedValues[modificationItem.field]}
onClickCreate={this.handleClickCreate}
onChange={this.handleSelectExist} />
Expand All @@ -247,8 +263,7 @@ class ForeignKeyCorrection extends React.Component {
}

render() {
const {newResource, fixedValues} = this.state;
const {modificationItem, foreignKeyField, descriptor, referenceTables} = this.props;
const {modificationItem, foreignKeyField, descriptor, referenceTables, isModificationTouched} = this.props;
const {value, message, field}= modificationItem;
const resourceName = foreignKeyField.reference.resource;
const referenceFieldResource = descriptor.resources.find((resource) => resource.name === resourceName);
Expand Down Expand Up @@ -333,11 +348,17 @@ class ForeignKeyCorrection extends React.Component {
{
this.state.showSolving &&
<FieldContainer isGrouped>
{
{/* {
modificationItem.fixed &&
<Control>
<Button isColor="info" onClick={this.handleHideSolving}>Cancel</Button>
</Control>
} */}
{
isModificationTouched &&
<Control>
<Button isColor="info" onClick={this.handleDiscard}>Discard modification</Button>
</Control>
}
<Control>
<Button isColor="info" isDisabled={isSubmitDisabled} onClick={this.handleSubmitForm}>Confirm this fix</Button>
Expand Down
17 changes: 16 additions & 1 deletion importApp/src/components/FormatCorrection.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ class FormatCorrection extends React.Component {
})
}

handleDiscard = () => {
this.props.onTouch(false);
const state = this.hydrateState()
this.setState({
...state
});
}

renderOriginal() {
const {modificationItem} = this.props;
const {value, message, field}= modificationItem;
Expand Down Expand Up @@ -99,7 +107,7 @@ class FormatCorrection extends React.Component {
}

renderInput() {
const {modificationItem, fieldDescriptor} = this.props;
const {modificationItem, fieldDescriptor, isModificationTouched} = this.props;
const {fieldValid} = this.state;
const isSubmitDisabled = !fieldValid || !fieldValid.valid

Expand All @@ -110,6 +118,7 @@ class FormatCorrection extends React.Component {
isNonchangable={false}
fieldDescriptor={fieldDescriptor}
fieldValue={modificationItem.value}
fixedValue={this.state.fixedValue}
onChange={this.handleFieldChange} />

<FieldContainer isGrouped>
Expand All @@ -119,6 +128,12 @@ class FormatCorrection extends React.Component {
<Button isColor="info" onClick={this.handleHideSolving}>Cancel</Button>
</Control>
}
{
isModificationTouched &&
<Control>
<Button isColor="info" onClick={this.handleDiscard}>Discard modification</Button>
</Control>
}
<Control>
<Button isColor="info" isDisabled={isSubmitDisabled} onClick={this.handleSubmitForm}>Confirm this fix</Button>
</Control>
Expand Down
2 changes: 2 additions & 0 deletions importApp/src/containers/DataModification/DataModification.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ class DataModification extends React.Component {
isCurrencyFixDisabled={isCurrencyFixDisabled}
modificationIndex={modificationIndex}
modificationItem={modificationItem}
isModificationTouched={this.state.isModificationTouched}
onTouch={this.handleTouchModification}
onDiscard={this.props.goNextError}
onSubmitModification={handleSubmitModification} />

<div style={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ const ModificationComponent = ({
descriptor,
schema,
isCurrencyFixDisabled,
isModificationTouched,
modificationItem,
modificationIndex,
onDiscard,
onTouch,
onSubmitModification,
}) => {
Expand Down Expand Up @@ -54,6 +56,8 @@ const ModificationComponent = ({
fieldDescriptor={getFieldDescriptor()}
modificationItem={modificationItem}
modificationIndex={modificationIndex}
isModificationTouched={isModificationTouched}
onDiscard={onDiscard}
onTouch={onTouch}
onSubmitForm={handleSubmitModification}
/>
Expand All @@ -65,9 +69,11 @@ const ModificationComponent = ({
descriptor={descriptor}
foreignKeyField={getForeignKeyField()}
isCurrencyFixDisabled={isCurrencyFixDisabled}
isModificationTouched={isModificationTouched}
referenceTables={referenceTables}
modificationItem={modificationItem}
modificationIndex={modificationIndex}
onDiscard={onDiscard}
onTouch={onTouch}
onSubmitForm={handleSubmitModification}
/>
Expand Down

0 comments on commit 0ff1a3b

Please sign in to comment.