-
Notifications
You must be signed in to change notification settings - Fork 4
Moved tag selector to a component #543
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
Open
OSPFNeighbour
wants to merge
3
commits into
master
Choose a base branch
from
tdykes.refactor_tags_to_modal
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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 hidden or 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,117 @@ | ||
| import React, { Component } from 'react'; | ||
| import CheckBox from 'react-native-check-box'; | ||
|
|
||
| import PropTypes from 'prop-types'; | ||
| import { View, Modal, TouchableOpacity, TouchableWithoutFeedback, Text, ScrollView } from 'react-native'; | ||
| import { SearchBar } from 'react-native-elements'; | ||
|
|
||
| import { Center } from '../Container'; | ||
|
|
||
| import styles from './styles'; | ||
|
|
||
| class TagModal extends Component { | ||
| isChecked = (option) => { | ||
| const index = this.props.selectedTags.indexOf(option.id); | ||
| return index !== -1; | ||
| }; | ||
|
|
||
| renderOption(option, isLastItem) { | ||
| return ( | ||
| <TouchableOpacity key={option.id}> | ||
| <View style={[styles.optionStyle, isLastItem && { borderBottomWidth: 0 }]}> | ||
| <CheckBox | ||
| style={{ flex: 1, padding: 10 }} | ||
| rightText={option.name} | ||
| onClick={() => this.props.onSelect(option)} | ||
| isChecked={this.isChecked(option)} | ||
| /> | ||
| </View> | ||
| </TouchableOpacity> | ||
| ); | ||
| } | ||
|
|
||
| renderOptionList() { | ||
| const options = this.props.dataIn.map((item, index) => | ||
| this.renderOption(item, index === this.props.dataIn.length - 1)); | ||
|
|
||
| if (options.length) { | ||
| return [options]; | ||
| } | ||
| return ( | ||
| <Center> | ||
| <Text>No matching tags found</Text> | ||
| </Center> | ||
| ); | ||
| } | ||
|
|
||
| render() { | ||
| return ( | ||
| <View> | ||
| <Modal | ||
| transparent | ||
| visible={this.props.visible} | ||
| onRequestClose={this.props.closeModal} | ||
| animationType="fade" | ||
| > | ||
| <TouchableWithoutFeedback | ||
| onPress={this.props.closeModal} | ||
| > | ||
| <View style={styles.overlayStyle}> | ||
| <View style={styles.headerContainer}> | ||
| <TouchableOpacity> | ||
| <View style={styles.headerStyle}> | ||
| <Text style={styles.headerTextStyle}>{this.props.headerText}</Text> | ||
| </View> | ||
| </TouchableOpacity> | ||
| </View> | ||
| <View style={styles.searchContainer}> | ||
| <SearchBar | ||
| lightTheme | ||
| round | ||
| showLoading={this.props.isLoading} | ||
| containerStyle={styles.searchbar} | ||
| onChangeText={this.props.onSearch} | ||
| onClearText={null} | ||
| placeholder="Search" | ||
| /> | ||
| </View> | ||
| <View | ||
| style={{ | ||
| borderBottomColor: 'grey', | ||
| borderBottomWidth: 1, | ||
| alignItems: 'center', | ||
| }} | ||
| /> | ||
| <View style={styles.headerContainer} /> | ||
| <View style={styles.optionContainerTags}> | ||
| <ScrollView keyboardShouldPersistTaps="handled"> | ||
| <View style={{ paddingHorizontal: 10 }}>{this.renderOptionList()}</View> | ||
| </ScrollView> | ||
| </View> | ||
| <View style={styles.cancelContainer}> | ||
| <TouchableOpacity onPress={this.props.backModal}> | ||
| <View style={styles.cancelStyle}> | ||
| <Text style={styles.cancelTextStyle}>Save</Text> | ||
| </View> | ||
| </TouchableOpacity> | ||
| </View> | ||
| </View> | ||
| </TouchableWithoutFeedback> | ||
| </Modal> | ||
| </View> | ||
| ); | ||
| } | ||
| } | ||
| TagModal.propTypes = { | ||
| dataIn: PropTypes.array, // eslint-disable-line react/forbid-prop-types | ||
| selectedTags: PropTypes.array, // eslint-disable-line react/forbid-prop-types | ||
| headerText: PropTypes.string.isRequired, | ||
| closeModal: PropTypes.func.isRequired, | ||
| onSearch: PropTypes.func.isRequired, | ||
| onSelect: PropTypes.func.isRequired, | ||
| isLoading: PropTypes.bool, | ||
| backModal: PropTypes.func.isRequired, | ||
| visible: PropTypes.bool.isRequired, | ||
| }; | ||
|
|
||
| export default TagModal; | ||
This file contains hidden or 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,65 @@ | ||
| import React from 'react'; | ||
| import renderer from 'react-test-renderer'; | ||
|
|
||
| import TagModal from '../TagModal'; | ||
|
|
||
| const noop = () => {}; | ||
|
|
||
| test('renders correctly', () => { | ||
| const normal = renderer.create( | ||
| <TagModal | ||
| headerText="test" | ||
| dataIn={[{ name: 'item1', id: 0 }]} | ||
| selectedTags={[]} | ||
| onSelect={noop} | ||
| closeModal={noop} | ||
| backModal={noop} | ||
| onSearch={noop} | ||
| isLoading={false} | ||
| visible | ||
| />, | ||
| ).toJSON(); | ||
| const selection = renderer.create( | ||
| <TagModal | ||
| headerText="test" | ||
| dataIn={[{ name: 'item1', id: 0 }]} | ||
| selectedTags={[0]} | ||
| onSelect={noop} | ||
| closeModal={noop} | ||
| backModal={noop} | ||
| onSearch={noop} | ||
| isLoading={false} | ||
| visible | ||
| />, | ||
| ).toJSON(); | ||
| const loading = renderer.create( | ||
| <TagModal | ||
| headerText="test" | ||
| dataIn={[{ name: 'item1', id: 0 }]} | ||
| selectedTags={[]} | ||
| onSelect={noop} | ||
| closeModal={noop} | ||
| backModal={noop} | ||
| onSearch={noop} | ||
| isLoading | ||
| visible | ||
| />, | ||
| ).toJSON(); | ||
| const empty = renderer.create( | ||
| <TagModal | ||
| headerText="test" | ||
| dataIn={[]} | ||
| selectedTags={[]} | ||
| onSelect={noop} | ||
| closeModal={noop} | ||
| backModal={noop} | ||
| onSearch={noop} | ||
| isLoading | ||
| visible | ||
| />, | ||
| ).toJSON(); | ||
| expect(normal).toMatchSnapshot(); | ||
| expect(selection).toMatchSnapshot(); | ||
| expect(loading).toMatchSnapshot(); | ||
| expect(empty).toMatchSnapshot(); | ||
| }); |
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.
if this was it's own component you wouldn't need the closure