Commit e6882d9d authored by Roman's avatar Roman

BRCD-1676 feat(Play) - Show\Hide play field in lists

parent 320be914
......@@ -4,7 +4,7 @@ import Immutable from 'immutable';
import changeCase from 'change-case';
import EntityList from '../EntityList';
import { getItemDateValue, getConfig } from '../../common/Util';
import { playsSettingsSelector } from '../../selectors/settingsSelector';
import { playsIsEnabledSelector } from '../../selectors/settingsSelector';
class SubscriptionsList extends Component {
......@@ -170,7 +170,7 @@ class SubscriptionsList extends Component {
const mapStateToProps = (state, props) => ({
isPlaysEnabled: (playsSettingsSelector(state, props) || Immutable.List()).size > 1,
isPlaysEnabled: playsIsEnabledSelector(state, props),
});
export default connect(mapStateToProps)(SubscriptionsList);
import React from 'react';
import React, { PropTypes } from 'react';
import { connect } from 'react-redux';
import Immutable from 'immutable';
import changeCase from 'change-case';
import EntityList from '../EntityList';
import { playsIsEnabledSelector } from '../../selectors/settingsSelector';
const PlansList = () => {
const PlansList = (props) => {
const parserTrial = (item) => {
if (item.getIn(['price', 0, 'trial'])) {
return `${item.getIn(['price', 0, 'to'])} ${item.getIn(['recurrence', 'periodicity'])}`;
......@@ -25,6 +27,10 @@ const PlansList = () => {
const parserChargingMode = item => (item.get('upfront') ? 'Upfront' : 'Arrears');
const parsePlay = item => item.get('play', Immutable.List()).join(', ');
const displayPlay = () => props.isPlaysEnabled;
const tableFields = [
{ id: 'description', title: 'Title', sort: true },
{ id: 'name', title: 'Key', sort: true },
......@@ -33,6 +39,7 @@ const PlansList = () => {
{ id: 'recurrence_frequency', title: 'Billing Frequency', parser: parserBillingFrequency },
{ id: 'charging_mode', title: 'Charging Mode', parser: parserChargingMode },
{ id: 'connection_type', display: false, showFilter: false },
{ id: 'play', title: 'Play', display: displayPlay(), parser: parsePlay },
];
const filterFields = [
......@@ -49,6 +56,7 @@ const PlansList = () => {
recurrence: 1,
upfront: 1,
price: 1,
play: 1,
name: 1,
};
......@@ -74,4 +82,17 @@ const PlansList = () => {
);
};
export default PlansList;
PlansList.propTypes = {
isPlaysEnabled: PropTypes.bool,
};
PlansList.defaultProps = {
isPlaysEnabled: false,
};
const mapStateToProps = (state, props) => ({
isPlaysEnabled: playsIsEnabledSelector(state, props),
});
export default connect(mapStateToProps)(PlansList);
......@@ -7,17 +7,21 @@ import { LoadingItemPlaceholder } from '../Elements';
import {
getSettings,
} from '../../actions/settingsActions';
import { playsIsEnabledSelector } from '../../selectors/settingsSelector';
class ProductsList extends Component {
static propTypes = {
fields: PropTypes.instanceOf(Immutable.List),
defaultListFields: PropTypes.arrayOf(PropTypes.string),
isPlaysEnabled: PropTypes.bool,
dispatch: PropTypes.func.isRequired,
};
static defaultProps = {
fields: null,
isPlaysEnabled: false,
defaultListFields: ['description', 'key', 'rates'],
}
......@@ -36,6 +40,14 @@ class ProductsList extends Component {
{ id: 'key', placeholder: 'Key' },
]);
filterPlayField = (field) => {
const { isPlaysEnabled } = this.props;
if (field.get('field_name', '') !== 'play') {
return true;
}
return isPlaysEnabled;
}
getProjectFields = () => {
const { fields, defaultListFields } = this.props;
return fields
......@@ -51,6 +63,7 @@ class ProductsList extends Component {
getFields = () => {
const { fields, defaultListFields } = this.props;
return fields
.filter(this.filterPlayField)
.filter(field => (field.get('show_in_list', false) || defaultListFields.includes(field.get('field_name', ''))))
.map((field) => {
const fieldname = field.get('field_name');
......@@ -93,6 +106,7 @@ class ProductsList extends Component {
const mapStateToProps = (state, props) => ({
fields: state.settings.getIn(['rates', 'fields']) || undefined,
isPlaysEnabled: playsIsEnabledSelector(state, props),
});
export default connect(mapStateToProps)(ProductsList);
import React from 'react';
import React, { PropTypes } from 'react';
import { connect } from 'react-redux';
import Immutable from 'immutable';
import pluralize from 'pluralize';
import { titleCase } from 'change-case';
import EntityList from '../EntityList';
......@@ -6,8 +8,10 @@ import {
getConfig,
convertServiceBalancePeriodToObject,
} from '../../common/Util';
import { playsIsEnabledSelector } from '../../selectors/settingsSelector';
const ServicesList = () => {
const ServicesList = (props) => {
const parserPrice = item => item.getIn(['price', 0, 'price'], '');
const parserQuantitative = item => (item.get('quantitative', false) ? 'Yes' : 'No');
......@@ -22,6 +26,10 @@ const ServicesList = () => {
return `${period.value} ${titleCase(pluralize(period.unit, Number(period.value)))}`;
};
const parsePlay = item => item.get('play', Immutable.List()).join(', ');
const displayPlay = () => props.isPlaysEnabled;
const filterFields = [
{ id: 'description', placeholder: 'Title' },
{ id: 'name', placeholder: 'Key' },
......@@ -33,6 +41,7 @@ const ServicesList = () => {
{ title: 'Price', parser: parserPrice, sort: true },
{ title: 'Quantitative', parser: parserQuantitative, sort: true },
{ title: 'Period', parser: parserPeriod, sort: true },
{ id: 'play', title: 'Play', display: displayPlay(), parser: parsePlay },
];
const projectFields = {
......@@ -41,6 +50,7 @@ const ServicesList = () => {
name: 1,
balance_period: 1,
quantitative: 1,
play: 1,
};
const actions = [
......@@ -60,4 +70,16 @@ const ServicesList = () => {
);
};
export default ServicesList;
ServicesList.propTypes = {
isPlaysEnabled: PropTypes.bool,
};
ServicesList.defaultProps = {
isPlaysEnabled: false,
};
const mapStateToProps = (state, props) => ({
isPlaysEnabled: playsIsEnabledSelector(state, props),
});
export default connect(mapStateToProps)(ServicesList);
......@@ -271,6 +271,19 @@ export const playsSettingsSelector = createSelector(
plays => plays,
);
export const playsEnabledSelector = createSelector(
playsSettingsSelector,
(plays = Immutable.List()) => (plays
? plays.filter(play => play.get('enabled', true))
: Immutable.List()
),
);
export const playsIsEnabledSelector = createSelector(
playsEnabledSelector,
(plays = Immutable.List()) => plays && plays.size > 1,
);
export const availablePlaysSettingsSelector = createSelector(
getPlaysSettings,
plays => (plays ? plays.filter(play => play.get('enabled', true)) : undefined),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment