import { connect } from 'react-redux';
import { withRouter } from 'react-router';
import type { Dispatch } from 'redux';
+import { uniq } from 'lodash';
import App from './App';
import { onFail } from '../../../store/rootActions';
import { getComponent, getCurrentUser } from '../../../store/rootReducer';
+import { getOrganizations } from '../../../api/organizations';
+import { receiveOrganizations } from '../../../store/organizations/duck';
import { searchIssues } from '../../../api/issues';
import { parseIssueFromResponse } from '../../../helpers/issues';
currentUser: getCurrentUser(state)
});
-const fetchIssues = (query: Query) => (dispatch: Dispatch<*>) =>
- searchIssues({ ...query, additionalFields: '_all' }).then(response => {
- const parsedIssues = response.issues.map(issue =>
- parseIssueFromResponse(issue, response.components, response.users, response.rules)
- );
- return { ...response, issues: parsedIssues };
- }, onFail(dispatch));
+const fetchIssueOrganizations = issues => dispatch => {
+ if (!issues.length) {
+ return Promise.resolve();
+ }
+
+ const organizationKeys = uniq(issues.map(issue => issue.organization));
+ return getOrganizations(organizationKeys).then(
+ response => dispatch(receiveOrganizations(response.organizations)),
+ onFail(dispatch)
+ );
+};
+
+const fetchIssues = (query: Query) => dispatch =>
+ searchIssues({ ...query, additionalFields: '_all' })
+ .then(response => {
+ const parsedIssues = response.issues.map(issue =>
+ parseIssueFromResponse(issue, response.components, response.users, response.rules)
+ );
+ return { ...response, issues: parsedIssues };
+ })
+ .then(response => dispatch(fetchIssueOrganizations(response.issues)).then(() => response))
+ .catch(onFail(dispatch));
const onRequestFail = (error: Error) => (dispatch: Dispatch<*>) => onFail(dispatch)(error);
import type { ReferencedComponent, Component } from '../utils';
import Organization from '../../../components/shared/Organization';
import QualifierIcon from '../../../components/shared/QualifierIcon';
-import { searchComponents, getTree } from '../../../api/components';
+import { searchProjects, getTree } from '../../../api/components';
import { translate } from '../../../helpers/l10n';
type Props = {|
value: component.refId
}))
)
- : searchComponents({ ps: 50, q: query, qualifiers: 'TRK' }).then(response =>
+ : searchProjects({
+ ps: 50,
+ filter: query ? `query = "${query}"` : ''
+ }).then(response =>
response.components.map(component => ({
label: component.name,
organization: component.organization,