Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Public Collections] Fix app crashing when language is not English #2949

Merged
merged 3 commits into from
Jan 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions jsapp/js/components/reportViewItem.es6
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ReactDOM from 'react-dom';
import _ from 'underscore';
import Chart from 'chart.js';
import {bem} from '../bem';
import {REPORT_STYLES} from 'js/constants';

class ReportTable extends React.Component {
constructor(props) {
Expand Down Expand Up @@ -184,19 +185,24 @@ class ReportViewItem extends React.Component {
Chart.defaults.global.elements.arc.backgroundColor = baseColor;
Chart.defaults.global.maintainAspectRatio = false;

if (chartType === 'donut') {
// if report styles are invalid we default to vertical
if (Array.from(REPORT_STYLES.keys()).includes(chartType) !== true) {
chartType = REPORT_STYLES.get('vertical').value;
}

if (chartType === REPORT_STYLES.get('donut').value) {
chartType = 'pie';
}

if (chartType === 'area') {
if (chartType === REPORT_STYLES.get('area').value) {
chartType = 'line';
}

if (chartType === 'horizontal') {
if (chartType === REPORT_STYLES.get('horizontal').value) {
chartType = 'horizontalBar';
}

if (chartType === 'vertical' || chartType === 'bar_chart') {
if (chartType === REPORT_STYLES.get('vertical').value || chartType === 'bar_chart') {
chartType = 'bar';
}

Expand Down Expand Up @@ -296,12 +302,12 @@ class ReportViewItem extends React.Component {
opts.options.scales.xAxes = [];
opts.options.scales.yAxes = [];

if (this.props.style.report_type === 'donut') {
if (this.props.style.report_type === REPORT_STYLES.get('donut').value) {
opts.options.cutoutPercentage = 50;
}
}

if (this.props.style.report_type === 'area') {
if (this.props.style.report_type === REPORT_STYLES.get('area').value) {
opts.data.datasets[0].backgroundColor = colors[0];
}

Expand Down
19 changes: 8 additions & 11 deletions jsapp/js/components/reports.es6
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,15 @@ import {
assign,
launchPrinting
} from 'utils';

function labelVal(label, value) {
return {label: label, value: (value || label.toLowerCase().replace(/\W+/g, '_'))};
}
import {REPORT_STYLES} from 'js/constants';

let reportStyles = [
labelVal(t('Vertical')),
labelVal(t('Donut')),
labelVal(t('Area')),
labelVal(t('Horizontal')),
labelVal(t('Pie')),
labelVal(t('Line')),
REPORT_STYLES.get('vertical'),
REPORT_STYLES.get('donut'),
REPORT_STYLES.get('area'),
REPORT_STYLES.get('horizontal'),
REPORT_STYLES.get('pie'),
REPORT_STYLES.get('line'),
];

class ChartTypePicker extends React.Component {
Expand Down Expand Up @@ -732,7 +729,7 @@ class Reports extends React.Component {

// TODO: improve the defaults below
if (reportStyles.default.report_type === undefined) {
reportStyles.default.report_type = 'vertical';
reportStyles.default.report_type = REPORT_STYLES.get('vertical').value;
}
if (reportStyles.default.translationIndex === undefined) {
reportStyles.default.translationIndex = 0;
Expand Down
6 changes: 3 additions & 3 deletions jsapp/js/components/searchcollectionlist.es6
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
ASSET_TYPES,
COMMON_QUERIES,
ACCESS_TYPES,
CATEGORY_LABELS
DEPLOYMENT_CATEGORIES
} from '../constants';

class SearchCollectionList extends Reflux.Component {
Expand Down Expand Up @@ -161,14 +161,14 @@ class SearchCollectionList extends Reflux.Component {
searchResultsBucket = 'searchResultsCategorizedResultsLists';
}

var results = ['Deployed', 'Draft', 'Archived'].map(
var results = Array.from(DEPLOYMENT_CATEGORIES.keys()).map(
(category, i) => {
if (this.state[searchResultsBucket][category].length < 1) {
return [];
}
return [
<bem.List__subheading key={i}>
{CATEGORY_LABELS[category]}
{DEPLOYMENT_CATEGORIES.get(category).label}
</bem.List__subheading>,

<bem.AssetItems m={i + 1} key={i + 2}>
Expand Down
22 changes: 16 additions & 6 deletions jsapp/js/constants.es6
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,20 @@ export const MATRIX_PAIR_PROPS = {
inChoices: 'list_name'
};

export const CATEGORY_LABELS = {
Deployed: t('Deployed'),
Draft: t('Draft'),
Archived: t('Archived')
};
export const DEPLOYMENT_CATEGORIES = new Map([
['Deployed', {id: 'Deployed', label: t('Deployed')}],
['Draft', {id: 'Draft', label: t('Draft')}],
['Archived', {id: 'Archived', label: t('Archived')}],
]);

export const REPORT_STYLES = new Map([
['vertical', {value: 'vertical', label: t('Vertical')}],
['donut', {value: 'donut', label: t('Donut')}],
['area', {value: 'area', label: t('Area')}],
['horizontal', {value: 'horizontal', label: t('Horizontal')}],
['pie', {value: 'pie', label: t('Pie')}],
['line', {value: 'line', label: t('Line')}],
]);

const constants = {
ROOT_URL,
Expand All @@ -434,7 +443,8 @@ const constants = {
FORM_VERSION_NAME,
SCORE_ROW_TYPE,
RANK_LEVEL_TYPE,
CATEGORY_LABELS,
DEPLOYMENT_CATEGORIES,
REPORT_STYLES,
};

export default constants;
34 changes: 18 additions & 16 deletions jsapp/js/lists/sidebarForms.es6
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {searches} from '../searches';
import {stores} from '../stores';
import {
COMMON_QUERIES,
CATEGORY_LABELS
DEPLOYMENT_CATEGORIES
} from 'js/constants';

class SidebarFormsList extends Reflux.Component {
Expand Down Expand Up @@ -119,40 +119,42 @@ class SidebarFormsList extends Reflux.Component {
</bem.Loading>
);
} else if (s.defaultQueryState === 'done') {
return [CATEGORY_LABELS.Deployed, CATEGORY_LABELS.Draft, CATEGORY_LABELS.Archived].map(
(category) => {
var categoryVisible = this.state.selectedCategories[category];
if (s[activeItems][category].length < 1) {
return Array.from(DEPLOYMENT_CATEGORIES.keys()).map(
(categoryId) => {
var categoryVisible = this.state.selectedCategories[categoryId];
if (s[activeItems][categoryId].length < 1) {
categoryVisible = false;
}

const icon = ['k-icon'];
if (category === CATEGORY_LABELS.Deployed) {
if (categoryId === DEPLOYMENT_CATEGORIES.get('Deployed').id) {
icon.push('k-icon-deploy');
}
if (category === CATEGORY_LABELS.Draft) {
if (categoryId === DEPLOYMENT_CATEGORIES.get('Draft').id) {
icon.push('k-icon-drafts');
}
if (category === CATEGORY_LABELS.Archived) {
if (categoryId === DEPLOYMENT_CATEGORIES.get('Archived').id) {
icon.push('k-icon-archived');
}

return [
<bem.FormSidebar__label
m={[category, categoryVisible ? 'visible' : 'collapsed']}
onClick={this.toggleCategory(category)}
key={`${category}-label`}
m={[categoryId, categoryVisible ? 'visible' : 'collapsed']}
onClick={this.toggleCategory(categoryId)}
key={`${categoryId}-label`}
>
<i className={icon.join(' ')}/>
<bem.FormSidebar__labelText>{category}</bem.FormSidebar__labelText>
<bem.FormSidebar__labelCount>{s[activeItems][category].length}</bem.FormSidebar__labelCount>
<bem.FormSidebar__labelText>
{DEPLOYMENT_CATEGORIES.get(categoryId).label}
</bem.FormSidebar__labelText>
<bem.FormSidebar__labelCount>{s[activeItems][categoryId].length}</bem.FormSidebar__labelCount>
</bem.FormSidebar__label>,

<bem.FormSidebar__grouping
m={[category, categoryVisible ? 'visible' : 'collapsed']}
key={`${category}-group`}
m={[categoryId, categoryVisible ? 'visible' : 'collapsed']}
key={`${categoryId}-group`}
>
{s[activeItems][category].map(this.renderMiniAssetRow.bind(this))}
{s[activeItems][categoryId].map(this.renderMiniAssetRow.bind(this))}
</bem.FormSidebar__grouping>
];
}
Expand Down