@dhis2-ui/organisation-unit-tree 6.24.0 → 7.0.1
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/organisation-unit-node/use-org-data/use-org-data.js +27 -26
- package/build/cjs/organisation-unit-tree/use-root-org-data/use-root-org-data.js +11 -26
- package/build/es/organisation-unit-node/use-org-data/use-org-data.js +28 -27
- package/build/es/organisation-unit-tree/use-root-org-data/use-root-org-data.js +12 -27
- package/package.json +9 -10
|
@@ -51,34 +51,35 @@ const useOrgData = (id, {
|
|
|
51
51
|
id,
|
|
52
52
|
isUserDataViewFallback
|
|
53
53
|
};
|
|
54
|
-
const
|
|
55
|
-
loading
|
|
56
|
-
error
|
|
57
|
-
data
|
|
54
|
+
const {
|
|
55
|
+
loading,
|
|
56
|
+
error,
|
|
57
|
+
data
|
|
58
|
+
} = (0, _appRuntime.useDataQuery)(ORG_DATA_QUERY, {
|
|
59
|
+
variables
|
|
58
60
|
});
|
|
59
|
-
(0,
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
orgUnit: node
|
|
63
|
-
}) => {
|
|
64
|
-
const sorted = !suppressAlphabeticalSorting ? (0, _index.sortNodeChildrenAlphabetically)(node) : node;
|
|
65
|
-
const nextData = { ...defaultData,
|
|
66
|
-
...sorted
|
|
67
|
-
};
|
|
68
|
-
setState({ ...state,
|
|
69
|
-
data: nextData,
|
|
70
|
-
loading: false
|
|
71
|
-
});
|
|
72
|
-
onComplete && onComplete(nextData);
|
|
73
|
-
},
|
|
74
|
-
onError: queryError => {
|
|
75
|
-
setState({ ...state,
|
|
76
|
-
error: queryError,
|
|
77
|
-
loading: false
|
|
78
|
-
});
|
|
61
|
+
const transformedData = (0, _react.useMemo)(() => {
|
|
62
|
+
if (!data) {
|
|
63
|
+
return defaultData;
|
|
79
64
|
}
|
|
80
|
-
|
|
81
|
-
|
|
65
|
+
|
|
66
|
+
const {
|
|
67
|
+
orgUnit: node
|
|
68
|
+
} = data;
|
|
69
|
+
const transformed = suppressAlphabeticalSorting ? node : (0, _index.sortNodeChildrenAlphabetically)(node);
|
|
70
|
+
const merged = { ...defaultData,
|
|
71
|
+
...transformed
|
|
72
|
+
};
|
|
73
|
+
return merged;
|
|
74
|
+
}, [data, suppressAlphabeticalSorting, id, displayName]);
|
|
75
|
+
(0, _react.useEffect)(() => {
|
|
76
|
+
onComplete && onComplete(transformedData);
|
|
77
|
+
}, [onComplete, transformedData]);
|
|
78
|
+
return {
|
|
79
|
+
loading,
|
|
80
|
+
error: error || null,
|
|
81
|
+
data: transformedData
|
|
82
|
+
};
|
|
82
83
|
};
|
|
83
84
|
|
|
84
85
|
exports.useOrgData = useOrgData;
|
|
@@ -42,36 +42,21 @@ const useRootOrgData = (ids, {
|
|
|
42
42
|
const variables = {
|
|
43
43
|
isUserDataViewFallback
|
|
44
44
|
};
|
|
45
|
-
const [state, setState] = (0, _react.useState)({
|
|
46
|
-
loading: true,
|
|
47
|
-
error: null,
|
|
48
|
-
data: null
|
|
49
|
-
});
|
|
50
45
|
const {
|
|
51
|
-
|
|
46
|
+
loading,
|
|
47
|
+
error,
|
|
48
|
+
data,
|
|
49
|
+
refetch
|
|
52
50
|
} = (0, _appRuntime.useDataQuery)(query, {
|
|
53
|
-
variables
|
|
54
|
-
onComplete: queryData => setState({ ...state,
|
|
55
|
-
data: queryData ? (0, _patchMissingDisplayName.patchMissingDisplayName)(queryData) : {},
|
|
56
|
-
loading: false
|
|
57
|
-
}),
|
|
58
|
-
onError: queryError => setState({ ...state,
|
|
59
|
-
error: queryError,
|
|
60
|
-
loading: false
|
|
61
|
-
})
|
|
51
|
+
variables
|
|
62
52
|
});
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
error: null,
|
|
67
|
-
loading: true
|
|
68
|
-
});
|
|
69
|
-
queryRefetch();
|
|
70
|
-
}, [queryRefetch, setState]);
|
|
53
|
+
const patchedData = (0, _react.useMemo)(() => {
|
|
54
|
+
return data ? (0, _patchMissingDisplayName.patchMissingDisplayName)(data) : data;
|
|
55
|
+
}, [data]);
|
|
71
56
|
return {
|
|
72
|
-
loading
|
|
73
|
-
error:
|
|
74
|
-
data:
|
|
57
|
+
loading,
|
|
58
|
+
error: error || null,
|
|
59
|
+
data: patchedData || null,
|
|
75
60
|
refetch
|
|
76
61
|
};
|
|
77
62
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useDataQuery } from '@dhis2/app-runtime';
|
|
2
|
-
import {
|
|
2
|
+
import { useMemo, useEffect } from 'react';
|
|
3
3
|
import { sortNodeChildrenAlphabetically } from '../../helpers/index.js';
|
|
4
4
|
const ORG_DATA_QUERY = {
|
|
5
5
|
orgUnit: {
|
|
@@ -41,32 +41,33 @@ export const useOrgData = (id, {
|
|
|
41
41
|
id,
|
|
42
42
|
isUserDataViewFallback
|
|
43
43
|
};
|
|
44
|
-
const
|
|
45
|
-
loading
|
|
46
|
-
error
|
|
47
|
-
data
|
|
44
|
+
const {
|
|
45
|
+
loading,
|
|
46
|
+
error,
|
|
47
|
+
data
|
|
48
|
+
} = useDataQuery(ORG_DATA_QUERY, {
|
|
49
|
+
variables
|
|
48
50
|
});
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
orgUnit: node
|
|
53
|
-
}) => {
|
|
54
|
-
const sorted = !suppressAlphabeticalSorting ? sortNodeChildrenAlphabetically(node) : node;
|
|
55
|
-
const nextData = { ...defaultData,
|
|
56
|
-
...sorted
|
|
57
|
-
};
|
|
58
|
-
setState({ ...state,
|
|
59
|
-
data: nextData,
|
|
60
|
-
loading: false
|
|
61
|
-
});
|
|
62
|
-
onComplete && onComplete(nextData);
|
|
63
|
-
},
|
|
64
|
-
onError: queryError => {
|
|
65
|
-
setState({ ...state,
|
|
66
|
-
error: queryError,
|
|
67
|
-
loading: false
|
|
68
|
-
});
|
|
51
|
+
const transformedData = useMemo(() => {
|
|
52
|
+
if (!data) {
|
|
53
|
+
return defaultData;
|
|
69
54
|
}
|
|
70
|
-
|
|
71
|
-
|
|
55
|
+
|
|
56
|
+
const {
|
|
57
|
+
orgUnit: node
|
|
58
|
+
} = data;
|
|
59
|
+
const transformed = suppressAlphabeticalSorting ? node : sortNodeChildrenAlphabetically(node);
|
|
60
|
+
const merged = { ...defaultData,
|
|
61
|
+
...transformed
|
|
62
|
+
};
|
|
63
|
+
return merged;
|
|
64
|
+
}, [data, suppressAlphabeticalSorting, id, displayName]);
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
onComplete && onComplete(transformedData);
|
|
67
|
+
}, [onComplete, transformedData]);
|
|
68
|
+
return {
|
|
69
|
+
loading,
|
|
70
|
+
error: error || null,
|
|
71
|
+
data: transformedData
|
|
72
|
+
};
|
|
72
73
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useDataQuery } from '@dhis2/app-runtime';
|
|
2
|
-
import {
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
3
|
import { patchMissingDisplayName } from './patch-missing-display-name.js';
|
|
4
4
|
export const createRootQuery = ids => ids.reduce((query, id) => ({ ...query,
|
|
5
5
|
[id]: {
|
|
@@ -29,36 +29,21 @@ export const useRootOrgData = (ids, {
|
|
|
29
29
|
const variables = {
|
|
30
30
|
isUserDataViewFallback
|
|
31
31
|
};
|
|
32
|
-
const [state, setState] = useState({
|
|
33
|
-
loading: true,
|
|
34
|
-
error: null,
|
|
35
|
-
data: null
|
|
36
|
-
});
|
|
37
32
|
const {
|
|
38
|
-
|
|
33
|
+
loading,
|
|
34
|
+
error,
|
|
35
|
+
data,
|
|
36
|
+
refetch
|
|
39
37
|
} = useDataQuery(query, {
|
|
40
|
-
variables
|
|
41
|
-
onComplete: queryData => setState({ ...state,
|
|
42
|
-
data: queryData ? patchMissingDisplayName(queryData) : {},
|
|
43
|
-
loading: false
|
|
44
|
-
}),
|
|
45
|
-
onError: queryError => setState({ ...state,
|
|
46
|
-
error: queryError,
|
|
47
|
-
loading: false
|
|
48
|
-
})
|
|
38
|
+
variables
|
|
49
39
|
});
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
error: null,
|
|
54
|
-
loading: true
|
|
55
|
-
});
|
|
56
|
-
queryRefetch();
|
|
57
|
-
}, [queryRefetch, setState]);
|
|
40
|
+
const patchedData = useMemo(() => {
|
|
41
|
+
return data ? patchMissingDisplayName(data) : data;
|
|
42
|
+
}, [data]);
|
|
58
43
|
return {
|
|
59
|
-
loading
|
|
60
|
-
error:
|
|
61
|
-
data:
|
|
44
|
+
loading,
|
|
45
|
+
error: error || null,
|
|
46
|
+
data: patchedData || null,
|
|
62
47
|
refetch
|
|
63
48
|
};
|
|
64
49
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dhis2-ui/organisation-unit-tree",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.1",
|
|
4
4
|
"description": "UI OrganisationUnitTree",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -26,18 +26,18 @@
|
|
|
26
26
|
"test": "d2-app-scripts test --jestConfig ../../jest.config.shared.js"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"@dhis2/app-runtime": "^
|
|
29
|
+
"@dhis2/app-runtime": "^3",
|
|
30
30
|
"@dhis2/d2-i18n": "^1",
|
|
31
31
|
"react": "^16.8",
|
|
32
32
|
"react-dom": "^16.8",
|
|
33
|
-
"styled-jsx": "^
|
|
33
|
+
"styled-jsx": "^4"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@dhis2-ui/checkbox": "
|
|
37
|
-
"@dhis2-ui/loader": "
|
|
38
|
-
"@dhis2-ui/node": "
|
|
36
|
+
"@dhis2-ui/checkbox": "7.0.1",
|
|
37
|
+
"@dhis2-ui/loader": "7.0.1",
|
|
38
|
+
"@dhis2-ui/node": "7.0.1",
|
|
39
39
|
"@dhis2/prop-types": "^1.6.4",
|
|
40
|
-
"@dhis2/ui-constants": "
|
|
40
|
+
"@dhis2/ui-constants": "7.0.1",
|
|
41
41
|
"classnames": "^2.3.1",
|
|
42
42
|
"prop-types": "^15.7.2"
|
|
43
43
|
},
|
|
@@ -45,11 +45,10 @@
|
|
|
45
45
|
"build"
|
|
46
46
|
],
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@dhis2/app-runtime": "^
|
|
48
|
+
"@dhis2/app-runtime": "^3.0.0",
|
|
49
49
|
"@dhis2/d2-i18n": "^1.1.0",
|
|
50
|
-
"@testing-library/react-hooks": "^7.0.1",
|
|
51
50
|
"react": "16.13",
|
|
52
51
|
"react-dom": "16.13",
|
|
53
|
-
"styled-jsx": "^
|
|
52
|
+
"styled-jsx": "^4.0.1"
|
|
54
53
|
}
|
|
55
54
|
}
|