Skip to content
Snippets Groups Projects
Commit 473312ea authored by esikkala's avatar esikkala
Browse files

Sort buttons for facet values

parent 0de7ebbc
No related branches found
No related tags found
No related merge requests found
...@@ -48,6 +48,8 @@ class FacetBar extends React.Component { ...@@ -48,6 +48,8 @@ class FacetBar extends React.Component {
<Paper className={classes.facetContainer}> <Paper className={classes.facetContainer}>
<FacetHeader <FacetHeader
label='Source' label='Source'
property='source'
hierarchical={false}
distinctValueCount={this.props.source.distinctValueCount} distinctValueCount={this.props.source.distinctValueCount}
sortBy={this.props.source.sortBy} sortBy={this.props.source.sortBy}
sortDirection={this.props.source.sortDirection} sortDirection={this.props.source.sortDirection}
...@@ -73,6 +75,8 @@ class FacetBar extends React.Component { ...@@ -73,6 +75,8 @@ class FacetBar extends React.Component {
<Paper className={classes.facetContainer}> <Paper className={classes.facetContainer}>
<FacetHeader <FacetHeader
label='Author' label='Author'
property='author'
hierarchical={false}
distinctValueCount={this.props.author.distinctValueCount} distinctValueCount={this.props.author.distinctValueCount}
sortBy={this.props.author.sortBy} sortBy={this.props.author.sortBy}
sortDirection={this.props.author.sortDirection} sortDirection={this.props.author.sortDirection}
...@@ -98,6 +102,8 @@ class FacetBar extends React.Component { ...@@ -98,6 +102,8 @@ class FacetBar extends React.Component {
<Paper className={classes.facetContainerLast}> <Paper className={classes.facetContainerLast}>
<FacetHeader <FacetHeader
label='Production place' label='Production place'
property='productionPlace'
hierarchical={true}
distinctValueCount={this.props.productionPlace.distinctValueCount} distinctValueCount={this.props.productionPlace.distinctValueCount}
sortBy={this.props.productionPlace.sortBy} sortBy={this.props.productionPlace.sortBy}
sortDirection={this.props.productionPlace.sortDirection} sortDirection={this.props.productionPlace.sortDirection}
......
...@@ -10,11 +10,6 @@ import { PieChart, ExpandLess, /*ExpandMore*/ } from '@material-ui/icons'; ...@@ -10,11 +10,6 @@ import { PieChart, ExpandLess, /*ExpandMore*/ } from '@material-ui/icons';
import Paper from '@material-ui/core/Paper'; import Paper from '@material-ui/core/Paper';
import Typography from '@material-ui/core/Typography'; import Typography from '@material-ui/core/Typography';
const options = [
'Sort alphabetically',
'Sort by manuscript count',
];
const styles = theme => ({ const styles = theme => ({
root: { root: {
width: '100%', width: '100%',
...@@ -51,46 +46,79 @@ class FacetHeader extends React.Component { ...@@ -51,46 +46,79 @@ class FacetHeader extends React.Component {
anchorEl: null, anchorEl: null,
}; };
handleClick = event => { handleSortByClick = event => {
this.setState({ anchorEl: event.currentTarget }); this.setState({ anchorEl: event.currentTarget });
}; };
handleClose = () => { handleMenuItemClick = (sortBy, isSelected) => () => {
this.setState({ anchorEl: null }); this.setState({ anchorEl: null });
let sortDirection = '';
if (isSelected) {
sortDirection = this.props.sortDirection === 'asc' ? 'desc' : 'asc';
} else {
if (sortBy === 'prefLabel') {
sortDirection = 'asc';
} else if (sortBy === 'instanceCount') {
sortDirection = 'desc';
}
}
this.props.fetchFacet(this.props.property, sortBy, sortDirection);
}; };
handleMenuClose = () => {
this.setState({ anchorEl: null });
}
render() { render() {
const { classes } = this.props; const { classes } = this.props;
const { anchorEl } = this.state; const { anchorEl } = this.state;
const open = Boolean(anchorEl); const open = Boolean(anchorEl);
const options = [
{
id: 'prefLabel',
menuItemText: 'Sort alphabetically',
selected: this.props.sortBy === 'prefLabel' ? true : false,
sortDirection: this.props.sortDirection,
},
{
id: 'instanceCount',
menuItemText: 'Sort by manuscript count',
selected: this.props.sortBy === 'instanceCount' ? true : false,
sortDirection: this.props.sortDirection,
},
];
return ( return (
<Paper className={classes.headingContainer}> <Paper className={classes.headingContainer}>
<Typography variant="h6">{this.props.label} {this.props.distinctValueCount > 0 ? `(${this.props.distinctValueCount})` : ''}</Typography> <Typography variant="h6">{this.props.label} {this.props.distinctValueCount > 0 ? `(${this.props.distinctValueCount})` : ''}</Typography>
<div className={classes.facetHeaderButtons}> <div className={classes.facetHeaderButtons}>
<IconButton disabled aria-label="Statistics"> {/*<IconButton disabled aria-label="Statistics">
<PieChart /> <PieChart />
</IconButton> </IconButton> */}
<IconButton {!this.props.hierarchical &&
aria-label="More" <React.Fragment>
aria-owns={open ? 'long-menu' : undefined} <IconButton
aria-haspopup="true" aria-label="More"
onClick={this.handleClick} aria-owns={open ? 'facet-menu' : undefined}
> aria-haspopup="true"
<SortByAlphaIcon /> onClick={this.handleSortByClick}
</IconButton> >
<Menu <SortByAlphaIcon />
id="long-menu" </IconButton>
anchorEl={anchorEl} <Menu
open={open} id="facet-menu"
onClose={this.handleClose} anchorEl={anchorEl}
> open={open}
{options.map(option => ( onClose={this.handleMenuClose}
<MenuItem key={option} selected={option === 'Pyxis'} onClick={this.handleClose}> >
{option} {options.map(option => (
</MenuItem> <MenuItem key={option.id} selected={option.selected} onClick={this.handleMenuItemClick(option.id, option.selected)}>
))} {option.menuItemText}
</Menu> </MenuItem>
))}
</Menu>
</React.Fragment>
}
<IconButton disabled aria-label="Expand"> <IconButton disabled aria-label="Expand">
<ExpandLess /> <ExpandLess />
</IconButton> </IconButton>
...@@ -103,7 +131,12 @@ class FacetHeader extends React.Component { ...@@ -103,7 +131,12 @@ class FacetHeader extends React.Component {
FacetHeader.propTypes = { FacetHeader.propTypes = {
classes: PropTypes.object.isRequired, classes: PropTypes.object.isRequired,
label: PropTypes.string.isRequired, label: PropTypes.string.isRequired,
distinctValueCount: PropTypes.number.isRequired property: PropTypes.string.isRequired,
hierarchical: PropTypes.bool.isRequired,
distinctValueCount: PropTypes.number.isRequired,
sortBy: PropTypes.string.isRequired,
sortDirection: PropTypes.string.isRequired,
fetchFacet: PropTypes.func.isRequired
}; };
export default withStyles(styles)(FacetHeader); export default withStyles(styles)(FacetHeader);
...@@ -82,8 +82,8 @@ const facet = (state = INITIAL_STATE, action) => { ...@@ -82,8 +82,8 @@ const facet = (state = INITIAL_STATE, action) => {
[ action.id ]: { [ action.id ]: {
distinctValueCount: 0, distinctValueCount: 0,
values: [], values: [],
sortBy: '', sortBy: action.sortBy,
sortDirection: '', sortDirection: action.sortDirection,
isFetching: true isFetching: true
} }
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment