Skip to content

Commit

Permalink
chore: use shared layout resources (#291)
Browse files Browse the repository at this point in the history
* chore: replace dimensionCreate

* chore: replace layoutGetAxisNameDimensionIdsObject

* chore: replace layoutGetAxisNameDimensionIdsObject

* chore: replace layout validation

* chore: replace constants

* chore: replace constants

* chore: replace constants

* fix: remove unused exports

* fix: update fn name

* fix: update d2uia version

* fix: update shared resources

* fix: update import + remove useless test file

* fix: remove local vars WIP

* chore: replace constants

* fix: update dialog manager test + snapshot

* fix: remove unused import
  • Loading branch information
janhenrikoverland committed May 27, 2019
1 parent 556e5b3 commit a1fef66
Show file tree
Hide file tree
Showing 28 changed files with 312 additions and 428 deletions.
10 changes: 2 additions & 8 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: 2019-04-18T12:38:17.377Z\n"
"PO-Revision-Date: 2019-04-18T12:38:17.377Z\n"
"POT-Creation-Date: 2019-05-22T13:11:50.814Z\n"
"PO-Revision-Date: 2019-05-22T13:11:50.814Z\n"

msgid "Rename successful"
msgstr ""
Expand Down Expand Up @@ -373,12 +373,6 @@ msgstr ""
msgid "Program indicators"
msgstr ""

msgid "Period"
msgstr ""

msgid "Organisation Unit"
msgstr ""

msgid "Add to series"
msgstr ""

Expand Down
2 changes: 1 addition & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"dependencies": {
"@dhis2/d2-i18n": "^1.0.3",
"@dhis2/d2-ui-analytics": "^1.0.2",
"@dhis2/d2-ui-analytics": "^1.0.4",
"@dhis2/d2-ui-core": "5.3.8",
"@dhis2/d2-ui-file-menu": "5.3.9",
"@dhis2/d2-ui-interpretations": "5.2.10",
Expand Down
6 changes: 2 additions & 4 deletions packages/app/src/api/analytics.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { DIMENSION_ID_PERIOD } from '@dhis2/d2-ui-analytics';
import { getInstance } from 'd2';
import { FIXED_DIMENSIONS } from '../modules/fixedDimensions';

const peId = FIXED_DIMENSIONS.pe.id;

export const apiDownloadImage = async (type, formData) => {
const d2 = await getInstance();
Expand Down Expand Up @@ -82,7 +80,7 @@ export const apiFetchAnalyticsForYearOverYear = async (current, options) => {
const currentDay = ('' + now.getDate()).padStart(2, 0);
const currentMonth = ('' + (now.getMonth() + 1)).padStart(2, 0);

yearlySeriesRes.metaData.dimensions[peId].forEach(period => {
yearlySeriesRes.metaData.dimensions[DIMENSION_ID_PERIOD].forEach(period => {
yearlySeriesLabels.push(yearlySeriesRes.metaData.items[period].name);

const startDate = `${period}-${currentMonth}-${currentDay}`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
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 { AXIS_NAME_COLUMNS } from '@dhis2/d2-ui-analytics';

import UpdateButton from '../../../UpdateButton/UpdateButton';
import Menu from './Menu';

import {
sGetUi,
sGetUiLayout,
Expand All @@ -28,7 +28,7 @@ const UNSELECTED_BUTTON_TYPE = -1;
const seriesItem = ADD_TO_LAYOUT_OPTIONS[0];
const filterItem = ADD_TO_LAYOUT_OPTIONS[2];
const itemsWithoutSeries = ADD_TO_LAYOUT_OPTIONS.filter(
option => option.axisKey !== 'columns'
option => option.axisKey !== AXIS_NAME_COLUMNS
);

export class AddToLayoutButton extends Component {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import {
DynamicDimension,
PeriodDimension,
OrgUnitDimension,
DIMENSION_ID_DATA,
DIMENSION_ID_PERIOD,
DIMENSION_ID_ORGUNIT,
FIXED_DIMENSIONS,
} from '@dhis2/d2-ui-analytics';

import HideButton from './HideButton';
Expand All @@ -38,16 +42,11 @@ import { sGetDimensions } from '../../../reducers/dimensions';
import { sGetMetadata } from '../../../reducers/metadata';
import { sGetSettingsDisplayNameProperty } from '../../../reducers/settings';
import { apiFetchRecommendedIds } from '../../../api/dimensions';
import { FIXED_DIMENSIONS } from '../../../modules/fixedDimensions';
import {
getOrgUnitsFromIds,
removeLastPathSegment,
} from '../../../modules/orgUnit';

const dxId = FIXED_DIMENSIONS.dx.id;
const peId = FIXED_DIMENSIONS.pe.id;
const ouId = FIXED_DIMENSIONS.ou.id;

export class DialogManager extends Component {
state = {
onMounted: false,
Expand All @@ -62,7 +61,10 @@ export class DialogManager extends Component {
this.fetchRecommended();
}

if (this.props.dialogId === ouId && !this.state.ouMounted) {
if (
this.props.dialogId === DIMENSION_ID_ORGUNIT &&
!this.state.ouMounted
) {
this.setState({ ouMounted: true });
}
};
Expand All @@ -83,7 +85,7 @@ export class DialogManager extends Component {
});

switch (dimensionId) {
case ouId: {
case DIMENSION_ID_ORGUNIT: {
const forMetadata = {};
const forParentGraphMap = {};

Expand Down Expand Up @@ -148,10 +150,11 @@ export class DialogManager extends Component {
if (this.state.ouMounted) {
const ouItems = getOrgUnitsFromIds(ouIds, metadata, parentGraphMap);

const display = ouId === dialogId ? 'block' : 'none';
const display =
DIMENSION_ID_ORGUNIT === dialogId ? 'block' : 'none';

return (
<div key={ouId} style={{ display }}>
<div key={DIMENSION_ID_ORGUNIT} style={{ display }}>
<OrgUnitDimension
displayNameProperty={displayNameProperty}
ouItems={ouItems}
Expand Down Expand Up @@ -183,7 +186,7 @@ export class DialogManager extends Component {
const dynamicContent = () => {
const selectedItems = this.getSelectedItems(dialogId);

if (dialogId === dxId) {
if (dialogId === DIMENSION_ID_DATA) {
return (
<DataDimension
displayNameProp={displayNameProperty}
Expand All @@ -193,7 +196,7 @@ export class DialogManager extends Component {
);
}

if (dialogId === peId) {
if (dialogId === DIMENSION_ID_PERIOD) {
return (
<PeriodDimension
selectedPeriods={selectedItems}
Expand Down Expand Up @@ -228,7 +231,7 @@ export class DialogManager extends Component {

render() {
const { dialogId, dimensions } = this.props;
const keepMounted = !dialogId || dialogId === ouId;
const keepMounted = !dialogId || dialogId === DIMENSION_ID_ORGUNIT;

return (
<Dialog
Expand Down Expand Up @@ -275,8 +278,8 @@ const mapStateToProps = state => ({
dimensions: sGetDimensions(state),
metadata: sGetMetadata(state),
parentGraphMap: sGetUiParentGraphMap(state),
dxIds: sGetUiItemsByDimension(state, dxId),
ouIds: sGetUiItemsByDimension(state, ouId),
dxIds: sGetUiItemsByDimension(state, DIMENSION_ID_DATA),
ouIds: sGetUiItemsByDimension(state, DIMENSION_ID_ORGUNIT),
selectedItems: sGetUiItems(state),
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import React from 'react';
import { shallow } from 'enzyme';
import {
DIMENSION_ID_DATA,
DIMENSION_ID_PERIOD,
DIMENSION_ID_ORGUNIT,
} from '@dhis2/d2-ui-analytics';

import { DialogManager } from '../DialogManager';
import { FIXED_DIMENSIONS } from '../../../../modules/fixedDimensions';

jest.mock('@material-ui/core/Dialog', () => props => {
console.log('children', props.children);
Expand All @@ -14,11 +19,23 @@ jest.mock('@material-ui/core/DialogActions', () => props => (
));

jest.mock('@dhis2/d2-ui-analytics', () => {
const dataId = 'dx';
const periodId = 'pe';
const ouId = 'ou';

return {
DataDimension: () => <div />,
DynamicDimension: () => <div />,
PeriodDimension: () => <div />,
OrgUnitDimension: () => <div />,
DIMENSION_ID_DATA: dataId,
DIMENSION_ID_PERIOD: periodId,
DIMENSION_ID_ORGUNIT: ouId,
FIXED_DIMENSIONS: {
[dataId]: {},
[periodId]: {},
[ouId]: {},
},
};
});

Expand Down Expand Up @@ -70,47 +87,47 @@ describe('The DialogManager component', () => {

it('should add the dialogId of fixed dimensions to state "mounted" on first time render', () => {
const dialog = dialogManager().setProps({
dialogId: FIXED_DIMENSIONS.ou.id,
dialogId: DIMENSION_ID_ORGUNIT,
});

expect(dialog.state().ouMounted).toBe(true);
});

it('renders the DataDimension content in dialog', () => {
const dialog = dialogManager().setProps({
dialogId: FIXED_DIMENSIONS.dx.id,
dialogId: DIMENSION_ID_DATA,
});

expect(dialog).toMatchSnapshot();
});

it('renders the OrgUnitDimension content in dialog', () => {
const dialog = dialogManager().setProps({
dialogId: FIXED_DIMENSIONS.ou.id,
dialogId: DIMENSION_ID_ORGUNIT,
});

expect(dialog).toMatchSnapshot();
});

it('renders the PeriodDimension content in dialog', () => {
const dialog = dialogManager().setProps({
dialogId: FIXED_DIMENSIONS.pe.id,
dialogId: DIMENSION_ID_PERIOD,
});

expect(dialog).toMatchSnapshot();
});

it('renders OUDimension content with display:none when previously mounted', () => {
const dialog = dialogManager().setProps({
dialogId: FIXED_DIMENSIONS.ou.id,
dialogId: DIMENSION_ID_ORGUNIT,
});

expect(dialog).toMatchSnapshot();

dialog.setProps({ dialogId: null });
expect(dialog).toMatchSnapshot();

dialog.setProps({ dialogId: FIXED_DIMENSIONS.dx.id });
dialog.setProps({ dialogId: DIMENSION_ID_DATA });
expect(dialog).toMatchSnapshot();
});

Expand Down Expand Up @@ -140,7 +157,7 @@ describe('The DialogManager component', () => {

it('calls the closeDialog function', () => {
const dialog = dialogManager().setProps({
dialogId: FIXED_DIMENSIONS.dx.id,
dialogId: DIMENSION_ID_DATA,
});

dialog.simulate('close');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { DimensionsPanel } from '@dhis2/d2-ui-analytics';
import { DIMENSION_ID_PERIOD, DimensionsPanel } from '@dhis2/d2-ui-analytics';

import DialogManager from './Dialogs/DialogManager';
import DimensionOptions from './DimensionOptions/DimensionOptions';
import { SOURCE_DIMENSIONS } from '../../modules/layout';
import { FIXED_DIMENSIONS } from '../../modules/fixedDimensions';
import { setDataTransfer } from '../../modules/dnd';
import { isYearOverYear } from '../../modules/chartTypes';
import * as fromReducers from '../../reducers';
Expand Down Expand Up @@ -42,7 +41,7 @@ export class Dimensions extends Component {

disabledDimension = dimension => {
return (
dimension.id === FIXED_DIMENSIONS.pe.id &&
dimension.id === DIMENSION_ID_PERIOD &&
isYearOverYear(this.props.type)
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { shallow } from 'enzyme';
import { DimensionsPanel } from '@dhis2/d2-ui-analytics';

import { Dimensions } from '../DimensionsPanel';

describe('The Dimensions component ', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/components/Layout/Chip.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import React from 'react';
import { connect } from 'react-redux';
import i18n from '@dhis2/d2-i18n';
import { FIXED_DIMENSIONS } from '@dhis2/d2-ui-analytics';

import Menu from './Menu';
import Tooltip from './Tooltip';
import { setDataTransfer } from '../../modules/dnd';
import { sGetDimensions } from '../../reducers/dimensions';
import { sGetUiItemsByDimension } from '../../reducers/ui';
import { styles } from './styles/Chip.style';
import { FIXED_DIMENSIONS } from '../../modules/fixedDimensions';
import DynamicDimensionIcon from '../../assets/DynamicDimensionIcon';
import { sGetMetadata } from '../../reducers/metadata';
import { styles } from './styles/Chip.style';

const TOOLTIP_ENTER_DELAY = 500;

Expand Down
18 changes: 9 additions & 9 deletions packages/app/src/components/Layout/DefaultLayout/DefaultAxis.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import { connect } from 'react-redux';
import i18n from '@dhis2/d2-i18n';
import MenuItem from '@material-ui/core/MenuItem';
import Divider from '@material-ui/core/Divider';
import {
AXIS_NAME_COLUMNS,
AXIS_NAMES,
DIMENSION_ID_DATA,
} from '@dhis2/d2-ui-analytics';

import Chip from '../Chip';
import { sGetUi } from '../../../reducers/ui';
Expand All @@ -12,17 +17,12 @@ import {
acRemoveUiLayoutDimensions,
acSetUiActiveModalDialog,
} from '../../../actions/ui';
import {
AXIS_NAMES,
SOURCE_DIMENSIONS,
menuLabels,
AXIS_NAME_COLUMNS,
} from '../../../modules/layout';
import styles from './styles/DefaultAxis.style';
import { SOURCE_DIMENSIONS, menuLabels } from '../../../modules/layout';
import { getAdaptedUiByType } from '../../../modules/ui';
import { isYearOverYear, isDualAxisType } from '../../../modules/chartTypes';
import { AXIS_SETUP_DIALOG_ID } from '../../AxisSetup/AxisSetup';
import { FIXED_DIMENSIONS } from '../../../modules/fixedDimensions';

import styles from './styles/DefaultAxis.style';

const axisLabels = {
columns: i18n.t('Series'),
Expand Down Expand Up @@ -64,7 +64,7 @@ class Axis extends React.Component {

isSeries = () => this.props.axisName === AXIS_NAME_COLUMNS;

isData = dimensionId => dimensionId === FIXED_DIMENSIONS.dx.id;
isData = dimensionId => dimensionId === DIMENSION_ID_DATA;

getItemsArrayByDimension = dimensionId =>
this.props.itemsByDimension[dimensionId] || [];
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/components/Layout/PieLayout/PieLayout.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import { AXIS_NAME_COLUMNS, AXIS_NAME_FILTERS } from '@dhis2/d2-ui-analytics';

import DefaultAxis from '../DefaultLayout/DefaultAxis';
import defaultAxisStyles from '../DefaultLayout/styles/DefaultAxis.style';
import defaultLayoutStyles from '../DefaultLayout/styles/DefaultLayout.style';
import { AXIS_NAME_COLUMNS, AXIS_NAME_FILTERS } from '../../../modules/layout';

const Layout = () => (
<div id="layout-ct" style={defaultLayoutStyles.ct}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { connect } from 'react-redux';
import { AXIS_NAME_FILTERS } from '@dhis2/d2-ui-analytics';

import DefaultAxis from '../DefaultLayout/DefaultAxis';
import defaultLayoutStyles from '../DefaultLayout/styles/DefaultLayout.style';
Expand All @@ -16,7 +17,6 @@ import {
acSetUiYearOverYearCategory,
} from '../../../actions/ui';
import { seriesOptions, categoryOptions } from '../../../modules/yearOverYear';
import { AXIS_NAME_FILTERS } from '../../../modules/layout';

const Layout = props => (
<div id="layout-ct" style={defaultLayoutStyles.ct}>
Expand Down
Loading

0 comments on commit a1fef66

Please sign in to comment.