-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: dynamic dimension filtering for thematic layers (#86)
- Loading branch information
Showing
23 changed files
with
1,153 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import * as types from '../constants/actionTypes'; | ||
|
||
// Load all dimensions | ||
export const loadDimensions = () => ({ | ||
type: types.DIMENSIONS_LOAD, | ||
}); | ||
|
||
// Set all dimensions | ||
export const setDimensions = dimensions => ({ | ||
type: types.DIMENSIONS_SET, | ||
payload: dimensions, | ||
}); | ||
|
||
// Load all dimension items | ||
export const loadDimensionItems = dimensionId => ({ | ||
type: types.DIMENSION_ITEMS_LOAD, | ||
dimensionId, | ||
}); | ||
|
||
// Set all dimension items | ||
export const setDimensionItems = (dimensionId, items) => ({ | ||
type: types.DIMENSION_ITEMS_SET, | ||
dimensionId, | ||
payload: items, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
import { withStyles } from '@material-ui/core/styles'; | ||
import i18n from '@dhis2/d2-i18n'; | ||
import Button from '@material-ui/core/Button'; | ||
import DimensionFilterRow from './DimensionFilterRow'; | ||
import { | ||
addDimensionFilter, | ||
removeDimensionFilter, | ||
changeDimensionFilter, | ||
} from '../../actions/layerEdit'; | ||
|
||
const styles = () => ({ | ||
container: { | ||
width: '100%', | ||
height: 300, | ||
paddingTop: 8, | ||
overflowY: 'auto', | ||
}, | ||
button: { | ||
marginTop: 8, | ||
}, | ||
}); | ||
|
||
class DimensionFilter extends Component { | ||
static propTypes = { | ||
dimensions: PropTypes.array, | ||
addDimensionFilter: PropTypes.func.isRequired, | ||
removeDimensionFilter: PropTypes.func.isRequired, | ||
changeDimensionFilter: PropTypes.func.isRequired, | ||
classes: PropTypes.object.isRequired, | ||
}; | ||
|
||
render() { | ||
const { | ||
addDimensionFilter, | ||
classes, | ||
dimensions = [], | ||
changeDimensionFilter, | ||
removeDimensionFilter, | ||
} = this.props; | ||
|
||
return ( | ||
<div className={classes.container}> | ||
{dimensions.map((item, index) => ( | ||
<DimensionFilterRow | ||
key={index} | ||
index={index} | ||
onChange={changeDimensionFilter} | ||
onRemove={removeDimensionFilter} | ||
{...item} | ||
/> | ||
))} | ||
<Button | ||
variant="contained" | ||
color="primary" | ||
onClick={() => addDimensionFilter()} | ||
className={classes.button} | ||
> | ||
{i18n.t('Add filter')} | ||
</Button> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default connect( | ||
null, | ||
{ addDimensionFilter, removeDimensionFilter, changeDimensionFilter } | ||
)(withStyles(styles)(DimensionFilter)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { withStyles } from '@material-ui/core/styles'; | ||
import DimensionSelect from './DimensionSelect'; | ||
import DimensionItemsSelect from './DimensionItemsSelect'; | ||
import RemoveFilter from '../filter/RemoveFilter'; | ||
|
||
const styles = theme => ({ | ||
container: { | ||
height: 68, | ||
marginBottom: 8, | ||
padding: '-0 56px 0 8px', | ||
backgroundColor: theme.palette.background.grey, | ||
position: 'relative', | ||
clear: 'both', | ||
borderRadius: 4, | ||
border: `1px solid ${theme.palette.divider}`, | ||
}, | ||
select: { | ||
marginRight: 24, | ||
float: 'left', | ||
width: 'calc((100% - 48px) / 8 * 3)', | ||
}, | ||
}); | ||
|
||
class DimensionFilterRow extends Component { | ||
static propTypes = { | ||
dimension: PropTypes.string, | ||
items: PropTypes.array, | ||
index: PropTypes.number, | ||
onChange: PropTypes.func.isRequired, | ||
onRemove: PropTypes.func.isRequired, | ||
classes: PropTypes.object.isRequired, | ||
}; | ||
|
||
onChange(dimension, items) { | ||
const { index, onChange } = this.props; | ||
|
||
onChange(index, { dimension, items }); | ||
} | ||
|
||
render() { | ||
const { dimension, items, index, onRemove, classes } = this.props; | ||
|
||
return ( | ||
<div className={classes.container}> | ||
<DimensionSelect | ||
dimension={dimension} | ||
onChange={dimension => this.onChange(dimension.id, items)} | ||
/> | ||
<DimensionItemsSelect | ||
dimension={dimension} | ||
value={items ? items.map(item => item.id) : null} | ||
onChange={items => this.onChange(dimension, items)} | ||
/> | ||
<RemoveFilter onClick={() => onRemove(index)} /> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default withStyles(styles)(DimensionFilterRow); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
import i18n from '@dhis2/d2-i18n'; | ||
import SelectField from '../core/SelectField'; | ||
import { loadDimensionItems } from '../../actions/dimensions'; | ||
|
||
const styles = { | ||
select: { | ||
width: '60%', | ||
}, | ||
}; | ||
|
||
export class DimensionItemsSelect extends Component { | ||
static propTypes = { | ||
dimension: PropTypes.string, | ||
items: PropTypes.array, | ||
value: PropTypes.array, | ||
onChange: PropTypes.func.isRequired, | ||
loadDimensionItems: PropTypes.func.isRequired, | ||
style: PropTypes.object, | ||
errorText: PropTypes.string, | ||
}; | ||
|
||
componentDidUpdate() { | ||
const { dimension, items, loadDimensionItems } = this.props; | ||
|
||
if (dimension && !items) { | ||
loadDimensionItems(dimension); | ||
} | ||
} | ||
|
||
onDimensionItemClick = ids => { | ||
const { items, onChange } = this.props; | ||
|
||
onChange(ids.map(id => items.find(item => item.id === id))); | ||
}; | ||
|
||
render() { | ||
const { items, value } = this.props; | ||
|
||
if (!items) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<SelectField | ||
label={i18n.t('Items')} | ||
items={items} | ||
value={value} | ||
multiple={true} | ||
onChange={this.onDimensionItemClick} | ||
style={styles.select} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
export default connect( | ||
({ dimensions }, { dimension }) => ({ | ||
items: | ||
dimensions && dimension | ||
? dimensions.find(dim => dim.id === dimension).items | ||
: null, | ||
}), | ||
{ loadDimensionItems } | ||
)(DimensionItemsSelect); |
Oops, something went wrong.