-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from Kitware/add-filter-support
Add filter support
- Loading branch information
Showing
6 changed files
with
283 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { Menu } from 'antd'; | ||
|
||
export default class Filters extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
filterMap: props.proxyManager.getProxyConfiguration().filters, | ||
filters: [], | ||
}; | ||
|
||
// Closure for callback | ||
this.onClick = this.onClick.bind(this); | ||
this.updateActiveSource = this.updateActiveSource.bind(this); | ||
} | ||
|
||
componentWillMount() { | ||
this.subscription = this.props.proxyManager.onActiveSourceChange( | ||
this.updateActiveSource | ||
); | ||
this.updateActiveSource(); | ||
} | ||
|
||
componentWillUnmount() { | ||
if (this.subscription) { | ||
this.subscription.unsubscribe(); | ||
this.subscription = null; | ||
} | ||
if (this.sourceSubscription) { | ||
this.sourceSubscription.unsubscribe(); | ||
this.sourceSubscription = null; | ||
} | ||
} | ||
|
||
onClick({ key }) { | ||
const inputProxy = this.props.proxyManager.getActiveSource(); | ||
if (inputProxy) { | ||
const filter = this.props.proxyManager.createProxy('Sources', key, { | ||
inputProxy, | ||
name: key, | ||
}); | ||
this.props.proxyManager.setActiveSource(filter); | ||
this.props.proxyManager.createRepresentationInAllViews(filter); | ||
this.props.proxyManager.renderAllViews(); | ||
this.props.updateTab('pipeline'); | ||
} | ||
} | ||
|
||
updateActiveSource() { | ||
if (this.sourceSubscription) { | ||
this.sourceSubscription.unsubscribe(); | ||
this.sourceSubscription = null; | ||
} | ||
const activeSource = this.props.proxyManager.getActiveSource(); | ||
const activeType = activeSource ? activeSource.getType() : ''; | ||
const filters = this.state.filterMap[activeType] || []; | ||
if (activeSource) { | ||
this.sourceSubscription = activeSource.onModified( | ||
this.updateActiveSource | ||
); | ||
} | ||
this.setState({ filters }); | ||
} | ||
|
||
render() { | ||
return ( | ||
<Menu onClick={this.onClick} selectable={false}> | ||
{this.state.filters.map((name) => ( | ||
<Menu.Item key={name}>{name}</Menu.Item> | ||
))} | ||
</Menu> | ||
); | ||
} | ||
} | ||
|
||
Filters.propTypes = { | ||
proxyManager: PropTypes.object.isRequired, | ||
updateTab: PropTypes.func, | ||
}; | ||
|
||
Filters.defaultProps = { | ||
updateTab: () => {}, | ||
}; |
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
Oops, something went wrong.