Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dynamic axis names based on vis type #623

Merged
merged 25 commits into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
72ba7e5
fix: correct axis name for pivot
martinkrulltott Feb 5, 2020
0404d3e
fix: updates to YoY
martinkrulltott Feb 5, 2020
e330058
fix: dynamic axis names for errors
martinkrulltott Feb 5, 2020
c612404
fix: dynamic options for the addToLayoutButton
martinkrulltott Feb 5, 2020
74a0189
Merge branch 'master' into fix/axis-names
martinkrulltott Feb 5, 2020
9a00cf7
fix: added missing interpolation
martinkrulltott Feb 6, 2020
67af84b
Merge branch 'fix/axis-names' of https://github.com/dhis2/data-visual…
martinkrulltott Feb 6, 2020
dcb618c
fix: force updated the pot file
martinkrulltott Feb 6, 2020
235bcbe
refactor: wrong variable name
martinkrulltott Feb 6, 2020
edf6407
refactor: spelling out visualization in i18n variables
martinkrulltott Feb 6, 2020
97c53c8
Merge branch 'master' into fix/axis-names
martinkrulltott Feb 6, 2020
cb2a3f5
fix: getAxisNameByVisType phased out in favor of ByLayoutType
martinkrulltott Feb 6, 2020
40f2b7d
Merge branch 'master' into fix/axis-names
martinkrulltott Feb 6, 2020
80b0224
fix: force updated the pot file
martinkrulltott Feb 7, 2020
e7d170d
fix: improved the i18n strings
martinkrulltott Feb 7, 2020
5c2cfb4
fix: updated the start screen label
martinkrulltott Feb 7, 2020
427d66c
refactor: prop typo
martinkrulltott Feb 7, 2020
a16567b
refactor: wrong import path
martinkrulltott Feb 7, 2020
b26cd87
Merge branch 'master' into fix/axis-names
martinkrulltott Feb 7, 2020
23e1fa7
chore: regenerated pot file
martinkrulltott Feb 7, 2020
4e4c923
fix: i18n for start screen
martinkrulltott Feb 7, 2020
5ccebbe
fix: upgraded to Analytics v3.1.3
martinkrulltott Feb 7, 2020
09f9038
chore: regenerated pot file
martinkrulltott Feb 7, 2020
378b361
fix: i18n for start screen and dimensions panel
martinkrulltott Feb 7, 2020
cbce4cd
Merge branch 'master' into fix/axis-names
martinkrulltott Feb 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 7 additions & 43 deletions packages/app/i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2020-02-02T13:49:38.927Z\n"
"PO-Revision-Date: 2020-02-02T13:49:38.927Z\n"
"POT-Creation-Date: 2020-02-06T07:29:22.870Z\n"
"PO-Revision-Date: 2020-02-06T07:29:22.870Z\n"

msgid "Rename successful"
msgstr ""
Expand Down Expand Up @@ -34,6 +34,9 @@ msgstr ""
msgid "Update"
msgstr ""

msgid "Add to"
martinkrulltott marked this conversation as resolved.
Show resolved Hide resolved
msgstr ""

msgid ""
"'{{visualizationType}}' is intended to show a single data item. Only the "
"first item will be used and saved."
Expand Down Expand Up @@ -107,12 +110,6 @@ msgstr ""
msgid "{{dimensionName}} is locked to {{axisName}} for {{visTypeName}}"
msgstr ""

msgid "Columns"
msgstr ""

msgid "Rows"
msgstr ""

msgid "None selected"
msgstr ""

Expand Down Expand Up @@ -182,9 +179,6 @@ msgstr ""
msgid "Title"
msgstr ""

msgid "Base line title"
msgstr ""

msgid "Value"
msgstr ""

Expand Down Expand Up @@ -418,9 +412,6 @@ msgstr ""
msgid "Target line"
msgstr ""

msgid "Target line title"
msgstr ""

msgid "Top limit"
msgstr ""

Expand Down Expand Up @@ -453,16 +444,10 @@ msgid ""
"you may not have access to it."
msgstr ""

msgid "Series is empty"
msgstr ""

msgid "Add at least one item to Series."
msgstr ""

msgid "Category is empty"
msgid "{{visType}} is empty"
martinkrulltott marked this conversation as resolved.
Show resolved Hide resolved
msgstr ""

msgid "Add at least one item to Category."
msgid "Add at least one item to {{visType}}."
msgstr ""

msgid "No period set"
Expand Down Expand Up @@ -498,24 +483,6 @@ msgstr ""
msgid "or"
msgstr ""

msgid "Add to series"
msgstr ""

msgid "Add to category"
msgstr ""

msgid "Add to filter"
msgstr ""

msgid "series"
msgstr ""

msgid "category"
msgstr ""

msgid "filter"
msgstr ""

msgid "Today"
msgstr ""

Expand Down Expand Up @@ -648,9 +615,6 @@ msgstr ""
msgid "Horizontal (x) axis"
msgstr ""

msgid "Colors & Legends"
msgstr ""

msgid "Chart style"
msgstr ""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { connect } from 'react-redux'
import Button from '@material-ui/core/Button'
import MenuItem from '@material-ui/core/Button'
import { withStyles } from '@material-ui/core/styles'
import { getAvailableAxes } from '@dhis2/analytics'
import { getAvailableAxes, getAxisNameByVisType } from '@dhis2/analytics'

import Menu from './Menu'
import { sGetUiActiveModalDialog, sGetUiType } from '../../../../reducers/ui'
import { acAddUiLayoutDimensions } from '../../../../actions/ui'

import { ADD_TO_LAYOUT_OPTIONS } from '../../../../modules/layout'
import styles from './styles/AddToLayoutButton.style'
import i18n from '@dhis2/d2-i18n'

export class AddToLayoutButton extends Component {
constructor(props) {
Expand All @@ -21,6 +21,8 @@ export class AddToLayoutButton extends Component {

state = { anchorEl: null }

labelPrefix = i18n.t('Add to')
martinkrulltott marked this conversation as resolved.
Show resolved Hide resolved

onClose = () => this.setState({ anchorEl: null })

onToggle = event =>
Expand All @@ -36,31 +38,25 @@ export class AddToLayoutButton extends Component {
this.props.onClick()
}

getAxisMeta = axisIdArray =>
axisIdArray.map(axisId =>
ADD_TO_LAYOUT_OPTIONS.find(
axisMetaObj => axisMetaObj.axisId === axisId
)
)

renderMenuItems = () =>
this.getAxisMeta(getAvailableAxes(this.props.visType))
getAvailableAxes(this.props.visType)
.slice(1)
.map(axisMetaObj => (
.map(axis => (
<MenuItem
className={this.props.classes.menuItem}
component="li"
key={axisMetaObj.axisId}
onClick={() => this.onUpdate(axisMetaObj.axisId)}
key={axis}
onClick={() => this.onUpdate(axis)}
>
{axisMetaObj.name}
{`${this.labelPrefix} ${getAxisNameByVisType(
axis,
this.props.visType
)}`}
</MenuItem>
))

render() {
const availableAxisMeta = this.getAxisMeta(
getAvailableAxes(this.props.visType)
)
const availableAxis = getAvailableAxes(this.props.visType)
martinkrulltott marked this conversation as resolved.
Show resolved Hide resolved

return (
<div ref={addToRef => (this.buttonRef = addToRef)}>
Expand All @@ -70,11 +66,14 @@ export class AddToLayoutButton extends Component {
color="primary"
disableRipple
disableFocusRipple
onClick={() => this.onUpdate(availableAxisMeta[0].axisId)}
onClick={() => this.onUpdate(availableAxis[0])}
>
{availableAxisMeta[0].name}
{`${this.labelPrefix} ${getAxisNameByVisType(
availableAxis[0],
this.props.visType
)}`}
</Button>
{availableAxisMeta.length > 1 ? (
{availableAxis.length > 1 ? (
<Menu
onClose={this.onClose}
onClick={this.onToggle}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import React from 'react'
import { shallow } from 'enzyme'
import Menu from '@material-ui/core/Menu'
import MenuItem from '@material-ui/core/MenuItem'
import { ADD_TO_LAYOUT_OPTIONS } from '../../../../../modules/layout'

import { DropDown } from '../Menu'
import DropDownButton from '../DropDownButton'
import { VIS_TYPE_COLUMN } from '@dhis2/analytics/build/modules/visTypes'
martinkrulltott marked this conversation as resolved.
Show resolved Hide resolved
import { getAvailableAxes } from '@dhis2/analytics'

describe('The DropDownButton component ', () => {
let props
Expand Down Expand Up @@ -55,7 +56,7 @@ describe('The DropDownButton component ', () => {
it('renders a Menu with children if prop anchorel is equal to a truthy value', () => {
props.anchorEl = { getBoundingClientRect: () => ({ bottom: 100 }) }

props.menuItems = ADD_TO_LAYOUT_OPTIONS.map((option, i) => (
props.menuItems = getAvailableAxes(VIS_TYPE_COLUMN).map((option, i) => (
<MenuItem key={i} value={option.axisId} />
))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ jest.mock('@dhis2/analytics', () => {
DIMENSION_ID_ORGUNIT: ouId,
getAxisMaxNumberOfItems: () => {},
filterOutPredefinedDimensions: () => [],
getAxisName: () => {},
getPredefinedDimensions: () => {},
getPredefinedDimensionProp: () => {},
}
Expand Down
7 changes: 5 additions & 2 deletions packages/app/src/components/Layout/Chip.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
getAxisMaxNumberOfItems,
hasAxisTooManyItems,
getDisplayNameByVisType,
getAxisName,
getAxisNameByVisType,
DIMENSION_ID_ASSIGNED_CATEGORIES,
isDimensionLocked,
DIMENSION_PROP_NO_ITEMS,
Expand Down Expand Up @@ -154,7 +154,10 @@ class Chip extends React.Component {
`{{dimensionName}} is locked to {{axisName}} for {{visTypeName}}`,
{
dimensionName: this.props.dimensionName,
axisName: getAxisName(this.props.axisId),
axisName: getAxisNameByVisType(
this.props.axisId,
this.props.type
),
visTypeName: getDisplayNameByVisType(this.props.type),
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { Droppable, Draggable } from 'react-beautiful-dnd'
import { getAxisName, isDimensionLocked } from '@dhis2/analytics'
import { getAxisNameByVisType, isDimensionLocked } from '@dhis2/analytics'
import { withStyles } from '@material-ui/core'

import Chip from '../Chip'
Expand All @@ -25,7 +25,7 @@ class Axis extends React.Component {
onDragOver={this.onDragOver}
>
<div style={styles.label}>
{this.props.label || getAxisName(axisId)}
{this.props.label || getAxisNameByVisType(axisId, type)}
</div>
<Droppable droppableId={axisId} direction="horizontal">
{provided => (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react'
import i18n from '@dhis2/d2-i18n'
import {
AXIS_ID_COLUMNS,
AXIS_ID_ROWS,
Expand All @@ -22,15 +21,13 @@ const Layout = () => (
>
<DefaultAxis
axisId={AXIS_ID_COLUMNS}
label={i18n.t('Columns')}
style={{
...defaultLayoutStyles.columns,
...defaultAxisStyles.axisContainerLeft,
}}
/>
<DefaultAxis
axisId={AXIS_ID_ROWS}
label={i18n.t('Rows')}
style={{
...defaultLayoutStyles.rows,
...defaultAxisStyles.axisContainerLeft,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import React from 'react'
import { connect } from 'react-redux'
import { getAxisName } from '@dhis2/analytics'
import {
getAxisNameByLayoutType,
LAYOUT_TYPE_YEAR_OVER_YEAR,
} from '@dhis2/analytics'
import PropTypes from 'prop-types'

import {
Expand All @@ -16,7 +19,7 @@ const YearOverYearAxis = props => (
style={{ ...defaultAxisStyles.axisContainer, ...props.style }}
>
<div className="label" style={defaultAxisStyles.label}>
{getAxisName(props.axisId)}
{getAxisNameByLayoutType(props.axisId, LAYOUT_TYPE_YEAR_OVER_YEAR)}
martinkrulltott marked this conversation as resolved.
Show resolved Hide resolved
</div>
<div
className="content"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import React from 'react'
import { connect } from 'react-redux'
import { AXIS_ID_FILTERS } from '@dhis2/analytics'
import {
AXIS_ID_FILTERS,
AXIS_ID_COLUMNS,
AXIS_ID_ROWS,
} from '@dhis2/analytics'
import PropTypes from 'prop-types'

import DefaultAxis from '../DefaultLayout/DefaultAxis'
Expand Down Expand Up @@ -29,7 +33,7 @@ const Layout = props => (
}}
>
<YearOverYearAxis
axisId="yearOverYearSeries"
axisId={AXIS_ID_COLUMNS}
style={{
...defaultLayoutStyles.columns,
...defaultAxisStyles.axisContainerLeft,
Expand All @@ -43,7 +47,7 @@ const Layout = props => (
/>
</YearOverYearAxis>
<YearOverYearAxis
axisId="yearOverYearCategory"
axisId={AXIS_ID_ROWS}
style={{
...defaultLayoutStyles.rows,
...defaultAxisStyles.axisContainerLeft,
Expand Down
Loading