This repository has been archived by the owner on Jun 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 154
Gatsby starter #335
Merged
Merged
Gatsby starter #335
Changes from 7 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
fd816ea
WIP: Business logic added. Styling needs to be improved.
AWolf81 a82bf3a
WIP: Fix flow typing
AWolf81 559fa13
added preview in codesandbox.
AWolf81 cb92fc0
fixed flow types
AWolf81 14e37fc
fixed test
AWolf81 9c1a182
removed toastr & used modal
AWolf81 86efa23
improved styling
AWolf81 badd311
improved styling
AWolf81 032cab4
added test for config variable substitution
AWolf81 a358134
WIP: CurrentStepIndex not working as expected.
AWolf81 2c55838
fixed flow types
AWolf81 8bb11ca
WIP: Added starter exists check. Dialog displayed too late.
AWolf81 2400326
fixed starter check
AWolf81 c277acf
fixed flow type
AWolf81 f1218d8
addressed review comments.
AWolf81 74533f4
removed starter modal & changed starter selection
AWolf81 b0cddab
small improvements
AWolf81 a69d553
added default spacing
AWolf81 a53bfd4
Merge branch 'master' into gatsby-starter
AWolf81 4830ae0
fixed flow
AWolf81 c741cba
added tests
AWolf81 c8e56fd
removed commented line
AWolf81 6ac1a17
addressed review - new typeahead logic
AWolf81 088357e
fixed flow
AWolf81 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
86 changes: 86 additions & 0 deletions
86
src/components/CreateNewProjectWizard/Gatsby/ProjectStarterSelection.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,86 @@ | ||
// @flow | ||
import React, { PureComponent } from 'react'; | ||
import { connect } from 'react-redux'; | ||
// import styled from 'styled-components'; | ||
|
||
// import { COLORS } from '../../constants'; | ||
|
||
import TextInputWithButton from '../../TextInputWithButton'; | ||
|
||
import * as actions from '../../../actions'; | ||
import type { Dispatch } from '../../../actions/types'; | ||
|
||
type State = { | ||
gatsbyStarter: string, | ||
}; | ||
|
||
type Props = { | ||
projectStarter: string, | ||
isFocused: boolean, | ||
handleFocus: string => void, | ||
onSelect: string => void, | ||
onFocus: () => void, | ||
showStarterSelection: Dispatch<typeof actions.showStarterSelectionModal>, | ||
}; | ||
|
||
class ProjectStarter extends PureComponent<Props, State> { | ||
state = { | ||
gatsbyStarter: '', | ||
}; | ||
|
||
static getDerivedStateFromProps(nextProps: Props, prevState: State) { | ||
return { | ||
gatsbyStarter: nextProps.projectStarter, | ||
}; | ||
} | ||
|
||
// Change method needed so we can dismiss the selection on close click of toastr | ||
changeGatsbyStarter = (selectedStarter: string) => { | ||
console.log('change starter', selectedStarter, this); | ||
this.setState( | ||
{ | ||
gatsbyStarter: selectedStarter, | ||
}, | ||
() => { | ||
console.log('updated', this.state); | ||
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. I feel like we don't need this callback? Also, there's another console.log above it. 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. Yes, that's right. Sorry, I've missed that debug stuff. I'll remove it. |
||
} | ||
); | ||
}; | ||
|
||
handleSelect = () => { | ||
this.props.onSelect(this.state.gatsbyStarter); | ||
|
||
// clear temporary state value | ||
// this.setState({ | ||
// gatsbyStarter: '', | ||
// }); | ||
}; | ||
|
||
render() { | ||
const { | ||
handleFocus, | ||
projectStarter, | ||
isFocused, | ||
onSelect, | ||
showStarterSelection, | ||
} = this.props; | ||
|
||
return ( | ||
<TextInputWithButton | ||
handleFocus={handleFocus} | ||
isFocused={isFocused} | ||
value={projectStarter} | ||
onChange={onSelect} | ||
onClick={showStarterSelection} | ||
/> | ||
); | ||
} | ||
} | ||
const mapDispatchToProps = { | ||
showStarterSelection: actions.showStarterSelectionModal, | ||
}; | ||
|
||
export default connect( | ||
null, | ||
mapDispatchToProps | ||
)(ProjectStarter); |
Oops, something went wrong.
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.
Hm, so I think in general this is a not-ideal pattern. I feel like either this component should own the state entirely, so it doesn't receive
projectStarter
from props, or it should always delegate to the parent'sprojectStarter
.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.
I think you're right but with-out this it would require me to modify modal state as I need to have the info about the entered starter before opening the modal.
So the user can dismiss the changes made in the modal. Anyway I'm not changing this as I'll check if I can remove the second modal - so this won't be needed anymore.
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.
It's acutally an anti-pattern to override local state unconditionally with every prop change.
There is a nice post you-probably-dont-need-derived-state about this in the React.js blog.
We don't need it here anymore as I'm rewriting this. But I wanted to note this as I've learned this and I wasn't aware of it.