@hisptz/dhis2-analytics 2.1.17 → 2.1.19
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/dist/components/Map/components/MapProvider/index.js +19 -13
- package/dist/components/Map/components/MapProvider/index.js.map +1 -1
- package/dist/esm/components/Map/components/MapProvider/index.js +15 -9
- package/dist/esm/components/Map/components/MapProvider/index.js.map +1 -1
- package/dist/types/components/Map/components/MapProvider/index.d.ts +2 -2
- package/dist/types/components/Map/components/MapProvider/index.d.ts.map +1 -1
- package/package.json +3 -3
|
@@ -6,8 +6,8 @@ var i18n = require('@dhis2/d2-i18n');
|
|
|
6
6
|
var ui = require('@dhis2/ui');
|
|
7
7
|
var lodash = require('lodash');
|
|
8
8
|
var react = require('react');
|
|
9
|
-
var
|
|
10
|
-
var
|
|
9
|
+
var state = require('../../state');
|
|
10
|
+
var utils = require('../../utils');
|
|
11
11
|
var dhis2Utils = require('@hisptz/dhis2-utils');
|
|
12
12
|
|
|
13
13
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -23,10 +23,10 @@ const boundaryQuery = {
|
|
|
23
23
|
},
|
|
24
24
|
analytics: {
|
|
25
25
|
resource: "analytics",
|
|
26
|
-
params: ({ orgUnitIds }) => ({
|
|
26
|
+
params: ({ orgUnitIds, periodIds }) => ({
|
|
27
27
|
dimension: [
|
|
28
28
|
`ou:${orgUnitIds.join(";")}`,
|
|
29
|
-
`pe:${
|
|
29
|
+
`pe:${periodIds.join(";")}`
|
|
30
30
|
],
|
|
31
31
|
skipData: true,
|
|
32
32
|
hierarchyMeta: true
|
|
@@ -39,16 +39,20 @@ function MapProvider({
|
|
|
39
39
|
periodSelection
|
|
40
40
|
}) {
|
|
41
41
|
const [orgUnits, setOrgUnits] = react.useState([]);
|
|
42
|
+
const [periods, setPeriods] = react.useState([]);
|
|
42
43
|
const { refetch, loading, error } = appRuntime.useDataQuery(boundaryQuery, {
|
|
43
44
|
lazy: true
|
|
44
45
|
});
|
|
45
46
|
react.useEffect(() => {
|
|
46
47
|
async function getOrgUnits() {
|
|
47
|
-
const rawOrgUnitIds =
|
|
48
|
-
const data = await refetch({
|
|
48
|
+
const rawOrgUnitIds = utils.getOrgUnitsSelection(orgUnitSelection);
|
|
49
|
+
const data = await refetch({
|
|
50
|
+
orgUnitIds: rawOrgUnitIds,
|
|
51
|
+
periodIds: periodSelection?.periods
|
|
52
|
+
});
|
|
49
53
|
const { analytics, boundaries } = data ?? {};
|
|
50
|
-
const rawOrgUnits =
|
|
51
|
-
const geoJSONObjects =
|
|
54
|
+
const rawOrgUnits = utils.sanitizeOrgUnits(analytics?.metaData);
|
|
55
|
+
const geoJSONObjects = utils.toGeoJson(
|
|
52
56
|
boundaries.filter((bound) => bound.co)
|
|
53
57
|
);
|
|
54
58
|
const orgUnits2 = lodash.compact(
|
|
@@ -67,6 +71,11 @@ function MapProvider({
|
|
|
67
71
|
};
|
|
68
72
|
})
|
|
69
73
|
);
|
|
74
|
+
const periodIds = analytics?.metaData?.dimensions?.pe ?? periodSelection?.periods;
|
|
75
|
+
const periods2 = periodIds.map(
|
|
76
|
+
(pe) => dhis2Utils.PeriodUtility.getPeriodById(pe)
|
|
77
|
+
);
|
|
78
|
+
setPeriods(periods2);
|
|
70
79
|
setOrgUnits(orgUnits2);
|
|
71
80
|
}
|
|
72
81
|
getOrgUnits().catch((error2) => console.log(error2));
|
|
@@ -81,12 +90,9 @@ function MapProvider({
|
|
|
81
90
|
error.message
|
|
82
91
|
] }) }) });
|
|
83
92
|
}
|
|
84
|
-
const periods = lodash.compact(
|
|
85
|
-
periodSelection?.periods?.map((pe) => dhis2Utils.PeriodUtility.getPeriodById(pe))
|
|
86
|
-
);
|
|
87
93
|
if (!lodash.isEmpty(orgUnits)) {
|
|
88
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
89
|
-
|
|
94
|
+
return /* @__PURE__ */ jsxRuntime.jsx(state.MapOrgUnitContext.Provider, { value: { orgUnitSelection, orgUnits }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
95
|
+
state.MapPeriodContext.Provider,
|
|
90
96
|
{
|
|
91
97
|
value: { ...periodSelection, periods },
|
|
92
98
|
children
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/components/Map/components/MapProvider/index.tsx"],"names":["useState","useDataQuery","useEffect","getOrgUnitsSelection","sanitizeOrgUnits","toGeoJson","orgUnits","compact","error","jsx","Center","CircularLoader","jsxs","i18n","
|
|
1
|
+
{"version":3,"sources":["../../../../../src/components/Map/components/MapProvider/index.tsx"],"names":["useState","useDataQuery","useEffect","getOrgUnitsSelection","sanitizeOrgUnits","toGeoJson","orgUnits","compact","periods","PeriodUtility","error","jsx","Center","CircularLoader","jsxs","i18n","isEmpty","MapOrgUnitContext","MapPeriodContext"],"mappings":";;;;;;;;;;;;;;;;AAUA,MAAM,aAAgB,GAAA;AAAA,EACrB,UAAY,EAAA;AAAA,IACX,QAAU,EAAA,aAAA;AAAA,IACV,MAAQ,EAAA,CAAC,EAAE,UAAA,EAAuB,MAAA;AAAA,MACjC,EAAI,EAAA,CAAA,GAAA,EAAM,UAAY,EAAA,IAAA,CAAK,GAAG,CAAC,CAAA;AAAA,KAChC;AAAA,GACD;AAAA,EACA,SAAW,EAAA;AAAA,IACV,QAAU,EAAA,WAAA;AAAA,IACV,MAAQ,EAAA,CAAC,EAAE,UAAA,EAAY,WAAsB,MAAA;AAAA,MAC5C,SAAW,EAAA;AAAA,QACV,CAAM,GAAA,EAAA,UAAA,CAAW,IAAK,CAAA,GAAG,CAAC,CAAA,CAAA;AAAA,QAC1B,CAAM,GAAA,EAAA,SAAA,CAAU,IAAK,CAAA,GAAG,CAAC,CAAA;AAAA,OAC1B;AAAA,MACA,QAAU,EAAA,IAAA;AAAA,MACV,aAAe,EAAA;AAAA,KAChB;AAAA;AAEF,CAAA;AAEO,SAAS,WAAY,CAAA;AAAA,EAC3B,QAAA;AAAA,EACA,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AAkB,QAAlB,EAAA,EAA2B,OAAO,EAAE,gBAAA,EAAkB,UACtD,EAAA,QAAA,kBAAAN,cAAA;AAAA,MAACO,sBAAiB,CAAA,QAAA;AAAA,MAAjB;AAAA,QACA,KAAO,EAAA,EAAE,GAAG,eAAA,EAAiB,OAAQ,EAAA;AAAA,QAEpC;AAAA;AAAA,KAEH,EAAA,CAAA;AAAA;AAIF,EAAO,OAAA,IAAA;AACR","file":"index.js","sourcesContent":["import { useDataQuery } from \"@dhis2/app-runtime\";\nimport i18n from \"@dhis2/d2-i18n\";\nimport { Center, CircularLoader } from \"@dhis2/ui\";\nimport { compact, isEmpty } from \"lodash\";\nimport React, { useEffect, useState } from \"react\";\nimport { MapOrgUnit, MapProviderProps } from \"../../interfaces\";\nimport { MapOrgUnitContext, MapPeriodContext } from \"../../state\";\nimport { getOrgUnitsSelection, sanitizeOrgUnits, toGeoJson } from \"../../utils\";\nimport { BasePeriod, PeriodUtility } from \"@hisptz/dhis2-utils\";\n\nconst boundaryQuery = {\n\tboundaries: {\n\t\tresource: \"geoFeatures\",\n\t\tparams: ({ orgUnitIds }: any) => ({\n\t\t\tou: `ou:${orgUnitIds?.join(\";\")}`,\n\t\t}),\n\t},\n\tanalytics: {\n\t\tresource: \"analytics\",\n\t\tparams: ({ orgUnitIds, periodIds }: any) => ({\n\t\t\tdimension: [\n\t\t\t\t`ou:${orgUnitIds.join(\";\")}`,\n\t\t\t\t`pe:${periodIds.join(\";\")}`,\n\t\t\t],\n\t\t\tskipData: true,\n\t\t\thierarchyMeta: true,\n\t\t}),\n\t},\n};\n\nexport function MapProvider({\n\tchildren,\n\torgUnitSelection,\n\tperiodSelection,\n}: MapProviderProps) {\n\tconst [orgUnits, setOrgUnits] = useState<MapOrgUnit[]>([]);\n\tconst [periods, setPeriods] = useState<BasePeriod[]>([]);\n\tconst { refetch, loading, error } = useDataQuery(boundaryQuery, {\n\t\tlazy: true,\n\t});\n\n\tuseEffect(() => {\n\t\tasync function getOrgUnits() {\n\t\t\tconst rawOrgUnitIds = getOrgUnitsSelection(orgUnitSelection);\n\t\t\tconst data = await refetch({\n\t\t\t\torgUnitIds: rawOrgUnitIds,\n\t\t\t\tperiodIds: periodSelection?.periods,\n\t\t\t});\n\t\t\tconst { analytics, boundaries } = (data as any) ?? {};\n\t\t\tconst rawOrgUnits = sanitizeOrgUnits(analytics?.metaData);\n\t\t\tconst geoJSONObjects = toGeoJson(\n\t\t\t\tboundaries.filter((bound: any) => bound.co),\n\t\t\t);\n\t\t\tconst orgUnits: MapOrgUnit[] = compact(\n\t\t\t\trawOrgUnits.map((orgUnit: any) => {\n\t\t\t\t\tconst geoJSONObject: any = geoJSONObjects?.find(\n\t\t\t\t\t\t(geoJSON: any) => geoJSON.properties.id === orgUnit.id,\n\t\t\t\t\t);\n\n\t\t\t\t\tif (!geoJSONObject) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...orgUnit,\n\t\t\t\t\t\tgeoJSON: geoJSONObject,\n\t\t\t\t\t\tbounds: [],\n\t\t\t\t\t\tlevel: geoJSONObject.properties.level,\n\t\t\t\t\t};\n\t\t\t\t}),\n\t\t\t);\n\t\t\tconst periodIds =\n\t\t\t\tanalytics?.metaData?.dimensions?.pe ?? periodSelection?.periods;\n\t\t\tconst periods = periodIds.map((pe: string) =>\n\t\t\t\tPeriodUtility.getPeriodById(pe),\n\t\t\t);\n\t\t\tsetPeriods(periods);\n\t\t\tsetOrgUnits(orgUnits);\n\t\t}\n\n\t\tgetOrgUnits().catch((error) => console.log(error));\n\t}, [orgUnitSelection, refetch]);\n\n\tif (loading) {\n\t\treturn (\n\t\t\t<div style={{ height: \"100%\", width: \"100%\" }}>\n\t\t\t\t<Center>\n\t\t\t\t\t<CircularLoader small />\n\t\t\t\t</Center>\n\t\t\t</div>\n\t\t);\n\t}\n\n\tif (error) {\n\t\treturn (\n\t\t\t<div style={{ height: \"100%\", width: \"100%\" }}>\n\t\t\t\t<Center>\n\t\t\t\t\t<h4>\n\t\t\t\t\t\t{i18n.t(\"Error\")}: {error.message}\n\t\t\t\t\t</h4>\n\t\t\t\t</Center>\n\t\t\t</div>\n\t\t);\n\t}\n\n\tif (!isEmpty(orgUnits)) {\n\t\treturn (\n\t\t\t<MapOrgUnitContext.Provider value={{ orgUnitSelection, orgUnits }}>\n\t\t\t\t<MapPeriodContext.Provider\n\t\t\t\t\tvalue={{ ...periodSelection, periods }}\n\t\t\t\t>\n\t\t\t\t\t{children}\n\t\t\t\t</MapPeriodContext.Provider>\n\t\t\t</MapOrgUnitContext.Provider>\n\t\t);\n\t}\n\n\treturn null;\n}\n"]}
|
|
@@ -2,10 +2,10 @@ import { jsx, jsxs } from 'react/jsx-runtime';
|
|
|
2
2
|
import { useDataQuery } from '@dhis2/app-runtime';
|
|
3
3
|
import i18n from '@dhis2/d2-i18n';
|
|
4
4
|
import { Center, CircularLoader } from '@dhis2/ui';
|
|
5
|
-
import {
|
|
5
|
+
import { isEmpty, compact } from 'lodash';
|
|
6
6
|
import { useState, useEffect } from 'react';
|
|
7
|
-
import { MapOrgUnitContext, MapPeriodContext } from '../../state
|
|
8
|
-
import { getOrgUnitsSelection, sanitizeOrgUnits, toGeoJson } from '../../utils
|
|
7
|
+
import { MapOrgUnitContext, MapPeriodContext } from '../../state';
|
|
8
|
+
import { getOrgUnitsSelection, sanitizeOrgUnits, toGeoJson } from '../../utils';
|
|
9
9
|
import { PeriodUtility } from '@hisptz/dhis2-utils';
|
|
10
10
|
|
|
11
11
|
const boundaryQuery = {
|
|
@@ -17,10 +17,10 @@ const boundaryQuery = {
|
|
|
17
17
|
},
|
|
18
18
|
analytics: {
|
|
19
19
|
resource: "analytics",
|
|
20
|
-
params: ({ orgUnitIds }) => ({
|
|
20
|
+
params: ({ orgUnitIds, periodIds }) => ({
|
|
21
21
|
dimension: [
|
|
22
22
|
`ou:${orgUnitIds.join(";")}`,
|
|
23
|
-
`pe:${
|
|
23
|
+
`pe:${periodIds.join(";")}`
|
|
24
24
|
],
|
|
25
25
|
skipData: true,
|
|
26
26
|
hierarchyMeta: true
|
|
@@ -33,13 +33,17 @@ function MapProvider({
|
|
|
33
33
|
periodSelection
|
|
34
34
|
}) {
|
|
35
35
|
const [orgUnits, setOrgUnits] = useState([]);
|
|
36
|
+
const [periods, setPeriods] = useState([]);
|
|
36
37
|
const { refetch, loading, error } = useDataQuery(boundaryQuery, {
|
|
37
38
|
lazy: true
|
|
38
39
|
});
|
|
39
40
|
useEffect(() => {
|
|
40
41
|
async function getOrgUnits() {
|
|
41
42
|
const rawOrgUnitIds = getOrgUnitsSelection(orgUnitSelection);
|
|
42
|
-
const data = await refetch({
|
|
43
|
+
const data = await refetch({
|
|
44
|
+
orgUnitIds: rawOrgUnitIds,
|
|
45
|
+
periodIds: periodSelection?.periods
|
|
46
|
+
});
|
|
43
47
|
const { analytics, boundaries } = data ?? {};
|
|
44
48
|
const rawOrgUnits = sanitizeOrgUnits(analytics?.metaData);
|
|
45
49
|
const geoJSONObjects = toGeoJson(
|
|
@@ -61,6 +65,11 @@ function MapProvider({
|
|
|
61
65
|
};
|
|
62
66
|
})
|
|
63
67
|
);
|
|
68
|
+
const periodIds = analytics?.metaData?.dimensions?.pe ?? periodSelection?.periods;
|
|
69
|
+
const periods2 = periodIds.map(
|
|
70
|
+
(pe) => PeriodUtility.getPeriodById(pe)
|
|
71
|
+
);
|
|
72
|
+
setPeriods(periods2);
|
|
64
73
|
setOrgUnits(orgUnits2);
|
|
65
74
|
}
|
|
66
75
|
getOrgUnits().catch((error2) => console.log(error2));
|
|
@@ -75,9 +84,6 @@ function MapProvider({
|
|
|
75
84
|
error.message
|
|
76
85
|
] }) }) });
|
|
77
86
|
}
|
|
78
|
-
const periods = compact(
|
|
79
|
-
periodSelection?.periods?.map((pe) => PeriodUtility.getPeriodById(pe))
|
|
80
|
-
);
|
|
81
87
|
if (!isEmpty(orgUnits)) {
|
|
82
88
|
return /* @__PURE__ */ jsx(MapOrgUnitContext.Provider, { value: { orgUnitSelection, orgUnits }, children: /* @__PURE__ */ jsx(
|
|
83
89
|
MapPeriodContext.Provider,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/components/Map/components/MapProvider/index.tsx"],"names":["orgUnits","error"],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/components/Map/components/MapProvider/index.tsx"],"names":["orgUnits","periods","error"],"mappings":";;;;;;;;;;AAUA,MAAM,aAAgB,GAAA;AAAA,EACrB,UAAY,EAAA;AAAA,IACX,QAAU,EAAA,aAAA;AAAA,IACV,MAAQ,EAAA,CAAC,EAAE,UAAA,EAAuB,MAAA;AAAA,MACjC,EAAI,EAAA,CAAA,GAAA,EAAM,UAAY,EAAA,IAAA,CAAK,GAAG,CAAC,CAAA;AAAA,KAChC;AAAA,GACD;AAAA,EACA,SAAW,EAAA;AAAA,IACV,QAAU,EAAA,WAAA;AAAA,IACV,MAAQ,EAAA,CAAC,EAAE,UAAA,EAAY,WAAsB,MAAA;AAAA,MAC5C,SAAW,EAAA;AAAA,QACV,CAAM,GAAA,EAAA,UAAA,CAAW,IAAK,CAAA,GAAG,CAAC,CAAA,CAAA;AAAA,QAC1B,CAAM,GAAA,EAAA,SAAA,CAAU,IAAK,CAAA,GAAG,CAAC,CAAA;AAAA,OAC1B;AAAA,MACA,QAAU,EAAA,IAAA;AAAA,MACV,aAAe,EAAA;AAAA,KAChB;AAAA;AAEF,CAAA;AAEO,SAAS,WAAY,CAAA;AAAA,EAC3B,QAAA;AAAA,EACA,gBAAA;AAAA,EACA;AACD,CAAqB,EAAA;AACpB,EAAA,MAAM,CAAC,QAAU,EAAA,WAAW,CAAI,GAAA,QAAA,CAAuB,EAAE,CAAA;AACzD,EAAA,MAAM,CAAC,OAAS,EAAA,UAAU,CAAI,GAAA,QAAA,CAAuB,EAAE,CAAA;AACvD,EAAA,MAAM,EAAE,OAAS,EAAA,OAAA,EAAS,KAAM,EAAA,GAAI,aA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{ useDataQuery } from \"@dhis2/app-runtime\";\nimport i18n from \"@dhis2/d2-i18n\";\nimport { Center, CircularLoader } from \"@dhis2/ui\";\nimport { compact, isEmpty } from \"lodash\";\nimport React, { useEffect, useState } from \"react\";\nimport { MapOrgUnit, MapProviderProps } from \"../../interfaces\";\nimport { MapOrgUnitContext, MapPeriodContext } from \"../../state\";\nimport { getOrgUnitsSelection, sanitizeOrgUnits, toGeoJson } from \"../../utils\";\nimport { BasePeriod, PeriodUtility } from \"@hisptz/dhis2-utils\";\n\nconst boundaryQuery = {\n\tboundaries: {\n\t\tresource: \"geoFeatures\",\n\t\tparams: ({ orgUnitIds }: any) => ({\n\t\t\tou: `ou:${orgUnitIds?.join(\";\")}`,\n\t\t}),\n\t},\n\tanalytics: {\n\t\tresource: \"analytics\",\n\t\tparams: ({ orgUnitIds, periodIds }: any) => ({\n\t\t\tdimension: [\n\t\t\t\t`ou:${orgUnitIds.join(\";\")}`,\n\t\t\t\t`pe:${periodIds.join(\";\")}`,\n\t\t\t],\n\t\t\tskipData: true,\n\t\t\thierarchyMeta: true,\n\t\t}),\n\t},\n};\n\nexport function MapProvider({\n\tchildren,\n\torgUnitSelection,\n\tperiodSelection,\n}: MapProviderProps) {\n\tconst [orgUnits, setOrgUnits] = useState<MapOrgUnit[]>([]);\n\tconst [periods, setPeriods] = useState<BasePeriod[]>([]);\n\tconst { refetch, loading, error } = useDataQuery(boundaryQuery, {\n\t\tlazy: true,\n\t});\n\n\tuseEffect(() => {\n\t\tasync function getOrgUnits() {\n\t\t\tconst rawOrgUnitIds = getOrgUnitsSelection(orgUnitSelection);\n\t\t\tconst data = await refetch({\n\t\t\t\torgUnitIds: rawOrgUnitIds,\n\t\t\t\tperiodIds: periodSelection?.periods,\n\t\t\t});\n\t\t\tconst { analytics, boundaries } = (data as any) ?? {};\n\t\t\tconst rawOrgUnits = sanitizeOrgUnits(analytics?.metaData);\n\t\t\tconst geoJSONObjects = toGeoJson(\n\t\t\t\tboundaries.filter((bound: any) => bound.co),\n\t\t\t);\n\t\t\tconst orgUnits: MapOrgUnit[] = compact(\n\t\t\t\trawOrgUnits.map((orgUnit: any) => {\n\t\t\t\t\tconst geoJSONObject: any = geoJSONObjects?.find(\n\t\t\t\t\t\t(geoJSON: any) => geoJSON.properties.id === orgUnit.id,\n\t\t\t\t\t);\n\n\t\t\t\t\tif (!geoJSONObject) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...orgUnit,\n\t\t\t\t\t\tgeoJSON: geoJSONObject,\n\t\t\t\t\t\tbounds: [],\n\t\t\t\t\t\tlevel: geoJSONObject.properties.level,\n\t\t\t\t\t};\n\t\t\t\t}),\n\t\t\t);\n\t\t\tconst periodIds =\n\t\t\t\tanalytics?.metaData?.dimensions?.pe ?? periodSelection?.periods;\n\t\t\tconst periods = periodIds.map((pe: string) =>\n\t\t\t\tPeriodUtility.getPeriodById(pe),\n\t\t\t);\n\t\t\tsetPeriods(periods);\n\t\t\tsetOrgUnits(orgUnits);\n\t\t}\n\n\t\tgetOrgUnits().catch((error) => console.log(error));\n\t}, [orgUnitSelection, refetch]);\n\n\tif (loading) {\n\t\treturn (\n\t\t\t<div style={{ height: \"100%\", width: \"100%\" }}>\n\t\t\t\t<Center>\n\t\t\t\t\t<CircularLoader small />\n\t\t\t\t</Center>\n\t\t\t</div>\n\t\t);\n\t}\n\n\tif (error) {\n\t\treturn (\n\t\t\t<div style={{ height: \"100%\", width: \"100%\" }}>\n\t\t\t\t<Center>\n\t\t\t\t\t<h4>\n\t\t\t\t\t\t{i18n.t(\"Error\")}: {error.message}\n\t\t\t\t\t</h4>\n\t\t\t\t</Center>\n\t\t\t</div>\n\t\t);\n\t}\n\n\tif (!isEmpty(orgUnits)) {\n\t\treturn (\n\t\t\t<MapOrgUnitContext.Provider value={{ orgUnitSelection, orgUnits }}>\n\t\t\t\t<MapPeriodContext.Provider\n\t\t\t\t\tvalue={{ ...periodSelection, periods }}\n\t\t\t\t>\n\t\t\t\t\t{children}\n\t\t\t\t</MapPeriodContext.Provider>\n\t\t\t</MapOrgUnitContext.Provider>\n\t\t);\n\t}\n\n\treturn null;\n}\n"]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { MapProviderProps } from "../../interfaces
|
|
2
|
-
export declare function MapProvider({ children, orgUnitSelection, periodSelection, }: MapProviderProps): import("react/jsx-runtime
|
|
1
|
+
import { MapProviderProps } from "../../interfaces";
|
|
2
|
+
export declare function MapProvider({ children, orgUnitSelection, periodSelection, }: MapProviderProps): import("react/jsx-runtime").JSX.Element | null;
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/components/Map/components/MapProvider/index.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAc,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/components/Map/components/MapProvider/index.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAc,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAyBhE,wBAAgB,WAAW,CAAC,EAC3B,QAAQ,EACR,gBAAgB,EAChB,eAAe,GACf,EAAE,gBAAgB,kDAmFlB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hisptz/dhis2-analytics",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.19",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/esm/index.js",
|
|
6
6
|
"types": "./dist/types/index.d.ts",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"tsup": "^8.4.0",
|
|
42
42
|
"typescript": "^5.3.3",
|
|
43
43
|
"usehooks-ts": "^2.16.0",
|
|
44
|
-
"@repo/
|
|
45
|
-
"@repo/
|
|
44
|
+
"@repo/typescript-config": "0.0.2",
|
|
45
|
+
"@repo/eslint-config": "0.0.0"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@google/earthengine": "^1.5.21",
|