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

feat: upgrade to ui@5 (TECH-387) #476

Merged
merged 30 commits into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d9305a1
fix: ui things have moved
jenniferarnesen Jun 3, 2020
33485dc
fix: partly working dynamic dimension
jenniferarnesen Jun 4, 2020
c55027c
refactor: replaced all ui- deps with ui
martinkrulltott Jun 4, 2020
aa12c8a
test: added DynamicDimension story
martinkrulltott Jun 4, 2020
a821728
test: snapshot update
martinkrulltott Jun 4, 2020
44d63a1
fix: dynamic dimensions works again
martinkrulltott Jun 4, 2020
930eb8d
fix: naming for clarity, story that needs addressing
jenniferarnesen Jun 4, 2020
8c698a7
fix: add missing prop in story
jenniferarnesen Jun 4, 2020
2801b3b
chore: fixed broken stories and added a dev note
martinkrulltott Jun 5, 2020
7b41d12
chore: comment for bug once pagination is added
martinkrulltott Jun 5, 2020
bd2c228
fix: period selector works again
martinkrulltott Jun 8, 2020
6223682
chore: merge branch 'master' into fix/upgrade-ui-to-5
martinkrulltott Jun 8, 2020
d43d172
chore: merge branch 'master' into fix/upgrade-ui-to-5
martinkrulltott Jun 9, 2020
0e5993f
fix: data dimension works again
martinkrulltott Jun 10, 2020
5474170
chore: bump ui to 5.0.2
martinkrulltott Jun 10, 2020
7bccf3a
chore: merge branch 'master' into fix/upgrade-ui-to-5
martinkrulltott Jun 10, 2020
77ed8b2
v7.1.0-alpha.1
martinkrulltott Jun 10, 2020
1228e5d
v7.1.0-alpha.2
martinkrulltott Jun 10, 2020
41c3e29
chore: merge branch 'master' into fix/upgrade-ui-to-5
martinkrulltott Jun 11, 2020
95f107d
Merge branch 'master' into fix/upgrade-ui-to-5
martinkrulltott Jun 11, 2020
6d30515
v7.1.0-alpha.3
martinkrulltott Jun 11, 2020
068849a
chore: yarn.lock auto update
martinkrulltott Jun 11, 2020
4ff5203
fix: transferOption icon reimplemented
martinkrulltott Jun 11, 2020
2ce5cf2
v7.1.0-alpha.4
martinkrulltott Jun 11, 2020
723796b
refactor: removed duplicate import
martinkrulltott Jun 11, 2020
10c0f96
refactor: removed obsolete check
martinkrulltott Jun 11, 2020
938777a
refactor: removed obsolete label variable
martinkrulltott Jun 11, 2020
f6d2709
refactor: spread props
jenniferarnesen Jun 11, 2020
c78ab8c
fix: restore package version
jenniferarnesen Jun 11, 2020
f7ca41b
fix: remove console.log
jenniferarnesen Jun 11, 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
7 changes: 5 additions & 2 deletions 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-05-22T11:34:10.538Z\n"
"PO-Revision-Date: 2020-05-22T11:34:10.538Z\n"
"POT-Creation-Date: 2020-06-03T21:43:03.758Z\n"
"PO-Revision-Date: 2020-06-03T21:43:03.758Z\n"

msgid "Data Type"
msgstr ""
Expand Down Expand Up @@ -59,6 +59,9 @@ msgstr ""
msgid "Dimension recommended with selected data"
msgstr ""

msgid "No items selected"
msgstr ""

msgid "Search"
msgstr ""

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
},
"dependencies": {
"@dhis2/d2-ui-org-unit-dialog": "^7.0.4",
"@dhis2/ui-core": "^4.21.1",
"@dhis2/ui": "^5.0.3",
"@material-ui/core": "^3.9.3",
"@material-ui/icons": "^3.0.2",
"classnames": "^2.2.6",
Expand Down
55 changes: 55 additions & 0 deletions src/__demo__/DynamicDimension.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React from 'react'
import { storiesOf } from '@storybook/react'

import ItemSelector from '../components/DynamicDimension/ItemSelector'

const items = [
{ id: '1', name: 'One' },
{ id: '2', name: 'Two' },
{ id: '3', name: 'Three' },
{ id: '4', name: 'Four' },
{ id: '5', name: 'Five' },
]

storiesOf('DynamicDimension', module).add('ItemSelector none selected', () => {
return (
<ItemSelector
onSelect={selected => console.log(selected)}
allItems={items}
/>
)
})

storiesOf('DynamicDimension', module).add('ItemSelector one selected', () => {
return (
<ItemSelector
onSelect={selected => console.log(selected)}
allItems={items}
initialSelectedItemIds={[items[2].id]}
/>
)
})

storiesOf('DynamicDimension', module).add(
'ItemSelector one selected not in options',
() => {
return (
<>
<ItemSelector
onSelect={selected => console.log(selected)}
allItems={items}
initialSelectedItemIds={['6']}
/>
<p>
Note: This currently does not work as ui (currently @5.0.1)
does not yet support selected items that are not part of the
options array{' '}
<a href="https://jira.dhis2.org/browse/TECH-380">
https://jira.dhis2.org/browse/TECH-380
</a>
</p>
</>
// TODO: fix the issue above
)
}
)
25 changes: 25 additions & 0 deletions src/__demo__/Filter.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React, { useState } from 'react'
import { storiesOf } from '@storybook/react'

import Filter from '../components/Filter/Filter'

function FilterWithState() {
const [text, setText] = useState(null)

const onTextChange = value => setText(value)
const onClearFilter = () => setText(null)
return (
<Filter
placeholder="Filter dimensions"
text={text}
onChange={onTextChange}
onClear={onClearFilter}
disableUnderline={true}
type="search"
/>
)
}

storiesOf('Filter', module).add('default', () => {
return <FilterWithState />
})
15 changes: 13 additions & 2 deletions src/__demo__/PeriodDimension.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ import { storiesOf } from '@storybook/react'

import PeriodDimension from '../components/PeriodDimension/PeriodDimension'

storiesOf('PeriodDimension', module).add('default', () => {
return <PeriodDimension />
const selectedPeriods = [{ id: 'LAST_12_MONTHS', name: 'Last 12 months' }]

storiesOf('PeriodDimension', module).add('None selected', () => {
return <PeriodDimension onSelect={selected => console.log(selected)} />
})

storiesOf('PeriodDimension', module).add('One selected', () => {
return (
<PeriodDimension
selectedPeriods={selectedPeriods}
onSelect={selected => console.log(selected)}
/>
)
})
7 changes: 2 additions & 5 deletions src/components/DataDimension/DataTypesSelector.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import PropTypes from 'prop-types'
import i18n from '@dhis2/d2-i18n'
import { SingleSelectField, SingleSelectOption } from '@dhis2/ui-core'
import { SingleSelectField, SingleSelectOption } from '@dhis2/ui'

import { dataTypes } from '../../modules/dataTypes'
import styles from './styles/DataTypesSelector.style'
Expand All @@ -10,10 +10,7 @@ export const DataTypes = ({ currentDataType, onChange }) => (
<div className="container">
<SingleSelectField
label={i18n.t('Data Type')}
selected={{
value: dataTypes[currentDataType]?.id,
label: dataTypes[currentDataType]?.getName(),
}}
selected={dataTypes[currentDataType]?.id}
onChange={ref => onChange(ref.selected.value)}
dense
>
Expand Down
12 changes: 2 additions & 10 deletions src/components/DataDimension/Detail.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import PropTypes from 'prop-types'
import i18n from '@dhis2/d2-i18n'
import { SingleSelectField, SingleSelectOption } from '@dhis2/ui-core'
import { SingleSelectField, SingleSelectOption } from '@dhis2/ui'
import { TOTALS, DETAIL } from '../../modules/dataTypes'

import styles from './styles/Detail.style'
Expand All @@ -13,19 +13,11 @@ const getOptions = () => ({

export const Detail = ({ currentValue, onChange }) => {
const options = getOptions()
const currentLabel = options[currentValue]
return (
<div className="detail-container">
<SingleSelectField
label={i18n.t('Detail')}
selected={
currentLabel
? {
value: currentValue,
label: currentLabel,
}
: null
}
selected={currentValue}
onChange={ref => onChange(ref.selected.value)}
dense
>
Expand Down
10 changes: 2 additions & 8 deletions src/components/DataDimension/Groups.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import PropTypes from 'prop-types'
import { SingleSelectField, SingleSelectOption } from '@dhis2/ui-core'
import { SingleSelectField, SingleSelectOption } from '@dhis2/ui'

import { Detail } from './Detail'
import { dataTypes } from '../../modules/dataTypes'
Expand All @@ -23,19 +23,13 @@ export const Groups = ({

const groupDetail = dataTypes[dataType].groupDetail

const selected = optionItems.find(item => item.id === groupId) || {}

return (
<div className="container">
<style jsx>{styles}</style>
<div className="group-container">
<SingleSelectField
label={dataTypes[dataType].getGroupLabel()}
selected={
selected.id && selected.name
? { value: selected.id, label: selected.name }
: {}
}
selected={groupId}
placeholder={
!groupId && dataTypes[dataType].getPlaceholder
? dataTypes[dataType].getPlaceholder()
Expand Down
2 changes: 1 addition & 1 deletion src/components/DataDimension/styles/Groups.style.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import css from 'styled-jsx/css'
import { colors } from '@dhis2/ui-core'
import { colors } from '@dhis2/ui'

export default css`
.container {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { colors, theme } from '@dhis2/ui-core'
import { colors, theme } from '@dhis2/ui'

export const styles = {
labelWrapper: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { colors, spacers } from '@dhis2/ui-core'
import { colors, spacers } from '@dhis2/ui'

// Fix for vertical flex scrolling in Firefox/Safari:
// Wrap the list in a div with position:relative (and flex:1 instead of on the list)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { colors, theme } from '@dhis2/ui-core'
import { colors, theme } from '@dhis2/ui'

export const styles = {
toolTip: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { colors } from '@dhis2/ui-core'
import { colors } from '@dhis2/ui'

export const styles = {
divContainer: {
Expand Down
24 changes: 15 additions & 9 deletions src/components/DynamicDimension/DynamicDimension.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ export const DynamicDimension = ({
}, [])

const getItems = async () =>
setItems(await apiFetchItemsByDimension(context, dimensionId))
setItems(await apiFetchItemsByDimension(context, dimensionId)) // TODO: refactor to use the data engine instead
// TODO: *** Once pagination is in use, check if there are items that are in selectedItems that needs to be added to the items list
// TODO: This needs to be refactored to use a loading spinner once Transfer supports it: https://jira.dhis2.org/browse/TECH-379

const selectItems = items => {
const formattedItems = items.map(item => ({
id: item.value,
name: item.label,
}))
const onSelectItems = selectedItemIds => {
const formattedItems = selectedItemIds.map(id => ({
id,
name: items.find(item => item.id === id).name, // TODO: Re: *** above, this won't work with pagination
})) // TODO: fetch the name from somewhere else, as not all content in selectedItems might be present in the items list
onSelect({
dimensionId: dimensionId,
items: formattedItems,
Expand All @@ -36,9 +37,9 @@ export const DynamicDimension = ({

return (
<ItemSelector
onSelect={selectItems}
onSelect={onSelectItems}
allItems={items}
initialSelectedItems={selectedItems}
initialSelectedItemIds={selectedItems.map(item => item.id)}
rightFooter={rightFooter}
// TODO: Pass in a func prop to fetch items, instead of fetching them on this level, to enable the loading spinner?
/>
Expand All @@ -48,7 +49,12 @@ export const DynamicDimension = ({
DynamicDimension.propTypes = {
context: PropTypes.object.isRequired,
dimensionId: PropTypes.string.isRequired,
selectedItems: PropTypes.array.isRequired,
selectedItems: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.string,
name: PropTypes.string,
})
).isRequired,
onSelect: PropTypes.func.isRequired,
rightFooter: PropTypes.node,
}
Expand Down
45 changes: 22 additions & 23 deletions src/components/DynamicDimension/ItemSelector.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from 'react'
import PropTypes from 'prop-types'
import { Transfer } from '@dhis2/ui-core'
import { Transfer } from '@dhis2/ui'
import i18n from '@dhis2/d2-i18n'

import styles from '../styles/DimensionSelector.style'
Expand All @@ -15,16 +15,12 @@ import {
const ItemSelector = ({
allItems,
onSelect,
initialSelectedItems,
initialSelectedItemIds,
leftHeader,
rightFooter,
}) => {
const [selectedItems, setSelectedItems] = useState(
initialSelectedItems.map(item => ({
label: item.name,
value: item.id,
key: item.id,
}))
const [selectedItemIds, setSelectedItemIds] = useState(
initialSelectedItemIds
)

const renderEmptySelection = () => (
Expand All @@ -37,10 +33,10 @@ const ItemSelector = ({
return (
<Transfer
onChange={({ selected }) => {
setSelectedItems(selected)
setSelectedItemIds(selected)
onSelect(selected)
}}
selected={selectedItems}
selected={selectedItemIds}
leftHeader={leftHeader}
filterable
enableOrderChange
Expand All @@ -49,31 +45,34 @@ const ItemSelector = ({
selectedWidth={TRANSFER_SELECTED_WIDTH}
selectedEmptyComponent={renderEmptySelection()}
rightFooter={rightFooter}
options={allItems.map(({ id, name }) => ({
label: name,
value: id,
}))}
renderOption={props => (
<TransferOption {...props} icon={GenericIcon} />
)}
// TODO: Add a filter placeholer once the Transfer component supports this (https://github.com/dhis2/ui/issues/131)
// TODO: Add rightHeader "Selected Periods" once the Transfer component supports this (https://github.com/dhis2/ui-core/issues/885)
>
{allItems.map(item => (
<TransferOption
label={item.name}
value={item.id}
key={item.id}
icon={GenericIcon}
/>
))}
</Transfer>
/>
)
}

ItemSelector.propTypes = {
allItems: PropTypes.arrayOf(PropTypes.object).isRequired,
allItems: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.string,
name: PropTypes.string,
})
).isRequired,
onSelect: PropTypes.func.isRequired,
initialSelectedItems: PropTypes.arrayOf(PropTypes.object),
initialSelectedItemIds: PropTypes.arrayOf(PropTypes.string),
leftHeader: PropTypes.node,
rightFooter: PropTypes.node,
}

ItemSelector.defaultProps = {
initialSelectedItems: [],
initialSelectedItemIds: [],
}

export default ItemSelector
2 changes: 1 addition & 1 deletion src/components/Filter/Filter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import PropTypes from 'prop-types'
import { InputField } from '@dhis2/ui-core'
import { InputField } from '@dhis2/ui'

export const Filter = ({ text, onChange, onClear, placeholder, type }) => (
<InputField
Expand Down
2 changes: 1 addition & 1 deletion src/components/Filter/__tests__/Filter.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { shallow } from 'enzyme'
import { InputField } from '@dhis2/ui-core'
import { InputField } from '@dhis2/ui'

import { Filter } from '../Filter'

Expand Down
Loading