forked from ibi-group/datatools-ui
-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create project and feed tweaks #255
Merged
landonreed
merged 7 commits into
create-project-and-feed
from
create-project-and-feed-ltr
Dec 3, 2018
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4c26e12
refactor(create-feed-project): tweaks to create feed and project forms
landonreed 37e900c
build(yarn): remove valid-url package
landonreed a4cbef4
fix(css): use leaflet cdn css (due to marker icon url issue)
landonreed f78bff0
refactor(loading): add style prop to loading component
landonreed dcde748
test(flow): fix flow type for Loading component props
landonreed e755adc
refactor(add autoFocus):
landonreed b35b4fa
refactor(create-project-feed): address PR comments
landonreed File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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 |
---|---|---|
|
@@ -78,6 +78,21 @@ export default class ProjectSettingsForm extends MessageComponent<Props, State> | |
|
||
componentWillMount () { | ||
this._updateStateFromProps(this.props) | ||
window.addEventListener('keydown', this._handleKeyDown) | ||
} | ||
|
||
componentWillUnmount () { | ||
window.removeEventListener('keydown', this._handleKeyDown) | ||
} | ||
|
||
_handleKeyDown = (e: SyntheticKeyboardEvent<HTMLInputElement>) => { | ||
switch( e.keyCode ) { | ||
case 13: // ENTER | ||
this._onSaveSettings() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There needs to be some kind of validation check done before calling |
||
break | ||
default: | ||
break | ||
} | ||
} | ||
|
||
componentWillReceiveProps (nextProps: Props) { | ||
|
@@ -208,17 +223,11 @@ export default class ProjectSettingsForm extends MessageComponent<Props, State> | |
} | ||
|
||
_onChangeName = ({target}: {target: HTMLInputElement}) => { | ||
const value = target.value | ||
const {name, value} = target | ||
this.setState( | ||
update(this.state, { | ||
model: { | ||
$merge: {[target.name]: value} | ||
}, | ||
validation: { | ||
name: { | ||
$set: value && value.length > 0 | ||
} | ||
} | ||
model: { $merge: {[name]: value} }, | ||
validation: { [name]: { $set: value && value.length > 0 } } | ||
}) | ||
) | ||
} | ||
|
@@ -289,32 +298,37 @@ export default class ProjectSettingsForm extends MessageComponent<Props, State> | |
} | ||
|
||
_onSaveSettings = () => { | ||
// if updating, only the things that have changed should be sent to the server | ||
const {project, updateProject} = this.props | ||
// Prevent a save if there have been no edits or form is invalid | ||
if (this._settingsAreUnedited() || !this._formIsValid()) return | ||
// Only the things that have changed should be sent to the server. This avoids | ||
// persisting JSON properties derived from a Jackson method. | ||
updateProject(project.id || '', this._getChanges(), true) | ||
} | ||
|
||
_getChanges = () => { | ||
const {model} = this.state | ||
let changes: any | ||
if (this.props.project.id) { | ||
// updating a project | ||
changes = {} | ||
Object.keys(model).map(k => { | ||
if (model[k] !== this.props.project[k]) { | ||
changes[k] = model[k] | ||
} | ||
}) | ||
} else { | ||
// creating a project | ||
changes = model | ||
} | ||
this.props.updateProject(this.props.project.id || '', changes, true) | ||
const {project} = this.props | ||
let changes: any = {} | ||
Object.keys(model).map(k => { | ||
if (model[k] !== project[k]) { | ||
changes[k] = model[k] | ||
} | ||
}) | ||
return changes | ||
} | ||
|
||
_settingsAreUnedited = () => Object.keys(this.state.model).length === 0 && | ||
this.state.model.constructor === Object | ||
_settingsAreUnedited = () => Object.keys(this._getChanges()).length === 0 | ||
|
||
_formIsValid = () => { | ||
const {validation} = this.state | ||
return Object.keys(validation).every(k => validation[k]) | ||
} | ||
|
||
render () { | ||
const {editDisabled, showDangerZone} = this.props | ||
const {model, validation} = this.state | ||
const {autoFetchHour, autoFetchMinute} = model | ||
const noEdits = Object.keys(model).length === 0 && model.constructor === Object | ||
const autoFetchChecked = model.autoFetchFeeds | ||
if (editDisabled) { | ||
return ( | ||
|
@@ -336,7 +350,8 @@ export default class ProjectSettingsForm extends MessageComponent<Props, State> | |
> | ||
<ControlLabel>{this.messages('fields.name')}</ControlLabel> | ||
<FormControl | ||
value={model.name} | ||
autoFocus | ||
value={model.name || ''} | ||
name={'name'} | ||
onChange={this._onChangeName} | ||
/> | ||
|
@@ -482,10 +497,8 @@ export default class ProjectSettingsForm extends MessageComponent<Props, State> | |
data-test-id='project-settings-form-save-button' | ||
disabled={ | ||
editDisabled || | ||
noEdits || | ||
!validation.name || | ||
!model.name || | ||
model.name === '' | ||
this._settingsAreUnedited() || | ||
!this._formIsValid() | ||
} | ||
onClick={this._onSaveSettings}> | ||
{this.messages('save')} | ||
|
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There needs to be some kind of validation check done before calling
_onSave
. It's possible to create a feed source without a name with this change.