Skip to content

Commit

Permalink
Rename category to region internally
Browse files Browse the repository at this point in the history
This is something that came up while I was working on the region
persistence feature. ensemble-transposer uses the generic term
"category" but as far as ensemble is concerned, they are always regions.
Using the name region internally is clearer.
  • Loading branch information
openjck committed Oct 12, 2018
1 parent 23b8a52 commit a27ecf7
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 44 deletions.
14 changes: 7 additions & 7 deletions src/components/containers/DashboardContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import Dashboard from '../views/Dashboard';
class DashboardContainer extends React.Component {
constructor(props) {
super(props);
this.state = { activeCategory: null };
this.state = { activeRegion: null };
}

_onCategoryChange = e => {
_onRegionChange = e => {
this.setState({
activeCategory: e.target.value,
activeRegion: e.target.value,
});
}

Expand All @@ -36,7 +36,7 @@ class DashboardContainer extends React.Component {
/>
);
} else if (dataFetch.fulfilled) {
const activeCategory = this.state.activeCategory || dataFetch.value.defaultCategory || dataFetch.value.categories[0];
const activeRegion = this.state.activeRegion || dataFetch.value.defaultCategory || dataFetch.value.categories[0];
return (
<Dashboard
title={dataFetch.value.title}
Expand All @@ -45,10 +45,10 @@ class DashboardContainer extends React.Component {
dates={dataFetch.value.dates}
metrics={dataFetch.value.metrics}
summaryMetrics={dataFetch.value.summaryMetrics}
categories={dataFetch.value.categories}
activeCategory={activeCategory}
regions={dataFetch.value.categories}
activeRegion={activeRegion}
dashboardSource={this.props.source}
onCategoryChange={this._onCategoryChange}
onRegionChange={this._onRegionChange}
/>
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/containers/MetricOverviewContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@ class MetricOverviewContainer extends React.Component {
}

export default connect(props => ({
dataFetch: { url: `${props.dashboardSource}/${props.activeCategory}/${props.slug}` },
dataFetch: { url: `${props.dashboardSource}/${props.activeRegion}/${props.slug}` },
}))(MetricOverviewContainer);
4 changes: 2 additions & 2 deletions src/components/containers/SummaryMetricContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class SummaryMetricContainer extends React.Component {
}

// Otherwise, if a chart has < otherThreshold representation, it
// should be grouped into an "Other" category.
// should be grouped into an "Other" region.
else {
otherValue += value;
}
Expand Down Expand Up @@ -115,5 +115,5 @@ class SummaryMetricContainer extends React.Component {
}

export default connect(props => ({
dataFetch: { url: `${props.dashboardSource}/${props.activeCategory}/${props.slug}` },
dataFetch: { url: `${props.dashboardSource}/${props.activeRegion}/${props.slug}` },
}))(SummaryMetricContainer);
28 changes: 14 additions & 14 deletions src/components/views/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default props => {
key={summaryMetricSlug}
slug={summaryMetricSlug}
dashboardSource={props.dashboardSource}
activeCategory={props.activeCategory}
activeRegion={props.activeRegion}
/>
);
});
Expand Down Expand Up @@ -62,17 +62,17 @@ export default props => {
);
}

let maybeCategory = null;
const sortedCategories = bumpSort(props.categories, 'All');
if (sortedCategories.length > 1) {
maybeCategory = (
<aside id="category">
let maybeRegion = null;
const sortedRegions = bumpSort(props.regions, 'All');
if (sortedRegions.length > 1) {
maybeRegion = (
<aside id="region">
<div className="labelled-selector">
<label htmlFor="category-selector">Region</label>
<select id="category-selector" name="category" value={props.activeCategory} onChange={props.onCategoryChange}>
{sortedCategories.map(categoryName => (
<option key={categoryName} value={categoryName}>
{categoryName}
<label htmlFor="region-selector">Region</label>
<select id="region-selector" name="region" value={props.activeRegion} onChange={props.onRegionChange}>
{sortedRegions.map(regionName => (
<option key={regionName} value={regionName}>
{regionName}
</option>
))}
</select>
Expand All @@ -92,7 +92,7 @@ export default props => {
sectionKey={s.key}
title={s.title}
metrics={s.metrics}
activeCategory={props.activeCategory}
activeRegion={props.activeRegion}
dashboardSource={props.dashboardSource}
/>
))}
Expand All @@ -102,7 +102,7 @@ export default props => {
body = (
<MetricOverviewCollection
metrics={props.metrics}
activeCategory={props.activeCategory}
activeRegion={props.activeRegion}
dashboardSource={props.dashboardSource}
/>
);
Expand All @@ -122,7 +122,7 @@ export default props => {
<header className="dashboard-header">
<h2 id="dashboard-title" className="contrasted">{props.title}</h2>
{maybeDescription}
{maybeCategory}
{maybeRegion}
</header>
{maybeSummaryMetrics}
<h3 id="metrics-heading">Metrics</h3>
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/DashboardSection.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default props => (
</header>
<MetricOverviewCollection
metrics={props.metrics}
activeCategory={props.activeCategory}
activeRegion={props.activeRegion}
sectionKey={props.sectionKey}
dashboardSource={props.dashboardSource}
inSection={true}
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/MetricOverviewCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default props => (
slug={metricSlug}
identifier={identifier}
dashboardSource={props.dashboardSource}
activeCategory={props.activeCategory}
activeRegion={props.activeRegion}
inSection={props.inSection}
/>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/css/Dashboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
margin: 0;
}

#category {
#region {
background: #fff;
padding: 20px 0;
z-index: 10;
Expand Down
12 changes: 6 additions & 6 deletions src/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
* > bumpSort(['group B', 'group A', 'group C', 'control'], 'control');
* ['control', 'group A', 'group B', 'group C']
*/
export function bumpSort(array, valueToBump) {
const arrayCopy = array.slice();
const valueIndex = arrayCopy.indexOf(valueToBump);
export function bumpSort(arr, valueToBump) {
const arrCopy = arr.slice();
const valueIndex = arrCopy.indexOf(valueToBump);

if (valueIndex === -1) return arrayCopy.sort();
if (valueIndex === -1) return arrCopy.sort();

const arrayOfBumped = arrayCopy.splice(valueIndex, 1);
return arrayOfBumped.concat(arrayCopy.sort());
const arrOfBumped = arrCopy.splice(valueIndex, 1);
return arrOfBumped.concat(arrCopy.sort());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/tests/jest/Dashboard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let requiredProps;
beforeAll(() => {
requiredProps = {
metrics: [],
categories: [],
regions: [],
};
});

Expand Down
10 changes: 5 additions & 5 deletions src/tests/nightwatch/dashboards/usage-behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,20 @@ module.exports = {
linkWorks(browser, '.next-button a');
},

'Page does not crash when category selector is used': browser => {
'Page does not crash when region selector is used': browser => {
const effectWait = 5000;

browser.waitForElementVisible('#category-selector');
browser.waitForElementVisible('#region-selector');

browser.click('#category-selector option:nth-child(1)');
browser.click('#region-selector option:nth-child(1)');
browser.pause(effectWait);
browser.expect.element('#dashboard').to.be.visible;

browser.click('#category-selector option:nth-child(2)');
browser.click('#region-selector option:nth-child(2)');
browser.pause(effectWait);
browser.expect.element('#dashboard').to.be.visible;

browser.click('#category-selector option:nth-child(3)');
browser.click('#region-selector option:nth-child(3)');
browser.pause(effectWait);
browser.expect.element('#dashboard').to.be.visible;
},
Expand Down
10 changes: 5 additions & 5 deletions src/tests/nightwatch/dashboards/user-activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,20 @@ module.exports = {
linkWorks(browser, '.next-button a');
},

'Page does not crash when category selector is used': browser => {
'Page does not crash when region selector is used': browser => {
const effectWait = 10000;

browser.waitForElementVisible('#category-selector');
browser.waitForElementVisible('#region-selector');

browser.click('#category-selector option:nth-child(1)');
browser.click('#region-selector option:nth-child(1)');
browser.pause(effectWait);
browser.expect.element('#dashboard').to.be.visible;

browser.click('#category-selector option:nth-child(2)');
browser.click('#region-selector option:nth-child(2)');
browser.pause(effectWait);
browser.expect.element('#dashboard').to.be.visible;

browser.click('#category-selector option:nth-child(3)');
browser.click('#region-selector option:nth-child(3)');
browser.pause(effectWait);
browser.expect.element('#dashboard').to.be.visible;
},
Expand Down

0 comments on commit a27ecf7

Please sign in to comment.