Skip to content

Commit

Permalink
Merge 91434cf into 7878147
Browse files Browse the repository at this point in the history
  • Loading branch information
nrvikas committed Nov 5, 2018
2 parents 7878147 + 91434cf commit ccfa712
Show file tree
Hide file tree
Showing 7 changed files with 234 additions and 10 deletions.
9 changes: 9 additions & 0 deletions client/actions/events/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,15 @@ const getCriteria = (
must.push({terms: {'subject.qcode': codes}});
},
},
{
condition: () => (Array.isArray(advancedSearch.place) &&
advancedSearch.place.length > 0),
do: () => {
const codes = advancedSearch.place.map((p) => p.qcode);

must.push({terms: {'place.qcode': codes}});
},
},
{
condition: () => (get(advancedSearch, 'dates')),
do: () => {
Expand Down
2 changes: 2 additions & 0 deletions client/actions/eventsPlanning/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const query = (
JSON.stringify(get(advancedSearch, 'anpa_category', []).map((c) => c.qcode)) : null,
subject: get(advancedSearch, 'subject.length', 0) ?
JSON.stringify(get(advancedSearch, 'subject', []).map((s) => s.qcode)) : null,
place: get(advancedSearch, 'place.length', 0) > 0 ?
JSON.stringify(get(advancedSearch, 'place', []).map((p) => p.qcode)) : null,
slugline: advancedSearch.slugline,
state: get(advancedSearch, 'state.length', 0) ?
JSON.stringify(get(advancedSearch, 'state', []).map((c) => c.qcode)) : null,
Expand Down
9 changes: 9 additions & 0 deletions client/actions/planning/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,15 @@ const getCriteria = ({
must.push({term: {featured: true}});
},
},
{
condition: () => (Array.isArray(advancedSearch.place) &&
advancedSearch.place.length > 0),
do: () => {
const codes = advancedSearch.place.map((p) => p.qcode);

must.push({terms: {'place.qcode': codes}});
},
},
].forEach((action) => {
if (action.condition()) {
action.do();
Expand Down
51 changes: 42 additions & 9 deletions client/components/AdvancedSearch/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import {get} from 'lodash';
import {get, sortBy} from 'lodash';
import {gettext} from '../../utils';
import {ContentBlock} from '../UI/SidePanel';
import {MAIN, SPIKED_STATE} from '../../constants';
Expand Down Expand Up @@ -104,6 +104,8 @@ export class AdvancedSearch extends React.Component {
onChange,
workflowStateOptions,
popupContainer,
searchProfile,
locators,
} = this.props;

// Change spikeState options based on workflow-state selection in the from
Expand Down Expand Up @@ -135,6 +137,7 @@ export class AdvancedSearch extends React.Component {
value: get(diff, 'advancedSearch.name', ''),
},
component: TextInput,
...get(searchProfile, 'name'),
},
slugline: {
props: {
Expand All @@ -143,6 +146,7 @@ export class AdvancedSearch extends React.Component {
value: get(diff, 'advancedSearch.slugline', ''),
},
component: TextInput,
...get(searchProfile, 'slugline'),
},
location: {
props: {
Expand All @@ -152,6 +156,7 @@ export class AdvancedSearch extends React.Component {
disableSearch: true,
},
component: GeoLookupInput,
...get(searchProfile, 'location'),
},
state: {
props: {
Expand All @@ -162,6 +167,7 @@ export class AdvancedSearch extends React.Component {
popupContainer: popupContainer,
},
component: SelectMetaTermsInput,
...get(searchProfile, 'state'),
},
anpa_category: {
props: {
Expand All @@ -172,6 +178,7 @@ export class AdvancedSearch extends React.Component {
popupContainer: popupContainer,
},
component: SelectMetaTermsInput,
...get(searchProfile, 'anpa_category'),
},
subject: {
props: {
Expand All @@ -182,6 +189,7 @@ export class AdvancedSearch extends React.Component {
popupContainer: popupContainer,
},
component: SelectMetaTermsInput,
...get(searchProfile, 'subject'),
},
source: {
props: {
Expand All @@ -192,6 +200,7 @@ export class AdvancedSearch extends React.Component {
valueKey: 'id',
},
component: SelectMetaTermsInput,
...get(searchProfile, 'source'),
},
urgency: {
props: {
Expand All @@ -202,6 +211,7 @@ export class AdvancedSearch extends React.Component {
iconName: 'urgency-label',
},
component: ColouredValueInput,
...get(searchProfile, 'urgency'),
},
noCoverage: {
props: {
Expand All @@ -211,6 +221,7 @@ export class AdvancedSearch extends React.Component {
labelLeft: true,
},
component: ToggleInput,
...get(searchProfile, 'no_coverage'),
},
featured: {
props: {
Expand All @@ -220,6 +231,7 @@ export class AdvancedSearch extends React.Component {
labelLeft: true,
},
component: ToggleInput,
...get(searchProfile, 'featured'),
},
contentType: {
props: {
Expand All @@ -231,6 +243,7 @@ export class AdvancedSearch extends React.Component {
clearable: true,
},
component: SelectInput,
...get(searchProfile, 'content_type'),
},
pubstatus: {
props: {
Expand All @@ -240,6 +253,7 @@ export class AdvancedSearch extends React.Component {
labelLeft: true,
},
component: ToggleInput,
...get(searchProfile, 'pub_status'),
},
startDateTime: {
props: {
Expand All @@ -252,6 +266,7 @@ export class AdvancedSearch extends React.Component {
},
component: DateTimeInput,
onChange: this.onDateChange,
...get(searchProfile, 'start_date_time'),
},
endDateTime: {
props: {
Expand All @@ -265,6 +280,7 @@ export class AdvancedSearch extends React.Component {
},
component: DateTimeInput,
onChange: this.onDateChange,
...get(searchProfile, 'end_date_time'),
},
spikeState: {
props: {
Expand All @@ -275,6 +291,7 @@ export class AdvancedSearch extends React.Component {
options: spikedStateOptions,
},
component: RadioButtonInput,
...get(searchProfile, 'spike_state'),
},
dateFilters: {
props: {
Expand Down Expand Up @@ -303,6 +320,19 @@ export class AdvancedSearch extends React.Component {
},
component: RadioButtonInput,
onChange: this.onDateChange,
...get(searchProfile, 'date_filter'),
},
place: {
props: {
field: 'advancedSearch.place',
label: gettext('Place'),
value: get(diff, 'advancedSearch.place', []),
options: locators,
popupContainer: popupContainer,
groupField: 'group',
},
component: SelectMetaTermsInput,
...get(searchProfile, 'place'),
},
};

Expand All @@ -312,27 +342,29 @@ export class AdvancedSearch extends React.Component {
[MAIN.FILTERS.COMBINED]: [
fields.slugline, fields.anpa_category, fields.subject, fields.state,
fields.pubstatus, fields.spikeState,
fields.startDateTime, fields.endDateTime,
fields.dateFilters,
fields.startDateTime, fields.endDateTime, fields.dateFilters,
],
[MAIN.FILTERS.EVENTS]: [
fields.name, fields.slugline,
fields.anpa_category, fields.subject, fields.source, fields.location, fields.state,
fields.pubstatus, fields.spikeState,
fields.startDateTime, fields.endDateTime,
fields.name, fields.slugline, fields.anpa_category, fields.subject,
fields.source, fields.location, fields.state, fields.pubstatus,
fields.spikeState, fields.startDateTime, fields.endDateTime,
fields.dateFilters,
],
[MAIN.FILTERS.PLANNING]: [
fields.slugline, fields.contentType, fields.noCoverage, fields.featured,
fields.anpa_category, fields.subject, fields.urgency, fields.state,
fields.pubstatus, fields.spikeState,
fields.startDateTime, fields.endDateTime, fields.dateFilters,
fields.startDateTime, fields.endDateTime, fields.dateFilters, fields.place,
],
};

if (activeFilter in searchForm) {
return searchForm[activeFilter]
return sortBy(searchForm[activeFilter], 'index')
.map((field, index) => {
if (!get(field, 'enabled')) {
return null;
}

const props = {
...field.props,
onChange: field.onChange || onChange,
Expand Down Expand Up @@ -365,6 +397,7 @@ AdvancedSearch.propTypes = {
diff: PropTypes.object.isRequired,
categories: PropTypes.array,
subjects: PropTypes.array,
locators: PropTypes.array,
urgencies: PropTypes.array,
contentTypes: PropTypes.array,
ingestProviders: PropTypes.array,
Expand Down
6 changes: 6 additions & 0 deletions client/components/Main/SearchPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ export class SearchPanelComponent extends React.Component {
isViewFiltered,
workflowStateOptions,
popupContainer,
searchProfile,
locators,
} = this.props;

const {
Expand Down Expand Up @@ -94,6 +96,8 @@ export class SearchPanelComponent extends React.Component {
onChange: this.onChangeHandler,
workflowStateOptions: workflowStateOptions || getWorkFlowStateAsOptions(activeFilter),
popupContainer: popupContainer,
searchProfile: searchProfile,
locators: locators,
};

return (
Expand Down Expand Up @@ -155,6 +159,8 @@ const mapStateToProps = (state) => ({
dateFormat: selectors.config.getDateFormat(state),
timeFormat: selectors.config.getTimeFormat(state),
isViewFiltered: selectors.main.isViewFiltered(state),
searchProfile: selectors.forms.searchProfile(state),
locators: selectors.vocabs.locators(state),
});

const mapDispatchToProps = (dispatch) => ({
Expand Down
20 changes: 19 additions & 1 deletion client/selectors/forms.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {createSelector} from 'reselect';
import {get, filter} from 'lodash';
import {ITEM_TYPE} from '../constants';
import {ITEM_TYPE, MAIN} from '../constants';
import {sessionId as getSessionId} from './general';
import {isExistingItem} from '../utils';

Expand All @@ -20,10 +20,28 @@ const getcurrentItem = (itemId, itemType, events, plannings, isLoading, values,
};

/** Profiles **/
export const activeFilter = (state) => get(state, 'main.filter', MAIN.FILTERS.COMBINED);
export const profiles = (state) => get(state, 'forms.profiles', {});
export const coverageProfile = createSelector([profiles], (p) => get(p, 'coverage', {}));
export const eventProfile = createSelector([profiles], (p) => get(p, 'event', {}));
export const planningProfile = createSelector([profiles], (p) => get(p, 'planning', {}));
export const searchProfile = createSelector(
[profiles, activeFilter],
(p, filter) => {
if (filter === MAIN.FILTERS.EVENTS) {
return get(p, 'advanced_search.editor.event', {});
}

if (filter === MAIN.FILTERS.PLANNING) {
return get(p, 'advanced_search.editor.planning', {});
}

if (filter === MAIN.FILTERS.COMBINED) {
return get(p, 'advanced_search.editor.combined', {});
}

return null;
});

export const listFields = createSelector([profiles], (p) => {
const fields = {};
Expand Down
Loading

0 comments on commit ccfa712

Please sign in to comment.