import { get } from 'lodash'; import { identity } from 'lodash/fp'; import React from 'react'; import { connect } from 'react-redux'; import { Loading } from 'wdk-client/Components'; import { RootState } from 'wdk-client/Core/State/Types'; import AttributeAnalysisTabs from 'wdk-client/Views/AttributeAnalysis/AttributeAnalysisTabs'; import { WordCloud, Tag } from 'wdk-client/Views/AttributeAnalysis/WordCloudAnalysis/WordCloudAnalysis'; import { changeRankRange, changeSort, openView, closeView } from 'wdk-client/Actions/WordCloudAnalysisActions'; import { Dispatch } from 'redux'; import {ResultType} from 'wdk-client/Utils/WdkResult'; const DEFAULT_RANK_RANGE_MAX = 50; interface OwnProps { resultType: ResultType; reporterType: string; attributeName: string; } type StateProps = Pick; interface DispatchProps { changeRankRange: typeof changeRankRange; changeSort: typeof changeSort; openView: typeof openView; closeView: typeof closeView; dispatch: Dispatch; } type Props = OwnProps & DispatchProps & StateProps; class WordCloudAnalysisController extends React.PureComponent { componentDidMount() { const { reporterType, resultType, attributeName, openView } = this.props; const reporterName = `${attributeName}-${reporterType}`; openView(reporterName, resultType); } componentWillUnmount() { const { reporterType, resultType, attributeName, closeView } = this.props; const reporterName = `${attributeName}-${reporterType}`; closeView(reporterName, resultType); } render() { const { attributeAnalysis, wordCloudAnalysis, dispatch, changeRankRange, changeSort } = this.props; const { report, table, activeTab } = attributeAnalysis; if (report.error) return

Oops... something went wrong. Please try again later.

; if (report.resource == null) return ; const tags: Tag[] = get(report.resource, 'tags'); const { rankRange = { min: 1, max: Math.min(DEFAULT_RANK_RANGE_MAX, tags.length) }, wordCloudSort: sort = 'rank' } = wordCloudAnalysis; return ( ) }} /> ); } } function mapStateToProps(state: RootState): StateProps { const { attributeAnalysis, wordCloudAnalysis } = state; return { attributeAnalysis, wordCloudAnalysis }; } const mapDispatchToProps = { dispatch: identity, openView, closeView, changeRankRange, changeSort }; export default connect( mapStateToProps, mapDispatchToProps )(WordCloudAnalysisController);