@hisptz/dhis2-analytics 1.0.10 → 1.0.12
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/components/ChartAnalytics/ChartAnalytics.stories.js +1 -1
- package/build/cjs/components/CircularProgressDashboard/CircularProgressIndicator.stories.js +1 -1
- package/build/cjs/components/CustomPivotTable/CustomPivotTable.stories.js +69 -0
- package/build/cjs/components/CustomPivotTable/components/Table/index.js +16 -0
- package/build/cjs/components/CustomPivotTable/components/TableBody/TableBody.module.css +12 -0
- package/build/cjs/components/CustomPivotTable/components/TableBody/index.js +109 -0
- package/build/cjs/components/CustomPivotTable/components/TableHeaders/TableHeaders.module.css +10 -0
- package/build/cjs/components/CustomPivotTable/components/TableHeaders/index.js +89 -0
- package/build/cjs/components/CustomPivotTable/index.js +30 -0
- package/build/cjs/components/CustomPivotTable/interfaces/index.js +1 -0
- package/build/cjs/components/CustomPivotTable/services/engine.js +89 -0
- package/build/cjs/components/CustomPivotTable/state/engine.js +23 -0
- package/build/cjs/components/Map/Map.stories.js +1 -1
- package/build/cjs/components/Map/components/EarthEngineLayerConfiguration/EarthEngineLayerConfigModal.stories.js +1 -1
- package/build/cjs/components/Map/components/EarthEngineLayerConfiguration/EarthEngineLayerConfiguration.stories.js +1 -1
- package/build/cjs/components/Map/components/MapProvider/components/MapLayerProvider/hooks/index.js +8 -1
- package/build/cjs/components/Map/components/ThematicLayerConfiguration/ThematicLayerConfigModal.stories.js +1 -1
- package/build/cjs/components/Map/components/ThematicLayerConfiguration/ThematicLayerConfiguration.stories.js +1 -1
- package/build/cjs/components/SingleValueContainer/SingleValueContainer.stories.js +1 -1
- package/build/cjs/dataProviders/map.js +1 -1
- package/build/cjs/index.js +11 -0
- package/build/es/components/ChartAnalytics/ChartAnalytics.stories.js +1 -1
- package/build/es/components/CircularProgressDashboard/CircularProgressIndicator.stories.js +1 -1
- package/build/es/components/CustomPivotTable/CustomPivotTable.stories.js +59 -0
- package/build/es/components/CustomPivotTable/components/Table/index.js +9 -0
- package/build/es/components/CustomPivotTable/components/TableBody/TableBody.module.css +12 -0
- package/build/es/components/CustomPivotTable/components/TableBody/index.js +100 -0
- package/build/es/components/CustomPivotTable/components/TableHeaders/TableHeaders.module.css +10 -0
- package/build/es/components/CustomPivotTable/components/TableHeaders/index.js +82 -0
- package/build/es/components/CustomPivotTable/index.js +22 -0
- package/build/es/components/CustomPivotTable/interfaces/index.js +1 -0
- package/build/es/components/CustomPivotTable/services/engine.js +82 -0
- package/build/es/components/CustomPivotTable/state/engine.js +14 -0
- package/build/es/components/Map/Map.stories.js +1 -1
- package/build/es/components/Map/components/EarthEngineLayerConfiguration/EarthEngineLayerConfigModal.stories.js +1 -1
- package/build/es/components/Map/components/EarthEngineLayerConfiguration/EarthEngineLayerConfiguration.stories.js +1 -1
- package/build/es/components/Map/components/MapProvider/components/MapLayerProvider/hooks/index.js +8 -1
- package/build/es/components/Map/components/ThematicLayerConfiguration/ThematicLayerConfigModal.stories.js +1 -1
- package/build/es/components/Map/components/ThematicLayerConfiguration/ThematicLayerConfiguration.stories.js +1 -1
- package/build/es/components/SingleValueContainer/SingleValueContainer.stories.js +1 -1
- package/build/es/dataProviders/map.js +1 -1
- package/build/es/index.js +1 -0
- package/build/types/{components → src/components}/ChartAnalytics/components/DownloadMenu/components/Menu.d.ts +0 -0
- package/build/types/{components → src/components}/ChartAnalytics/components/DownloadMenu/constants/menu.d.ts +0 -0
- package/build/types/{components → src/components}/ChartAnalytics/components/DownloadMenu/index.d.ts +0 -0
- package/build/types/{components → src/components}/ChartAnalytics/components/DownloadMenu/interfaces/menu.d.ts +0 -0
- package/build/types/{components → src/components}/ChartAnalytics/hooks/useChart.d.ts +0 -0
- package/build/types/{components → src/components}/ChartAnalytics/index.d.ts +0 -0
- package/build/types/{components → src/components}/ChartAnalytics/models/column.d.ts +0 -0
- package/build/types/{components → src/components}/ChartAnalytics/models/index.d.ts +0 -0
- package/build/types/{components → src/components}/ChartAnalytics/models/line.d.ts +0 -0
- package/build/types/{components → src/components}/ChartAnalytics/models/multi-series.d.ts +0 -0
- package/build/types/{components → src/components}/ChartAnalytics/models/pie.d.ts +0 -0
- package/build/types/{components → src/components}/ChartAnalytics/services/export.d.ts +0 -0
- package/build/types/{components → src/components}/ChartAnalytics/types/props.d.ts +0 -0
- package/build/types/{components → src/components}/ChartAnalytics/utils/chart.d.ts +0 -0
- package/build/types/{components → src/components}/CircularProgressDashboard/index.d.ts +0 -0
- package/build/types/{components → src/components}/CircularProgressDashboard/types/props.d.ts +0 -0
- package/build/types/src/components/CustomPivotTable/components/Table/index.d.ts +11 -0
- package/build/types/src/components/CustomPivotTable/components/TableBody/index.d.ts +2 -0
- package/build/types/src/components/CustomPivotTable/components/TableHeaders/index.d.ts +2 -0
- package/build/types/src/components/CustomPivotTable/index.d.ts +40 -0
- package/build/types/src/components/CustomPivotTable/interfaces/index.d.ts +1 -0
- package/build/types/src/components/CustomPivotTable/services/engine.d.ts +58 -0
- package/build/types/src/components/CustomPivotTable/state/engine.d.ts +7 -0
- package/build/types/{components → src/components}/Map/components/EarthEngineLayerConfiguration/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/MapArea/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/MapArea/interfaces/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/MapControls/components/CustomControl/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/MapControls/components/DownloadControl/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/MapControls/components/FullscreenControl/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/MapControls/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/MapLayer/components/BoundaryLayer/hooks/useBoundaryData.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/MapLayer/components/BoundaryLayer/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/MapLayer/components/GoogleEngineLayer/components/EarthEngineLegend.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/MapLayer/components/GoogleEngineLayer/constants/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/MapLayer/components/GoogleEngineLayer/hooks/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/MapLayer/components/GoogleEngineLayer/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/MapLayer/components/GoogleEngineLayer/interfaces/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/MapLayer/components/GoogleEngineLayer/services/api.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/MapLayer/components/GoogleEngineLayer/services/engine.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/MapLayer/components/GoogleEngineLayer/utils/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/MapLayer/components/LegendArea/components/LegendCardHeader/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/MapLayer/components/LegendArea/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/MapLayer/components/PointLayer/components/PointLegend/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/MapLayer/components/PointLayer/hooks/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/MapLayer/components/PointLayer/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/MapLayer/components/ThematicLayer/components/Bubble/components/BubbleLegend/components/Bubble.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/MapLayer/components/ThematicLayer/components/Bubble/components/BubbleLegend/components/Bubbles.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/MapLayer/components/ThematicLayer/components/Bubble/components/BubbleLegend/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/MapLayer/components/ThematicLayer/components/Bubble/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/MapLayer/components/ThematicLayer/components/Choropleth/components/ChoroplethLegend.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/MapLayer/components/ThematicLayer/components/Choropleth/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/MapLayer/components/ThematicLayer/components/CustomTooltip/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/MapLayer/components/ThematicLayer/hooks/config.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/MapLayer/components/ThematicLayer/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/MapLayer/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/MapLayer/interfaces/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/MapProvider/components/MapLayerProvider/hooks/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/MapProvider/components/MapLayerProvider/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/MapProvider/hooks/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/MapProvider/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/MapUpdater/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/ThematicLayerConfiguration/components/ColorScaleSelect/components/ColorScale/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/ThematicLayerConfiguration/components/ColorScaleSelect/constants/colors.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/ThematicLayerConfiguration/components/ColorScaleSelect/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/ThematicLayerConfiguration/components/ColorScaleSelect/utils/colors.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/ThematicLayerConfiguration/components/CustomLegend/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/ThematicLayerConfiguration/components/IndicatorSelectorModal/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/ThematicLayerConfiguration/components/LegendSetSelector/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/components/ThematicLayerConfiguration/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/constants/colors.d.ts +0 -0
- package/build/types/{components → src/components}/Map/constants/legendSet.d.ts +0 -0
- package/build/types/{components → src/components}/Map/hooks/map.d.ts +0 -0
- package/build/types/{components → src/components}/Map/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/interfaces/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/state/index.d.ts +0 -0
- package/build/types/{components → src/components}/Map/utils/colors.d.ts +0 -0
- package/build/types/{components → src/components}/Map/utils/helpers.d.ts +0 -0
- package/build/types/{components → src/components}/Map/utils/map.d.ts +0 -0
- package/build/types/{components → src/components}/SingleValueContainer/components/SingleValueItem/SingleValueItem.d.ts +0 -0
- package/build/types/{components → src/components}/SingleValueContainer/components/SingleValueItem/SingleValuePercentage.d.ts +0 -0
- package/build/types/{components → src/components}/SingleValueContainer/index.d.ts +0 -0
- package/build/types/{components → src/components}/SingleValueContainer/types/props.d.ts +0 -0
- package/build/types/{dataProviders → src/dataProviders}/map.d.ts +0 -0
- package/build/types/{index.d.ts → src/index.d.ts} +1 -0
- package/package.json +6 -3
- package/build/cjs/data/map.json +0 -5984
- package/build/es/data/map.json +0 -5984
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { CustomPivotTable } from ".";
|
|
3
|
+
import pivotTableData from "../../../data/large-table-data.json";
|
|
4
|
+
import simpleData from "../../../data/simple-data.json";
|
|
5
|
+
const Template = args => /*#__PURE__*/React.createElement(CustomPivotTable, args);
|
|
6
|
+
export const Default = Template.bind({});
|
|
7
|
+
Default.args = {
|
|
8
|
+
analytics: simpleData,
|
|
9
|
+
config: {
|
|
10
|
+
layout: {
|
|
11
|
+
columns: [{
|
|
12
|
+
dimension: "ou"
|
|
13
|
+
}, {
|
|
14
|
+
dimension: "pe",
|
|
15
|
+
label: "Period"
|
|
16
|
+
}],
|
|
17
|
+
rows: [{
|
|
18
|
+
dimension: "dx",
|
|
19
|
+
label: "Services"
|
|
20
|
+
}],
|
|
21
|
+
filter: []
|
|
22
|
+
},
|
|
23
|
+
options: {}
|
|
24
|
+
},
|
|
25
|
+
tableProps: {}
|
|
26
|
+
};
|
|
27
|
+
export const WithManyData = Template.bind({});
|
|
28
|
+
WithManyData.args = {
|
|
29
|
+
analytics: pivotTableData,
|
|
30
|
+
config: {
|
|
31
|
+
layout: {
|
|
32
|
+
columns: [{
|
|
33
|
+
dimension: "dx"
|
|
34
|
+
}, {
|
|
35
|
+
dimension: "J5jldMd8OHv",
|
|
36
|
+
label: "Facility Type"
|
|
37
|
+
}],
|
|
38
|
+
rows: [{
|
|
39
|
+
dimension: "pe",
|
|
40
|
+
label: "Period"
|
|
41
|
+
}, {
|
|
42
|
+
dimension: "ou",
|
|
43
|
+
label: "Organisation unit"
|
|
44
|
+
}],
|
|
45
|
+
filter: []
|
|
46
|
+
},
|
|
47
|
+
options: {
|
|
48
|
+
fixColumnHeaders: false
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
tableProps: {
|
|
52
|
+
scrollHeight: "800px",
|
|
53
|
+
scrollWidth: "1400px"
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
export default {
|
|
57
|
+
title: "Analytics/Pivot table",
|
|
58
|
+
component: CustomPivotTable
|
|
59
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { DataTable } from '@dhis2/ui';
|
|
3
|
+
export function PivotTable(_ref) {
|
|
4
|
+
let {
|
|
5
|
+
tableProps,
|
|
6
|
+
children
|
|
7
|
+
} = _ref;
|
|
8
|
+
return /*#__PURE__*/React.createElement(DataTable, tableProps !== null && tableProps !== void 0 ? tableProps : {}, children);
|
|
9
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { isEmpty, slice } from "lodash";
|
|
2
|
+
import { useCustomPivotTableEngine } from "../../state/engine";
|
|
3
|
+
import { DataTableCell, DataTableRow, TableBody } from '@dhis2/ui';
|
|
4
|
+
import React, { Fragment } from "react";
|
|
5
|
+
import classes from "./TableBody.module.css";
|
|
6
|
+
import { useElementSize } from "usehooks-ts";
|
|
7
|
+
function DataRowRenderer(_ref) {
|
|
8
|
+
let {
|
|
9
|
+
mapper,
|
|
10
|
+
item,
|
|
11
|
+
dimension
|
|
12
|
+
} = _ref;
|
|
13
|
+
const engine = useCustomPivotTableEngine();
|
|
14
|
+
const columnMappers = engine === null || engine === void 0 ? void 0 : engine.columnMap;
|
|
15
|
+
const completeMapper = columnMappers === null || columnMappers === void 0 ? void 0 : columnMappers.map(map => ({
|
|
16
|
+
...map,
|
|
17
|
+
...mapper,
|
|
18
|
+
[dimension]: item.uid
|
|
19
|
+
}));
|
|
20
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, completeMapper === null || completeMapper === void 0 ? void 0 : completeMapper.map(mapper => {
|
|
21
|
+
var _engine$getValue;
|
|
22
|
+
return /*#__PURE__*/React.createElement(DataTableCell, {
|
|
23
|
+
key: `${Object.values(mapper).join('-')}-value`,
|
|
24
|
+
align: "center",
|
|
25
|
+
bordered: true
|
|
26
|
+
}, (_engine$getValue = engine === null || engine === void 0 ? void 0 : engine.getValue(mapper)) !== null && _engine$getValue !== void 0 ? _engine$getValue : '');
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
function RowRenderer(_ref2) {
|
|
30
|
+
var _row$items;
|
|
31
|
+
let {
|
|
32
|
+
row,
|
|
33
|
+
index,
|
|
34
|
+
config: {
|
|
35
|
+
rows,
|
|
36
|
+
columns,
|
|
37
|
+
mapper,
|
|
38
|
+
prevWidth,
|
|
39
|
+
fixRowHeaders
|
|
40
|
+
}
|
|
41
|
+
} = _ref2;
|
|
42
|
+
const [cellRef, {
|
|
43
|
+
width
|
|
44
|
+
}] = useElementSize();
|
|
45
|
+
const rowSpan = slice(rows, index + 1).reduce((acc, column) => {
|
|
46
|
+
var _column$items$length, _column$items;
|
|
47
|
+
return acc * ((_column$items$length = (_column$items = column.items) === null || _column$items === void 0 ? void 0 : _column$items.length) !== null && _column$items$length !== void 0 ? _column$items$length : 1);
|
|
48
|
+
}, 1);
|
|
49
|
+
const hasSubRows = !isEmpty(rows[index + 1]);
|
|
50
|
+
const nextRow = rows[index + 1];
|
|
51
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, row === null || row === void 0 ? void 0 : (_row$items = row.items) === null || _row$items === void 0 ? void 0 : _row$items.map(item => {
|
|
52
|
+
return /*#__PURE__*/React.createElement(Fragment, {
|
|
53
|
+
key: `${item.name}-${row.dimension}-fragment`
|
|
54
|
+
}, /*#__PURE__*/React.createElement(DataTableRow, {
|
|
55
|
+
key: `${item.name}-${row.dimension}-row`
|
|
56
|
+
}, /*#__PURE__*/React.createElement(DataTableCell, {
|
|
57
|
+
ref: cellRef,
|
|
58
|
+
fixed: fixRowHeaders,
|
|
59
|
+
left: `${prevWidth}px`,
|
|
60
|
+
className: classes['header-cell'],
|
|
61
|
+
tag: "th",
|
|
62
|
+
bordered: true,
|
|
63
|
+
rowSpan: (rowSpan + (hasSubRows ? 1 : 0)).toString()
|
|
64
|
+
}, item.name), !hasSubRows ? /*#__PURE__*/React.createElement(DataRowRenderer, {
|
|
65
|
+
dimension: row.dimension,
|
|
66
|
+
mapper: mapper,
|
|
67
|
+
item: item
|
|
68
|
+
}) : null), hasSubRows ? /*#__PURE__*/React.createElement(RowRenderer, {
|
|
69
|
+
row: nextRow,
|
|
70
|
+
index: index + 1,
|
|
71
|
+
config: {
|
|
72
|
+
rows,
|
|
73
|
+
columns,
|
|
74
|
+
prevWidth: width,
|
|
75
|
+
mapper: {
|
|
76
|
+
...mapper,
|
|
77
|
+
[row.dimension]: item.uid
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}) : null);
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
export function CustomPivotTableBody() {
|
|
84
|
+
const engine = useCustomPivotTableEngine();
|
|
85
|
+
const rows = engine === null || engine === void 0 ? void 0 : engine.rowHeaders;
|
|
86
|
+
const columns = engine === null || engine === void 0 ? void 0 : engine.columnHeaders;
|
|
87
|
+
const fixRowHeaders = engine === null || engine === void 0 ? void 0 : engine.fixRowHeaders;
|
|
88
|
+
if (!rows || isEmpty(rows)) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
return /*#__PURE__*/React.createElement(TableBody, null, /*#__PURE__*/React.createElement(RowRenderer, {
|
|
92
|
+
row: rows[0],
|
|
93
|
+
index: 0,
|
|
94
|
+
config: {
|
|
95
|
+
rows,
|
|
96
|
+
columns,
|
|
97
|
+
fixRowHeaders
|
|
98
|
+
}
|
|
99
|
+
}));
|
|
100
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { useCustomPivotTableEngine } from "../../state/engine";
|
|
3
|
+
import { DataTableColumnHeader, DataTableRow, TableHead } from '@dhis2/ui';
|
|
4
|
+
import { isEmpty, slice, times } from "lodash";
|
|
5
|
+
import classes from "./TableHeaders.module.css";
|
|
6
|
+
import { useElementSize } from "usehooks-ts";
|
|
7
|
+
function ColumnRenderer(_ref) {
|
|
8
|
+
let {
|
|
9
|
+
column,
|
|
10
|
+
index,
|
|
11
|
+
config: {
|
|
12
|
+
fixColumnHeaders,
|
|
13
|
+
rowHeaders,
|
|
14
|
+
prevHeight = 0,
|
|
15
|
+
columns
|
|
16
|
+
}
|
|
17
|
+
} = _ref;
|
|
18
|
+
const [columnHeaderRef, {
|
|
19
|
+
height
|
|
20
|
+
}] = useElementSize();
|
|
21
|
+
if (!column) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
const colSpan = slice(columns, index + 1).reduce((acc, column) => {
|
|
25
|
+
var _column$items$length, _column$items;
|
|
26
|
+
return acc * ((_column$items$length = (_column$items = column.items) === null || _column$items === void 0 ? void 0 : _column$items.length) !== null && _column$items$length !== void 0 ? _column$items$length : 1);
|
|
27
|
+
}, 1);
|
|
28
|
+
const hasSubColumns = !isEmpty(columns[index + 1]);
|
|
29
|
+
const nextColumn = columns[index + 1];
|
|
30
|
+
const multiplicationFactor = slice(columns, 0, index).reduce((acc, column) => {
|
|
31
|
+
var _column$items$length2, _column$items2;
|
|
32
|
+
return acc * ((_column$items$length2 = (_column$items2 = column.items) === null || _column$items2 === void 0 ? void 0 : _column$items2.length) !== null && _column$items$length2 !== void 0 ? _column$items$length2 : 1);
|
|
33
|
+
}, 1);
|
|
34
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(DataTableRow, null, index === 0 && (rowHeaders === null || rowHeaders === void 0 ? void 0 : rowHeaders.map(header => {
|
|
35
|
+
var _header$label;
|
|
36
|
+
return /*#__PURE__*/React.createElement(DataTableColumnHeader, {
|
|
37
|
+
fixed: fixColumnHeaders,
|
|
38
|
+
top: "0",
|
|
39
|
+
className: classes['table-header'],
|
|
40
|
+
rowSpan: columns.length.toString(),
|
|
41
|
+
key: `${header.dimension}-header-column`
|
|
42
|
+
}, (_header$label = header.label) !== null && _header$label !== void 0 ? _header$label : "");
|
|
43
|
+
})), times(multiplicationFactor, colNo => {
|
|
44
|
+
var _column$items3;
|
|
45
|
+
return (_column$items3 = column.items) === null || _column$items3 === void 0 ? void 0 : _column$items3.map(item => /*#__PURE__*/React.createElement(DataTableColumnHeader, {
|
|
46
|
+
fixed: fixColumnHeaders,
|
|
47
|
+
top: `${prevHeight.toString()}px`,
|
|
48
|
+
ref: index === 0 ? columnHeaderRef : undefined,
|
|
49
|
+
className: classes['table-header'],
|
|
50
|
+
align: "center",
|
|
51
|
+
colSpan: colSpan.toString(),
|
|
52
|
+
key: `${colNo}-${item.name}-column-header`
|
|
53
|
+
}, item.name));
|
|
54
|
+
})), hasSubColumns ? /*#__PURE__*/React.createElement(ColumnRenderer, {
|
|
55
|
+
column: nextColumn,
|
|
56
|
+
index: index + 1,
|
|
57
|
+
config: {
|
|
58
|
+
columns,
|
|
59
|
+
rowHeaders,
|
|
60
|
+
prevHeight: height,
|
|
61
|
+
fixColumnHeaders
|
|
62
|
+
}
|
|
63
|
+
}) : null);
|
|
64
|
+
}
|
|
65
|
+
export function TableHeaders() {
|
|
66
|
+
const engine = useCustomPivotTableEngine();
|
|
67
|
+
const columns = engine === null || engine === void 0 ? void 0 : engine.columnHeaders;
|
|
68
|
+
const rowHeaders = engine === null || engine === void 0 ? void 0 : engine.rowHeaders;
|
|
69
|
+
const fixColumnHeaders = engine === null || engine === void 0 ? void 0 : engine.fixColumnHeaders;
|
|
70
|
+
if (!columns || isEmpty(columns)) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
return /*#__PURE__*/React.createElement(TableHead, null, /*#__PURE__*/React.createElement(ColumnRenderer, {
|
|
74
|
+
column: columns[0],
|
|
75
|
+
index: 0,
|
|
76
|
+
config: {
|
|
77
|
+
rowHeaders,
|
|
78
|
+
columns,
|
|
79
|
+
fixColumnHeaders
|
|
80
|
+
}
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CustomPivotTableEngine } from "./services/engine";
|
|
2
|
+
import React, { useMemo } from "react";
|
|
3
|
+
import { CustomPivotTableEngineProvider } from "./state/engine";
|
|
4
|
+
import { PivotTable } from "./components/Table";
|
|
5
|
+
import { TableHeaders } from "./components/TableHeaders";
|
|
6
|
+
import { CustomPivotTableBody } from "./components/TableBody";
|
|
7
|
+
export function CustomPivotTable(_ref) {
|
|
8
|
+
let {
|
|
9
|
+
analytics,
|
|
10
|
+
config,
|
|
11
|
+
tableProps
|
|
12
|
+
} = _ref;
|
|
13
|
+
const engine = useMemo(() => new CustomPivotTableEngine({
|
|
14
|
+
analytics,
|
|
15
|
+
config
|
|
16
|
+
}), [analytics, config]);
|
|
17
|
+
return /*#__PURE__*/React.createElement(CustomPivotTableEngineProvider, {
|
|
18
|
+
engine: engine
|
|
19
|
+
}, /*#__PURE__*/React.createElement(PivotTable, {
|
|
20
|
+
tableProps: tableProps
|
|
21
|
+
}, /*#__PURE__*/React.createElement(TableHeaders, null), /*#__PURE__*/React.createElement(CustomPivotTableBody, null)));
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
3
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
4
|
+
import { compact, findIndex, intersection, times, zip } from "lodash";
|
|
5
|
+
export class CustomPivotTableEngine {
|
|
6
|
+
constructor(_ref) {
|
|
7
|
+
let {
|
|
8
|
+
analytics,
|
|
9
|
+
config
|
|
10
|
+
} = _ref;
|
|
11
|
+
_defineProperty(this, "analyticsData", void 0);
|
|
12
|
+
_defineProperty(this, "valueIndex", void 0);
|
|
13
|
+
_defineProperty(this, "config", void 0);
|
|
14
|
+
_defineProperty(this, "rowHeaders", void 0);
|
|
15
|
+
_defineProperty(this, "columnHeaders", void 0);
|
|
16
|
+
_defineProperty(this, "columnMap", void 0);
|
|
17
|
+
this.config = config;
|
|
18
|
+
this.analyticsData = analytics;
|
|
19
|
+
this.valueIndex = findIndex(this.analyticsData.headers, ['name', 'value']);
|
|
20
|
+
this.getHeaders();
|
|
21
|
+
this.getColumnMap();
|
|
22
|
+
}
|
|
23
|
+
get fixColumnHeaders() {
|
|
24
|
+
var _this$config$options$, _this$config$options;
|
|
25
|
+
return (_this$config$options$ = (_this$config$options = this.config.options) === null || _this$config$options === void 0 ? void 0 : _this$config$options.fixColumnHeaders) !== null && _this$config$options$ !== void 0 ? _this$config$options$ : true;
|
|
26
|
+
}
|
|
27
|
+
get fixRowHeaders() {
|
|
28
|
+
var _this$config$options$2, _this$config$options2;
|
|
29
|
+
return (_this$config$options$2 = (_this$config$options2 = this.config.options) === null || _this$config$options2 === void 0 ? void 0 : _this$config$options2.fixRowHeaders) !== null && _this$config$options$2 !== void 0 ? _this$config$options$2 : true;
|
|
30
|
+
}
|
|
31
|
+
getDimensionItems(dimension) {
|
|
32
|
+
var _this$analyticsData$m, _this$analyticsData$m2;
|
|
33
|
+
return (_this$analyticsData$m = (_this$analyticsData$m2 = this.analyticsData.metaData) === null || _this$analyticsData$m2 === void 0 ? void 0 : _this$analyticsData$m2.dimensions[dimension]) !== null && _this$analyticsData$m !== void 0 ? _this$analyticsData$m : [];
|
|
34
|
+
}
|
|
35
|
+
getItem(id) {
|
|
36
|
+
var _this$analyticsData$m3;
|
|
37
|
+
return (_this$analyticsData$m3 = this.analyticsData.metaData) === null || _this$analyticsData$m3 === void 0 ? void 0 : _this$analyticsData$m3.items[id];
|
|
38
|
+
}
|
|
39
|
+
getValue(mapper) {
|
|
40
|
+
var _this$analyticsData$r;
|
|
41
|
+
const dimensions = Object.values(mapper);
|
|
42
|
+
const data = (_this$analyticsData$r = this.analyticsData.rows) === null || _this$analyticsData$r === void 0 ? void 0 : _this$analyticsData$r.filter(row => intersection(row, dimensions).length >= dimensions.length);
|
|
43
|
+
return data === null || data === void 0 ? void 0 : data.reduce((acc, row) => {
|
|
44
|
+
return acc + parseFloat(row[this.valueIndex]);
|
|
45
|
+
}, 0);
|
|
46
|
+
}
|
|
47
|
+
getHeaders() {
|
|
48
|
+
this.rowHeaders = this.config.layout.rows.map(rowConfig => {
|
|
49
|
+
return {
|
|
50
|
+
...rowConfig,
|
|
51
|
+
items: compact(this.getDimensionItems(rowConfig.dimension).map(itemId => this.getItem(itemId)))
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
this.columnHeaders = this.config.layout.columns.map(columnConfig => {
|
|
55
|
+
return {
|
|
56
|
+
...columnConfig,
|
|
57
|
+
items: compact(this.getDimensionItems(columnConfig.dimension).map(itemId => this.getItem(itemId)))
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
getColumnMap() {
|
|
62
|
+
var _compact;
|
|
63
|
+
const columns = this.columnHeaders;
|
|
64
|
+
const sanitizedColumns = (_compact = compact(columns === null || columns === void 0 ? void 0 : columns.map(column => {
|
|
65
|
+
var _column$items;
|
|
66
|
+
return (_column$items = column.items) === null || _column$items === void 0 ? void 0 : _column$items.map(item => ({
|
|
67
|
+
[column.dimension]: item.uid
|
|
68
|
+
}));
|
|
69
|
+
}))) !== null && _compact !== void 0 ? _compact : [];
|
|
70
|
+
const size = sanitizedColumns.reduce((acc, items) => {
|
|
71
|
+
var _items$length;
|
|
72
|
+
return acc * ((_items$length = items === null || items === void 0 ? void 0 : items.length) !== null && _items$length !== void 0 ? _items$length : 1);
|
|
73
|
+
}, 1);
|
|
74
|
+
const standardiseColumns = sanitizedColumns.map(items => [...times(size / items.length, () => items).flat()]);
|
|
75
|
+
this.columnMap = compact(zip(...standardiseColumns).map(arr => arr.reduce((obj, value) => {
|
|
76
|
+
return {
|
|
77
|
+
...obj,
|
|
78
|
+
...value
|
|
79
|
+
};
|
|
80
|
+
})));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React, { createContext, useContext } from "react";
|
|
2
|
+
const CustomPivotTableEngineContext = /*#__PURE__*/createContext(null);
|
|
3
|
+
export function useCustomPivotTableEngine() {
|
|
4
|
+
return useContext(CustomPivotTableEngineContext);
|
|
5
|
+
}
|
|
6
|
+
export function CustomPivotTableEngineProvider(_ref) {
|
|
7
|
+
let {
|
|
8
|
+
children,
|
|
9
|
+
engine
|
|
10
|
+
} = _ref;
|
|
11
|
+
return /*#__PURE__*/React.createElement(CustomPivotTableEngineContext.Provider, {
|
|
12
|
+
value: engine
|
|
13
|
+
}, children);
|
|
14
|
+
}
|
|
@@ -10,7 +10,7 @@ Basic.args = {
|
|
|
10
10
|
open: true
|
|
11
11
|
};
|
|
12
12
|
export default {
|
|
13
|
-
title: "
|
|
13
|
+
title: "Analytics/Map/Earth Engine Config Modal",
|
|
14
14
|
component: EarthEngineLayerConfiguration,
|
|
15
15
|
decorators: [MapStory => {
|
|
16
16
|
return /*#__PURE__*/React.createElement("div", {
|
|
@@ -18,7 +18,7 @@ const Template = args => {
|
|
|
18
18
|
export const Basic = Template.bind({});
|
|
19
19
|
Basic.args = {};
|
|
20
20
|
export default {
|
|
21
|
-
title: "
|
|
21
|
+
title: "Analytics/Map/Earth Engine Configuration",
|
|
22
22
|
component: EarthEngineLayerConfiguration,
|
|
23
23
|
decorators: [MapStory => {
|
|
24
24
|
return /*#__PURE__*/React.createElement("div", {
|
package/build/es/components/Map/components/MapProvider/components/MapLayerProvider/hooks/index.js
CHANGED
|
@@ -163,7 +163,7 @@ export function useThematicLayers() {
|
|
|
163
163
|
scale: defaultClasses,
|
|
164
164
|
colorClass: defaultColorScaleName
|
|
165
165
|
};
|
|
166
|
-
const sortedData = sortBy(layer.data, "data");
|
|
166
|
+
const sortedData = sortBy(layer.data.filter(datum => !!datum.data), "data");
|
|
167
167
|
const autoLegends = generateLegends((_last$data = (_last = last(sortedData)) === null || _last === void 0 ? void 0 : _last.data) !== null && _last$data !== void 0 ? _last$data : 0, (_head$data = (_head = head(sortedData)) === null || _head === void 0 ? void 0 : _head.data) !== null && _head$data !== void 0 ? _head$data : 0, {
|
|
168
168
|
classesCount: scale,
|
|
169
169
|
colorClass
|
|
@@ -338,10 +338,17 @@ export function useGoogleEngineLayers() {
|
|
|
338
338
|
}
|
|
339
339
|
}
|
|
340
340
|
const sanitizeLayers = useCallback(async layers => {
|
|
341
|
+
if (isEmpty(layers)) {
|
|
342
|
+
return [];
|
|
343
|
+
}
|
|
341
344
|
try {
|
|
342
345
|
const {
|
|
343
346
|
token
|
|
344
347
|
} = await refresh();
|
|
348
|
+
if (!token) {
|
|
349
|
+
console.error(`Google token not available in this instance`);
|
|
350
|
+
return [];
|
|
351
|
+
}
|
|
345
352
|
await EarthEngine.setToken(token, refresh);
|
|
346
353
|
return map(layers, asyncify(async layer => {
|
|
347
354
|
try {
|
|
@@ -10,7 +10,7 @@ Basic.args = {
|
|
|
10
10
|
open: true
|
|
11
11
|
};
|
|
12
12
|
export default {
|
|
13
|
-
title: "
|
|
13
|
+
title: "Analytics/Map/Thematic Layer Config Modal",
|
|
14
14
|
component: ThematicLayerConfigModal,
|
|
15
15
|
decorators: [MapStory => {
|
|
16
16
|
return /*#__PURE__*/React.createElement("div", {
|
|
@@ -18,7 +18,7 @@ const Template = args => {
|
|
|
18
18
|
export const Basic = Template.bind({});
|
|
19
19
|
Basic.args = {};
|
|
20
20
|
export default {
|
|
21
|
-
title: "
|
|
21
|
+
title: "Analytics/Map/Thematic Layer Configuration",
|
|
22
22
|
component: ThematicLayerConfiguration,
|
|
23
23
|
decorators: [MapStory => {
|
|
24
24
|
return /*#__PURE__*/React.createElement("div", {
|
|
@@ -107,7 +107,7 @@ SingleValuesWithDecimalPlaces.args = {
|
|
|
107
107
|
}]
|
|
108
108
|
};
|
|
109
109
|
export default {
|
|
110
|
-
title: "
|
|
110
|
+
title: "Analytics/Single Value Container",
|
|
111
111
|
component: SingleValueContainer,
|
|
112
112
|
decorators: [SingleValueStory => {
|
|
113
113
|
return /*#__PURE__*/React.createElement(SingleValueStory, null);
|
package/build/es/index.js
CHANGED
|
File without changes
|
|
File without changes
|
package/build/types/{components → src/components}/ChartAnalytics/components/DownloadMenu/index.d.ts
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/build/types/{components → src/components}/CircularProgressDashboard/types/props.d.ts
RENAMED
|
File without changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export interface PivotTableProps {
|
|
3
|
+
children: React.ReactNode;
|
|
4
|
+
tableProps?: {
|
|
5
|
+
scrollHeight?: string;
|
|
6
|
+
scrollWidth?: string;
|
|
7
|
+
layout?: string;
|
|
8
|
+
width?: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export declare function PivotTable({ tableProps, children }: PivotTableProps): JSX.Element;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Analytics, LegendSet } from "@hisptz/dhis2-utils";
|
|
3
|
+
import { DHIS2Dimension } from "./interfaces";
|
|
4
|
+
export interface CustomPivotTableProps {
|
|
5
|
+
analytics: Analytics;
|
|
6
|
+
tableProps?: {
|
|
7
|
+
scrollHeight?: string;
|
|
8
|
+
scrollWidth?: string;
|
|
9
|
+
layout?: string;
|
|
10
|
+
width?: string;
|
|
11
|
+
};
|
|
12
|
+
config: {
|
|
13
|
+
layout: {
|
|
14
|
+
columns: {
|
|
15
|
+
dimension: DHIS2Dimension;
|
|
16
|
+
label?: string;
|
|
17
|
+
}[];
|
|
18
|
+
rows: {
|
|
19
|
+
dimension: DHIS2Dimension;
|
|
20
|
+
label?: string;
|
|
21
|
+
}[];
|
|
22
|
+
filter?: {
|
|
23
|
+
dimension: DHIS2Dimension;
|
|
24
|
+
label?: string;
|
|
25
|
+
}[];
|
|
26
|
+
};
|
|
27
|
+
options?: {
|
|
28
|
+
legendSets?: LegendSet[];
|
|
29
|
+
hideEmptyColumns?: boolean;
|
|
30
|
+
hideEmptyRows?: boolean;
|
|
31
|
+
showRowTotals?: boolean;
|
|
32
|
+
showColumnTotals?: boolean;
|
|
33
|
+
showRowSubtotals?: boolean;
|
|
34
|
+
showColumnSubtotals?: boolean;
|
|
35
|
+
fixColumnHeaders?: boolean;
|
|
36
|
+
fixRowHeaders?: boolean;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export declare function CustomPivotTable({ analytics, config, tableProps }: CustomPivotTableProps): JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type DHIS2Dimension = "ou" | "pe" | "dx" | "co" | string;
|