Skip to content

Commit

Permalink
fix: Handle error if org unit selection is invalid for thematic layer…
Browse files Browse the repository at this point in the history
…s (DHIS2-8479) (#496)

* fix: Handle error if org unit selection is invalid for thematic layers (DHIS2-8479)

* chore: remove redundant code
  • Loading branch information
turban committed Mar 17, 2020
1 parent ef2946b commit 8ec724e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/components/map/Layer.js
Expand Up @@ -27,6 +27,8 @@ class Layer extends PureComponent {
isVisible: true,
};

state = {};

constructor(...args) {
super(...args);
this.setPeriod();
Expand All @@ -43,7 +45,7 @@ class Layer extends PureComponent {
editCounter,
dataFilters,
} = this.props;
const { period } = this.state || {};
const { period } = this.state;
const { period: prevPeriod } = prevState || {};
const isEdited = editCounter !== prevProps.editCounter;

Expand Down
6 changes: 6 additions & 0 deletions src/components/map/ThematicLayer.js
Expand Up @@ -31,6 +31,7 @@ class ThematicLayer extends Layer {
valuesByPeriod,
renderingStrategy = 'SINGLE',
} = this.props;

const { period } = this.state;
let periodData = data;

Expand Down Expand Up @@ -86,6 +87,11 @@ class ThematicLayer extends Layer {
// Set initial period
setPeriod(callback) {
const { period, periods, renderingStrategy } = this.props;

if (!period || !periods) {
return;
}

const initialPeriod = {
period:
renderingStrategy === 'SINGLE' ? null : period || periods[0],
Expand Down
24 changes: 13 additions & 11 deletions src/loaders/thematicLoader.js
Expand Up @@ -26,6 +26,18 @@ import {
} from '../constants/layers';

const thematicLoader = async config => {
const {
columns,
rows,
radiusLow = DEFAULT_RADIUS_LOW,
radiusHigh = DEFAULT_RADIUS_HIGH,
classes,
colorScale,
renderingStrategy = 'SINGLE',
} = config;

const dataItem = getDataItemFromColumns(columns);

let error;

const response = await loadData(config).catch(err => {
Expand All @@ -40,23 +52,14 @@ const thematicLoader = async config => {
alerts: [createAlert(i18n.t('Error'), error.message)],
}
: {}),
name: dataItem ? dataItem.name : i18n.t('Thematic layer'),
isLoaded: true,
isVisible: true,
};
}

const [features, data] = response;

const {
columns,
rows,
radiusLow = DEFAULT_RADIUS_LOW,
radiusHigh = DEFAULT_RADIUS_HIGH,
classes,
colorScale,
renderingStrategy = 'SINGLE',
} = config;

const isSingle = renderingStrategy === 'SINGLE';
const period = getPeriodFromFilters(config.filters);
const periods = getPeriodsFromMetaData(data.metaData);
Expand All @@ -70,7 +73,6 @@ const thematicLoader = async config => {
const orderedValues = getOrderedValues(data);
const minValue = orderedValues[0];
const maxValue = orderedValues[orderedValues.length - 1];
const dataItem = getDataItemFromColumns(columns);
const name = names[dataItem.id];

let legendSet = config.legendSet;
Expand Down

0 comments on commit 8ec724e

Please sign in to comment.