@dhis2-ui/organisation-unit-tree 10.16.3 → 10.16.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/__e2e__/children_as_child_nodes.js +8 -11
- package/build/cjs/__e2e__/common.js +19 -26
- package/build/cjs/__e2e__/controlled_expanded.js +7 -10
- package/build/cjs/__e2e__/displaying_loading_error.js +1 -4
- package/build/cjs/__e2e__/expanded.js +25 -34
- package/build/cjs/__e2e__/force_reload.js +15 -22
- package/build/cjs/__e2e__/get-organisation-unit-data.js +25 -29
- package/build/cjs/__e2e__/highlight.js +7 -10
- package/build/cjs/__e2e__/loading_state.js +7 -13
- package/build/cjs/__e2e__/multi_selection.js +8 -11
- package/build/cjs/__e2e__/no_selection.js +15 -21
- package/build/cjs/__e2e__/path_based_filtering.js +16 -22
- package/build/cjs/__e2e__/single_selection.js +10 -16
- package/build/cjs/__e2e__/sub_unit_as_root.js +5 -7
- package/build/cjs/__e2e__/tree_api.js +15 -21
- package/build/cjs/__stories__/custom-expanded-imperative-open.js +7 -10
- package/build/cjs/__stories__/custom-node-label.js +4 -5
- package/build/cjs/__stories__/development-stories.js +6 -8
- package/build/cjs/__stories__/force-reload-all.js +1 -2
- package/build/cjs/__stories__/loading-error-grandchild.js +1 -4
- package/build/cjs/__stories__/loading.js +1 -4
- package/build/cjs/__stories__/multiple-roots.js +9 -12
- package/build/cjs/__stories__/root-error.js +1 -4
- package/build/cjs/__stories__/root-loading.js +1 -4
- package/build/cjs/__stories__/shared.js +46 -79
- package/build/cjs/features/controlled_expanded/index.js +3 -6
- package/build/cjs/locales/index.js +49 -27
- package/build/cjs/organisation-unit-node/error-message.js +10 -13
- package/build/cjs/organisation-unit-node/label/disabled-selection-label.js +9 -12
- package/build/cjs/organisation-unit-node/label/icon-empty.js +19 -22
- package/build/cjs/organisation-unit-node/label/icon-folder-closed.js +25 -28
- package/build/cjs/organisation-unit-node/label/icon-folder-open.js +34 -37
- package/build/cjs/organisation-unit-node/label/icon-single.js +28 -31
- package/build/cjs/organisation-unit-node/label/icon.js +6 -7
- package/build/cjs/organisation-unit-node/label/iconized-checkbox.js +12 -13
- package/build/cjs/organisation-unit-node/label/label-container.js +13 -16
- package/build/cjs/organisation-unit-node/label/label.js +27 -30
- package/build/cjs/organisation-unit-node/label/single-selection-label.js +18 -21
- package/build/cjs/organisation-unit-node/organisation-unit-node-children.js +27 -29
- package/build/cjs/organisation-unit-node/organisation-unit-node.js +22 -23
- package/build/cjs/organisation-unit-node/use-open-state.js +8 -9
- package/build/cjs/organisation-unit-node/use-org-children.js +14 -21
- package/build/cjs/organisation-unit-node/use-org-children.test.js +40 -59
- package/build/cjs/organisation-unit-node/use-org-data/use-org-data.js +13 -20
- package/build/cjs/organisation-unit-node/use-org-data/use-org-data.test.js +17 -27
- package/build/cjs/organisation-unit-tree/default-render-node-label/default-render-node-label.js +3 -6
- package/build/cjs/organisation-unit-tree/organisation-unit-tree-root-error.js +9 -12
- package/build/cjs/organisation-unit-tree/organisation-unit-tree-root-loading.js +10 -13
- package/build/cjs/organisation-unit-tree/organisation-unit-tree.js +24 -26
- package/build/cjs/organisation-unit-tree/use-expanded/create-expand-handlers.js +14 -17
- package/build/cjs/organisation-unit-tree/use-expanded/use-expanded.js +8 -9
- package/build/cjs/organisation-unit-tree/use-root-org-data/patch-missing-display-name.js +1 -2
- package/build/cjs/organisation-unit-tree/use-root-org-data/use-root-org-data.js +10 -14
- package/build/cjs/organisation-unit-tree/use-root-org-data/use-root-org-unit.test.js +32 -46
- package/build/es/__e2e__/children_as_child_nodes.js +8 -11
- package/build/es/__e2e__/common.js +18 -24
- package/build/es/__e2e__/controlled_expanded.js +6 -8
- package/build/es/__e2e__/displaying_loading_error.js +1 -4
- package/build/es/__e2e__/expanded.js +25 -34
- package/build/es/__e2e__/force_reload.js +14 -20
- package/build/es/__e2e__/get-organisation-unit-data.js +25 -29
- package/build/es/__e2e__/highlight.js +7 -10
- package/build/es/__e2e__/loading_state.js +7 -13
- package/build/es/__e2e__/multi_selection.js +8 -11
- package/build/es/__e2e__/no_selection.js +15 -21
- package/build/es/__e2e__/path_based_filtering.js +16 -22
- package/build/es/__e2e__/single_selection.js +10 -16
- package/build/es/__e2e__/sub_unit_as_root.js +4 -5
- package/build/es/__e2e__/tree_api.js +15 -21
- package/build/es/__stories__/custom-expanded-imperative-open.js +6 -8
- package/build/es/__stories__/custom-node-label.js +4 -5
- package/build/es/__stories__/development-stories.js +5 -6
- package/build/es/__stories__/loading-error-grandchild.js +1 -4
- package/build/es/__stories__/loading.js +1 -4
- package/build/es/__stories__/multiple-roots.js +9 -12
- package/build/es/__stories__/root-error.js +1 -4
- package/build/es/__stories__/root-loading.js +1 -4
- package/build/es/__stories__/shared.js +45 -77
- package/build/es/features/controlled_expanded/index.js +3 -6
- package/build/es/locales/index.js +40 -18
- package/build/es/organisation-unit-node/error-message.js +10 -13
- package/build/es/organisation-unit-node/label/disabled-selection-label.js +9 -12
- package/build/es/organisation-unit-node/label/icon-empty.js +19 -22
- package/build/es/organisation-unit-node/label/icon-folder-closed.js +25 -28
- package/build/es/organisation-unit-node/label/icon-folder-open.js +34 -37
- package/build/es/organisation-unit-node/label/icon-single.js +28 -31
- package/build/es/organisation-unit-node/label/icon.js +6 -7
- package/build/es/organisation-unit-node/label/iconized-checkbox.js +12 -13
- package/build/es/organisation-unit-node/label/label-container.js +13 -16
- package/build/es/organisation-unit-node/label/label.js +27 -30
- package/build/es/organisation-unit-node/label/single-selection-label.js +18 -21
- package/build/es/organisation-unit-node/organisation-unit-node-children.js +27 -29
- package/build/es/organisation-unit-node/organisation-unit-node.js +22 -23
- package/build/es/organisation-unit-node/use-open-state.js +8 -9
- package/build/es/organisation-unit-node/use-org-children.js +14 -21
- package/build/es/organisation-unit-node/use-org-children.test.js +40 -59
- package/build/es/organisation-unit-node/use-org-data/use-org-data.js +13 -20
- package/build/es/organisation-unit-node/use-org-data/use-org-data.test.js +17 -27
- package/build/es/organisation-unit-tree/default-render-node-label/default-render-node-label.js +3 -6
- package/build/es/organisation-unit-tree/organisation-unit-tree-root-error.js +9 -12
- package/build/es/organisation-unit-tree/organisation-unit-tree-root-loading.js +10 -13
- package/build/es/organisation-unit-tree/organisation-unit-tree.js +23 -24
- package/build/es/organisation-unit-tree/use-expanded/create-expand-handlers.js +14 -17
- package/build/es/organisation-unit-tree/use-expanded/use-expanded.js +8 -9
- package/build/es/organisation-unit-tree/use-root-org-data/patch-missing-display-name.js +1 -2
- package/build/es/organisation-unit-tree/use-root-org-data/use-root-org-data.js +10 -14
- package/build/es/organisation-unit-tree/use-root-org-data/use-root-org-unit.test.js +32 -46
- package/package.json +6 -6
- package/src/locales/index.js +57 -18
- package/src/organisation-unit-tree/use-root-org-data/use-root-org-unit.test.js +14 -14
|
@@ -3,19 +3,18 @@ import { Checkbox } from '@dhis2-ui/checkbox';
|
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
4
|
import React from 'react';
|
|
5
5
|
import { Icon } from './icon.js';
|
|
6
|
-
export const IconizedCheckbox =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
} = _ref;
|
|
6
|
+
export const IconizedCheckbox = ({
|
|
7
|
+
checked,
|
|
8
|
+
dataTest,
|
|
9
|
+
hasChildren,
|
|
10
|
+
indeterminate,
|
|
11
|
+
children,
|
|
12
|
+
loading,
|
|
13
|
+
name,
|
|
14
|
+
open,
|
|
15
|
+
value,
|
|
16
|
+
onChange
|
|
17
|
+
}) => {
|
|
19
18
|
const icon = /*#__PURE__*/React.createElement(Icon, {
|
|
20
19
|
loading: loading,
|
|
21
20
|
open: open,
|
|
@@ -10,22 +10,19 @@ import React from 'react';
|
|
|
10
10
|
* @param {React.Component|React.Component[]} props.children
|
|
11
11
|
* @returns {React.Component}
|
|
12
12
|
*/
|
|
13
|
-
export const LabelContainer =
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
dynamic: [colors.teal200]
|
|
27
|
-
}, ["div.__jsx-style-dynamic-selector{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;}", "span.__jsx-style-dynamic-selector{display:block;}", `.highlighted.__jsx-style-dynamic-selector{background:${colors.teal200};padding-inline-end:4px;}`]));
|
|
28
|
-
};
|
|
13
|
+
export const LabelContainer = ({
|
|
14
|
+
highlighted,
|
|
15
|
+
children
|
|
16
|
+
}) => /*#__PURE__*/React.createElement("div", {
|
|
17
|
+
className: _JSXStyle.dynamic([["1387769986", [colors.teal200]]]) + " " + (cx({
|
|
18
|
+
highlighted
|
|
19
|
+
}) || "")
|
|
20
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
21
|
+
className: _JSXStyle.dynamic([["1387769986", [colors.teal200]]])
|
|
22
|
+
}, children), /*#__PURE__*/React.createElement(_JSXStyle, {
|
|
23
|
+
id: "1387769986",
|
|
24
|
+
dynamic: [colors.teal200]
|
|
25
|
+
}, ["div.__jsx-style-dynamic-selector{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;}", "span.__jsx-style-dynamic-selector{display:block;}", `.highlighted.__jsx-style-dynamic-selector{background:${colors.teal200};padding-inline-end:4px;}`]));
|
|
29
26
|
LabelContainer.propTypes = {
|
|
30
27
|
children: PropTypes.node,
|
|
31
28
|
highlighted: PropTypes.bool
|
|
@@ -5,13 +5,12 @@ import { DisabledSelectionLabel } from './disabled-selection-label.js';
|
|
|
5
5
|
import { IconizedCheckbox } from './iconized-checkbox.js';
|
|
6
6
|
import { LabelContainer } from './label-container.js';
|
|
7
7
|
import { SingleSelectionLabel } from './single-selection-label.js';
|
|
8
|
-
const createNewSelected =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
} = _ref;
|
|
8
|
+
const createNewSelected = ({
|
|
9
|
+
selected,
|
|
10
|
+
path,
|
|
11
|
+
checked,
|
|
12
|
+
singleSelection
|
|
13
|
+
}) => {
|
|
15
14
|
const pathIndex = selected.indexOf(path);
|
|
16
15
|
if (checked && pathIndex !== -1) {
|
|
17
16
|
return selected;
|
|
@@ -35,29 +34,27 @@ const createNewSelected = _ref => {
|
|
|
35
34
|
const nextSlice = selected.slice(pathIndex + 1);
|
|
36
35
|
return [...prevSlice, ...nextSlice];
|
|
37
36
|
};
|
|
38
|
-
const Label =
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
checked
|
|
60
|
-
} = _ref3;
|
|
37
|
+
const Label = ({
|
|
38
|
+
checked,
|
|
39
|
+
children,
|
|
40
|
+
dataTest,
|
|
41
|
+
disableSelection,
|
|
42
|
+
fullPath,
|
|
43
|
+
hasChildren,
|
|
44
|
+
hasSelectedDescendants,
|
|
45
|
+
highlighted,
|
|
46
|
+
loading,
|
|
47
|
+
node,
|
|
48
|
+
onChange,
|
|
49
|
+
onToggleOpen,
|
|
50
|
+
open,
|
|
51
|
+
rootId,
|
|
52
|
+
selected,
|
|
53
|
+
singleSelection
|
|
54
|
+
}) => {
|
|
55
|
+
const onClick = ({
|
|
56
|
+
checked
|
|
57
|
+
}, event) => {
|
|
61
58
|
const newSelected = createNewSelected({
|
|
62
59
|
path: fullPath,
|
|
63
60
|
selected,
|
|
@@ -12,29 +12,26 @@ import React from 'react';
|
|
|
12
12
|
* @param {Function} [props.onChange]
|
|
13
13
|
* @returns {React.Component}
|
|
14
14
|
*/
|
|
15
|
-
export const SingleSelectionLabel =
|
|
16
|
-
|
|
15
|
+
export const SingleSelectionLabel = ({
|
|
16
|
+
checked,
|
|
17
|
+
children,
|
|
18
|
+
onChange,
|
|
19
|
+
loading
|
|
20
|
+
}) => /*#__PURE__*/React.createElement("span", {
|
|
21
|
+
onClick: event => {
|
|
22
|
+
const payload = {
|
|
23
|
+
checked: !checked
|
|
24
|
+
};
|
|
25
|
+
onChange(payload, event);
|
|
26
|
+
},
|
|
27
|
+
className: _JSXStyle.dynamic([["321503310", [colors.grey900, colors.teal700]]]) + " " + (cx({
|
|
17
28
|
checked,
|
|
18
|
-
children,
|
|
19
|
-
onChange,
|
|
20
29
|
loading
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
};
|
|
27
|
-
onChange(payload, event);
|
|
28
|
-
},
|
|
29
|
-
className: _JSXStyle.dynamic([["321503310", [colors.grey900, colors.teal700]]]) + " " + (cx({
|
|
30
|
-
checked,
|
|
31
|
-
loading
|
|
32
|
-
}) || "")
|
|
33
|
-
}, children, /*#__PURE__*/React.createElement(_JSXStyle, {
|
|
34
|
-
id: "321503310",
|
|
35
|
-
dynamic: [colors.grey900, colors.teal700]
|
|
36
|
-
}, [`span.__jsx-style-dynamic-selector{background:transparent;border-radius:3px;color:${colors.grey900};cursor:pointer;display:inline-block;font-size:14px;line-height:24px;padding:0 5px;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;white-space:nowrap;}`, `.checked.__jsx-style-dynamic-selector{background:${colors.teal700};color:white;}`, ".loading.__jsx-style-dynamic-selector{cursor:auto;}"]));
|
|
37
|
-
};
|
|
30
|
+
}) || "")
|
|
31
|
+
}, children, /*#__PURE__*/React.createElement(_JSXStyle, {
|
|
32
|
+
id: "321503310",
|
|
33
|
+
dynamic: [colors.grey900, colors.teal700]
|
|
34
|
+
}, [`span.__jsx-style-dynamic-selector{background:transparent;border-radius:3px;color:${colors.grey900};cursor:pointer;display:inline-block;font-size:14px;line-height:24px;padding:0 5px;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;white-space:nowrap;}`, `.checked.__jsx-style-dynamic-selector{background:${colors.teal700};color:white;}`, ".loading.__jsx-style-dynamic-selector{cursor:auto;}"]));
|
|
38
35
|
SingleSelectionLabel.propTypes = {
|
|
39
36
|
children: PropTypes.any.isRequired,
|
|
40
37
|
checked: PropTypes.bool,
|
|
@@ -5,12 +5,11 @@ import i18n from '../locales/index.js';
|
|
|
5
5
|
import { orgUnitPathPropType } from '../prop-types.js';
|
|
6
6
|
import { LoadingSpinner } from './loading-spinner.js';
|
|
7
7
|
import { useOrgChildren } from './use-org-children.js';
|
|
8
|
-
const getFilteredChildren =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} = _ref;
|
|
8
|
+
const getFilteredChildren = ({
|
|
9
|
+
orgChildren,
|
|
10
|
+
filter,
|
|
11
|
+
node
|
|
12
|
+
}) => {
|
|
14
13
|
if (!(filter !== null && filter !== void 0 && filter.length)) {
|
|
15
14
|
return orgChildren;
|
|
16
15
|
}
|
|
@@ -18,29 +17,28 @@ const getFilteredChildren = _ref => {
|
|
|
18
17
|
return isPathIncluded(filter, `${node.path}/${child.id}`);
|
|
19
18
|
});
|
|
20
19
|
};
|
|
21
|
-
export const OrganisationUnitNodeChildren =
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
} = _ref2;
|
|
20
|
+
export const OrganisationUnitNodeChildren = ({
|
|
21
|
+
node,
|
|
22
|
+
autoExpandLoadingError,
|
|
23
|
+
dataTest,
|
|
24
|
+
disableSelection,
|
|
25
|
+
displayProperty,
|
|
26
|
+
expanded,
|
|
27
|
+
filter,
|
|
28
|
+
highlighted,
|
|
29
|
+
isUserDataViewFallback,
|
|
30
|
+
onChange,
|
|
31
|
+
onChildrenLoaded,
|
|
32
|
+
onCollapse,
|
|
33
|
+
onExpand,
|
|
34
|
+
parentPath,
|
|
35
|
+
renderNodeLabel,
|
|
36
|
+
rootId,
|
|
37
|
+
selected,
|
|
38
|
+
singleSelection,
|
|
39
|
+
suppressAlphabeticalSorting,
|
|
40
|
+
OrganisationUnitNode
|
|
41
|
+
}) => {
|
|
44
42
|
const orgChildren = useOrgChildren({
|
|
45
43
|
node,
|
|
46
44
|
isUserDataViewFallback,
|
|
@@ -11,29 +11,28 @@ import { LoadingSpinner } from './loading-spinner.js';
|
|
|
11
11
|
import { OrganisationUnitNodeChildren } from './organisation-unit-node-children.js';
|
|
12
12
|
import { useOpenState } from './use-open-state.js';
|
|
13
13
|
import { useOrgData } from './use-org-data/index.js';
|
|
14
|
-
export const OrganisationUnitNode =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
} = _ref;
|
|
14
|
+
export const OrganisationUnitNode = ({
|
|
15
|
+
autoExpandLoadingError,
|
|
16
|
+
dataTest,
|
|
17
|
+
disableSelection,
|
|
18
|
+
displayName,
|
|
19
|
+
displayProperty,
|
|
20
|
+
expanded,
|
|
21
|
+
highlighted,
|
|
22
|
+
id,
|
|
23
|
+
isUserDataViewFallback,
|
|
24
|
+
path,
|
|
25
|
+
renderNodeLabel,
|
|
26
|
+
rootId,
|
|
27
|
+
selected,
|
|
28
|
+
singleSelection,
|
|
29
|
+
filter,
|
|
30
|
+
suppressAlphabeticalSorting,
|
|
31
|
+
onChange,
|
|
32
|
+
onChildrenLoaded,
|
|
33
|
+
onCollapse,
|
|
34
|
+
onExpand
|
|
35
|
+
}) => {
|
|
37
36
|
const orgData = useOrgData(id, {
|
|
38
37
|
isUserDataViewFallback,
|
|
39
38
|
displayName
|
|
@@ -10,15 +10,14 @@ import { useEffect, useState } from 'react';
|
|
|
10
10
|
* @param {Function} [args.onCollapse]
|
|
11
11
|
* @returns {Object}
|
|
12
12
|
*/
|
|
13
|
-
export const useOpenState =
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
} = _ref;
|
|
13
|
+
export const useOpenState = ({
|
|
14
|
+
path,
|
|
15
|
+
expanded,
|
|
16
|
+
onExpand,
|
|
17
|
+
onCollapse,
|
|
18
|
+
errorMessage,
|
|
19
|
+
autoExpandLoadingError
|
|
20
|
+
}) => {
|
|
22
21
|
const autoExpand = autoExpandLoadingError && !!errorMessage;
|
|
23
22
|
const [openedOnceDueToError, setOpenedOnce] = useState(!!errorMessage);
|
|
24
23
|
useEffect(() => {
|
|
@@ -4,20 +4,14 @@ import { sortNodeChildrenAlphabetically } from '../helpers/index.js';
|
|
|
4
4
|
const ORG_DATA_QUERY = {
|
|
5
5
|
orgUnit: {
|
|
6
6
|
resource: `organisationUnits`,
|
|
7
|
-
id:
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
displayProperty
|
|
16
|
-
} = _ref2;
|
|
17
|
-
return {
|
|
18
|
-
fields: displayProperty === 'displayName' ? 'children[id,path,displayName]' : `children[id,path,${displayProperty}~rename(displayName)]`
|
|
19
|
-
};
|
|
20
|
-
}
|
|
7
|
+
id: ({
|
|
8
|
+
id
|
|
9
|
+
}) => id,
|
|
10
|
+
params: ({
|
|
11
|
+
displayProperty
|
|
12
|
+
}) => ({
|
|
13
|
+
fields: displayProperty === 'displayName' ? 'children[id,path,displayName]' : `children[id,path,${displayProperty}~rename(displayName)]`
|
|
14
|
+
})
|
|
21
15
|
}
|
|
22
16
|
};
|
|
23
17
|
|
|
@@ -29,13 +23,12 @@ const ORG_DATA_QUERY = {
|
|
|
29
23
|
* @param {'displayName'|'displayShortName'} [options.displayProperty]
|
|
30
24
|
* @returns {Object}
|
|
31
25
|
*/
|
|
32
|
-
export const useOrgChildren =
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
} = _ref3;
|
|
26
|
+
export const useOrgChildren = ({
|
|
27
|
+
node,
|
|
28
|
+
suppressAlphabeticalSorting,
|
|
29
|
+
onComplete,
|
|
30
|
+
displayProperty = 'displayName'
|
|
31
|
+
}) => {
|
|
39
32
|
const onCompleteCalledRef = useRef(false);
|
|
40
33
|
const {
|
|
41
34
|
called,
|
|
@@ -4,10 +4,9 @@ import React from 'react';
|
|
|
4
4
|
import { useOrgChildren } from './use-org-children.js';
|
|
5
5
|
describe('OrganisationUnitTree - useOrgChildren', () => {
|
|
6
6
|
const dataProviderData = {
|
|
7
|
-
organisationUnits: jest.fn((type,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
} = _ref;
|
|
7
|
+
organisationUnits: jest.fn((type, {
|
|
8
|
+
id
|
|
9
|
+
}) => {
|
|
11
10
|
if (id === 'A0000000000') {
|
|
12
11
|
return {
|
|
13
12
|
children: [{
|
|
@@ -21,14 +20,11 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
|
|
|
21
20
|
return Promise.reject(`No org unit with id "${id}"`);
|
|
22
21
|
})
|
|
23
22
|
};
|
|
24
|
-
const wrapper =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
data: dataProviderData
|
|
30
|
-
}, children);
|
|
31
|
-
};
|
|
23
|
+
const wrapper = ({
|
|
24
|
+
children
|
|
25
|
+
}) => /*#__PURE__*/React.createElement(CustomDataProvider, {
|
|
26
|
+
data: dataProviderData
|
|
27
|
+
}, children);
|
|
32
28
|
const node = {
|
|
33
29
|
id: 'A0000000000',
|
|
34
30
|
path: '/A0000000000',
|
|
@@ -78,18 +74,15 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
|
|
|
78
74
|
});
|
|
79
75
|
});
|
|
80
76
|
it('should provide the error', async () => {
|
|
81
|
-
const errorWrapper =
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
organisationUnits: async () => {
|
|
88
|
-
throw new Error('Error message');
|
|
89
|
-
}
|
|
77
|
+
const errorWrapper = ({
|
|
78
|
+
children
|
|
79
|
+
}) => /*#__PURE__*/React.createElement(CustomDataProvider, {
|
|
80
|
+
data: {
|
|
81
|
+
organisationUnits: async () => {
|
|
82
|
+
throw new Error('Error message');
|
|
90
83
|
}
|
|
91
|
-
}
|
|
92
|
-
};
|
|
84
|
+
}
|
|
85
|
+
}, children);
|
|
93
86
|
const {
|
|
94
87
|
result
|
|
95
88
|
} = renderHook(() => useOrgChildren({
|
|
@@ -131,10 +124,9 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
|
|
|
131
124
|
});
|
|
132
125
|
it("should sort the node's children alphabetically by default", async () => {
|
|
133
126
|
const dataProviderDataWithUnsortedChildren = {
|
|
134
|
-
organisationUnits: jest.fn((type,
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
} = _ref4;
|
|
127
|
+
organisationUnits: jest.fn((type, {
|
|
128
|
+
id
|
|
129
|
+
}) => {
|
|
138
130
|
if (id === 'A0000000000') {
|
|
139
131
|
return {
|
|
140
132
|
children: [{
|
|
@@ -153,14 +145,11 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
|
|
|
153
145
|
return Promise.reject(`No org unit with id "${id}"`);
|
|
154
146
|
})
|
|
155
147
|
};
|
|
156
|
-
const wrapperWithUnsortedChildren =
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
data: dataProviderDataWithUnsortedChildren
|
|
162
|
-
}, children);
|
|
163
|
-
};
|
|
148
|
+
const wrapperWithUnsortedChildren = ({
|
|
149
|
+
children
|
|
150
|
+
}) => /*#__PURE__*/React.createElement(CustomDataProvider, {
|
|
151
|
+
data: dataProviderDataWithUnsortedChildren
|
|
152
|
+
}, children);
|
|
164
153
|
const {
|
|
165
154
|
result
|
|
166
155
|
} = renderHook(() => useOrgChildren({
|
|
@@ -192,10 +181,9 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
|
|
|
192
181
|
});
|
|
193
182
|
it(`should not sort the node's children alphabetically when "suppressAlphabeticalSorting" is true`, async () => {
|
|
194
183
|
const dataProviderDataWithUnsortedChildren = {
|
|
195
|
-
organisationUnits: jest.fn((type,
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
} = _ref6;
|
|
184
|
+
organisationUnits: jest.fn((type, {
|
|
185
|
+
id
|
|
186
|
+
}) => {
|
|
199
187
|
if (id === 'A0000000000') {
|
|
200
188
|
return {
|
|
201
189
|
children: [{
|
|
@@ -214,14 +202,11 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
|
|
|
214
202
|
return Promise.reject(`No org unit with id "${id}"`);
|
|
215
203
|
})
|
|
216
204
|
};
|
|
217
|
-
const wrapperWithUnsortedChildren =
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
data: dataProviderDataWithUnsortedChildren
|
|
223
|
-
}, children);
|
|
224
|
-
};
|
|
205
|
+
const wrapperWithUnsortedChildren = ({
|
|
206
|
+
children
|
|
207
|
+
}) => /*#__PURE__*/React.createElement(CustomDataProvider, {
|
|
208
|
+
data: dataProviderDataWithUnsortedChildren
|
|
209
|
+
}, children);
|
|
225
210
|
const options = {
|
|
226
211
|
node: {
|
|
227
212
|
...node,
|
|
@@ -255,10 +240,9 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
|
|
|
255
240
|
});
|
|
256
241
|
it(`should not sort the node's children alphabetically when "suppressAlphabeticalSorting" is true`, async () => {
|
|
257
242
|
const dataProviderDataWithUnsortedChildren = {
|
|
258
|
-
organisationUnits: jest.fn((type,
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
} = _ref8;
|
|
243
|
+
organisationUnits: jest.fn((type, {
|
|
244
|
+
id
|
|
245
|
+
}) => {
|
|
262
246
|
if (id === 'A0000000000') {
|
|
263
247
|
return {
|
|
264
248
|
children: [{
|
|
@@ -277,14 +261,11 @@ describe('OrganisationUnitTree - useOrgChildren', () => {
|
|
|
277
261
|
return Promise.reject(`No org unit with id "${id}"`);
|
|
278
262
|
})
|
|
279
263
|
};
|
|
280
|
-
const wrapperWithUnsortedChildren =
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
data: dataProviderDataWithUnsortedChildren
|
|
286
|
-
}, children);
|
|
287
|
-
};
|
|
264
|
+
const wrapperWithUnsortedChildren = ({
|
|
265
|
+
children
|
|
266
|
+
}) => /*#__PURE__*/React.createElement(CustomDataProvider, {
|
|
267
|
+
data: dataProviderDataWithUnsortedChildren
|
|
268
|
+
}, children);
|
|
288
269
|
const options = {
|
|
289
270
|
node: {
|
|
290
271
|
...node,
|
|
@@ -2,21 +2,15 @@ import { useDataQuery } from '@dhis2/app-runtime';
|
|
|
2
2
|
const ORG_DATA_QUERY = {
|
|
3
3
|
orgUnit: {
|
|
4
4
|
resource: `organisationUnits`,
|
|
5
|
-
id:
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
} = _ref2;
|
|
15
|
-
return {
|
|
16
|
-
isUserDataViewFallback,
|
|
17
|
-
fields: ['path', 'children::size']
|
|
18
|
-
};
|
|
19
|
-
}
|
|
5
|
+
id: ({
|
|
6
|
+
id
|
|
7
|
+
}) => id,
|
|
8
|
+
params: ({
|
|
9
|
+
isUserDataViewFallback
|
|
10
|
+
}) => ({
|
|
11
|
+
isUserDataViewFallback,
|
|
12
|
+
fields: ['path', 'children::size']
|
|
13
|
+
})
|
|
20
14
|
}
|
|
21
15
|
};
|
|
22
16
|
|
|
@@ -27,11 +21,10 @@ const ORG_DATA_QUERY = {
|
|
|
27
21
|
* @param {bool} options.isUserDataViewFallback
|
|
28
22
|
* @returns {Object}
|
|
29
23
|
*/
|
|
30
|
-
export const useOrgData = (id,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
} = _ref3;
|
|
24
|
+
export const useOrgData = (id, {
|
|
25
|
+
displayName,
|
|
26
|
+
isUserDataViewFallback
|
|
27
|
+
}) => {
|
|
35
28
|
if (!displayName) {
|
|
36
29
|
throw new Error('"displayName" is required');
|
|
37
30
|
}
|
|
@@ -5,10 +5,7 @@ import { useOrgData } from './use-org-data.js';
|
|
|
5
5
|
describe('OrganisationUnitTree - useOrgData', () => {
|
|
6
6
|
// @TODO: Figure out why this is necessary at all...
|
|
7
7
|
const origError = console.error;
|
|
8
|
-
jest.spyOn(console, 'error').mockImplementation(
|
|
9
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
10
|
-
args[_key] = arguments[_key];
|
|
11
|
-
}
|
|
8
|
+
jest.spyOn(console, 'error').mockImplementation((...args) => {
|
|
12
9
|
const [err] = args;
|
|
13
10
|
if (!err.toString().match(/^Warning: An update to/)) {
|
|
14
11
|
origError(...args);
|
|
@@ -18,10 +15,9 @@ describe('OrganisationUnitTree - useOrgData', () => {
|
|
|
18
15
|
console.error.mockRestore();
|
|
19
16
|
});
|
|
20
17
|
const dataProviderData = {
|
|
21
|
-
organisationUnits: jest.fn((type,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
} = _ref;
|
|
18
|
+
organisationUnits: jest.fn((type, {
|
|
19
|
+
id
|
|
20
|
+
}) => {
|
|
25
21
|
if (id === 'A0000000000') {
|
|
26
22
|
return {
|
|
27
23
|
id: 'A0000000000',
|
|
@@ -32,14 +28,11 @@ describe('OrganisationUnitTree - useOrgData', () => {
|
|
|
32
28
|
return Promise.reject(`No org unit with id "${id}"`);
|
|
33
29
|
})
|
|
34
30
|
};
|
|
35
|
-
const wrapper =
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
data: dataProviderData
|
|
41
|
-
}, children);
|
|
42
|
-
};
|
|
31
|
+
const wrapper = ({
|
|
32
|
+
children
|
|
33
|
+
}) => /*#__PURE__*/React.createElement(CustomDataProvider, {
|
|
34
|
+
data: dataProviderData
|
|
35
|
+
}, children);
|
|
43
36
|
it('should respond with `loading: true`, `error: null` and `data: { displayName, id }` initially', () => {
|
|
44
37
|
const {
|
|
45
38
|
result
|
|
@@ -78,18 +71,15 @@ describe('OrganisationUnitTree - useOrgData', () => {
|
|
|
78
71
|
});
|
|
79
72
|
});
|
|
80
73
|
it('should provide the error', async () => {
|
|
81
|
-
const errorWrapper =
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
organisationUnits: async () => {
|
|
88
|
-
throw new Error('Error message');
|
|
89
|
-
}
|
|
74
|
+
const errorWrapper = ({
|
|
75
|
+
children
|
|
76
|
+
}) => /*#__PURE__*/React.createElement(CustomDataProvider, {
|
|
77
|
+
data: {
|
|
78
|
+
organisationUnits: async () => {
|
|
79
|
+
throw new Error('Error message');
|
|
90
80
|
}
|
|
91
|
-
}
|
|
92
|
-
};
|
|
81
|
+
}
|
|
82
|
+
}, children);
|
|
93
83
|
const {
|
|
94
84
|
result
|
|
95
85
|
} = renderHook(() => useOrgData('A0000000000', {
|