Skip to content

Commit

Permalink
fix: require legend set selection (DHIS2-9314) (#985)
Browse files Browse the repository at this point in the history
* fix: require legend set selection
* chore: correct proptype
  • Loading branch information
turban authored Aug 24, 2020
1 parent f058e0d commit 03c01a8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/components/classification/LegendSetSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class LegendSetSelect extends Component {
static propTypes = {
legendSet: PropTypes.object,
legendSets: PropTypes.array,
legendSetError: PropTypes.string,
loadLegendSets: PropTypes.func.isRequired,
setLegendSet: PropTypes.func.isRequired,
};
Expand All @@ -27,14 +28,20 @@ export class LegendSetSelect extends Component {
}

render() {
const { legendSet, legendSets, setLegendSet } = this.props;
const {
legendSet,
legendSets,
legendSetError,
setLegendSet,
} = this.props;

return (
<SelectField
label={i18n.t('Legend set')}
loading={legendSets ? false : true}
items={legendSets}
value={legendSet ? legendSet.id : null}
errorText={legendSetError}
onChange={setLegendSet}
style={style}
/>
Expand Down
4 changes: 3 additions & 1 deletion src/components/classification/NumericLegendStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const NumericLegendStyle = props => {
dataItem,
setClassification,
setLegendSet,
legendSetError,
style,
} = props;

Expand Down Expand Up @@ -49,7 +50,7 @@ const NumericLegendStyle = props => {
{isSingleColor ? (
<SingleColor />
) : isPredefined ? (
<LegendSetSelect />
<LegendSetSelect legendSetError={legendSetError} />
) : (
<Classification />
)}
Expand All @@ -62,6 +63,7 @@ NumericLegendStyle.propTypes = {
method: PropTypes.number,
colorScale: PropTypes.string,
legendSet: PropTypes.object,
legendSetError: PropTypes.string,
dataItem: PropTypes.object,
setClassification: PropTypes.func.isRequired,
setLegendSet: PropTypes.func.isRequired,
Expand Down
13 changes: 13 additions & 0 deletions src/components/edit/thematic/ThematicDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export class ThematicDialog extends Component {
labelFontStyle: PropTypes.string,
labelFontWeight: PropTypes.string,
legendSet: PropTypes.object,
method: PropTypes.number,
indicatorGroup: PropTypes.object,
dataElementGroup: PropTypes.object,
noDataColor: PropTypes.string,
Expand Down Expand Up @@ -297,6 +298,7 @@ export class ThematicDialog extends Component {
periodTypeError,
periodError,
orgUnitsError,
legendSetError,
} = this.state;

const orgUnits = getOrgUnitsFromRows(rows);
Expand Down Expand Up @@ -612,6 +614,7 @@ export class ThematicDialog extends Component {
<NumericLegendStyle
mapType={thematicMapType}
dataItem={dataItem}
legendSetError={legendSetError}
style={styles.select}
/>
</div>
Expand Down Expand Up @@ -646,6 +649,8 @@ export class ThematicDialog extends Component {
endDate,
radiusLow,
radiusHigh,
method,
legendSet,
} = this.props;
const dataItem = getDataItemFromColumns(columns);
const period = getPeriodFromFilters(filters);
Expand Down Expand Up @@ -744,6 +749,14 @@ export class ThematicDialog extends Component {
);
}

if (method === CLASSIFICATION_PREDEFINED && !legendSet) {
return this.setErrorState(
'legendSetError',
i18n.t('No legend set is selected'),
'style'
);
}

if (!isValidRadius(radiusLow, radiusHigh)) {
this.setState({ tab: 'style' });
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/components/orgunits/SelectedOrgUnits.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ SelectedOrgUnits.propTypes = {
mode: PropTypes.string,
units: PropTypes.string,
rows: PropTypes.array,
error: PropTypes.object,
error: PropTypes.string,
};

export default SelectedOrgUnits;

0 comments on commit 03c01a8

Please sign in to comment.