Skip to content

Commit

Permalink
Merge branch 'master' into cp-lji
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkLark86 committed Jun 1, 2020
2 parents 3d4eab5 + 92e5f4b commit 4403fe2
Show file tree
Hide file tree
Showing 49 changed files with 540 additions and 139 deletions.
30 changes: 29 additions & 1 deletion assets/company-reports/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const REPORTS_NAMES = {
'SUBSCRIBER_ACTIVITY': 'subscriber-activity',
'CONTENT_ACTIVITY': 'content-activity',
'COMPANY_NEWS_API_USAGE': 'company-news-api-usage',
'PRODUCT_COMPANIES': 'product-companies',
};


Expand All @@ -23,6 +24,7 @@ export const REPORTS = {
[REPORTS_NAMES.SUBSCRIBER_ACTIVITY]: '/reports/subscriber-activity',
[REPORTS_NAMES.CONTENT_ACTIVITY]: '/reports/content-activity',
[REPORTS_NAMES.COMPANY_NEWS_API_USAGE]: '/reports/company-news-api-usage',
[REPORTS_NAMES.PRODUCT_COMPANIES]: '/reports/product-companies',
};

function getReportQueryString(currentState, next, exportReport, notify) {
Expand All @@ -48,6 +50,10 @@ function getReportQueryString(currentState, next, exportReport, notify) {
params.section = get(getItemFromArray(params.section, currentState.sections, 'name'), '_id');
}

if (params.product) {
params.product = get(getItemFromArray(params.product, currentState.products, 'name'), '_id');
}

if (exportReport) {
params.export = true;
}
Expand All @@ -63,7 +69,10 @@ function getReportQueryString(currentState, next, exportReport, notify) {

export const INIT_DATA = 'INIT_DATA';
export function initData(data) {
return {type: INIT_DATA, data};
return function (dispatch) {
dispatch(fetchProducts());
dispatch({type: INIT_DATA, data});
};
}

export const QUERY_REPORT = 'QUERY_REPORT';
Expand Down Expand Up @@ -96,6 +105,11 @@ export function isLoading(data = false) {
return {type: SET_IS_LOADING, data};
}

export const GET_PRODUCTS = 'GET_PRODUCTS';
export function getProducts(data) {
return {type: GET_PRODUCTS, data};
}

export function runReport() {
return function (dispatch, getState) {
dispatch(queryReport());
Expand Down Expand Up @@ -191,3 +205,17 @@ export function printReport() {
return Promise.resolve();
};
}

/**
* Fetches products
*
*/
export function fetchProducts() {
return function (dispatch) {
return server.get('/products/search')
.then((data) => {
dispatch(getProducts(data));
})
.catch((error) => errorHandler(error, dispatch, setError));
};
}
6 changes: 5 additions & 1 deletion assets/company-reports/components/CompanyReportsApp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const options = [
{value: REPORTS_NAMES.COMPANY, text: gettext('Company')},
{value: REPORTS_NAMES.SUBSCRIBER_ACTIVITY, text: gettext('Subscriber activity')},
{value: REPORTS_NAMES.CONTENT_ACTIVITY, text: gettext('Content activity')},
{value: REPORTS_NAMES.PRODUCT_COMPANIES, text: gettext('Companies per Product')},

];


Expand Down Expand Up @@ -87,6 +89,7 @@ CompanyReportsApp.propTypes = {
printReport: PropTypes.func,
isLoading: PropTypes.bool,
apiEnabled: PropTypes.bool,
products: PropTypes.array,
};

const mapStateToProps = (state) => ({
Expand All @@ -96,7 +99,8 @@ const mapStateToProps = (state) => ({
apiEnabled: state.apiEnabled,
reportParams: state.reportParams,
isLoading: state.isLoading,
resultHeaders: state.resultHeaders
resultHeaders: state.resultHeaders,
products: state.products,
});

const mapDispatchToProps = {
Expand Down
110 changes: 110 additions & 0 deletions assets/company-reports/components/ProductCompanies.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import React, {Fragment} from 'react';
import PropTypes from 'prop-types';
import {connect} from 'react-redux';
import { get } from 'lodash';
import DropdownFilter from '../../components/DropdownFilter';
import ReportsTable from './ReportsTable';
import {toggleFilterAndQuery, runReport} from '../actions';

import { gettext } from 'utils';

class ProductCompanies extends React.Component {
constructor(props, context) {
super(props, context);

this.products = [...this.props.products.map((p) => ({...p, 'label': p.name}))];
this.state = { product: this.props.products[0] };

this.filters = [{
label: gettext('All Products'),
field: 'product'
}];
this.getDropdownItems = this.getDropdownItems.bind(this);
this.results = [];
}

getDropdownItems(filter) {
const { toggleFilterAndQuery } = this.props;
let getName = (text) => (text);
let itemsArray = [];
switch (filter.field) {
case 'product':
itemsArray = this.products;
break;
}

return itemsArray.map((item, i) => (<button
key={i}
className='dropdown-item'
onClick={() => toggleFilterAndQuery(filter.field, item.name)}
>{getName(item.name)}</button>));
}

getFilterLabel(filter, activeFilter) {
if (activeFilter[filter.field]) {
return activeFilter[filter.field];
} else {
return filter.label;
}
}

render() {
const {results, print, reportParams, toggleFilterAndQuery} = this.props;
const headers = [gettext('Product'), gettext('Active Companies'), gettext('Disabled Companies')];
const list = get(results, 'length', 0) > 0 ? results.map((item) =>
<tr key={item._id}>
<td>{item.product}</td>
<td>{item.enabled_companies.map((company) => (
<Fragment key={company}>
{company}<br />
</Fragment>
))}</td>
<td>{item.disabled_companies.map((company) => (
<Fragment key={company}>
{company}<br />
</Fragment>
))}</td>
</tr>
) : ([(<tr key='no_data_row'>
<td></td>
<td></td>
<td></td>
</tr>)]);

let filterNodes = this.filters.map((filter) => (
<DropdownFilter
key={filter.label}
filter={filter}
getDropdownItems={this.getDropdownItems}
activeFilter={reportParams}
getFilterLabel={this.getFilterLabel}
toggleFilter={toggleFilterAndQuery}
/>
));
const filterSection = (<div key='report_filters' className="align-items-center d-flex flex-sm-nowrap flex-wrap m-0 px-3 wire-column__main-header-agenda">{filterNodes}</div>);

return [filterSection,
(<ReportsTable key='report_table' headers={headers} rows={list} print={print} />)];

}
}

ProductCompanies.propTypes = {
results: PropTypes.array,
print: PropTypes.bool,
products: PropTypes.array,
reportParams: PropTypes.object,
toggleFilterAndQuery: PropTypes.func,
runReport: PropTypes.func,
isLoading: PropTypes.bool,
};

const mapStateToProps = (state) => ({
products: state.products,
reportParams: state.reportParams,
isLoading: state.isLoading,
});

const mapDispatchToProps = { toggleFilterAndQuery, runReport};

export default connect(mapStateToProps, mapDispatchToProps)(ProductCompanies);
7 changes: 7 additions & 0 deletions assets/company-reports/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
TOGGLE_REPORT_FILTER,
ADD_RESULTS,
SET_IS_LOADING,
GET_PRODUCTS,
} from './actions';

const initialState = {
Expand All @@ -20,13 +21,15 @@ const initialState = {
aggregations: null,
companies: [],
sections: [],
products: [],
reportParams: {
date_from: Date.now(),
date_to: Date.now(),
timezone_offset: getTimezoneOffset(),
company: null,
action: null,
section: null,
product: null,
}
};

Expand All @@ -40,6 +43,7 @@ export default function companyReportReducer(state = initialState, action) {
companies: action.data.companies,
sections: action.data.sections,
apiEnabled: action.data.api_enabled || false,
products: action.data.products,
};

case QUERY_REPORT: {
Expand Down Expand Up @@ -92,6 +96,9 @@ export default function companyReportReducer(state = initialState, action) {
isLoading: action.data
};

case GET_PRODUCTS:
return {...state, products: action.data};

case 'RECEIVE_REPORT_AGGREGATIONS':
return {
...state,
Expand Down
2 changes: 2 additions & 0 deletions assets/company-reports/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Company from './components/Company';
import SubscriberActivity from './components/SubscriberActivity';
import ContentActivity from './components/ContentActivity';
import ComapnyNewsApiUsage from './components/ComapnyNewsApiUsage';
import ProductCompanies from './components/ProductCompanies';
import {REPORTS_NAMES} from './actions';

export const panels = {
Expand All @@ -17,4 +18,5 @@ export const panels = {
[REPORTS_NAMES.SUBSCRIBER_ACTIVITY]: SubscriberActivity,
[REPORTS_NAMES.CONTENT_ACTIVITY]: ContentActivity,
[REPORTS_NAMES.COMPANY_NEWS_API_USAGE]: ComapnyNewsApiUsage,
[REPORTS_NAMES.PRODUCT_COMPANIES]: ProductCompanies,
};
4 changes: 2 additions & 2 deletions assets/components/cards/render/MoreNewsButton.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from 'react';
import PropTypes from 'prop-types';
import { gettext, getProductQuery } from 'utils';
import {gettext} from 'utils';

function MoreNewsButton({title, product, photoUrl, photoUrlLabel}) {
return ([<div key='heading' className='col-6 col-sm-8'>
<h3 className='home-section-heading'>{title}</h3>
</div>,
<div key='more-news' className='col-6 col-sm-4 d-flex align-items-start justify-content-end'>
{product &&
<a href={`/wire?q=${getProductQuery(product)}`} role='button' className='btn btn-outline-primary btn-sm mb-3'>
<a href={`/wire?product=${product._id}`} role='button' className='btn btn-outline-primary btn-sm mb-3'>
{gettext('More news')}
</a>}
{photoUrl &&
Expand Down
3 changes: 2 additions & 1 deletion assets/home/components/HomeApp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ HomeApp.propTypes = {
itemsByCard: PropTypes.object,
products: PropTypes.array,
user: PropTypes.string,
userType: PropTypes.string,
company: PropTypes.string,
format: PropTypes.array,
itemToOpen: PropTypes.object,
Expand All @@ -207,6 +208,7 @@ const mapStateToProps = (state) => ({
itemsByCard: state.itemsByCard,
products: state.products,
user: state.user,
userType: state.userType,
company: state.company,
format: PropTypes.format,
itemToOpen: state.itemToOpen,
Expand All @@ -225,7 +227,6 @@ const mapDispatchToProps = (dispatch) => ({
fetchCardExternalItems: (cardId, cardLabel) => dispatch(fetchCardExternalItems(cardId, cardLabel)),
followStory: (item) => followStory(item, 'wire'),
downloadVideo: (href, id, mimeType) => dispatch(downloadVideo(href, id, mimeType)),

});


Expand Down
1 change: 1 addition & 0 deletions assets/home/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default function homeReducer(state=initialState, action) {
itemsByCard: action.data.itemsByCard,
products: action.data.products,
user: action.data.user,
userType: action.data.userType,
company: action.data.company,
formats: action.data.formats || [],
userSections: action.data.userSections,
Expand Down
8 changes: 7 additions & 1 deletion assets/layout/components/BaseApp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
import { get } from 'lodash';
import { createPortal } from 'react-dom';
import { isTouchDevice, gettext, isDisplayed } from 'utils';
import {getSingleFilterValue} from 'search/utils';

// tabs
import TopicsTab from 'search/components/TopicsTab';
Expand Down Expand Up @@ -59,21 +60,26 @@ export default class BaseApp extends React.Component {
}
}

renderNavBreadcrumb(navigations, activeNavigation, activeTopic) {
renderNavBreadcrumb(navigations, activeNavigation, activeTopic, activeProduct = null, activeFilter = null) {
const dest = document.getElementById('nav-breadcrumb');
if (!dest) {
return null;
}

let name;
const numNavigations = get(activeNavigation, 'length', 0);
const filterValue = getSingleFilterValue(activeFilter, ['genre', 'subject']);

if (activeTopic) {
name = `/ ${activeTopic.label}`;
} else if (numNavigations > 1) {
name = '/ ' + gettext('Custom View');
} else if (numNavigations === 1) {
name = '/ ' + get(navigations.find((nav) => nav._id === activeNavigation[0]), 'name', '');
} else if (activeProduct != null) {
name = `/ ${activeProduct.name}`;
} else if (filterValue !== null) {
name = `/ ${filterValue}`;
} else {
name = '';
}
Expand Down
11 changes: 11 additions & 0 deletions assets/search/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export function toggleNavigation(navigation, disableSameNavigationDeselect) {
created: null,
navigation: getNavigationUrlParam(newNavigation, false),
filter: null,
product: null,
},
state
);
Expand Down Expand Up @@ -342,6 +343,11 @@ export function setSearchCreated(created) {
return {type: SET_SEARCH_CREATED, payload: created};
}

export const SET_SEARCH_PRODUCT = 'SET_SEARCH_PRODUCT';
export function setSearchProduct(productId) {
return {type: SET_SEARCH_PRODUCT, payload: productId};
}

export const RESET_SEARCH_PARAMS = 'RESET_SEARCH_PARAMS';
export function resetSearchParams() {
return {type: RESET_SEARCH_PARAMS};
Expand All @@ -364,6 +370,10 @@ export function setParams(params) {
if (get(params, 'filter')) {
dispatch(setSearchFilters(params.filter));
}

if (get(params, 'product')) {
dispatch(setSearchProduct(params.product));
}
};
}

Expand All @@ -379,6 +389,7 @@ export function initParams(params) {
created: params.get('created') ? JSON.parse(params.get('created')) : null,
navigation: params.get('navigation') ? JSON.parse(params.get('navigation')) : null,
filter: params.get('filter') ? JSON.parse(params.get('filter')) : null,
product: params.get('product'),
};
let topic = {};

Expand Down
Loading

0 comments on commit 4403fe2

Please sign in to comment.