diff --git a/src/assets/DimensionItemIcons/GenericIcon.js b/src/assets/DimensionItemIcons/GenericIcon.js
new file mode 100644
index 000000000..4f3aea414
--- /dev/null
+++ b/src/assets/DimensionItemIcons/GenericIcon.js
@@ -0,0 +1,15 @@
+import React from 'react'
+
+export default (
+
+)
diff --git a/src/components/DataDimension/DataDimension.js b/src/components/DataDimension/DataDimension.js
index 0410398ed..42009c895 100644
--- a/src/components/DataDimension/DataDimension.js
+++ b/src/components/DataDimension/DataDimension.js
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
import debounce from 'lodash/debounce'
import isEqual from 'lodash/isEqual'
-import ItemSelector from '../ItemSelector/ItemSelector'
+import ItemSelector from '../ItemSelector/ItemSelector' //TODO: Deprecate ItemSelector once this dependency is removed?
import DataTypes from './DataTypesSelector'
import Groups from './Groups'
import FilterField from '../FilterField'
diff --git a/src/components/DynamicDimension/DynamicDimension.js b/src/components/DynamicDimension/DynamicDimension.js
index fb4c16dda..f7036174c 100644
--- a/src/components/DynamicDimension/DynamicDimension.js
+++ b/src/components/DynamicDimension/DynamicDimension.js
@@ -1,139 +1,61 @@
-import React, { Component } from 'react'
+import React, { useEffect, useState } from 'react'
import PropTypes from 'prop-types'
-import ItemSelector from '../ItemSelector/ItemSelector'
-import FilterField from '../FilterField'
+import ItemSelector from './ItemSelector'
import { apiFetchItemsByDimension } from '../../api/dimensions'
-export class DynamicDimension extends Component {
- state = {
- filterText: '',
- nextPage: null,
- items: [],
- unselectedIds: [],
- selectedIds: [],
- }
-
- componentDidMount = async () => {
- const items = await apiFetchItemsByDimension(
- this.props.d2,
- this.props.dialogId
- )
-
- this.setState({ items })
- }
-
- onClearFilter = () => {
- this.setState({ filterText: '' })
- }
-
- onFilterTextChange = filterText => {
- const filteredItems = this.state.items.map(
- item =>
- item.name.toLowerCase().includes(filterText.toLowerCase()) &&
- item.id
- )
-
- this.setState({
- filterText,
- unselectedIds: filteredItems,
- })
- }
-
- selectItems = selectedIds => {
- const unselectedIds = this.state.unselectedIds.filter(
- id => !selectedIds.includes(id)
- )
- this.setState({ unselectedIds })
-
- const itemsToAdd = this.state.items.filter(di =>
- selectedIds.includes(di.id)
- )
-
- this.props.onSelect({
- dimensionId: this.props.dialogId,
- items: [
- ...this.props.selectedItems.filter(
- item => !selectedIds.includes(item.id)
- ),
- ...itemsToAdd,
- ],
- })
- }
-
- deselectItems = ids => {
- const unselectedIds = [
- ...new Set([...this.state.unselectedIds, ...ids]),
- ]
- this.setState({ unselectedIds })
-
- this.props.onDeselect({
- dimensionId: this.props.dialogId,
- itemIdsToRemove: ids,
+export const DynamicDimension = ({
+ context,
+ dimensionId,
+ onSelect,
+ selectedItems,
+ rightFooter,
+}) => {
+ const [items, setItems] = useState([])
+
+ useEffect(() => {
+ if (!items || !items.length) {
+ getItems()
+ }
+ }, [])
+
+ const getItems = async () =>
+ setItems(await apiFetchItemsByDimension(context, dimensionId))
+ // 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,
+ }))
+ onSelect({
+ dimensionId: dimensionId,
+ items: formattedItems,
})
}
- reorderItems = itemIds =>
- this.props.onReorder({
- dimensionId: this.props.dialogId,
- itemIds,
- })
-
- getUnselectedItems = () =>
- this.state.items.filter(
- item => !this.props.selectedItems.find(i => i.id === item.id)
- )
-
- render = () => {
- const filterZone = () => {
- return (
-
{i18n.t('No items selected')}
+ + > + ) + + return ( +