@ltht-react/table 2.0.119 → 2.0.121

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.
@@ -1,334 +1,349 @@
1
- import { ActionMenuOption } from '@ltht-react/menu'
2
- import {
3
- Axis,
4
- Maybe,
5
- Questionnaire,
6
- QuestionnaireItem,
7
- QuestionnaireResponse,
8
- QuestionnaireResponseItem,
9
- QuestionnaireResponseItemAnswer,
10
- QuestionnaireResponseStatus,
11
- } from '@ltht-react/types'
12
- import { EnsureMaybe, EnsureMaybeArray, partialDateTimeText } from '@ltht-react/utils'
13
- import { getZIndex, TableDataWithPopUp } from '@ltht-react/styles'
14
- import { DataEntity, Header, TableData } from '../molecules/table'
15
- import { CellProps } from '../molecules/table-cell'
16
- import QuestionnaireWithdrawnTableCell from '../atoms/questionnaire-withdrawn-table-cell'
17
-
18
- const withdrawnWrapper = (text: string): JSX.Element => <QuestionnaireWithdrawnTableCell text={text} />
19
-
20
- const mapQuestionnaireDefinitionAndResponsesToTableData = (
21
- definition: Questionnaire,
22
- questionnaireResponses: QuestionnaireResponse[],
23
- axis: Axis,
24
- adminActions?: AdminActionsForQuestionnaire[]
25
- ): TableData | undefined => {
26
- const definitionItems = EnsureMaybeArray<QuestionnaireItem>(
27
- EnsureMaybe<Maybe<QuestionnaireItem>[]>(definition.item, [])
28
- )
29
-
30
- if (definitionItems.length === 0) {
31
- return undefined
32
- }
33
-
34
- if (axis === 'y') {
35
- return mapQuestionnaireObjectsToVerticalTableData(definitionItems, questionnaireResponses, adminActions)
36
- }
37
- return mapQuestionnaireObjectsToHorizontalTableData(definitionItems, questionnaireResponses, adminActions)
38
- }
39
-
40
- const mapQuestionnaireObjectsToHorizontalTableData = (
41
- definitionItems: Array<QuestionnaireItem>,
42
- records: QuestionnaireResponse[],
43
- adminActions?: AdminActionsForQuestionnaire[]
44
- ): TableData => {
45
- const tableData: TableData = {
46
- headers: [
47
- {
48
- id: 'date',
49
- type: 'accessor',
50
- cellProps: { text: 'Record Date' },
51
- },
52
- ...recursivelyMapQuestionnaireItemsIntoHeaders(definitionItems),
53
- ],
54
- rows: mapQuestionnaireResponsesIntoDataEntities(records, adminActions),
55
- }
56
-
57
- if (adminActions) {
58
- tableData.headers.splice(1, 0, {
59
- id: 'adminactions',
60
- type: 'accessor',
61
- cellProps: { text: 'Actions' },
62
- })
63
- }
64
- return tableData
65
- }
66
-
67
- const recursivelyMapQuestionnaireItemsIntoHeaders = (questionnaireItems: QuestionnaireItem[]): Header[] =>
68
- questionnaireItems.map((questionnaireItem) => {
69
- const subItems = EnsureMaybeArray<QuestionnaireItem>(questionnaireItem.item ?? [])
70
-
71
- return {
72
- id: questionnaireItem?.linkId ?? '',
73
- type: subItems.length > 0 ? 'group' : 'accessor',
74
- cellProps: { text: questionnaireItem?.text ?? '' },
75
- subHeaders: recursivelyMapQuestionnaireItemsIntoHeaders(subItems),
76
- }
77
- })
78
-
79
- const mapQuestionnaireResponsesIntoDataEntities = (
80
- records: QuestionnaireResponse[],
81
- adminActions?: AdminActionsForQuestionnaire[]
82
- ): DataEntity[] =>
83
- records
84
- .filter((record) => !!record.item)
85
- .map((record) => {
86
- let dataEntity: DataEntity = {}
87
-
88
- dataEntity.date = {
89
- customComponentOverride:
90
- record.status === QuestionnaireResponseStatus.EnteredInError
91
- ? withdrawnWrapper(partialDateTimeText(record.authored))
92
- : undefined,
93
- text: partialDateTimeText(record.authored),
94
- }
95
-
96
- if (adminActions) {
97
- const adminActionsForThisDataEntity = adminActions.find(
98
- (actionForForm) => actionForForm.questionnaire === record.id
99
- )
100
- if (adminActionsForThisDataEntity) {
101
- dataEntity.adminactions = {
102
- adminActions: adminActionsForThisDataEntity.adminActions,
103
- parentStyle: { zIndex: getZIndex(TableDataWithPopUp) },
104
- }
105
- }
106
- }
107
- record.item
108
- ?.filter((item) => item?.linkId && item?.answer)
109
- .forEach((item) => {
110
- const linkId = EnsureMaybe<string>(item?.linkId)
111
- const answer = EnsureMaybe<QuestionnaireResponseItemAnswer>(item?.answer?.find((answer) => !!answer))
112
-
113
- dataEntity[linkId] = createCellPropsForAnswer(
114
- answer,
115
- false,
116
- record.status === QuestionnaireResponseStatus.EnteredInError
117
- )
118
-
119
- if (answer.item) {
120
- dataEntity = recursivelyMapResponseItemsOntoData(
121
- EnsureMaybeArray<QuestionnaireResponseItem>(answer.item),
122
- dataEntity,
123
- record.status
124
- )
125
- }
126
- })
127
-
128
- return dataEntity
129
- })
130
-
131
- const recursivelyMapResponseItemsOntoData = (
132
- items: QuestionnaireResponseItem[],
133
- dataEntity: DataEntity,
134
- status: QuestionnaireResponseStatus
135
- ): DataEntity => {
136
- let updatedDataEntity = { ...dataEntity }
137
- items.forEach((item) => {
138
- const firstAnswer = item.answer ? item.answer[0] : undefined
139
-
140
- if (item.linkId && firstAnswer) {
141
- const props = createCellPropsForAnswer(firstAnswer, false, status === QuestionnaireResponseStatus.EnteredInError)
142
- updatedDataEntity[item.linkId] = {
143
- customComponentOverride: props.customComponentOverride,
144
- text: props.text,
145
- }
146
-
147
- if (firstAnswer.item) {
148
- updatedDataEntity = recursivelyMapResponseItemsOntoData(
149
- EnsureMaybeArray<QuestionnaireResponseItem>(firstAnswer.item),
150
- updatedDataEntity,
151
- status
152
- )
153
- }
154
- }
155
- })
156
- return updatedDataEntity
157
- }
158
-
159
- const mapQuestionnaireObjectsToVerticalTableData = (
160
- definitionItems: Array<QuestionnaireItem>,
161
- records: QuestionnaireResponse[],
162
- adminActions?: AdminActionsForQuestionnaire[]
163
- ): TableData => ({
164
- headers: [
165
- {
166
- id: 'property',
167
- type: 'accessor',
168
- cellProps: { text: '' },
169
- },
170
- ...records.map(
171
- (record): Header => ({
172
- id: record?.id ?? '',
173
- type: 'accessor',
174
- cellProps: {
175
- customComponentOverride:
176
- record.status === QuestionnaireResponseStatus.EnteredInError
177
- ? withdrawnWrapper(partialDateTimeText(record.authored) ?? '')
178
- : undefined,
179
- text: partialDateTimeText(record.authored) ?? '',
180
- },
181
- })
182
- ),
183
- ],
184
- rows: buildVerticalCellRows(definitionItems, records, adminActions),
185
- })
186
-
187
- const buildVerticalCellRows = (
188
- definitionItems: QuestionnaireItem[],
189
- records: QuestionnaireResponse[],
190
- adminActions?: AdminActionsForQuestionnaire[]
191
- ): DataEntity[] => {
192
- const dataEntities = definitionItems.map((item) => {
193
- let dataEntity: DataEntity = {}
194
-
195
- dataEntity = buildVerticalCellRowsRecursive(EnsureMaybeArray<QuestionnaireItem>([item]), records, dataEntity)
196
-
197
- return dataEntity
198
- })
199
-
200
- if (adminActions) {
201
- const actionsDataEntity: DataEntity = {}
202
- actionsDataEntity.property = { text: 'Actions' }
203
-
204
- records.forEach((record) => {
205
- const adminActionsForThisDataEntity = adminActions.find(
206
- (actionForForm) => actionForForm.questionnaire === record.id
207
- )
208
-
209
- if (adminActionsForThisDataEntity) {
210
- actionsDataEntity[record.id] = {
211
- adminActions: adminActionsForThisDataEntity.adminActions,
212
- parentStyle: { zIndex: getZIndex(TableDataWithPopUp) },
213
- }
214
- }
215
- })
216
-
217
- return [actionsDataEntity].concat(dataEntities)
218
- }
219
- return dataEntities
220
- }
221
-
222
- const buildVerticalCellRowsRecursive = (
223
- definitionItems: QuestionnaireItem[],
224
- records: QuestionnaireResponse[],
225
- dataEntity: DataEntity
226
- ): DataEntity => {
227
- let updatedDataEntity = { ...dataEntity }
228
- definitionItems.forEach((definitionItem) => {
229
- updatedDataEntity.property = { text: definitionItem.text ?? '' }
230
-
231
- if (definitionItem.linkId) {
232
- records.forEach((record) => {
233
- updatedDataEntity = getRecordItemByLinkId(
234
- EnsureMaybeArray<QuestionnaireResponseItem>(record.item ?? []),
235
- EnsureMaybe<string>(definitionItem.linkId),
236
- updatedDataEntity,
237
- record.id,
238
- record.status
239
- )
240
- })
241
- }
242
-
243
- if (definitionItem.item && definitionItem.item.length > 0) {
244
- updatedDataEntity.subRows = buildVerticalCellRows(
245
- EnsureMaybeArray<QuestionnaireItem>(definitionItem.item),
246
- records
247
- )
248
- }
249
- })
250
-
251
- return updatedDataEntity
252
- }
253
-
254
- const getRecordItemByLinkId = (
255
- recordItems: QuestionnaireResponseItem[],
256
- linkId: string,
257
- dataEntity: DataEntity,
258
- recordId: string,
259
- status: QuestionnaireResponseStatus
260
- ) => {
261
- let updatedDataEntity = { ...dataEntity }
262
- recordItems.forEach((recordItem) => {
263
- const recordItemAnswer =
264
- recordItem.answer && recordItem.answer.length > 0 ? EnsureMaybe(recordItem.answer[0]) : undefined
265
-
266
- if (recordItemAnswer) {
267
- if (recordItem?.linkId && recordItem?.linkId === linkId) {
268
- updatedDataEntity[recordId] = createCellPropsForAnswer(
269
- recordItemAnswer,
270
- true,
271
- status === QuestionnaireResponseStatus.EnteredInError
272
- )
273
- }
274
- if (recordItemAnswer.item && recordItemAnswer.item.length > 0) {
275
- updatedDataEntity = getRecordItemByLinkId(
276
- EnsureMaybeArray<QuestionnaireResponseItem>(recordItemAnswer.item),
277
- linkId,
278
- updatedDataEntity,
279
- recordId,
280
- status
281
- )
282
- }
283
- }
284
- })
285
-
286
- return updatedDataEntity
287
- }
288
-
289
- const createCellPropsForAnswer = (
290
- answer: QuestionnaireResponseItemAnswer,
291
- shouldRenderCheckbox: boolean,
292
- isEnteredInError: boolean
293
- ): CellProps => {
294
- if (answer.valueString) {
295
- if (shouldRenderCheckbox && answer.valueString === 'CHECKBOX') {
296
- return {
297
- iconProps: { type: 'checkbox', size: 'medium' },
298
- }
299
- }
300
- return {
301
- customComponentOverride: isEnteredInError ? withdrawnWrapper(answer.valueString) : undefined,
302
- text: answer.valueString,
303
- }
304
- }
305
- if (answer.valueBoolean != null) {
306
- const parsedBoolean = answer.valueBoolean ? 'Yes' : 'No'
307
- return {
308
- customComponentOverride: isEnteredInError ? withdrawnWrapper(parsedBoolean) : undefined,
309
- text: parsedBoolean,
310
- }
311
- }
312
- if (answer.valueInteger != null) {
313
- return {
314
- customComponentOverride: isEnteredInError ? withdrawnWrapper(answer.valueInteger.toString()) : undefined,
315
- text: answer.valueInteger.toString(),
316
- }
317
- }
318
- if (answer.valueDecimal != null) {
319
- return {
320
- customComponentOverride: isEnteredInError ? withdrawnWrapper(answer.valueDecimal.toString()) : undefined,
321
- text: answer.valueDecimal.toString(),
322
- }
323
- }
324
- return {
325
- text: '',
326
- }
327
- }
328
-
329
- export interface AdminActionsForQuestionnaire {
330
- questionnaire: string
331
- adminActions: ActionMenuOption[]
332
- }
333
-
334
- export default mapQuestionnaireDefinitionAndResponsesToTableData
1
+ import { CSSProperties } from 'react'
2
+ import { ActionMenuOption } from '@ltht-react/menu'
3
+ import {
4
+ Axis,
5
+ Maybe,
6
+ Questionnaire,
7
+ QuestionnaireItem,
8
+ QuestionnaireResponse,
9
+ QuestionnaireResponseItem,
10
+ QuestionnaireResponseItemAnswer,
11
+ QuestionnaireResponseStatus,
12
+ } from '@ltht-react/types'
13
+ import { EnsureMaybe, EnsureMaybeArray, partialDateTimeText } from '@ltht-react/utils'
14
+ import { getZIndex, TableDataWithPopUp } from '@ltht-react/styles'
15
+ import { DataEntity, Header, TableData } from '../molecules/table'
16
+ import { CellProps } from '../molecules/table-cell'
17
+ import QuestionnaireWithdrawnTableCell from '../atoms/questionnaire-withdrawn-table-cell'
18
+
19
+ const DEFAULT_VERTICAL_HEADER_CELL_STYLE: CSSProperties = {
20
+ maxWidth: '15rem',
21
+ textWrap: 'wrap',
22
+ textAlign: 'left',
23
+ }
24
+
25
+ const withdrawnWrapper = (text: string): JSX.Element => <QuestionnaireWithdrawnTableCell text={text} />
26
+
27
+ const mapQuestionnaireDefinitionAndResponsesToTableData = (
28
+ definition: Questionnaire,
29
+ questionnaireResponses: QuestionnaireResponse[],
30
+ axis: Axis,
31
+ adminActions?: AdminActionsForQuestionnaire[]
32
+ ): TableData | undefined => {
33
+ const definitionItems = EnsureMaybeArray<QuestionnaireItem>(
34
+ EnsureMaybe<Maybe<QuestionnaireItem>[]>(definition.item, [])
35
+ )
36
+
37
+ if (definitionItems.length === 0) {
38
+ return undefined
39
+ }
40
+
41
+ if (axis === 'y') {
42
+ return mapQuestionnaireObjectsToVerticalTableData(definitionItems, questionnaireResponses, adminActions)
43
+ }
44
+ return mapQuestionnaireObjectsToHorizontalTableData(definitionItems, questionnaireResponses, adminActions)
45
+ }
46
+
47
+ const mapQuestionnaireObjectsToHorizontalTableData = (
48
+ definitionItems: Array<QuestionnaireItem>,
49
+ records: QuestionnaireResponse[],
50
+ adminActions?: AdminActionsForQuestionnaire[]
51
+ ): TableData => {
52
+ const tableData: TableData = {
53
+ headers: [
54
+ {
55
+ id: 'date',
56
+ type: 'accessor',
57
+ cellProps: { text: 'Record Date' },
58
+ },
59
+ ...recursivelyMapQuestionnaireItemsIntoHeaders(definitionItems),
60
+ ],
61
+ rows: mapQuestionnaireResponsesIntoDataEntities(records, adminActions),
62
+ }
63
+
64
+ if (adminActions) {
65
+ tableData.headers.splice(1, 0, {
66
+ id: 'adminactions',
67
+ type: 'accessor',
68
+ cellProps: { text: 'Actions' },
69
+ })
70
+ }
71
+ return tableData
72
+ }
73
+
74
+ const recursivelyMapQuestionnaireItemsIntoHeaders = (questionnaireItems: QuestionnaireItem[]): Header[] =>
75
+ questionnaireItems.map((questionnaireItem) => {
76
+ const subItems = EnsureMaybeArray<QuestionnaireItem>(questionnaireItem.item ?? [])
77
+
78
+ return {
79
+ id: questionnaireItem?.linkId ?? '',
80
+ type: subItems.length > 0 ? 'group' : 'accessor',
81
+ cellProps: { text: questionnaireItem?.text ?? '' },
82
+ subHeaders: recursivelyMapQuestionnaireItemsIntoHeaders(subItems),
83
+ }
84
+ })
85
+
86
+ const mapQuestionnaireResponsesIntoDataEntities = (
87
+ records: QuestionnaireResponse[],
88
+ adminActions?: AdminActionsForQuestionnaire[]
89
+ ): DataEntity[] =>
90
+ records
91
+ .filter((record) => !!record.item)
92
+ .map((record) => {
93
+ let dataEntity: DataEntity = {}
94
+
95
+ dataEntity.date = {
96
+ customComponentOverride:
97
+ record.status === QuestionnaireResponseStatus.EnteredInError
98
+ ? withdrawnWrapper(partialDateTimeText(record.authored))
99
+ : undefined,
100
+ text: partialDateTimeText(record.authored),
101
+ }
102
+
103
+ if (adminActions) {
104
+ const adminActionsForThisDataEntity = adminActions.find(
105
+ (actionForForm) => actionForForm.questionnaire === record.id
106
+ )
107
+ if (adminActionsForThisDataEntity) {
108
+ dataEntity.adminactions = {
109
+ adminActions: adminActionsForThisDataEntity.adminActions,
110
+ parentStyle: { zIndex: getZIndex(TableDataWithPopUp) },
111
+ }
112
+ }
113
+ }
114
+ record.item
115
+ ?.filter((item) => item?.linkId && item?.answer)
116
+ .forEach((item) => {
117
+ const linkId = EnsureMaybe<string>(item?.linkId)
118
+ const answer = EnsureMaybe<QuestionnaireResponseItemAnswer>(item?.answer?.find((answer) => !!answer))
119
+
120
+ dataEntity[linkId] = createCellPropsForAnswer(
121
+ answer,
122
+ false,
123
+ record.status === QuestionnaireResponseStatus.EnteredInError
124
+ )
125
+
126
+ if (answer.item) {
127
+ dataEntity = recursivelyMapResponseItemsOntoData(
128
+ EnsureMaybeArray<QuestionnaireResponseItem>(answer.item),
129
+ dataEntity,
130
+ record.status
131
+ )
132
+ }
133
+ })
134
+
135
+ return dataEntity
136
+ })
137
+
138
+ const recursivelyMapResponseItemsOntoData = (
139
+ items: QuestionnaireResponseItem[],
140
+ dataEntity: DataEntity,
141
+ status: QuestionnaireResponseStatus
142
+ ): DataEntity => {
143
+ let updatedDataEntity = { ...dataEntity }
144
+ items.forEach((item) => {
145
+ const firstAnswer = item.answer ? item.answer[0] : undefined
146
+
147
+ if (item.linkId && firstAnswer) {
148
+ const props = createCellPropsForAnswer(firstAnswer, false, status === QuestionnaireResponseStatus.EnteredInError)
149
+ updatedDataEntity[item.linkId] = {
150
+ customComponentOverride: props.customComponentOverride,
151
+ text: props.text,
152
+ }
153
+
154
+ if (firstAnswer.item) {
155
+ updatedDataEntity = recursivelyMapResponseItemsOntoData(
156
+ EnsureMaybeArray<QuestionnaireResponseItem>(firstAnswer.item),
157
+ updatedDataEntity,
158
+ status
159
+ )
160
+ }
161
+ }
162
+ })
163
+ return updatedDataEntity
164
+ }
165
+
166
+ const mapQuestionnaireObjectsToVerticalTableData = (
167
+ definitionItems: Array<QuestionnaireItem>,
168
+ records: QuestionnaireResponse[],
169
+ adminActions?: AdminActionsForQuestionnaire[]
170
+ ): TableData => ({
171
+ headers: [
172
+ {
173
+ id: 'property',
174
+ type: 'accessor',
175
+ cellProps: { text: '' },
176
+ },
177
+ ...records.map(
178
+ (record): Header => ({
179
+ id: record?.id ?? '',
180
+ type: 'accessor',
181
+ cellProps: {
182
+ customComponentOverride:
183
+ record.status === QuestionnaireResponseStatus.EnteredInError
184
+ ? withdrawnWrapper(partialDateTimeText(record.authored) ?? '')
185
+ : undefined,
186
+ text: partialDateTimeText(record.authored) ?? '',
187
+ },
188
+ })
189
+ ),
190
+ ],
191
+ rows: buildVerticalCellRows(definitionItems, records, adminActions),
192
+ })
193
+
194
+ const buildVerticalCellRows = (
195
+ definitionItems: QuestionnaireItem[],
196
+ records: QuestionnaireResponse[],
197
+ adminActions?: AdminActionsForQuestionnaire[]
198
+ ): DataEntity[] => {
199
+ const dataEntities = definitionItems.map((item) => {
200
+ let dataEntity: DataEntity = {}
201
+
202
+ dataEntity = buildVerticalCellRowsRecursive(EnsureMaybeArray<QuestionnaireItem>([item]), records, dataEntity)
203
+
204
+ return dataEntity
205
+ })
206
+
207
+ if (adminActions) {
208
+ const actionsDataEntity: DataEntity = {}
209
+ actionsDataEntity.property = { text: 'Actions', parentStyle: DEFAULT_VERTICAL_HEADER_CELL_STYLE }
210
+
211
+ records.forEach((record) => {
212
+ const adminActionsForThisDataEntity = adminActions.find(
213
+ (actionForForm) => actionForForm.questionnaire === record.id
214
+ )
215
+
216
+ if (adminActionsForThisDataEntity) {
217
+ actionsDataEntity[record.id] = {
218
+ adminActions: adminActionsForThisDataEntity.adminActions,
219
+ parentStyle: { zIndex: getZIndex(TableDataWithPopUp) },
220
+ }
221
+ }
222
+ })
223
+
224
+ return [actionsDataEntity].concat(dataEntities)
225
+ }
226
+ return dataEntities
227
+ }
228
+
229
+ const buildVerticalCellRowsRecursive = (
230
+ definitionItems: QuestionnaireItem[],
231
+ records: QuestionnaireResponse[],
232
+ dataEntity: DataEntity
233
+ ): DataEntity => {
234
+ let updatedDataEntity = { ...dataEntity }
235
+ definitionItems.forEach((definitionItem) => {
236
+ const containsChildItems = !!definitionItem.item && definitionItem.item.length > 0
237
+
238
+ updatedDataEntity.property = {
239
+ text: definitionItem.text ?? '',
240
+ parentStyle: {
241
+ ...DEFAULT_VERTICAL_HEADER_CELL_STYLE,
242
+ fontWeight: containsChildItems ? 'bold' : 'normal',
243
+ },
244
+ }
245
+
246
+ if (definitionItem.linkId) {
247
+ records.forEach((record) => {
248
+ updatedDataEntity = getRecordItemByLinkId(
249
+ EnsureMaybeArray<QuestionnaireResponseItem>(record.item ?? []),
250
+ EnsureMaybe<string>(definitionItem.linkId),
251
+ updatedDataEntity,
252
+ record.id,
253
+ record.status
254
+ )
255
+ })
256
+ }
257
+
258
+ if (definitionItem.item && definitionItem.item.length > 0) {
259
+ updatedDataEntity.subRows = buildVerticalCellRows(
260
+ EnsureMaybeArray<QuestionnaireItem>(definitionItem.item),
261
+ records
262
+ )
263
+ }
264
+ })
265
+
266
+ return updatedDataEntity
267
+ }
268
+
269
+ const getRecordItemByLinkId = (
270
+ recordItems: QuestionnaireResponseItem[],
271
+ linkId: string,
272
+ dataEntity: DataEntity,
273
+ recordId: string,
274
+ status: QuestionnaireResponseStatus
275
+ ) => {
276
+ let updatedDataEntity = { ...dataEntity }
277
+ recordItems.forEach((recordItem) => {
278
+ const recordItemAnswer =
279
+ recordItem.answer && recordItem.answer.length > 0 ? EnsureMaybe(recordItem.answer[0]) : undefined
280
+
281
+ if (recordItemAnswer) {
282
+ if (recordItem?.linkId && recordItem?.linkId === linkId) {
283
+ updatedDataEntity[recordId] = createCellPropsForAnswer(
284
+ recordItemAnswer,
285
+ true,
286
+ status === QuestionnaireResponseStatus.EnteredInError
287
+ )
288
+ }
289
+ if (recordItemAnswer.item && recordItemAnswer.item.length > 0) {
290
+ updatedDataEntity = getRecordItemByLinkId(
291
+ EnsureMaybeArray<QuestionnaireResponseItem>(recordItemAnswer.item),
292
+ linkId,
293
+ updatedDataEntity,
294
+ recordId,
295
+ status
296
+ )
297
+ }
298
+ }
299
+ })
300
+
301
+ return updatedDataEntity
302
+ }
303
+
304
+ const createCellPropsForAnswer = (
305
+ answer: QuestionnaireResponseItemAnswer,
306
+ shouldRenderCheckbox: boolean,
307
+ isEnteredInError: boolean
308
+ ): CellProps => {
309
+ if (answer.valueString) {
310
+ if (shouldRenderCheckbox && answer.valueString === 'CHECKBOX') {
311
+ return {
312
+ iconProps: { type: 'checkbox', size: 'medium' },
313
+ }
314
+ }
315
+ return {
316
+ customComponentOverride: isEnteredInError ? withdrawnWrapper(answer.valueString) : undefined,
317
+ text: answer.valueString,
318
+ }
319
+ }
320
+ if (answer.valueBoolean != null) {
321
+ const parsedBoolean = answer.valueBoolean ? 'Yes' : 'No'
322
+ return {
323
+ customComponentOverride: isEnteredInError ? withdrawnWrapper(parsedBoolean) : undefined,
324
+ text: parsedBoolean,
325
+ }
326
+ }
327
+ if (answer.valueInteger != null) {
328
+ return {
329
+ customComponentOverride: isEnteredInError ? withdrawnWrapper(answer.valueInteger.toString()) : undefined,
330
+ text: answer.valueInteger.toString(),
331
+ }
332
+ }
333
+ if (answer.valueDecimal != null) {
334
+ return {
335
+ customComponentOverride: isEnteredInError ? withdrawnWrapper(answer.valueDecimal.toString()) : undefined,
336
+ text: answer.valueDecimal.toString(),
337
+ }
338
+ }
339
+ return {
340
+ text: '',
341
+ }
342
+ }
343
+
344
+ export interface AdminActionsForQuestionnaire {
345
+ questionnaire: string
346
+ adminActions: ActionMenuOption[]
347
+ }
348
+
349
+ export default mapQuestionnaireDefinitionAndResponsesToTableData