Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Genesys Website
Commits
0d148b49
Commit
0d148b49
authored
Jan 09, 2019
by
Matija Obreza
Browse files
Fix: Don't update Subset and Dataset basic info unless form is dirty
- Prevents updates on simple UI navigation
parent
6eca93c4
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/datasets/ui/dashboard/dataset-stepper/steps/basic-info/index.tsx
View file @
0d148b49
import
*
as
React
from
'
react
'
;
import
{
bindActionCreators
}
from
'
redux
'
;
import
{
connect
}
from
'
react-redux
'
;
import
{
submit
,
isInvalid
}
from
'
redux-form
'
;
import
{
submit
,
isDirty
,
isInvalid
}
from
'
redux-form
'
;
// actions
import
{
loadMyPartners
}
from
'
partners/actions/dashboard
'
;
import
{
loadCrops
}
from
'
crop/actions/public
'
;
...
...
@@ -10,14 +10,13 @@ import { DATASET_BASIC_INFO_FORM } from 'datasets/constants';
// models
import
Partner
from
'
model/genesys/Partner
'
;
import
Crop
from
'
model/genesys/Crop
'
;
// utilities
import
{
log
}
from
'
utilities/debug
'
;
// ui
import
StepperTemplate
from
'
ui/common/stepper/StepperTemplate
'
;
import
BasicInfoForm
from
'
./BasicInfoForm
'
;
interface
IDatasetProps
extends
React
.
ClassAttributes
<
any
>
{
isFormDirty
:
boolean
;
loadMyPartners
:
any
;
myPartners
:
Partner
[];
submit
:
any
;
...
...
@@ -28,9 +27,13 @@ interface IDatasetProps extends React.ClassAttributes<any> {
class
BasicInfoStep
extends
StepperTemplate
<
IDatasetProps
>
{
protected
gotoStep
=
(
id
)
=>
{
const
{
submit
,
onGotoStep
}
=
this
.
props
;
log
(
'
Saving form
'
);
submit
(
DATASET_BASIC_INFO_FORM
);
const
{
submit
,
isFormDirty
,
onGotoStep
}
=
this
.
props
;
if
(
isFormDirty
)
{
// log('Saving form');
submit
(
DATASET_BASIC_INFO_FORM
);
}
else
{
console
.
log
(
`Form
${
DATASET_BASIC_INFO_FORM
}
not dirty`
);
}
setTimeout
(()
=>
onGotoStep
(
id
));
}
...
...
@@ -52,6 +55,7 @@ const mapStateToProps = (state, ownProps) => ({
crops
:
state
.
crop
.
public
.
list
,
myPartners
:
state
.
partner
.
dashboard
.
myPartners
,
isInvalidForm
:
isInvalid
(
DATASET_BASIC_INFO_FORM
)(
state
),
isFormDirty
:
isDirty
(
DATASET_BASIC_INFO_FORM
)(
state
),
});
const
mapDispatchToProps
=
(
dispatch
)
=>
bindActionCreators
({
...
...
src/subsets/ui/dashboard/subset-stepper/steps/basic-info/index.tsx
View file @
0d148b49
import
*
as
React
from
'
react
'
;
import
{
translate
}
from
'
react-i18next
'
;
import
{
bindActionCreators
}
from
'
redux
'
;
import
{
isInvalid
,
submit
}
from
'
redux-form
'
;
import
{
isInvalid
,
isDirty
,
submit
}
from
'
redux-form
'
;
import
{
connect
}
from
'
react-redux
'
;
// constants
import
{
SUBSET_FORM
}
from
'
subsets/constants
'
;
...
...
@@ -13,6 +13,7 @@ import StepperTemplate from 'ui/common/stepper/StepperTemplate';
interface
ISubsetProps
extends
React
.
ClassAttributes
<
any
>
{
isInvalidForm
:
boolean
;
isFormDirty
:
boolean
;
submit
:
any
;
crops
:
Crop
[];
t
:
any
;
...
...
@@ -23,9 +24,14 @@ class BasicInfoStep extends StepperTemplate<ISubsetProps> {
protected
renderContent
=
()
=>
(<
BasicInfoForm
initialValues
=
{
this
.
props
.
item
}
t
=
{
this
.
props
.
t
}
crops
=
{
this
.
props
.
crops
}
/>);
protected
gotoStep
=
(
id
)
=>
{
const
{
onGotoStep
,
submit
}
=
this
.
props
;
const
{
onGotoStep
,
submit
,
isFormDirty
}
=
this
.
props
;
if
(
onGotoStep
)
{
submit
(
SUBSET_FORM
);
if
(
isFormDirty
)
{
submit
(
SUBSET_FORM
);
}
else
{
console
.
log
(
`Form
${
SUBSET_FORM
}
not dirty`
);
}
setTimeout
(()
=>
onGotoStep
(
id
));
}
}
...
...
@@ -39,6 +45,7 @@ class BasicInfoStep extends StepperTemplate<ISubsetProps> {
const
mapStateToProps
=
(
state
,
ownProps
)
=>
({
crops
:
state
.
crop
.
public
.
list
,
isInvalidForm
:
isInvalid
(
SUBSET_FORM
)(
state
),
isFormDirty
:
isDirty
(
SUBSET_FORM
)(
state
),
});
const
mapDispatchToProps
=
(
dispatch
)
=>
bindActionCreators
({
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment