@dhis2-ui/organisation-unit-tree 7.2.0 → 7.2.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.
@@ -12,7 +12,10 @@ exports.isPathIncluded = void 0;
12
12
  */
13
13
  const isPathIncluded = (includedPaths, path) => {
14
14
  const isIncluded = includedPaths.some(includedPath => {
15
- if (path === includedPath) return true;
15
+ if (path === includedPath) {
16
+ return true;
17
+ }
18
+
16
19
  return includedPath.startsWith(`${path}/`);
17
20
  });
18
21
  return isIncluded;
@@ -6,10 +6,16 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.sortNodeChildrenAlphabetically = void 0;
7
7
 
8
8
  const sortNodeChildrenAlphabetically = node => {
9
- if (!node.children) return node;
9
+ if (!node.children) {
10
+ return node;
11
+ }
12
+
10
13
  const sortedChildren = [...node.children];
11
14
  sortedChildren.sort((left, right) => {
12
- if (left.displayName === right.displayName) return 0;
15
+ if (left.displayName === right.displayName) {
16
+ return 0;
17
+ }
18
+
13
19
  return left.displayName.localeCompare(right.displayName);
14
20
  });
15
21
  return { ...node,
@@ -28,12 +28,31 @@ const createNewSelected = ({
28
28
  singleSelection
29
29
  }) => {
30
30
  const pathIndex = selected.indexOf(path);
31
- if (checked && pathIndex !== -1) return selected;
32
- if (singleSelection && checked) return [path];
33
- if (checked) return [...selected, path];
34
- if (pathIndex === -1) return selected;
35
- if (singleSelection) return [];
36
- if (selected.indexOf(path) === 0) return selected.slice(1);
31
+
32
+ if (checked && pathIndex !== -1) {
33
+ return selected;
34
+ }
35
+
36
+ if (singleSelection && checked) {
37
+ return [path];
38
+ }
39
+
40
+ if (checked) {
41
+ return [...selected, path];
42
+ }
43
+
44
+ if (pathIndex === -1) {
45
+ return selected;
46
+ }
47
+
48
+ if (singleSelection) {
49
+ return [];
50
+ }
51
+
52
+ if (selected.indexOf(path) === 0) {
53
+ return selected.slice(1);
54
+ }
55
+
37
56
  const prevSlice = selected.slice(0, pathIndex);
38
57
  const nextSlice = selected.slice(pathIndex + 1);
39
58
  return [...prevSlice, ...nextSlice];
@@ -8,7 +8,10 @@ exports.filterRootIds = void 0;
8
8
  var _index = require("../helpers/index.js");
9
9
 
10
10
  const filterRootIds = (filter, rootIds) => {
11
- if (!(filter !== null && filter !== void 0 && filter.length)) return rootIds;
11
+ if (!(filter !== null && filter !== void 0 && filter.length)) {
12
+ return rootIds;
13
+ }
14
+
12
15
  return rootIds.filter(rootId => (0, _index.isPathIncluded)(filter, `/${rootId}`));
13
16
  };
14
17
 
@@ -5,7 +5,10 @@
5
5
  */
6
6
  export const isPathIncluded = (includedPaths, path) => {
7
7
  const isIncluded = includedPaths.some(includedPath => {
8
- if (path === includedPath) return true;
8
+ if (path === includedPath) {
9
+ return true;
10
+ }
11
+
9
12
  return includedPath.startsWith(`${path}/`);
10
13
  });
11
14
  return isIncluded;
@@ -1,8 +1,14 @@
1
1
  export const sortNodeChildrenAlphabetically = node => {
2
- if (!node.children) return node;
2
+ if (!node.children) {
3
+ return node;
4
+ }
5
+
3
6
  const sortedChildren = [...node.children];
4
7
  sortedChildren.sort((left, right) => {
5
- if (left.displayName === right.displayName) return 0;
8
+ if (left.displayName === right.displayName) {
9
+ return 0;
10
+ }
11
+
6
12
  return left.displayName.localeCompare(right.displayName);
7
13
  });
8
14
  return { ...node,
@@ -13,12 +13,31 @@ const createNewSelected = ({
13
13
  singleSelection
14
14
  }) => {
15
15
  const pathIndex = selected.indexOf(path);
16
- if (checked && pathIndex !== -1) return selected;
17
- if (singleSelection && checked) return [path];
18
- if (checked) return [...selected, path];
19
- if (pathIndex === -1) return selected;
20
- if (singleSelection) return [];
21
- if (selected.indexOf(path) === 0) return selected.slice(1);
16
+
17
+ if (checked && pathIndex !== -1) {
18
+ return selected;
19
+ }
20
+
21
+ if (singleSelection && checked) {
22
+ return [path];
23
+ }
24
+
25
+ if (checked) {
26
+ return [...selected, path];
27
+ }
28
+
29
+ if (pathIndex === -1) {
30
+ return selected;
31
+ }
32
+
33
+ if (singleSelection) {
34
+ return [];
35
+ }
36
+
37
+ if (selected.indexOf(path) === 0) {
38
+ return selected.slice(1);
39
+ }
40
+
22
41
  const prevSlice = selected.slice(0, pathIndex);
23
42
  const nextSlice = selected.slice(pathIndex + 1);
24
43
  return [...prevSlice, ...nextSlice];
@@ -1,5 +1,8 @@
1
1
  import { isPathIncluded } from '../helpers/index.js';
2
2
  export const filterRootIds = (filter, rootIds) => {
3
- if (!(filter !== null && filter !== void 0 && filter.length)) return rootIds;
3
+ if (!(filter !== null && filter !== void 0 && filter.length)) {
4
+ return rootIds;
5
+ }
6
+
4
7
  return rootIds.filter(rootId => isPathIncluded(filter, `/${rootId}`));
5
8
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhis2-ui/organisation-unit-tree",
3
- "version": "7.2.0",
3
+ "version": "7.2.4",
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": "7.2.0",
38
- "@dhis2-ui/loader": "7.2.0",
39
- "@dhis2-ui/node": "7.2.0",
40
- "@dhis2/ui-constants": "7.2.0",
37
+ "@dhis2-ui/checkbox": "7.2.4",
38
+ "@dhis2-ui/loader": "7.2.4",
39
+ "@dhis2-ui/node": "7.2.4",
40
+ "@dhis2/ui-constants": "7.2.4",
41
41
  "classnames": "^2.3.1",
42
42
  "prop-types": "^15.7.2"
43
43
  },