@ltht-react/table 1.0.112 → 1.0.114

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.
Files changed (47) hide show
  1. package/README.md +15 -15
  2. package/lib/atoms/questionnaire-withdrawn-table-cell.d.ts +6 -6
  3. package/lib/atoms/questionnaire-withdrawn-table-cell.js +18 -18
  4. package/lib/index.d.ts +6 -6
  5. package/lib/index.js +12 -12
  6. package/lib/molecules/table-cell.d.ts +16 -16
  7. package/lib/molecules/table-cell.js +95 -95
  8. package/lib/molecules/table-component.d.ts +22 -22
  9. package/lib/molecules/table-component.js +71 -71
  10. package/lib/molecules/table-methods.d.ts +11 -12
  11. package/lib/molecules/table-methods.js +193 -209
  12. package/lib/molecules/table-methods.js.map +1 -1
  13. package/lib/molecules/table-styled-components.d.ts +86 -86
  14. package/lib/molecules/table-styled-components.js +105 -105
  15. package/lib/molecules/table-styled-components.js.map +1 -1
  16. package/lib/molecules/table.d.ts +37 -37
  17. package/lib/molecules/table.js +90 -98
  18. package/lib/molecules/table.js.map +1 -1
  19. package/lib/molecules/useDimensionRef.d.ts +5 -5
  20. package/lib/molecules/useDimensionRef.js +30 -30
  21. package/lib/molecules/useScrollRef.d.ts +8 -8
  22. package/lib/molecules/useScrollRef.js +27 -27
  23. package/lib/organisms/generic-table.d.ts +11 -11
  24. package/lib/organisms/generic-table.js +35 -35
  25. package/lib/organisms/questionnaire-table-methods.d.ts +9 -9
  26. package/lib/organisms/questionnaire-table-methods.js +231 -231
  27. package/lib/organisms/questionnaire-table.d.ts +13 -13
  28. package/lib/organisms/questionnaire-table.js +44 -44
  29. package/package.json +8 -8
  30. package/lib/atoms/horizontal.d.ts +0 -8
  31. package/lib/atoms/horizontal.js +0 -130
  32. package/lib/atoms/horizontal.js.map +0 -1
  33. package/lib/atoms/table.d.ts +0 -36
  34. package/lib/atoms/table.js +0 -106
  35. package/lib/atoms/table.js.map +0 -1
  36. package/lib/atoms/vertical.d.ts +0 -8
  37. package/lib/atoms/vertical.js +0 -89
  38. package/lib/atoms/vertical.js.map +0 -1
  39. package/lib/molecules/generic-table.d.ts +0 -11
  40. package/lib/molecules/generic-table.js +0 -36
  41. package/lib/molecules/generic-table.js.map +0 -1
  42. package/lib/molecules/questionnaire-table.d.ts +0 -12
  43. package/lib/molecules/questionnaire-table.js +0 -131
  44. package/lib/molecules/questionnaire-table.js.map +0 -1
  45. package/lib/types.d.ts +0 -3
  46. package/lib/types.js +0 -3
  47. package/lib/types.js.map +0 -1
@@ -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
@@ -1,13 +1,13 @@
1
- import { QuestionnaireResponse, Axis, Questionnaire } from '@ltht-react/types';
2
- import { FC } from 'react';
3
- import { IPaginationProps, ITableDimensionProps } from '../molecules/table';
4
- import { AdminActionsForQuestionnaire } from './questionnaire-table-methods';
5
- declare const QuestionnaireTable: FC<IProps>;
6
- interface IProps extends IPaginationProps, ITableDimensionProps {
7
- definition: Questionnaire;
8
- records: QuestionnaireResponse[];
9
- headerAxis?: Axis;
10
- adminActions?: AdminActionsForQuestionnaire[];
11
- staticColumns?: 0 | 1 | 2;
12
- }
13
- export default QuestionnaireTable;
1
+ import { QuestionnaireResponse, Axis, Questionnaire } from '@ltht-react/types';
2
+ import { FC } from 'react';
3
+ import { IPaginationProps, ITableDimensionProps } from '../molecules/table';
4
+ import { AdminActionsForQuestionnaire } from './questionnaire-table-methods';
5
+ declare const QuestionnaireTable: FC<IProps>;
6
+ interface IProps extends IPaginationProps, ITableDimensionProps {
7
+ definition: Questionnaire;
8
+ records: QuestionnaireResponse[];
9
+ headerAxis?: Axis;
10
+ adminActions?: AdminActionsForQuestionnaire[];
11
+ staticColumns?: 0 | 1 | 2;
12
+ }
13
+ export default QuestionnaireTable;
@@ -1,45 +1,45 @@
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 react_1 = require("react");
30
- var icon_1 = __importDefault(require("@ltht-react/icon"));
31
- var table_1 = __importDefault(require("../molecules/table"));
32
- var questionnaire_table_methods_1 = __importDefault(require("./questionnaire-table-methods"));
33
- var QuestionnaireTable = function (_a) {
34
- var definition = _a.definition, records = _a.records, _b = _a.headerAxis, headerAxis = _b === void 0 ? 'y' : _b, _c = _a.staticColumns, staticColumns = _c === void 0 ? 0 : _c, adminActions = _a.adminActions, _d = _a.pageSize, pageSize = _d === void 0 ? 10 : _d, _e = _a.currentPage, currentPage = _e === void 0 ? 1 : _e, _f = _a.keepPreviousData, keepPreviousData = _f === void 0 ? true : _f, props = __rest(_a, ["definition", "records", "headerAxis", "staticColumns", "adminActions", "pageSize", "currentPage", "keepPreviousData"]);
35
- var tableData = react_1.useMemo(function () { return questionnaire_table_methods_1.default(definition, records, headerAxis, adminActions); }, [headerAxis, definition, records, adminActions]);
36
- // TODO: Replace this fragment with a properly styled error component.
37
- // Maybe this could be a re-usable atom?
38
- if (!tableData) {
39
- return (jsx_runtime_1.jsxs(jsx_runtime_1.Fragment, { children: [jsx_runtime_1.jsx(icon_1.default, { type: "exclamation", size: "large", color: "red" }, void 0),
40
- jsx_runtime_1.jsx("div", { children: "An error occurred whilst loading this table." }, void 0)] }, void 0));
41
- }
42
- return (jsx_runtime_1.jsx(table_1.default, __assign({ tableData: tableData, staticColumns: staticColumns, headerAxis: headerAxis, pageSize: pageSize, currentPage: currentPage, keepPreviousData: keepPreviousData }, props), void 0));
43
- };
44
- exports.default = QuestionnaireTable;
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 react_1 = require("react");
30
+ var icon_1 = __importDefault(require("@ltht-react/icon"));
31
+ var table_1 = __importDefault(require("../molecules/table"));
32
+ var questionnaire_table_methods_1 = __importDefault(require("./questionnaire-table-methods"));
33
+ var QuestionnaireTable = function (_a) {
34
+ var definition = _a.definition, records = _a.records, _b = _a.headerAxis, headerAxis = _b === void 0 ? 'y' : _b, _c = _a.staticColumns, staticColumns = _c === void 0 ? 0 : _c, adminActions = _a.adminActions, _d = _a.pageSize, pageSize = _d === void 0 ? 10 : _d, _e = _a.currentPage, currentPage = _e === void 0 ? 1 : _e, _f = _a.keepPreviousData, keepPreviousData = _f === void 0 ? true : _f, props = __rest(_a, ["definition", "records", "headerAxis", "staticColumns", "adminActions", "pageSize", "currentPage", "keepPreviousData"]);
35
+ var tableData = react_1.useMemo(function () { return questionnaire_table_methods_1.default(definition, records, headerAxis, adminActions); }, [headerAxis, definition, records, adminActions]);
36
+ // TODO: Replace this fragment with a properly styled error component.
37
+ // Maybe this could be a re-usable atom?
38
+ if (!tableData) {
39
+ return (jsx_runtime_1.jsxs(jsx_runtime_1.Fragment, { children: [jsx_runtime_1.jsx(icon_1.default, { type: "exclamation", size: "large", color: "red" }, void 0),
40
+ jsx_runtime_1.jsx("div", { children: "An error occurred whilst loading this table." }, void 0)] }, void 0));
41
+ }
42
+ return (jsx_runtime_1.jsx(table_1.default, __assign({ tableData: tableData, staticColumns: staticColumns, headerAxis: headerAxis, pageSize: pageSize, currentPage: currentPage, keepPreviousData: keepPreviousData }, props), void 0));
43
+ };
44
+ exports.default = QuestionnaireTable;
45
45
  //# sourceMappingURL=questionnaire-table.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ltht-react/table",
3
- "version": "1.0.112",
3
+ "version": "1.0.114",
4
4
  "description": "ltht-react Table component.",
5
5
  "author": "LTHT",
6
6
  "homepage": "",
@@ -27,17 +27,17 @@
27
27
  "dependencies": {
28
28
  "@emotion/react": "^11.0.0",
29
29
  "@emotion/styled": "^11.0.0",
30
- "@ltht-react/button": "^1.3.237",
31
- "@ltht-react/icon": "^1.3.237",
32
- "@ltht-react/menu": "^1.0.79",
33
- "@ltht-react/styles": "^1.3.229",
34
- "@ltht-react/types": "^1.0.233",
35
- "@ltht-react/utils": "^1.1.235",
30
+ "@ltht-react/button": "^1.3.239",
31
+ "@ltht-react/icon": "^1.3.239",
32
+ "@ltht-react/menu": "^1.0.81",
33
+ "@ltht-react/styles": "^1.3.231",
34
+ "@ltht-react/types": "^1.0.235",
35
+ "@ltht-react/utils": "^1.1.237",
36
36
  "@tanstack/react-table": "^8.5.22",
37
37
  "react": "^17.0.0",
38
38
  "react-uuid": "^2.0.0"
39
39
  },
40
- "gitHead": "5b7b8c7975543e372387d9179ee8e252c6c18d1a",
40
+ "gitHead": "ce1b99e5104749fb5b82268597921fa8b563e037",
41
41
  "devDependencies": {
42
42
  "@types/react-table": "^7.7.12"
43
43
  }
@@ -1,8 +0,0 @@
1
- import { FC } from 'react';
2
- import { Maybe, QuestionnaireItem, QuestionnaireResponse } from '@ltht-react/types';
3
- declare const HorizontalTable: FC<IProps>;
4
- interface IProps {
5
- definitionItems: Array<Maybe<QuestionnaireItem>>;
6
- records: QuestionnaireResponse[];
7
- }
8
- export default HorizontalTable;