forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
for apache#3502
- Loading branch information
Grace Guo
committed
Sep 25, 2017
1 parent
3aba1f2
commit cc29e51
Showing
12 changed files
with
196 additions
and
16 deletions.
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
62 changes: 62 additions & 0 deletions
62
superset/assets/javascripts/explore/components/controls/SelectAsyncControl.jsx
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,62 @@ | ||
/* global notify */ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import Select from '../../../components/AsyncSelect'; | ||
import { t } from '../../../locales'; | ||
|
||
const propTypes = { | ||
onChange: PropTypes.func, | ||
value: PropTypes.oneOfType([ | ||
PropTypes.string, | ||
PropTypes.number, | ||
PropTypes.arrayOf(PropTypes.string), | ||
PropTypes.arrayOf(PropTypes.number), | ||
]), | ||
}; | ||
|
||
const defaultProps = { | ||
onChange: () => {}, | ||
}; | ||
|
||
class SelectAsyncControl extends React.PureComponent { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
value: this.props.value, | ||
}; | ||
} | ||
|
||
onChange(options) { | ||
const optionValues = options.map(option => option.value); | ||
this.setState({ value: optionValues }); | ||
this.props.onChange(optionValues); | ||
} | ||
|
||
mutator(data) { | ||
if (!data || !data.result) { | ||
return []; | ||
} | ||
|
||
return data.result.map(layer => ({ value: layer.id, label: layer.name })); | ||
} | ||
|
||
render() { | ||
return ( | ||
<Select | ||
dataEndpoint={'/annotationlayermodelview/api/read?'} | ||
onChange={this.onChange.bind(this)} | ||
onAsyncError={() => notify.error(t('Error while fetching annotation layers'))} | ||
mutator={this.mutator} | ||
multi | ||
value={this.state.value} | ||
placeholder={t('Select a annotation layer')} | ||
valueRenderer={v => (<div>{v.label}</div>)} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
SelectAsyncControl.propTypes = propTypes; | ||
SelectAsyncControl.defaultProps = defaultProps; | ||
|
||
export default SelectAsyncControl; |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"""empty message | ||
Revision ID: d39b1e37131d | ||
Revises: ('a9c47e2c1547', 'ddd6ebdd853b') | ||
Create Date: 2017-09-19 15:09:14.292633 | ||
""" | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'd39b1e37131d' | ||
down_revision = ('a9c47e2c1547', 'ddd6ebdd853b') | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
def upgrade(): | ||
pass | ||
|
||
|
||
def downgrade(): | ||
pass |
File renamed without changes.
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,22 @@ | ||
"""empty message | ||
Revision ID: f959a6652acd | ||
Revises: ('472d2f73dfd4', 'd39b1e37131d') | ||
Create Date: 2017-09-24 20:18:35.791707 | ||
""" | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'f959a6652acd' | ||
down_revision = ('472d2f73dfd4', 'd39b1e37131d') | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
def upgrade(): | ||
pass | ||
|
||
|
||
def downgrade(): | ||
pass |
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