@ltht-react/table 1.0.137 → 1.0.138
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/lib/atoms/questionnaire-withdrawn-table-cell.d.ts +6 -6
- package/lib/atoms/questionnaire-withdrawn-table-cell.js +18 -18
- package/lib/index.d.ts +6 -6
- package/lib/index.js +12 -12
- package/lib/molecules/table-cell.d.ts +16 -16
- package/lib/molecules/table-cell.js +95 -95
- package/lib/molecules/table-component.d.ts +20 -20
- package/lib/molecules/table-component.js +71 -71
- package/lib/molecules/table-methods.d.ts +11 -11
- package/lib/molecules/table-methods.js +193 -193
- package/lib/molecules/table-styled-components.d.ts +86 -86
- package/lib/molecules/table-styled-components.js +105 -105
- package/lib/molecules/table.d.ts +42 -42
- package/lib/molecules/table.js +90 -90
- package/lib/molecules/useDimensionRef.d.ts +5 -5
- package/lib/molecules/useDimensionRef.js +30 -30
- package/lib/molecules/useScrollRef.d.ts +8 -8
- package/lib/molecules/useScrollRef.js +27 -27
- package/lib/organisms/generic-table.d.ts +9 -9
- package/lib/organisms/generic-table.js +35 -35
- package/lib/organisms/questionnaire-table-methods.d.ts +9 -9
- package/lib/organisms/questionnaire-table-methods.js +231 -231
- package/lib/organisms/questionnaire-table.d.ts +11 -11
- package/lib/organisms/questionnaire-table.js +44 -44
- package/package.json +8 -8
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var react_1 = require("react");
|
|
4
|
-
var useScrollRef = function (elementRef) {
|
|
5
|
-
var _a = react_1.useState(), scrollState = _a[0], setScrollState = _a[1];
|
|
6
|
-
var element = elementRef.current;
|
|
7
|
-
react_1.useEffect(function () {
|
|
8
|
-
var getScrollState = function () {
|
|
9
|
-
var _a, _b, _c, _d, _e, _f;
|
|
10
|
-
return ({
|
|
11
|
-
scrollWidth: (_a = element === null || element === void 0 ? void 0 : element.scrollWidth) !== null && _a !== void 0 ? _a : 0,
|
|
12
|
-
scrollHeight: (_b = element === null || element === void 0 ? void 0 : element.scrollHeight) !== null && _b !== void 0 ? _b : 0,
|
|
13
|
-
currentXScroll: ((_c = element === null || element === void 0 ? void 0 : element.scrollLeft) !== null && _c !== void 0 ? _c : 0) + ((_d = element === null || element === void 0 ? void 0 : element.clientWidth) !== null && _d !== void 0 ? _d : 0),
|
|
14
|
-
currentYScroll: ((_e = element === null || element === void 0 ? void 0 : element.scrollTop) !== null && _e !== void 0 ? _e : 0) + ((_f = element === null || element === void 0 ? void 0 : element.clientHeight) !== null && _f !== void 0 ? _f : 0),
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
var handleScroll = function () {
|
|
18
|
-
setScrollState(getScrollState());
|
|
19
|
-
};
|
|
20
|
-
element === null || element === void 0 ? void 0 : element.addEventListener('scroll', handleScroll);
|
|
21
|
-
return function () {
|
|
22
|
-
element === null || element === void 0 ? void 0 : element.removeEventListener('scroll', handleScroll);
|
|
23
|
-
};
|
|
24
|
-
}, [element]);
|
|
25
|
-
return scrollState;
|
|
26
|
-
};
|
|
27
|
-
exports.default = useScrollRef;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var react_1 = require("react");
|
|
4
|
+
var useScrollRef = function (elementRef) {
|
|
5
|
+
var _a = react_1.useState(), scrollState = _a[0], setScrollState = _a[1];
|
|
6
|
+
var element = elementRef.current;
|
|
7
|
+
react_1.useEffect(function () {
|
|
8
|
+
var getScrollState = function () {
|
|
9
|
+
var _a, _b, _c, _d, _e, _f;
|
|
10
|
+
return ({
|
|
11
|
+
scrollWidth: (_a = element === null || element === void 0 ? void 0 : element.scrollWidth) !== null && _a !== void 0 ? _a : 0,
|
|
12
|
+
scrollHeight: (_b = element === null || element === void 0 ? void 0 : element.scrollHeight) !== null && _b !== void 0 ? _b : 0,
|
|
13
|
+
currentXScroll: ((_c = element === null || element === void 0 ? void 0 : element.scrollLeft) !== null && _c !== void 0 ? _c : 0) + ((_d = element === null || element === void 0 ? void 0 : element.clientWidth) !== null && _d !== void 0 ? _d : 0),
|
|
14
|
+
currentYScroll: ((_e = element === null || element === void 0 ? void 0 : element.scrollTop) !== null && _e !== void 0 ? _e : 0) + ((_f = element === null || element === void 0 ? void 0 : element.clientHeight) !== null && _f !== void 0 ? _f : 0),
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
var handleScroll = function () {
|
|
18
|
+
setScrollState(getScrollState());
|
|
19
|
+
};
|
|
20
|
+
element === null || element === void 0 ? void 0 : element.addEventListener('scroll', handleScroll);
|
|
21
|
+
return function () {
|
|
22
|
+
element === null || element === void 0 ? void 0 : element.removeEventListener('scroll', handleScroll);
|
|
23
|
+
};
|
|
24
|
+
}, [element]);
|
|
25
|
+
return scrollState;
|
|
26
|
+
};
|
|
27
|
+
exports.default = useScrollRef;
|
|
28
28
|
//# sourceMappingURL=useScrollRef.js.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { IPaginationProps, ITableDimensionProps, ITableConfig, TableData } from '../molecules/table';
|
|
3
|
-
declare const GenericTable: <TColumn, TRow>({ columnData, rowData, mapToTableData, headerAxis, pageSize, currentPage, keepPreviousData, ...props }: IProps<TColumn, TRow>) => JSX.Element;
|
|
4
|
-
interface IProps<TColumn, TRow> extends ITableConfig, IPaginationProps, ITableDimensionProps {
|
|
5
|
-
columnData: TColumn;
|
|
6
|
-
rowData: TRow;
|
|
7
|
-
mapToTableData: (colData: TColumn, rowData: TRow) => TableData;
|
|
8
|
-
}
|
|
9
|
-
export default GenericTable;
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { IPaginationProps, ITableDimensionProps, ITableConfig, TableData } from '../molecules/table';
|
|
3
|
+
declare const GenericTable: <TColumn, TRow>({ columnData, rowData, mapToTableData, headerAxis, pageSize, currentPage, keepPreviousData, ...props }: IProps<TColumn, TRow>) => JSX.Element;
|
|
4
|
+
interface IProps<TColumn, TRow> extends ITableConfig, IPaginationProps, ITableDimensionProps {
|
|
5
|
+
columnData: TColumn;
|
|
6
|
+
rowData: TRow;
|
|
7
|
+
mapToTableData: (colData: TColumn, rowData: TRow) => TableData;
|
|
8
|
+
}
|
|
9
|
+
export default GenericTable;
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
14
|
-
var t = {};
|
|
15
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
16
|
-
t[p] = s[p];
|
|
17
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
18
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
19
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
20
|
-
t[p[i]] = s[p[i]];
|
|
21
|
-
}
|
|
22
|
-
return t;
|
|
23
|
-
};
|
|
24
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
25
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
26
|
-
};
|
|
27
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
29
|
-
var table_1 = __importDefault(require("../molecules/table"));
|
|
30
|
-
var GenericTable = function (_a) {
|
|
31
|
-
var columnData = _a.columnData, rowData = _a.rowData, mapToTableData = _a.mapToTableData, _b = _a.headerAxis, headerAxis = _b === void 0 ? 'x' : _b, _c = _a.pageSize, pageSize = _c === void 0 ? 10 : _c, _d = _a.currentPage, currentPage = _d === void 0 ? 1 : _d, _e = _a.keepPreviousData, keepPreviousData = _e === void 0 ? true : _e, props = __rest(_a, ["columnData", "rowData", "mapToTableData", "headerAxis", "pageSize", "currentPage", "keepPreviousData"]);
|
|
32
|
-
var tableData = mapToTableData(columnData, rowData);
|
|
33
|
-
return (jsx_runtime_1.jsx(table_1.default, __assign({ tableData: tableData, headerAxis: headerAxis, pageSize: pageSize, currentPage: currentPage, keepPreviousData: keepPreviousData }, props), void 0));
|
|
34
|
-
};
|
|
35
|
-
exports.default = GenericTable;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
14
|
+
var t = {};
|
|
15
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
16
|
+
t[p] = s[p];
|
|
17
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
18
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
19
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
20
|
+
t[p[i]] = s[p[i]];
|
|
21
|
+
}
|
|
22
|
+
return t;
|
|
23
|
+
};
|
|
24
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
25
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
26
|
+
};
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
29
|
+
var table_1 = __importDefault(require("../molecules/table"));
|
|
30
|
+
var GenericTable = function (_a) {
|
|
31
|
+
var columnData = _a.columnData, rowData = _a.rowData, mapToTableData = _a.mapToTableData, _b = _a.headerAxis, headerAxis = _b === void 0 ? 'x' : _b, _c = _a.pageSize, pageSize = _c === void 0 ? 10 : _c, _d = _a.currentPage, currentPage = _d === void 0 ? 1 : _d, _e = _a.keepPreviousData, keepPreviousData = _e === void 0 ? true : _e, props = __rest(_a, ["columnData", "rowData", "mapToTableData", "headerAxis", "pageSize", "currentPage", "keepPreviousData"]);
|
|
32
|
+
var tableData = mapToTableData(columnData, rowData);
|
|
33
|
+
return (jsx_runtime_1.jsx(table_1.default, __assign({ tableData: tableData, headerAxis: headerAxis, pageSize: pageSize, currentPage: currentPage, keepPreviousData: keepPreviousData }, props), void 0));
|
|
34
|
+
};
|
|
35
|
+
exports.default = GenericTable;
|
|
36
36
|
//# sourceMappingURL=generic-table.js.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ActionMenuOption } from '@ltht-react/menu';
|
|
2
|
-
import { Axis, Questionnaire, QuestionnaireResponse } from '@ltht-react/types';
|
|
3
|
-
import { TableData } from '../molecules/table';
|
|
4
|
-
declare const mapQuestionnaireDefinitionAndResponsesToTableData: (definition: Questionnaire, questionnaireResponses: QuestionnaireResponse[], axis: Axis, adminActions?: AdminActionsForQuestionnaire[] | undefined) => TableData | undefined;
|
|
5
|
-
export interface AdminActionsForQuestionnaire {
|
|
6
|
-
questionnaire: string;
|
|
7
|
-
adminActions: ActionMenuOption[];
|
|
8
|
-
}
|
|
9
|
-
export default mapQuestionnaireDefinitionAndResponsesToTableData;
|
|
1
|
+
import { ActionMenuOption } from '@ltht-react/menu';
|
|
2
|
+
import { Axis, Questionnaire, QuestionnaireResponse } from '@ltht-react/types';
|
|
3
|
+
import { TableData } from '../molecules/table';
|
|
4
|
+
declare const mapQuestionnaireDefinitionAndResponsesToTableData: (definition: Questionnaire, questionnaireResponses: QuestionnaireResponse[], axis: Axis, adminActions?: AdminActionsForQuestionnaire[] | undefined) => TableData | undefined;
|
|
5
|
+
export interface AdminActionsForQuestionnaire {
|
|
6
|
+
questionnaire: string;
|
|
7
|
+
adminActions: ActionMenuOption[];
|
|
8
|
+
}
|
|
9
|
+
export default mapQuestionnaireDefinitionAndResponsesToTableData;
|
|
@@ -1,232 +1,232 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
14
|
-
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
15
|
-
to[j] = from[i];
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
19
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
20
|
-
};
|
|
21
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
23
|
-
var types_1 = require("@ltht-react/types");
|
|
24
|
-
var utils_1 = require("@ltht-react/utils");
|
|
25
|
-
var styles_1 = require("@ltht-react/styles");
|
|
26
|
-
var questionnaire_withdrawn_table_cell_1 = __importDefault(require("../atoms/questionnaire-withdrawn-table-cell"));
|
|
27
|
-
var withdrawnWrapper = function (text) { return jsx_runtime_1.jsx(questionnaire_withdrawn_table_cell_1.default, { text: text }, void 0); };
|
|
28
|
-
var mapQuestionnaireDefinitionAndResponsesToTableData = function (definition, questionnaireResponses, axis, adminActions) {
|
|
29
|
-
var definitionItems = utils_1.EnsureMaybeArray(utils_1.EnsureMaybe(definition.item, []));
|
|
30
|
-
if (definitionItems.length === 0) {
|
|
31
|
-
return undefined;
|
|
32
|
-
}
|
|
33
|
-
if (axis === 'y') {
|
|
34
|
-
return mapQuestionnaireObjectsToVerticalTableData(definitionItems, questionnaireResponses, adminActions);
|
|
35
|
-
}
|
|
36
|
-
return mapQuestionnaireObjectsToHorizontalTableData(definitionItems, questionnaireResponses, adminActions);
|
|
37
|
-
};
|
|
38
|
-
var mapQuestionnaireObjectsToHorizontalTableData = function (definitionItems, records, adminActions) {
|
|
39
|
-
var tableData = {
|
|
40
|
-
headers: __spreadArray([
|
|
41
|
-
{
|
|
42
|
-
id: 'date',
|
|
43
|
-
type: 'accessor',
|
|
44
|
-
cellProps: { text: 'Record Date' },
|
|
45
|
-
}
|
|
46
|
-
], recursivelyMapQuestionnaireItemsIntoHeaders(definitionItems)),
|
|
47
|
-
rows: mapQuestionnaireResponsesIntoDataEntities(records, adminActions),
|
|
48
|
-
};
|
|
49
|
-
if (adminActions) {
|
|
50
|
-
tableData.headers.splice(1, 0, {
|
|
51
|
-
id: 'adminactions',
|
|
52
|
-
type: 'accessor',
|
|
53
|
-
cellProps: { text: 'Actions' },
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
return tableData;
|
|
57
|
-
};
|
|
58
|
-
var recursivelyMapQuestionnaireItemsIntoHeaders = function (questionnaireItems) {
|
|
59
|
-
return questionnaireItems.map(function (questionnaireItem) {
|
|
60
|
-
var _a, _b, _c;
|
|
61
|
-
var subItems = utils_1.EnsureMaybeArray((_a = questionnaireItem.item) !== null && _a !== void 0 ? _a : []);
|
|
62
|
-
return {
|
|
63
|
-
id: (_b = questionnaireItem === null || questionnaireItem === void 0 ? void 0 : questionnaireItem.linkId) !== null && _b !== void 0 ? _b : '',
|
|
64
|
-
type: subItems.length > 0 ? 'group' : 'accessor',
|
|
65
|
-
cellProps: { text: (_c = questionnaireItem === null || questionnaireItem === void 0 ? void 0 : questionnaireItem.text) !== null && _c !== void 0 ? _c : '' },
|
|
66
|
-
subHeaders: recursivelyMapQuestionnaireItemsIntoHeaders(subItems),
|
|
67
|
-
};
|
|
68
|
-
});
|
|
69
|
-
};
|
|
70
|
-
var mapQuestionnaireResponsesIntoDataEntities = function (records, adminActions) {
|
|
71
|
-
return records
|
|
72
|
-
.filter(function (record) { return !!record.item; })
|
|
73
|
-
.map(function (record) {
|
|
74
|
-
var _a;
|
|
75
|
-
var dataEntity = {};
|
|
76
|
-
dataEntity.date = {
|
|
77
|
-
customComponentOverride: record.status === types_1.QuestionnaireResponseStatus.EnteredInError
|
|
78
|
-
? withdrawnWrapper(utils_1.partialDateTimeText(record.authored))
|
|
79
|
-
: undefined,
|
|
80
|
-
text: utils_1.partialDateTimeText(record.authored),
|
|
81
|
-
};
|
|
82
|
-
if (adminActions) {
|
|
83
|
-
var adminActionsForThisDataEntity = adminActions.find(function (actionForForm) { return actionForForm.questionnaire === record.id; });
|
|
84
|
-
if (adminActionsForThisDataEntity) {
|
|
85
|
-
dataEntity.adminactions = {
|
|
86
|
-
adminActions: adminActionsForThisDataEntity.adminActions,
|
|
87
|
-
parentStyle: { zIndex: styles_1.getZIndex(styles_1.TableDataWithPopUp) },
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
(_a = record.item) === null || _a === void 0 ? void 0 : _a.filter(function (item) { return (item === null || item === void 0 ? void 0 : item.linkId) && (item === null || item === void 0 ? void 0 : item.answer); }).forEach(function (item) {
|
|
92
|
-
var _a;
|
|
93
|
-
var linkId = utils_1.EnsureMaybe(item === null || item === void 0 ? void 0 : item.linkId);
|
|
94
|
-
var answer = utils_1.EnsureMaybe((_a = item === null || item === void 0 ? void 0 : item.answer) === null || _a === void 0 ? void 0 : _a.find(function (answer) { return !!answer; }));
|
|
95
|
-
dataEntity[linkId] = createCellPropsForAnswer(answer, false, record.status === types_1.QuestionnaireResponseStatus.EnteredInError);
|
|
96
|
-
if (answer.item) {
|
|
97
|
-
dataEntity = recursivelyMapResponseItemsOntoData(utils_1.EnsureMaybeArray(answer.item), dataEntity, record.status);
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
return dataEntity;
|
|
101
|
-
});
|
|
102
|
-
};
|
|
103
|
-
var recursivelyMapResponseItemsOntoData = function (items, dataEntity, status) {
|
|
104
|
-
var updatedDataEntity = __assign({}, dataEntity);
|
|
105
|
-
items.forEach(function (item) {
|
|
106
|
-
var firstAnswer = item.answer ? item.answer[0] : undefined;
|
|
107
|
-
if (item.linkId && firstAnswer) {
|
|
108
|
-
var props = createCellPropsForAnswer(firstAnswer, false, status === types_1.QuestionnaireResponseStatus.EnteredInError);
|
|
109
|
-
updatedDataEntity[item.linkId] = {
|
|
110
|
-
customComponentOverride: props.customComponentOverride,
|
|
111
|
-
text: props.text,
|
|
112
|
-
};
|
|
113
|
-
if (firstAnswer.item) {
|
|
114
|
-
updatedDataEntity = recursivelyMapResponseItemsOntoData(utils_1.EnsureMaybeArray(firstAnswer.item), updatedDataEntity, status);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
return updatedDataEntity;
|
|
119
|
-
};
|
|
120
|
-
var mapQuestionnaireObjectsToVerticalTableData = function (definitionItems, records, adminActions) { return ({
|
|
121
|
-
headers: __spreadArray([
|
|
122
|
-
{
|
|
123
|
-
id: 'property',
|
|
124
|
-
type: 'accessor',
|
|
125
|
-
cellProps: { text: '' },
|
|
126
|
-
}
|
|
127
|
-
], records.map(function (record) {
|
|
128
|
-
var _a, _b, _c;
|
|
129
|
-
return ({
|
|
130
|
-
id: (_a = record === null || record === void 0 ? void 0 : record.id) !== null && _a !== void 0 ? _a : '',
|
|
131
|
-
type: 'accessor',
|
|
132
|
-
cellProps: {
|
|
133
|
-
customComponentOverride: record.status === types_1.QuestionnaireResponseStatus.EnteredInError
|
|
134
|
-
? withdrawnWrapper((_b = utils_1.partialDateTimeText(record.authored)) !== null && _b !== void 0 ? _b : '')
|
|
135
|
-
: undefined,
|
|
136
|
-
text: (_c = utils_1.partialDateTimeText(record.authored)) !== null && _c !== void 0 ? _c : '',
|
|
137
|
-
},
|
|
138
|
-
});
|
|
139
|
-
})),
|
|
140
|
-
rows: buildVerticalCellRows(definitionItems, records, adminActions),
|
|
141
|
-
}); };
|
|
142
|
-
var buildVerticalCellRows = function (definitionItems, records, adminActions) {
|
|
143
|
-
var dataEntities = definitionItems.map(function (item) {
|
|
144
|
-
var dataEntity = {};
|
|
145
|
-
dataEntity = buildVerticalCellRowsRecursive(utils_1.EnsureMaybeArray([item]), records, dataEntity);
|
|
146
|
-
return dataEntity;
|
|
147
|
-
});
|
|
148
|
-
if (adminActions) {
|
|
149
|
-
var actionsDataEntity_1 = {};
|
|
150
|
-
actionsDataEntity_1.property = { text: 'Actions' };
|
|
151
|
-
records.forEach(function (record) {
|
|
152
|
-
var adminActionsForThisDataEntity = adminActions.find(function (actionForForm) { return actionForForm.questionnaire === record.id; });
|
|
153
|
-
if (adminActionsForThisDataEntity) {
|
|
154
|
-
actionsDataEntity_1[record.id] = {
|
|
155
|
-
adminActions: adminActionsForThisDataEntity.adminActions,
|
|
156
|
-
parentStyle: { zIndex: styles_1.getZIndex(styles_1.TableDataWithPopUp) },
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
return [actionsDataEntity_1].concat(dataEntities);
|
|
161
|
-
}
|
|
162
|
-
return dataEntities;
|
|
163
|
-
};
|
|
164
|
-
var buildVerticalCellRowsRecursive = function (definitionItems, records, dataEntity) {
|
|
165
|
-
var updatedDataEntity = __assign({}, dataEntity);
|
|
166
|
-
definitionItems.forEach(function (definitionItem) {
|
|
167
|
-
var _a;
|
|
168
|
-
updatedDataEntity.property = { text: (_a = definitionItem.text) !== null && _a !== void 0 ? _a : '' };
|
|
169
|
-
if (definitionItem.linkId) {
|
|
170
|
-
records.forEach(function (record) {
|
|
171
|
-
var _a;
|
|
172
|
-
updatedDataEntity = getRecordItemByLinkId(utils_1.EnsureMaybeArray((_a = record.item) !== null && _a !== void 0 ? _a : []), utils_1.EnsureMaybe(definitionItem.linkId), updatedDataEntity, record.id, record.status);
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
if (definitionItem.item && definitionItem.item.length > 0) {
|
|
176
|
-
updatedDataEntity.subRows = buildVerticalCellRows(utils_1.EnsureMaybeArray(definitionItem.item), records);
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
return updatedDataEntity;
|
|
180
|
-
};
|
|
181
|
-
var getRecordItemByLinkId = function (recordItems, linkId, dataEntity, recordId, status) {
|
|
182
|
-
var updatedDataEntity = __assign({}, dataEntity);
|
|
183
|
-
recordItems.forEach(function (recordItem) {
|
|
184
|
-
var recordItemAnswer = recordItem.answer && recordItem.answer.length > 0 ? utils_1.EnsureMaybe(recordItem.answer[0]) : undefined;
|
|
185
|
-
if (recordItemAnswer) {
|
|
186
|
-
if ((recordItem === null || recordItem === void 0 ? void 0 : recordItem.linkId) && (recordItem === null || recordItem === void 0 ? void 0 : recordItem.linkId) === linkId) {
|
|
187
|
-
updatedDataEntity[recordId] = createCellPropsForAnswer(recordItemAnswer, true, status === types_1.QuestionnaireResponseStatus.EnteredInError);
|
|
188
|
-
}
|
|
189
|
-
if (recordItemAnswer.item && recordItemAnswer.item.length > 0) {
|
|
190
|
-
updatedDataEntity = getRecordItemByLinkId(utils_1.EnsureMaybeArray(recordItemAnswer.item), linkId, updatedDataEntity, recordId, status);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
return updatedDataEntity;
|
|
195
|
-
};
|
|
196
|
-
var createCellPropsForAnswer = function (answer, shouldRenderCheckbox, isEnteredInError) {
|
|
197
|
-
if (answer.valueString) {
|
|
198
|
-
if (shouldRenderCheckbox && answer.valueString === 'CHECKBOX') {
|
|
199
|
-
return {
|
|
200
|
-
iconProps: { type: 'checkbox', size: 'medium' },
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
return {
|
|
204
|
-
customComponentOverride: isEnteredInError ? withdrawnWrapper(answer.valueString) : undefined,
|
|
205
|
-
text: answer.valueString,
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
if (answer.valueBoolean != null) {
|
|
209
|
-
var parsedBoolean = answer.valueBoolean ? 'Yes' : 'No';
|
|
210
|
-
return {
|
|
211
|
-
customComponentOverride: isEnteredInError ? withdrawnWrapper(parsedBoolean) : undefined,
|
|
212
|
-
text: parsedBoolean,
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
if (answer.valueInteger != null) {
|
|
216
|
-
return {
|
|
217
|
-
customComponentOverride: isEnteredInError ? withdrawnWrapper(answer.valueInteger.toString()) : undefined,
|
|
218
|
-
text: answer.valueInteger.toString(),
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
if (answer.valueDecimal != null) {
|
|
222
|
-
return {
|
|
223
|
-
customComponentOverride: isEnteredInError ? withdrawnWrapper(answer.valueDecimal.toString()) : undefined,
|
|
224
|
-
text: answer.valueDecimal.toString(),
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
return {
|
|
228
|
-
text: '',
|
|
229
|
-
};
|
|
230
|
-
};
|
|
231
|
-
exports.default = mapQuestionnaireDefinitionAndResponsesToTableData;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
14
|
+
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
15
|
+
to[j] = from[i];
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
19
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
23
|
+
var types_1 = require("@ltht-react/types");
|
|
24
|
+
var utils_1 = require("@ltht-react/utils");
|
|
25
|
+
var styles_1 = require("@ltht-react/styles");
|
|
26
|
+
var questionnaire_withdrawn_table_cell_1 = __importDefault(require("../atoms/questionnaire-withdrawn-table-cell"));
|
|
27
|
+
var withdrawnWrapper = function (text) { return jsx_runtime_1.jsx(questionnaire_withdrawn_table_cell_1.default, { text: text }, void 0); };
|
|
28
|
+
var mapQuestionnaireDefinitionAndResponsesToTableData = function (definition, questionnaireResponses, axis, adminActions) {
|
|
29
|
+
var definitionItems = utils_1.EnsureMaybeArray(utils_1.EnsureMaybe(definition.item, []));
|
|
30
|
+
if (definitionItems.length === 0) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
if (axis === 'y') {
|
|
34
|
+
return mapQuestionnaireObjectsToVerticalTableData(definitionItems, questionnaireResponses, adminActions);
|
|
35
|
+
}
|
|
36
|
+
return mapQuestionnaireObjectsToHorizontalTableData(definitionItems, questionnaireResponses, adminActions);
|
|
37
|
+
};
|
|
38
|
+
var mapQuestionnaireObjectsToHorizontalTableData = function (definitionItems, records, adminActions) {
|
|
39
|
+
var tableData = {
|
|
40
|
+
headers: __spreadArray([
|
|
41
|
+
{
|
|
42
|
+
id: 'date',
|
|
43
|
+
type: 'accessor',
|
|
44
|
+
cellProps: { text: 'Record Date' },
|
|
45
|
+
}
|
|
46
|
+
], recursivelyMapQuestionnaireItemsIntoHeaders(definitionItems)),
|
|
47
|
+
rows: mapQuestionnaireResponsesIntoDataEntities(records, adminActions),
|
|
48
|
+
};
|
|
49
|
+
if (adminActions) {
|
|
50
|
+
tableData.headers.splice(1, 0, {
|
|
51
|
+
id: 'adminactions',
|
|
52
|
+
type: 'accessor',
|
|
53
|
+
cellProps: { text: 'Actions' },
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return tableData;
|
|
57
|
+
};
|
|
58
|
+
var recursivelyMapQuestionnaireItemsIntoHeaders = function (questionnaireItems) {
|
|
59
|
+
return questionnaireItems.map(function (questionnaireItem) {
|
|
60
|
+
var _a, _b, _c;
|
|
61
|
+
var subItems = utils_1.EnsureMaybeArray((_a = questionnaireItem.item) !== null && _a !== void 0 ? _a : []);
|
|
62
|
+
return {
|
|
63
|
+
id: (_b = questionnaireItem === null || questionnaireItem === void 0 ? void 0 : questionnaireItem.linkId) !== null && _b !== void 0 ? _b : '',
|
|
64
|
+
type: subItems.length > 0 ? 'group' : 'accessor',
|
|
65
|
+
cellProps: { text: (_c = questionnaireItem === null || questionnaireItem === void 0 ? void 0 : questionnaireItem.text) !== null && _c !== void 0 ? _c : '' },
|
|
66
|
+
subHeaders: recursivelyMapQuestionnaireItemsIntoHeaders(subItems),
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
var mapQuestionnaireResponsesIntoDataEntities = function (records, adminActions) {
|
|
71
|
+
return records
|
|
72
|
+
.filter(function (record) { return !!record.item; })
|
|
73
|
+
.map(function (record) {
|
|
74
|
+
var _a;
|
|
75
|
+
var dataEntity = {};
|
|
76
|
+
dataEntity.date = {
|
|
77
|
+
customComponentOverride: record.status === types_1.QuestionnaireResponseStatus.EnteredInError
|
|
78
|
+
? withdrawnWrapper(utils_1.partialDateTimeText(record.authored))
|
|
79
|
+
: undefined,
|
|
80
|
+
text: utils_1.partialDateTimeText(record.authored),
|
|
81
|
+
};
|
|
82
|
+
if (adminActions) {
|
|
83
|
+
var adminActionsForThisDataEntity = adminActions.find(function (actionForForm) { return actionForForm.questionnaire === record.id; });
|
|
84
|
+
if (adminActionsForThisDataEntity) {
|
|
85
|
+
dataEntity.adminactions = {
|
|
86
|
+
adminActions: adminActionsForThisDataEntity.adminActions,
|
|
87
|
+
parentStyle: { zIndex: styles_1.getZIndex(styles_1.TableDataWithPopUp) },
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
(_a = record.item) === null || _a === void 0 ? void 0 : _a.filter(function (item) { return (item === null || item === void 0 ? void 0 : item.linkId) && (item === null || item === void 0 ? void 0 : item.answer); }).forEach(function (item) {
|
|
92
|
+
var _a;
|
|
93
|
+
var linkId = utils_1.EnsureMaybe(item === null || item === void 0 ? void 0 : item.linkId);
|
|
94
|
+
var answer = utils_1.EnsureMaybe((_a = item === null || item === void 0 ? void 0 : item.answer) === null || _a === void 0 ? void 0 : _a.find(function (answer) { return !!answer; }));
|
|
95
|
+
dataEntity[linkId] = createCellPropsForAnswer(answer, false, record.status === types_1.QuestionnaireResponseStatus.EnteredInError);
|
|
96
|
+
if (answer.item) {
|
|
97
|
+
dataEntity = recursivelyMapResponseItemsOntoData(utils_1.EnsureMaybeArray(answer.item), dataEntity, record.status);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
return dataEntity;
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
var recursivelyMapResponseItemsOntoData = function (items, dataEntity, status) {
|
|
104
|
+
var updatedDataEntity = __assign({}, dataEntity);
|
|
105
|
+
items.forEach(function (item) {
|
|
106
|
+
var firstAnswer = item.answer ? item.answer[0] : undefined;
|
|
107
|
+
if (item.linkId && firstAnswer) {
|
|
108
|
+
var props = createCellPropsForAnswer(firstAnswer, false, status === types_1.QuestionnaireResponseStatus.EnteredInError);
|
|
109
|
+
updatedDataEntity[item.linkId] = {
|
|
110
|
+
customComponentOverride: props.customComponentOverride,
|
|
111
|
+
text: props.text,
|
|
112
|
+
};
|
|
113
|
+
if (firstAnswer.item) {
|
|
114
|
+
updatedDataEntity = recursivelyMapResponseItemsOntoData(utils_1.EnsureMaybeArray(firstAnswer.item), updatedDataEntity, status);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
return updatedDataEntity;
|
|
119
|
+
};
|
|
120
|
+
var mapQuestionnaireObjectsToVerticalTableData = function (definitionItems, records, adminActions) { return ({
|
|
121
|
+
headers: __spreadArray([
|
|
122
|
+
{
|
|
123
|
+
id: 'property',
|
|
124
|
+
type: 'accessor',
|
|
125
|
+
cellProps: { text: '' },
|
|
126
|
+
}
|
|
127
|
+
], records.map(function (record) {
|
|
128
|
+
var _a, _b, _c;
|
|
129
|
+
return ({
|
|
130
|
+
id: (_a = record === null || record === void 0 ? void 0 : record.id) !== null && _a !== void 0 ? _a : '',
|
|
131
|
+
type: 'accessor',
|
|
132
|
+
cellProps: {
|
|
133
|
+
customComponentOverride: record.status === types_1.QuestionnaireResponseStatus.EnteredInError
|
|
134
|
+
? withdrawnWrapper((_b = utils_1.partialDateTimeText(record.authored)) !== null && _b !== void 0 ? _b : '')
|
|
135
|
+
: undefined,
|
|
136
|
+
text: (_c = utils_1.partialDateTimeText(record.authored)) !== null && _c !== void 0 ? _c : '',
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
})),
|
|
140
|
+
rows: buildVerticalCellRows(definitionItems, records, adminActions),
|
|
141
|
+
}); };
|
|
142
|
+
var buildVerticalCellRows = function (definitionItems, records, adminActions) {
|
|
143
|
+
var dataEntities = definitionItems.map(function (item) {
|
|
144
|
+
var dataEntity = {};
|
|
145
|
+
dataEntity = buildVerticalCellRowsRecursive(utils_1.EnsureMaybeArray([item]), records, dataEntity);
|
|
146
|
+
return dataEntity;
|
|
147
|
+
});
|
|
148
|
+
if (adminActions) {
|
|
149
|
+
var actionsDataEntity_1 = {};
|
|
150
|
+
actionsDataEntity_1.property = { text: 'Actions' };
|
|
151
|
+
records.forEach(function (record) {
|
|
152
|
+
var adminActionsForThisDataEntity = adminActions.find(function (actionForForm) { return actionForForm.questionnaire === record.id; });
|
|
153
|
+
if (adminActionsForThisDataEntity) {
|
|
154
|
+
actionsDataEntity_1[record.id] = {
|
|
155
|
+
adminActions: adminActionsForThisDataEntity.adminActions,
|
|
156
|
+
parentStyle: { zIndex: styles_1.getZIndex(styles_1.TableDataWithPopUp) },
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
return [actionsDataEntity_1].concat(dataEntities);
|
|
161
|
+
}
|
|
162
|
+
return dataEntities;
|
|
163
|
+
};
|
|
164
|
+
var buildVerticalCellRowsRecursive = function (definitionItems, records, dataEntity) {
|
|
165
|
+
var updatedDataEntity = __assign({}, dataEntity);
|
|
166
|
+
definitionItems.forEach(function (definitionItem) {
|
|
167
|
+
var _a;
|
|
168
|
+
updatedDataEntity.property = { text: (_a = definitionItem.text) !== null && _a !== void 0 ? _a : '' };
|
|
169
|
+
if (definitionItem.linkId) {
|
|
170
|
+
records.forEach(function (record) {
|
|
171
|
+
var _a;
|
|
172
|
+
updatedDataEntity = getRecordItemByLinkId(utils_1.EnsureMaybeArray((_a = record.item) !== null && _a !== void 0 ? _a : []), utils_1.EnsureMaybe(definitionItem.linkId), updatedDataEntity, record.id, record.status);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
if (definitionItem.item && definitionItem.item.length > 0) {
|
|
176
|
+
updatedDataEntity.subRows = buildVerticalCellRows(utils_1.EnsureMaybeArray(definitionItem.item), records);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
return updatedDataEntity;
|
|
180
|
+
};
|
|
181
|
+
var getRecordItemByLinkId = function (recordItems, linkId, dataEntity, recordId, status) {
|
|
182
|
+
var updatedDataEntity = __assign({}, dataEntity);
|
|
183
|
+
recordItems.forEach(function (recordItem) {
|
|
184
|
+
var recordItemAnswer = recordItem.answer && recordItem.answer.length > 0 ? utils_1.EnsureMaybe(recordItem.answer[0]) : undefined;
|
|
185
|
+
if (recordItemAnswer) {
|
|
186
|
+
if ((recordItem === null || recordItem === void 0 ? void 0 : recordItem.linkId) && (recordItem === null || recordItem === void 0 ? void 0 : recordItem.linkId) === linkId) {
|
|
187
|
+
updatedDataEntity[recordId] = createCellPropsForAnswer(recordItemAnswer, true, status === types_1.QuestionnaireResponseStatus.EnteredInError);
|
|
188
|
+
}
|
|
189
|
+
if (recordItemAnswer.item && recordItemAnswer.item.length > 0) {
|
|
190
|
+
updatedDataEntity = getRecordItemByLinkId(utils_1.EnsureMaybeArray(recordItemAnswer.item), linkId, updatedDataEntity, recordId, status);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
return updatedDataEntity;
|
|
195
|
+
};
|
|
196
|
+
var createCellPropsForAnswer = function (answer, shouldRenderCheckbox, isEnteredInError) {
|
|
197
|
+
if (answer.valueString) {
|
|
198
|
+
if (shouldRenderCheckbox && answer.valueString === 'CHECKBOX') {
|
|
199
|
+
return {
|
|
200
|
+
iconProps: { type: 'checkbox', size: 'medium' },
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
return {
|
|
204
|
+
customComponentOverride: isEnteredInError ? withdrawnWrapper(answer.valueString) : undefined,
|
|
205
|
+
text: answer.valueString,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
if (answer.valueBoolean != null) {
|
|
209
|
+
var parsedBoolean = answer.valueBoolean ? 'Yes' : 'No';
|
|
210
|
+
return {
|
|
211
|
+
customComponentOverride: isEnteredInError ? withdrawnWrapper(parsedBoolean) : undefined,
|
|
212
|
+
text: parsedBoolean,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
if (answer.valueInteger != null) {
|
|
216
|
+
return {
|
|
217
|
+
customComponentOverride: isEnteredInError ? withdrawnWrapper(answer.valueInteger.toString()) : undefined,
|
|
218
|
+
text: answer.valueInteger.toString(),
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
if (answer.valueDecimal != null) {
|
|
222
|
+
return {
|
|
223
|
+
customComponentOverride: isEnteredInError ? withdrawnWrapper(answer.valueDecimal.toString()) : undefined,
|
|
224
|
+
text: answer.valueDecimal.toString(),
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
return {
|
|
228
|
+
text: '',
|
|
229
|
+
};
|
|
230
|
+
};
|
|
231
|
+
exports.default = mapQuestionnaireDefinitionAndResponsesToTableData;
|
|
232
232
|
//# sourceMappingURL=questionnaire-table-methods.js.map
|