Skip to content

Commit

Permalink
fix: hide vis action buttons for single value charts (#336)
Browse files Browse the repository at this point in the history
* extract action button rendering + update snapshots

* update snapshot

* code style

* add comment

* add comment

* minor fix
  • Loading branch information
janhenrikoverland authored Sep 25, 2019
1 parent 8e65eef commit b42812a
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 568 deletions.
3 changes: 2 additions & 1 deletion src/components/Item/VisualizationItem/Item.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export class Item extends Component {
const itemName = pluginManager.getName(item);

return (
<div style={{ display: 'flex', alignItems: 'center' }}>
<div style={{ display: 'flex' }}>
<span className={classes.title} title={itemName}>
{itemName}
</span>
Expand All @@ -255,6 +255,7 @@ export class Item extends Component {
) && !this.props.editMode ? (
<VisualizationItemHeaderButtons
item={this.props.item}
visualization={this.props.visualization}
activeFooter={this.state.showFooter}
activeType={this.getActiveType()}
onSelectVisualization={this.onSelectVisualization}
Expand Down
71 changes: 48 additions & 23 deletions src/components/Item/VisualizationItem/ItemHeaderButtons.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
EVENT_CHART,
EVENT_REPORT,
DOMAIN_TYPE_AGGREGATE,
CHART_TYPE_SINGLE_VALUE,
} from '../../../modules/itemTypes';
import { colors, theme } from '@dhis2/ui-core';

Expand Down Expand Up @@ -85,16 +86,50 @@ export const getItemTypeId = (itemTypeMap, visualizationType, domainType) => {
return item.id;
};

// TODO: Import this from @dhis2/analytics when available
const isSingleValue = (itemType, chartType) =>
itemType === VISUALIZATION_TYPE_CHART &&
chartType === CHART_TYPE_SINGLE_VALUE;

class VisualizationItemHeaderButtons extends Component {
render() {
renderInterpretationButton() {
const { activeFooter, onToggleFooter } = this.props;

const toggleFooterBase = activeFooter ? activeStyle : baseStyle;

const toggleFooter = {
...toggleFooterBase,
container: {
...toggleFooterBase.container,
...style.toggleFooterPadding,
...style.border,
},
};

return (
<Fragment>
<ItemHeaderButton
style={toggleFooter.container}
onClick={onToggleFooter}
>
<MessageIcon style={toggleFooter.icon} />
</ItemHeaderButton>
</Fragment>
);
}

renderVisualizationButtons() {
const {
item,
visualization,
onSelectVisualization,
activeFooter,
activeType,
onToggleFooter,
} = this.props;

if (isSingleValue(item.type, visualization.type)) {
return null;
}

const domainType = itemTypeMap[item.type].domainType;

const onViewTable = () =>
Expand All @@ -112,17 +147,6 @@ class VisualizationItemHeaderButtons extends Component {
getItemTypeId(itemTypeMap, VISUALIZATION_TYPE_MAP, domainType)
);

const toggleFooterBase = activeFooter ? activeStyle : baseStyle;

const toggleFooter = {
...toggleFooterBase,
container: {
...toggleFooterBase.container,
...style.toggleFooterPadding,
...style.border,
},
};

// disable toggle buttons
let disabled = false;

Expand All @@ -137,15 +161,7 @@ class VisualizationItemHeaderButtons extends Component {
const mapButtonStyle = mapBtnStyle(activeType, disabled);

return (
<Fragment>
<div style={{ marginRight: 10 }}>
<ItemHeaderButton
style={toggleFooter.container}
onClick={onToggleFooter}
>
<MessageIcon style={toggleFooter.icon} />
</ItemHeaderButton>
</div>
<div style={{ marginLeft: 10 }}>
<div style={style.border}>
<ItemHeaderButton
disabled={disabled}
Expand All @@ -171,6 +187,15 @@ class VisualizationItemHeaderButtons extends Component {
</ItemHeaderButton>
) : null}
</div>
</div>
);
}

render() {
return (
<Fragment>
{this.renderInterpretationButton()}
{this.renderVisualizationButtons()}
</Fragment>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ it('renders correctly', () => {
type: 'CHART',
chart: { type: 'NOT_YOY', domainType: 'AGGREGATE' },
}}
visualization={{
type: 'SINGLE_VALUE',
}}
onSelectVisualization={Function.prototype}
activeFooter={false}
activeType={'CHART'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,22 @@ ShallowWrapper {
}
onSelectVisualization={[Function]}
onToggleFooter={[Function]}
visualization={
Object {
"columns": Array [],
"description": "Test pivot mock",
"filters": Array [],
"name": "Test pivot",
"rows": Array [],
}
}
/>
}
editMode={false}
title={
<div
style={
Object {
"alignItems": "center",
"display": "flex",
}
}
Expand Down Expand Up @@ -128,12 +136,20 @@ ShallowWrapper {
}
onSelectVisualization={[Function]}
onToggleFooter={[Function]}
visualization={
Object {
"columns": Array [],
"description": "Test pivot mock",
"filters": Array [],
"name": "Test pivot",
"rows": Array [],
}
}
/>,
"editMode": false,
"title": <div
style={
Object {
"alignItems": "center",
"display": "flex",
}
}
Expand Down Expand Up @@ -199,14 +215,22 @@ ShallowWrapper {
}
onSelectVisualization={[Function]}
onToggleFooter={[Function]}
visualization={
Object {
"columns": Array [],
"description": "Test pivot mock",
"filters": Array [],
"name": "Test pivot",
"rows": Array [],
}
}
/>
}
editMode={false}
title={
<div
style={
Object {
"alignItems": "center",
"display": "flex",
}
}
Expand Down Expand Up @@ -257,12 +281,20 @@ ShallowWrapper {
}
onSelectVisualization={[Function]}
onToggleFooter={[Function]}
visualization={
Object {
"columns": Array [],
"description": "Test pivot mock",
"filters": Array [],
"name": "Test pivot",
"rows": Array [],
}
}
/>,
"editMode": false,
"title": <div
style={
Object {
"alignItems": "center",
"display": "flex",
}
}
Expand Down
Loading

0 comments on commit b42812a

Please sign in to comment.