Skip to content

Commit

Permalink
chore: prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
edoardo committed Dec 9, 2019
1 parent 2d1351f commit a77d14c
Showing 1 changed file with 41 additions and 45 deletions.
86 changes: 41 additions & 45 deletions packages/app/src/components/Layout/DefaultLayout/DefaultAxis.js
Original file line number Diff line number Diff line change
@@ -1,76 +1,76 @@
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { Droppable, Draggable } from 'react-beautiful-dnd';
import i18n from '@dhis2/d2-i18n';
import MenuItem from '@material-ui/core/MenuItem';
import Divider from '@material-ui/core/Divider';
import React from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { Droppable, Draggable } from 'react-beautiful-dnd'
import i18n from '@dhis2/d2-i18n'
import MenuItem from '@material-ui/core/MenuItem'
import Divider from '@material-ui/core/Divider'
import {
AXIS_ID_COLUMNS,
DEFAULT_AXIS_IDS,
DIMENSION_ID_DATA,
isYearOverYear,
isDualAxisType,
getAxisName,
} from '@dhis2/analytics';
} from '@dhis2/analytics'

import Chip from '../Chip';
import { sGetUi } from '../../../reducers/ui';
import { decodeDataTransfer } from '../../../modules/dnd';
import Chip from '../Chip'
import { sGetUi } from '../../../reducers/ui'
import { decodeDataTransfer } from '../../../modules/dnd'
import {
acAddUiLayoutDimensions,
acSetUiActiveModalDialog,
} from '../../../actions/ui';
import { SOURCE_DIMENSIONS, menuLabels } from '../../../modules/layout';
import { getAdaptedUiByType } from '../../../modules/ui';
} from '../../../actions/ui'
import { SOURCE_DIMENSIONS, menuLabels } from '../../../modules/layout'
import { getAdaptedUiByType } from '../../../modules/ui'

import styles from './styles/DefaultAxis.style';
import styles from './styles/DefaultAxis.style'
class Axis extends React.Component {
onDragOver = e => {
e.preventDefault();
};
e.preventDefault()
}

onDrop = e => {
e.preventDefault();
e.preventDefault()

const { dimensionId, source } = decodeDataTransfer(e);
const { dimensionId, source } = decodeDataTransfer(e)

this.props.onAddDimension({
[dimensionId]: this.props.axisId,
});
})

const items = this.props.itemsByDimension[dimensionId];
const hasNoItems = Boolean(!items || !items.length);
const items = this.props.itemsByDimension[dimensionId]
const hasNoItems = Boolean(!items || !items.length)

if (source === SOURCE_DIMENSIONS && hasNoItems) {
this.props.onDropWithoutItems(dimensionId);
this.props.onDropWithoutItems(dimensionId)
}
};
}

isMoveSupported = () => !isYearOverYear(this.props.type);
isMoveSupported = () => !isYearOverYear(this.props.type)

getAxisMenuItems = dimensionId =>
DEFAULT_AXIS_IDS.filter(key => key !== this.props.axisId).map(key => (
<MenuItem
key={`${dimensionId}-to-${key}`}
onClick={this.props.getMoveHandler({ [dimensionId]: key })}
>{`${i18n.t('Move to')} ${menuLabels[key]}`}</MenuItem>
));
))

isSeries = () => this.props.axisId === AXIS_ID_COLUMNS;
isSeries = () => this.props.axisId === AXIS_ID_COLUMNS

isData = dimensionId => dimensionId === DIMENSION_ID_DATA;
isData = dimensionId => dimensionId === DIMENSION_ID_DATA

getItemsArrayByDimension = dimensionId =>
this.props.itemsByDimension[dimensionId] || [];
this.props.itemsByDimension[dimensionId] || []

shouldHaveDualAxis = dimensionId =>
Boolean(
this.isSeries() &&
this.isData(dimensionId) &&
isDualAxisType(this.props.type) &&
this.getItemsArrayByDimension(this.props.axis[0]).length > 1
);
)

getDualAxisItem = dimensionId => (
<MenuItem
Expand All @@ -79,7 +79,7 @@ class Axis extends React.Component {
>
{i18n.t('Manage axes')}
</MenuItem>
);
)

getRemoveMenuItem = dimensionId => (
<MenuItem
Expand All @@ -88,9 +88,9 @@ class Axis extends React.Component {
>
{i18n.t('Remove')}
</MenuItem>
);
)

getDividerItem = key => <Divider light key={key} />;
getDividerItem = key => <Divider light key={key} />

getMenuItems = dimensionId => [
this.shouldHaveDualAxis(dimensionId)
Expand Down Expand Up @@ -172,34 +172,30 @@ Axis.propTypes = {
onAddDimension: PropTypes.func,
onDropWithoutItems: PropTypes.func,
onOpenAxisSetup: PropTypes.func,
};
}

const mapStateToProps = state => ({
ui: sGetUi(state),
});
})

const mapDispatchToProps = dispatch => ({
onAddDimension: map => dispatch(acAddUiLayoutDimensions(map)),
onDropWithoutItems: dimensionId =>
dispatch(acSetUiActiveModalDialog(dimensionId)),
getOpenHandler: dimensionId => () =>
dispatch(acSetUiActiveModalDialog(dimensionId)),
});
})

const mergeProps = (stateProps, dispatchProps, ownProps) => {
const adaptedUi = getAdaptedUiByType(stateProps.ui);
const adaptedUi = getAdaptedUiByType(stateProps.ui)

return {
axis: adaptedUi.layout[ownProps.axisId],
itemsByDimension: adaptedUi.itemsByDimension,
type: adaptedUi.type,
...dispatchProps,
...ownProps,
};
};

export default connect(
mapStateToProps,
mapDispatchToProps,
mergeProps
)(Axis);
}
}

export default connect(mapStateToProps, mapDispatchToProps, mergeProps)(Axis)

0 comments on commit a77d14c

Please sign in to comment.