@dhis2-ui/organisation-unit-tree 8.2.0 → 8.2.3

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.
Files changed (125) hide show
  1. package/build/cjs/__e2e__/children_as_child_nodes.stories.e2e.js +11 -8
  2. package/build/cjs/__e2e__/common.js +53 -43
  3. package/build/cjs/__e2e__/controlled_expanded.stories.e2e.js +10 -7
  4. package/build/cjs/__e2e__/displaying_loading_error.stories.e2e.js +5 -1
  5. package/build/cjs/__e2e__/expanded.stories.e2e.js +35 -26
  6. package/build/cjs/__e2e__/force_reload.stories.e2e.js +21 -14
  7. package/build/cjs/__e2e__/highlight.stories.e2e.js +10 -7
  8. package/build/cjs/__e2e__/loading_state.stories.e2e.js +14 -7
  9. package/build/cjs/__e2e__/multi_selection.stories.e2e.js +11 -8
  10. package/build/cjs/__e2e__/no_selection.stories.e2e.js +21 -15
  11. package/build/cjs/__e2e__/path_based_filtering.stories.e2e.js +23 -17
  12. package/build/cjs/__e2e__/single_selection.stories.e2e.js +17 -10
  13. package/build/cjs/__e2e__/sub_unit_as_root.stories.e2e.js +6 -5
  14. package/build/cjs/__e2e__/tree_api.stories.e2e.js +22 -15
  15. package/build/cjs/__stories__/custom-expanded-imperative-open.js +9 -6
  16. package/build/cjs/__stories__/custom-node-label.js +6 -4
  17. package/build/cjs/__stories__/development-stories.js +7 -6
  18. package/build/cjs/__stories__/loading-error-grandchild.js +5 -1
  19. package/build/cjs/__stories__/loading.js +5 -1
  20. package/build/cjs/__stories__/multiple-roots.js +12 -9
  21. package/build/cjs/__stories__/root-error.js +5 -1
  22. package/build/cjs/__stories__/root-loading.js +5 -1
  23. package/build/cjs/__stories__/shared.js +82 -45
  24. package/build/cjs/features/controlled_expanded/index.js +8 -5
  25. package/build/cjs/features/expanded/index.js +1 -7
  26. package/build/cjs/features/path_based_filtering/index.js +2 -2
  27. package/build/cjs/features/sub_unit_as_root/index.js +1 -7
  28. package/build/cjs/get-all-expanded-paths/get-all-expanded-paths.js +1 -1
  29. package/build/cjs/helpers/is-path-included.js +1 -1
  30. package/build/cjs/helpers/left-trim-to-root-id.js +1 -1
  31. package/build/cjs/organisation-unit-node/compute-child-nodes.js +1 -1
  32. package/build/cjs/organisation-unit-node/error-message.js +13 -10
  33. package/build/cjs/organisation-unit-node/has-descendant-selected-paths.js +1 -1
  34. package/build/cjs/organisation-unit-node/label/disabled-selection-label.js +12 -9
  35. package/build/cjs/organisation-unit-node/label/icon-empty.js +22 -19
  36. package/build/cjs/organisation-unit-node/label/icon-folder-closed.js +28 -25
  37. package/build/cjs/organisation-unit-node/label/icon-folder-open.js +37 -34
  38. package/build/cjs/organisation-unit-node/label/icon-single.js +31 -28
  39. package/build/cjs/organisation-unit-node/label/icon.js +8 -6
  40. package/build/cjs/organisation-unit-node/label/iconized-checkbox.js +14 -12
  41. package/build/cjs/organisation-unit-node/label/label-container.js +16 -13
  42. package/build/cjs/organisation-unit-node/label/label.js +31 -27
  43. package/build/cjs/organisation-unit-node/label/single-selection-label.js +21 -18
  44. package/build/cjs/organisation-unit-node/organisation-unit-node-children.js +32 -29
  45. package/build/cjs/organisation-unit-node/organisation-unit-node.js +26 -25
  46. package/build/cjs/organisation-unit-node/use-open-state.js +9 -8
  47. package/build/cjs/organisation-unit-node/use-org-children.js +13 -9
  48. package/build/cjs/organisation-unit-node/use-org-children.test.js +69 -46
  49. package/build/cjs/organisation-unit-node/use-org-data/use-org-data.js +22 -14
  50. package/build/cjs/organisation-unit-node/use-org-data/use-org-data.test.js +30 -18
  51. package/build/cjs/organisation-unit-tree/default-render-node-label/default-render-node-label.js +6 -3
  52. package/build/cjs/organisation-unit-tree/filter-root-ids.js +1 -1
  53. package/build/cjs/organisation-unit-tree/organisation-unit-tree.js +23 -22
  54. package/build/cjs/organisation-unit-tree/root-error.js +12 -9
  55. package/build/cjs/organisation-unit-tree/root-loading.js +13 -10
  56. package/build/cjs/organisation-unit-tree/use-expanded/create-expand-handlers.js +19 -14
  57. package/build/cjs/organisation-unit-tree/use-expanded/use-expanded.js +9 -8
  58. package/build/cjs/organisation-unit-tree/use-root-org-data/patch-missing-display-name.js +2 -1
  59. package/build/cjs/organisation-unit-tree/use-root-org-data/use-root-org-data.js +14 -10
  60. package/build/cjs/organisation-unit-tree/use-root-org-data/use-root-org-unit.test.js +37 -20
  61. package/build/cjs/organisation-unit-tree.stories.js +32 -57
  62. package/build/cjs/prop-types.js +5 -5
  63. package/build/es/__e2e__/children_as_child_nodes.stories.e2e.js +11 -8
  64. package/build/es/__e2e__/common.js +52 -42
  65. package/build/es/__e2e__/controlled_expanded.stories.e2e.js +9 -6
  66. package/build/es/__e2e__/displaying_loading_error.stories.e2e.js +5 -1
  67. package/build/es/__e2e__/expanded.stories.e2e.js +34 -25
  68. package/build/es/__e2e__/force_reload.stories.e2e.js +21 -14
  69. package/build/es/__e2e__/highlight.stories.e2e.js +10 -7
  70. package/build/es/__e2e__/loading_state.stories.e2e.js +14 -7
  71. package/build/es/__e2e__/multi_selection.stories.e2e.js +11 -8
  72. package/build/es/__e2e__/no_selection.stories.e2e.js +21 -15
  73. package/build/es/__e2e__/path_based_filtering.stories.e2e.js +23 -17
  74. package/build/es/__e2e__/single_selection.stories.e2e.js +17 -10
  75. package/build/es/__e2e__/sub_unit_as_root.stories.e2e.js +5 -4
  76. package/build/es/__e2e__/tree_api.stories.e2e.js +22 -15
  77. package/build/es/__stories__/custom-expanded-imperative-open.js +9 -6
  78. package/build/es/__stories__/custom-node-label.js +6 -4
  79. package/build/es/__stories__/development-stories.js +6 -5
  80. package/build/es/__stories__/loading-error-grandchild.js +5 -1
  81. package/build/es/__stories__/loading.js +5 -1
  82. package/build/es/__stories__/multiple-roots.js +12 -9
  83. package/build/es/__stories__/root-error.js +5 -1
  84. package/build/es/__stories__/root-loading.js +5 -1
  85. package/build/es/__stories__/shared.js +82 -45
  86. package/build/es/features/controlled_expanded/index.js +8 -5
  87. package/build/es/features/expanded/index.js +1 -7
  88. package/build/es/features/path_based_filtering/index.js +2 -2
  89. package/build/es/features/sub_unit_as_root/index.js +1 -7
  90. package/build/es/get-all-expanded-paths/get-all-expanded-paths.js +1 -1
  91. package/build/es/helpers/is-path-included.js +1 -1
  92. package/build/es/helpers/left-trim-to-root-id.js +1 -1
  93. package/build/es/organisation-unit-node/compute-child-nodes.js +1 -1
  94. package/build/es/organisation-unit-node/error-message.js +13 -10
  95. package/build/es/organisation-unit-node/has-descendant-selected-paths.js +1 -1
  96. package/build/es/organisation-unit-node/label/disabled-selection-label.js +12 -9
  97. package/build/es/organisation-unit-node/label/icon-empty.js +22 -19
  98. package/build/es/organisation-unit-node/label/icon-folder-closed.js +28 -25
  99. package/build/es/organisation-unit-node/label/icon-folder-open.js +37 -34
  100. package/build/es/organisation-unit-node/label/icon-single.js +31 -28
  101. package/build/es/organisation-unit-node/label/icon.js +8 -6
  102. package/build/es/organisation-unit-node/label/iconized-checkbox.js +13 -12
  103. package/build/es/organisation-unit-node/label/label-container.js +16 -13
  104. package/build/es/organisation-unit-node/label/label.js +31 -27
  105. package/build/es/organisation-unit-node/label/single-selection-label.js +21 -18
  106. package/build/es/organisation-unit-node/organisation-unit-node-children.js +32 -29
  107. package/build/es/organisation-unit-node/organisation-unit-node.js +26 -25
  108. package/build/es/organisation-unit-node/use-open-state.js +9 -8
  109. package/build/es/organisation-unit-node/use-org-children.js +13 -9
  110. package/build/es/organisation-unit-node/use-org-children.test.js +69 -46
  111. package/build/es/organisation-unit-node/use-org-data/use-org-data.js +22 -14
  112. package/build/es/organisation-unit-node/use-org-data/use-org-data.test.js +30 -18
  113. package/build/es/organisation-unit-tree/default-render-node-label/default-render-node-label.js +6 -3
  114. package/build/es/organisation-unit-tree/filter-root-ids.js +1 -1
  115. package/build/es/organisation-unit-tree/organisation-unit-tree.js +23 -22
  116. package/build/es/organisation-unit-tree/root-error.js +12 -9
  117. package/build/es/organisation-unit-tree/root-loading.js +13 -10
  118. package/build/es/organisation-unit-tree/use-expanded/create-expand-handlers.js +19 -14
  119. package/build/es/organisation-unit-tree/use-expanded/use-expanded.js +9 -8
  120. package/build/es/organisation-unit-tree/use-root-org-data/patch-missing-display-name.js +2 -1
  121. package/build/es/organisation-unit-tree/use-root-org-data/use-root-org-data.js +14 -10
  122. package/build/es/organisation-unit-tree/use-root-org-data/use-root-org-unit.test.js +37 -20
  123. package/build/es/organisation-unit-tree.stories.js +2 -27
  124. package/build/es/prop-types.js +4 -4
  125. package/package.json +5 -5
@@ -11,7 +11,8 @@
11
11
  */
12
12
  export const patchMissingDisplayName = nodes => {
13
13
  const nodeEntries = Object.entries(nodes);
14
- const nodesWithDisplayName = nodeEntries.map(([id, node]) => {
14
+ const nodesWithDisplayName = nodeEntries.map(_ref => {
15
+ let [id, node] = _ref;
15
16
  const displayName = node.displayName || '';
16
17
  return [id, { ...node,
17
18
  displayName
@@ -4,13 +4,16 @@ import { patchMissingDisplayName } from './patch-missing-display-name.js';
4
4
  export const createRootQuery = ids => ids.reduce((query, id) => ({ ...query,
5
5
  [id]: {
6
6
  id,
7
- resource: `organisationUnits`,
8
- params: ({
9
- isUserDataViewFallback
10
- }) => ({
11
- isUserDataViewFallback,
12
- fields: ['displayName', 'path', 'id']
13
- })
7
+ resource: "organisationUnits",
8
+ params: _ref => {
9
+ let {
10
+ isUserDataViewFallback
11
+ } = _ref;
12
+ return {
13
+ isUserDataViewFallback,
14
+ fields: ['displayName', 'path', 'id']
15
+ };
16
+ }
14
17
  }
15
18
  }), {});
16
19
  /**
@@ -21,9 +24,10 @@ export const createRootQuery = ids => ids.reduce((query, id) => ({ ...query,
21
24
  * @returns {Object}
22
25
  */
23
26
 
24
- export const useRootOrgData = (ids, {
25
- isUserDataViewFallback
26
- } = {}) => {
27
+ export const useRootOrgData = function (ids) {
28
+ let {
29
+ isUserDataViewFallback
30
+ } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
27
31
  const query = createRootQuery(ids);
28
32
  const variables = {
29
33
  isUserDataViewFallback
@@ -5,7 +5,11 @@ import { useRootOrgData } from './use-root-org-data.js';
5
5
  describe('OrganisationUnitTree - useRootOrgData', () => {
6
6
  // @TODO: Figure out why this is necessary at all...
7
7
  const origError = console.error;
8
- jest.spyOn(console, 'error').mockImplementation((...args) => {
8
+ jest.spyOn(console, 'error').mockImplementation(function () {
9
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
10
+ args[_key] = arguments[_key];
11
+ }
12
+
9
13
  const [err] = args;
10
14
 
11
15
  if (!err.toString().match(/^Warning: An update to/)) {
@@ -15,7 +19,11 @@ describe('OrganisationUnitTree - useRootOrgData', () => {
15
19
 
16
20
  const origWarn = console.warn;
17
21
  const dynamicQueryWarningMsg = "The query should be static, don't create it within the render loop!";
18
- jest.spyOn(console, 'warn').mockImplementation((...args) => {
22
+ jest.spyOn(console, 'warn').mockImplementation(function () {
23
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
24
+ args[_key2] = arguments[_key2];
25
+ }
26
+
19
27
  const [err] = args;
20
28
 
21
29
  if (!err.toString().match(dynamicQueryWarningMsg)) {
@@ -36,11 +44,14 @@ describe('OrganisationUnitTree - useRootOrgData', () => {
36
44
  })
37
45
  };
38
46
 
39
- const wrapper = ({
40
- children
41
- }) => /*#__PURE__*/React.createElement(CustomDataProvider, {
42
- data: dataProviderData
43
- }, children);
47
+ const wrapper = _ref => {
48
+ let {
49
+ children
50
+ } = _ref;
51
+ return /*#__PURE__*/React.createElement(CustomDataProvider, {
52
+ data: dataProviderData
53
+ }, children);
54
+ };
44
55
 
45
56
  it('should respond with `loading: false`, `error: null` and `data: null` initially', () => {
46
57
  const {
@@ -76,15 +87,18 @@ describe('OrganisationUnitTree - useRootOrgData', () => {
76
87
  }));
77
88
  });
78
89
  it('should provide the error', async () => {
79
- const errorWrapper = ({
80
- children
81
- }) => /*#__PURE__*/React.createElement(CustomDataProvider, {
82
- data: {
83
- organisationUnits: async () => {
84
- throw new Error('Error message');
90
+ const errorWrapper = _ref2 => {
91
+ let {
92
+ children
93
+ } = _ref2;
94
+ return /*#__PURE__*/React.createElement(CustomDataProvider, {
95
+ data: {
96
+ organisationUnits: async () => {
97
+ throw new Error('Error message');
98
+ }
85
99
  }
86
- }
87
- }, children);
100
+ }, children);
101
+ };
88
102
 
89
103
  const {
90
104
  result,
@@ -140,11 +154,14 @@ describe('OrganisationUnitTree - useRootOrgData', () => {
140
154
  })
141
155
  };
142
156
 
143
- const wrapperWithoutDisplayName = ({
144
- children
145
- }) => /*#__PURE__*/React.createElement(CustomDataProvider, {
146
- data: dataProviderDataWithoutDisplayName
147
- }, children);
157
+ const wrapperWithoutDisplayName = _ref3 => {
158
+ let {
159
+ children
160
+ } = _ref3;
161
+ return /*#__PURE__*/React.createElement(CustomDataProvider, {
162
+ data: dataProviderDataWithoutDisplayName
163
+ }, children);
164
+ };
148
165
 
149
166
  const {
150
167
  result,
@@ -3,34 +3,9 @@ import React from 'react';
3
3
  import { customData } from './__stories__/shared.js';
4
4
  import { OrganisationUnitTree } from './index.js';
5
5
  const subtitle = 'Display, manipulate and select organization units displayed in a hierarchical tree';
6
- const description = `
7
- This is a complex, controlled component. It needs access to an App Runtime data provider to fetch org unit data.
8
-
9
- Several props require arrays of org. unit paths (referred to as \`orgUnitPathPropType[]\` in the table below). Take a look at the \`initiallyExpanded\` and \`filter\` props in the example to see an example of the paths format.
10
-
11
- Example:
12
-
13
- \`\`\`js
14
- import { OrganisationUnitTree } from '@dhis2/ui'
15
-
16
- const orgUnitTree = (
17
- <OrganisationUnitTree
18
- name="Root org unit"
19
- roots="A0000000000"
20
- onChange={onChange}
21
- onExpand={onExpand}
22
- onCollapse={onCollapse}
23
- onChildrenLoaded={onChildrenLoaded}
24
- // Notice the format of the org unit paths
25
- initiallyExpanded={['/A0000000000/A0000000001']}
26
- filter={['/A0000000000/A0000000001/A0000000003']}
27
- />
28
- )
29
- \`\`\`
30
-
31
- `;
6
+ const description = "\nThis is a complex, controlled component. It needs access to an App Runtime data provider to fetch org unit data.\n\nSeveral props require arrays of org. unit paths (referred to as `orgUnitPathPropType[]` in the table below). Take a look at the `initiallyExpanded` and `filter` props in the example to see an example of the paths format.\n\nExample:\n\n```js\nimport { OrganisationUnitTree } from '@dhis2/ui'\n\nconst orgUnitTree = (\n <OrganisationUnitTree\n name=\"Root org unit\"\n roots=\"A0000000000\"\n onChange={onChange}\n onExpand={onExpand}\n onCollapse={onCollapse}\n onChildrenLoaded={onChildrenLoaded}\n // Notice the format of the org unit paths\n initiallyExpanded={['/A0000000000/A0000000001']}\n filter={['/A0000000000/A0000000001/A0000000003']}\n />\n)\n```\n\n";
32
7
  export default {
33
- title: 'Forms/Organisation Unit Tree',
8
+ title: 'Organisation Unit Tree',
34
9
  component: OrganisationUnitTree,
35
10
  decorators: [fn => /*#__PURE__*/React.createElement(CustomDataProvider, {
36
11
  data: customData
@@ -1,14 +1,14 @@
1
1
  /* eslint-disable max-params */
2
2
  const UNIT_ID_PATTERN = '[a-zA-Z][a-zA-Z0-9]{10}';
3
- const orgUnitIdRegExp = new RegExp(`^${UNIT_ID_PATTERN}$`);
4
- const orgUnitPathRegExp = new RegExp(`(/${UNIT_ID_PATTERN})+`);
3
+ const orgUnitIdRegExp = new RegExp("^".concat(UNIT_ID_PATTERN, "$"));
4
+ const orgUnitPathRegExp = new RegExp("(/".concat(UNIT_ID_PATTERN, ")+"));
5
5
  export const orgUnitPathPropType = (propValue, key, compName, location, propFullName) => {
6
6
  if (!orgUnitPathRegExp.test(propValue[key])) {
7
- return new Error(`Invalid org unit path \`${propValue[key]}\` supplied to \`${compName}.${propFullName}\``);
7
+ return new Error("Invalid org unit path `".concat(propValue[key], "` supplied to `").concat(compName, ".").concat(propFullName, "`"));
8
8
  }
9
9
  };
10
10
  export const orgUnitIdPropType = (propValue, key, compName, location, propFullName) => {
11
11
  if (!orgUnitIdRegExp.test(propValue[key])) {
12
- return new Error(`Invalid org unit id \`${propValue[key]}\` supplied to \`${compName}.${propFullName}\``);
12
+ return new Error("Invalid org unit id `".concat(propValue[key], "` supplied to `").concat(compName, ".").concat(propFullName, "`"));
13
13
  }
14
14
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhis2-ui/organisation-unit-tree",
3
- "version": "8.2.0",
3
+ "version": "8.2.3",
4
4
  "description": "UI OrganisationUnitTree",
5
5
  "repository": {
6
6
  "type": "git",
@@ -34,10 +34,10 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "@dhis2/prop-types": "^3.0.0-beta.1",
37
- "@dhis2-ui/checkbox": "8.2.0",
38
- "@dhis2-ui/loader": "8.2.0",
39
- "@dhis2-ui/node": "8.2.0",
40
- "@dhis2/ui-constants": "8.2.0",
37
+ "@dhis2-ui/checkbox": "8.2.3",
38
+ "@dhis2-ui/loader": "8.2.3",
39
+ "@dhis2-ui/node": "8.2.3",
40
+ "@dhis2/ui-constants": "8.2.3",
41
41
  "classnames": "^2.3.1",
42
42
  "prop-types": "^15.7.2"
43
43
  },