@aehrc/smart-forms-renderer 0.9.2 → 0.10.0
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/.swcrc +11 -0
- package/lib/components/FormComponents/GroupItem/NextTabButtonWrapper.js +5 -5
- package/lib/components/FormComponents/GroupItem/NextTabButtonWrapper.js.map +1 -1
- package/lib/components/FormComponents/RepeatGroup/DeleteItemButton.js +1 -1
- package/lib/components/FormComponents/RepeatItem/RemoveItemButton.d.ts +10 -0
- package/lib/components/FormComponents/RepeatItem/RemoveItemButton.js +30 -0
- package/lib/components/FormComponents/RepeatItem/RemoveItemButton.js.map +1 -0
- package/lib/components/FormComponents/RepeatItem/RepeatField.js +2 -2
- package/lib/components/FormComponents/SingleItem/SingleItem.js +2 -2
- package/lib/components/FormComponents/SingleItem/SingleItem.js.map +1 -1
- package/lib/components/FormComponents/Tables/GroupTable.d.ts +1 -2
- package/lib/components/FormComponents/Tables/GroupTable.js +44 -59
- package/lib/components/FormComponents/Tables/GroupTable.js.map +1 -1
- package/lib/components/FormComponents/Tables/GroupTableBody.d.ts +17 -0
- package/lib/components/FormComponents/Tables/GroupTableBody.js +48 -0
- package/lib/components/FormComponents/Tables/GroupTableBody.js.map +1 -0
- package/lib/components/FormComponents/Tables/GroupTableRow.d.ts +18 -5
- package/lib/components/FormComponents/Tables/GroupTableRow.js +17 -25
- package/lib/components/FormComponents/Tables/GroupTableRow.js.map +1 -1
- package/lib/components/FormComponents/Tables/GroupTableRowCells.d.ts +11 -0
- package/lib/components/FormComponents/Tables/GroupTableRowCells.js +57 -0
- package/lib/components/FormComponents/Tables/GroupTableRowCells.js.map +1 -0
- package/lib/components/FormComponents/Tables/GroupTableRows.d.ts +17 -0
- package/lib/components/FormComponents/Tables/GroupTableRows.js +45 -0
- package/lib/components/FormComponents/Tables/GroupTableRows.js.map +1 -0
- package/lib/components/FormComponents/Tables/GroupTableTestRow.d.ts +22 -0
- package/lib/components/FormComponents/Tables/GroupTableTestRow.js +43 -0
- package/lib/components/FormComponents/Tables/GroupTableTestRow.js.map +1 -0
- package/lib/components/FormComponents/Tables/GroupTableView.d.ts +21 -0
- package/lib/components/FormComponents/Tables/GroupTableView.js +65 -0
- package/lib/components/FormComponents/Tables/GroupTableView.js.map +1 -0
- package/lib/components/FormComponents/Tables/RemoveRowButton.d.ts +10 -0
- package/lib/components/FormComponents/Tables/RemoveRowButton.js +32 -0
- package/lib/components/FormComponents/Tables/RemoveRowButton.js.map +1 -0
- package/lib/components/FormComponents/Tables/SelectRowButton.d.ts +7 -0
- package/lib/components/FormComponents/Tables/SelectRowButton.js +26 -0
- package/lib/components/FormComponents/Tables/SelectRowButton.js.map +1 -0
- package/lib/components/FormComponents/Tables/Table.styles.d.ts +8 -0
- package/lib/components/FormComponents/Tables/Table.styles.js +17 -0
- package/lib/components/FormComponents/Tables/Table.styles.js.map +1 -1
- package/lib/components/Renderer/BaseRenderer.js +5 -6
- package/lib/components/Renderer/BaseRenderer.js.map +1 -1
- package/lib/components/Renderer/FormBodyCollapsible.js +4 -4
- package/lib/components/Renderer/FormBodyCollapsible.js.map +1 -1
- package/lib/components/Renderer/FormBodyTabbed.js +3 -3
- package/lib/components/Renderer/FormBodyTabbed.js.map +1 -1
- package/lib/components/Tabs/CompleteTabButton.js +2 -2
- package/lib/components/Tabs/CompleteTabButton.js.map +1 -1
- package/lib/components/Tabs/FormBodySingleTab.js +2 -2
- package/lib/components/Tabs/FormBodySingleTab.js.map +1 -1
- package/lib/components/Tabs/FormBodyTabList.js +4 -4
- package/lib/components/Tabs/FormBodyTabList.js.map +1 -1
- package/lib/hooks/useDecimalCalculatedExpression.js +2 -2
- package/lib/hooks/useDecimalCalculatedExpression.js.map +1 -1
- package/lib/hooks/useHidden.js +4 -4
- package/lib/hooks/useHidden.js.map +1 -1
- package/lib/hooks/useInitialiseGroupTable.d.ts +2 -2
- package/lib/hooks/useInitialiseGroupTable.js.map +1 -1
- package/lib/hooks/useInitialiseRenderer.js +11 -14
- package/lib/hooks/useInitialiseRenderer.js.map +1 -1
- package/lib/hooks/useIntegerCalculatedExpression.js +2 -2
- package/lib/hooks/useIntegerCalculatedExpression.js.map +1 -1
- package/lib/hooks/useMinimalStringCalculatedExpression.js +25 -13
- package/lib/hooks/useStringCalculatedExpression.js +2 -2
- package/lib/hooks/useStringCalculatedExpression.js.map +1 -1
- package/lib/hooks/useTerminologyServerQuery.js +3 -4
- package/lib/hooks/useTerminologyServerQuery.js.map +1 -1
- package/lib/hooks/useValueSetCodings.js +10 -12
- package/lib/hooks/useValueSetCodings.js.map +1 -1
- package/lib/index.js +19 -20
- package/lib/index.js.map +1 -1
- package/lib/interfaces/groupTable.interface.d.ts +1 -1
- package/lib/setup-jest.js +1 -0
- package/lib/setup-jest.js.map +1 -0
- package/lib/stores/index.d.ts +4 -3
- package/lib/stores/index.js +4 -3
- package/lib/stores/index.js.map +1 -1
- package/lib/stores/questionnaireResponseStore.d.ts +28 -0
- package/lib/stores/questionnaireResponseStore.js +64 -0
- package/lib/stores/questionnaireResponseStore.js.map +1 -0
- package/lib/stores/questionnaireStore.d.ts +65 -0
- package/lib/stores/questionnaireStore.js +172 -0
- package/lib/stores/questionnaireStore.js.map +1 -0
- package/lib/stores/smartConfigStore.d.ts +25 -0
- package/lib/stores/smartConfigStore.js +30 -0
- package/lib/stores/smartConfigStore.js.map +1 -0
- package/lib/stores/terminologyServerStore.d.ts +14 -0
- package/lib/stores/terminologyServerStore.js +26 -0
- package/lib/stores/terminologyServerStore.js.map +1 -0
- package/lib/stores/useQuestionnaireResponseStore.d.ts +14 -2
- package/lib/stores/useQuestionnaireResponseStore.js +4 -2
- package/lib/stores/useQuestionnaireResponseStore.js.map +1 -1
- package/lib/stores/useQuestionnaireStore.d.ts +30 -2
- package/lib/stores/useQuestionnaireStore.js +4 -2
- package/lib/stores/useQuestionnaireStore.js.map +1 -1
- package/lib/stories/MedicalHistoryTable.stories.js +49 -0
- package/lib/stories/MedicalHistoryTable.stories.js.map +1 -0
- package/lib/stories/SmartFormsRenderer.stories.js +103 -0
- package/lib/stories/SmartFormsRenderer.stories.js.map +1 -0
- package/lib/theme/overrides/Table.d.ts +1 -0
- package/lib/theme/overrides/Table.js +2 -1
- package/lib/theme/overrides/Table.js.map +1 -1
- package/lib/utils/calculatedExpression.js +1 -2
- package/lib/utils/calculatedExpression.js.map +1 -1
- package/lib/utils/groupTable.d.ts +3 -0
- package/lib/utils/groupTable.js +29 -0
- package/lib/utils/groupTable.js.map +1 -0
- package/package.json +10 -5
- package/src/components/FormComponents/GroupItem/NextTabButtonWrapper.tsx +5 -5
- package/src/components/FormComponents/RepeatGroup/DeleteItemButton.tsx +1 -1
- package/src/components/FormComponents/RepeatItem/{DeleteItemButton.tsx → RemoveItemButton.tsx} +4 -4
- package/src/components/FormComponents/RepeatItem/RepeatField.tsx +2 -2
- package/src/components/FormComponents/SingleItem/SingleItem.tsx +2 -2
- package/src/components/FormComponents/Tables/GroupTable.tsx +71 -120
- package/src/components/FormComponents/Tables/GroupTableBody.tsx +116 -0
- package/src/components/FormComponents/Tables/GroupTableRow.tsx +89 -49
- package/src/components/FormComponents/Tables/GroupTableRowCells.tsx +87 -0
- package/src/components/FormComponents/Tables/GroupTableView.tsx +169 -0
- package/src/components/FormComponents/Tables/{DeleteRowButton.tsx → RemoveRowButton.tsx} +7 -7
- package/src/components/FormComponents/Tables/SelectRowButton.tsx +37 -0
- package/src/components/FormComponents/Tables/Table.styles.tsx +25 -0
- package/src/components/Renderer/BaseRenderer.tsx +5 -6
- package/src/components/Renderer/FormBodyCollapsible.tsx +4 -5
- package/src/components/Renderer/FormBodyTabbed.tsx +3 -3
- package/src/components/Tabs/CompleteTabButton.tsx +2 -2
- package/src/components/Tabs/FormBodySingleTab.tsx +2 -3
- package/src/components/Tabs/FormBodyTabList.tsx +4 -4
- package/src/hooks/useDecimalCalculatedExpression.ts +2 -2
- package/src/hooks/useHidden.ts +4 -4
- package/src/hooks/useInitialiseGroupTable.ts +3 -3
- package/src/hooks/useInitialiseRenderer.ts +17 -18
- package/src/hooks/useIntegerCalculatedExpression.ts +2 -2
- package/src/hooks/useStringCalculatedExpression.ts +2 -2
- package/src/hooks/useTerminologyServerQuery.ts +3 -4
- package/src/hooks/useValueSetCodings.ts +10 -12
- package/src/index.ts +19 -20
- package/src/interfaces/groupTable.interface.ts +1 -1
- package/src/stores/index.ts +7 -3
- package/src/stores/questionnaireResponseStore.ts +83 -0
- package/src/stores/{useQuestionnaireStore.ts → questionnaireStore.ts} +7 -6
- package/src/stores/smartConfigStore.ts +45 -0
- package/src/stores/{useTerminologyServerStore.ts → terminologyServerStore.ts} +5 -4
- package/src/stories/MedicalHistoryTable.stories.tsx +61 -0
- package/src/stories/SmartFormsRenderer.stories.ts +15 -5
- package/src/stories/assets/QItems-and-QRItems/QR_GTableMedicalHistory.json +80 -0
- package/src/stories/assets/QItems-and-QRItems/Q_GTableMedicalHistory.json +109 -0
- package/src/stories/assets/Qs-and-QRs/QDev715.json +16081 -0
- package/src/theme/overrides/Table.ts +2 -1
- package/src/utils/calculatedExpression.ts +1 -2
- package/src/utils/groupTable.ts +37 -0
- package/src/stores/useQuestionnaireResponseStore.ts +0 -63
- package/src/stores/useSmartConfigStore.ts +0 -27
- /package/src/stories/assets/{Q715.json → Qs-and-QRs/Q715.json} +0 -0
- /package/src/stories/assets/{QTestGrid.json → Qs-and-QRs/QTestGrid.json} +0 -0
- /package/src/stories/assets/{R715.json → Qs-and-QRs/R715.json} +0 -0
- /package/src/stories/assets/{RTestGrid.json → Qs-and-QRs/RTestGrid.json} +0 -0
|
@@ -20,7 +20,8 @@ export default function Table(theme) {
|
|
|
20
20
|
styleOverrides: {
|
|
21
21
|
head: {
|
|
22
22
|
color: theme.palette.text.secondary,
|
|
23
|
-
backgroundColor: theme.palette.customBackground.neutral
|
|
23
|
+
backgroundColor: theme.palette.customBackground.neutral,
|
|
24
|
+
borderBottom: '1px solid #e5e7eb'
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Table.js","sourceRoot":"","sources":["../../../src/theme/overrides/Table.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,KAAY;IACxC,OAAO;QACL,YAAY,EAAE;YACZ,cAAc,EAAE;gBACd,IAAI,EAAE;oBACJ,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS;oBACnC,eAAe,EAAE,KAAK,CAAC,OAAO,CAAC,gBAAgB,CAAC,OAAO;
|
|
1
|
+
{"version":3,"file":"Table.js","sourceRoot":"","sources":["../../../src/theme/overrides/Table.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,KAAY;IACxC,OAAO;QACL,YAAY,EAAE;YACZ,cAAc,EAAE;gBACd,IAAI,EAAE;oBACJ,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS;oBACnC,eAAe,EAAE,KAAK,CAAC,OAAO,CAAC,gBAAgB,CAAC,OAAO;oBACvD,YAAY,EAAE,mBAAmB;iBAClC;aACF;SACF;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -23,7 +23,6 @@ import { getQrItemsIndex, mapQItemsIndex } from './mapItem';
|
|
|
23
23
|
import { updateQrItemsInGroup } from './qrItem';
|
|
24
24
|
import cloneDeep from 'lodash.clonedeep';
|
|
25
25
|
import dayjs from 'dayjs';
|
|
26
|
-
import moment from 'moment';
|
|
27
26
|
export function evaluateInitialCalculatedExpressions(params) {
|
|
28
27
|
const { initialResponse, calculatedExpressions, variablesFhirPath, existingFhirPathContext } = params;
|
|
29
28
|
// Return early if initialResponse is empty or there are no calculated expressions to evaluate
|
|
@@ -217,7 +216,7 @@ function parseValueToAnswer(qItem, value) {
|
|
|
217
216
|
export function checkIsDateTime(value) {
|
|
218
217
|
const acceptedFormats = ['YYYY', 'YYYY-MM', 'YYYY-MM-DD', 'YYYY-MM-DDTHH:mm:ssZ'];
|
|
219
218
|
const formattedDate = dayjs(value).format();
|
|
220
|
-
return
|
|
219
|
+
return dayjs(formattedDate, acceptedFormats, true).isValid();
|
|
221
220
|
}
|
|
222
221
|
/**
|
|
223
222
|
* Check if an answer is in a time format - Regex: ([01][0-9]|2[0-3]):[0-5][0-9]:([0-5][0-9]|60)(\.[0-9]+)?
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculatedExpression.js","sourceRoot":"","sources":["../../src/utils/calculatedExpression.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,iBAAiB,MAAM,0BAA0B,CAAC;AAUzD,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,SAAS,MAAM,kBAAkB,CAAC;AACzC,OAAO,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"calculatedExpression.js","sourceRoot":"","sources":["../../src/utils/calculatedExpression.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,iBAAiB,MAAM,0BAA0B,CAAC;AAUzD,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CA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jC;IAED,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,IAAI,WAAW,CAAC,KAAK,CAAC,EAAE;QAC/C,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;KAC7B;IAED,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;AAChC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,KAAa;IAC3C,MAAM,eAAe,GAAG,CAAC,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,sBAAsB,CAAC,CAAC;IAClF,MAAM,aAAa,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;IAC5C,OAAO,KAAK,CAAC,aAAa,EAAE,eAAe,EAAE,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;AAC/D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,KAAa;IACvC,MAAM,SAAS,GAAG,4DAA4D,CAAC;IAC/E,OAAO,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { GroupTableRowModel } from '../interfaces/groupTable.interface';
|
|
2
|
+
export declare function reorderRows(rows: GroupTableRowModel[], sourceIndex: number, destinationIndex: number): GroupTableRowModel[];
|
|
3
|
+
export declare function getGroupTableItemsToUpdate(tableRows: GroupTableRowModel[], selectedIds: string[]): import("fhir/r4").QuestionnaireResponseItem[];
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2023 Commonwealth Scientific and Industrial Research
|
|
3
|
+
* Organisation (CSIRO) ABN 41 687 119 230.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import cloneDeep from 'lodash.clonedeep';
|
|
18
|
+
export function reorderRows(rows, sourceIndex, destinationIndex) {
|
|
19
|
+
const result = Array.from(rows);
|
|
20
|
+
const [removed] = result.splice(sourceIndex, 1);
|
|
21
|
+
result.splice(destinationIndex, 0, removed);
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
export function getGroupTableItemsToUpdate(tableRows, selectedIds) {
|
|
25
|
+
return tableRows
|
|
26
|
+
.filter((row) => selectedIds.includes(row.nanoId))
|
|
27
|
+
.flatMap((singleRow) => (singleRow.qrItem ? [cloneDeep(singleRow.qrItem)] : []));
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=groupTable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"groupTable.js","sourceRoot":"","sources":["../../src/utils/groupTable.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,SAAS,MAAM,kBAAkB,CAAC;AAEzC,MAAM,UAAU,WAAW,CACzB,IAA0B,EAC1B,WAAmB,EACnB,gBAAwB;IAExB,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChC,MAAM,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;IAChD,MAAM,CAAC,MAAM,CAAC,gBAAgB,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;IAE5C,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,SAA+B,EAAE,WAAqB;IAC/F,OAAO,SAAS;SACb,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;SACjD,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACrF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aehrc/smart-forms-renderer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "FHIR Structured Data Captured (SDC) rendering engine for Smart Forms",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"compile": "tsc",
|
|
8
8
|
"compile:watch": "tsc -w",
|
|
9
|
+
"compile:swc:watch": "npx swc src --out-dir lib -w",
|
|
9
10
|
"prepare": "npm run compile",
|
|
10
11
|
"test": "jest",
|
|
11
12
|
"test:watch": "jest --watch",
|
|
@@ -30,13 +31,13 @@
|
|
|
30
31
|
"deep-diff": "^1.0.2",
|
|
31
32
|
"fhirclient": "^2.5.2",
|
|
32
33
|
"fhirpath": "^3.7.1",
|
|
33
|
-
"html-react-parser": "
|
|
34
|
+
"html-react-parser": "4.2.10",
|
|
34
35
|
"lodash.clonedeep": "^4.5.0",
|
|
35
36
|
"lodash.debounce": "^4.0.8",
|
|
36
37
|
"nanoid": "^5.0.1",
|
|
38
|
+
"react-beautiful-dnd": "^13.1.1",
|
|
37
39
|
"react-markdown": "^8.0.7",
|
|
38
|
-
"zustand": "^4.4.1"
|
|
39
|
-
"moment": "^2.29.4"
|
|
40
|
+
"zustand": "^4.4.1"
|
|
40
41
|
},
|
|
41
42
|
"peerDependencies": {
|
|
42
43
|
"@emotion/react": ">=11.11.0",
|
|
@@ -60,15 +61,19 @@
|
|
|
60
61
|
"@storybook/react": "^7.4.3",
|
|
61
62
|
"@storybook/react-vite": "^7.4.5",
|
|
62
63
|
"@storybook/testing-library": "^0.2.1",
|
|
64
|
+
"@swc/cli": "^0.1.63",
|
|
65
|
+
"@swc/core": "^1.3.99",
|
|
63
66
|
"@testing-library/jest-dom": "^6.1.2",
|
|
64
67
|
"@testing-library/react": "^14.0.0",
|
|
65
68
|
"@testing-library/react-hooks": "^7.0.2",
|
|
66
69
|
"@types/deep-diff": "^1.0.4",
|
|
67
70
|
"@types/jest": "^29.5.7",
|
|
68
|
-
"@types/lodash.debounce": "^4.0.7",
|
|
69
71
|
"@types/lodash.clonedeep": "^4.5.7",
|
|
72
|
+
"@types/lodash.debounce": "^4.0.7",
|
|
70
73
|
"@types/react": "^18.2.37",
|
|
74
|
+
"@types/react-beautiful-dnd": "^13.1.7",
|
|
71
75
|
"@types/react-dom": "^18.2.9",
|
|
76
|
+
"chokidar": "^3.5.3",
|
|
72
77
|
"jest": "^29.7.0",
|
|
73
78
|
"jest-environment-jsdom": "^29.7.0",
|
|
74
79
|
"react": "^18.2.0",
|
|
@@ -19,7 +19,7 @@ import React, { memo } from 'react';
|
|
|
19
19
|
import Box from '@mui/material/Box';
|
|
20
20
|
import { findNumOfVisibleTabs, getNextVisibleTabIndex } from '../../../utils/tabs';
|
|
21
21
|
import type { Tabs } from '../../../interfaces/tab.interface';
|
|
22
|
-
import useQuestionnaireStore from '../../../stores
|
|
22
|
+
import { useQuestionnaireStore } from '../../../stores';
|
|
23
23
|
import NextTabButton from './NextTabButton';
|
|
24
24
|
|
|
25
25
|
interface NextTabButtonWrapperProps {
|
|
@@ -30,10 +30,10 @@ interface NextTabButtonWrapperProps {
|
|
|
30
30
|
const NextTabButtonWrapper = memo(function NextTabWrapper(props: NextTabButtonWrapperProps) {
|
|
31
31
|
const { currentTabIndex, tabs } = props;
|
|
32
32
|
|
|
33
|
-
const enableWhenIsActivated = useQuestionnaireStore
|
|
34
|
-
const enableWhenItems = useQuestionnaireStore
|
|
35
|
-
const enableWhenExpressions = useQuestionnaireStore
|
|
36
|
-
const switchTab = useQuestionnaireStore
|
|
33
|
+
const enableWhenIsActivated = useQuestionnaireStore.use.enableWhenIsActivated();
|
|
34
|
+
const enableWhenItems = useQuestionnaireStore.use.enableWhenItems();
|
|
35
|
+
const enableWhenExpressions = useQuestionnaireStore.use.enableWhenExpressions();
|
|
36
|
+
const switchTab = useQuestionnaireStore.use.switchTab();
|
|
37
37
|
|
|
38
38
|
const tabsNotDefined = currentTabIndex === undefined || tabs === undefined;
|
|
39
39
|
|
|
@@ -34,7 +34,7 @@ function DeleteItemButton(props: DeleteItemButtonProps) {
|
|
|
34
34
|
const isDisabled = nullableQrItem === null || numOfRepeatGroups === 1 || readOnly;
|
|
35
35
|
|
|
36
36
|
return (
|
|
37
|
-
<RepeatDeleteTooltip className="repeat-group-delete" title="
|
|
37
|
+
<RepeatDeleteTooltip className="repeat-group-delete" title="Remove item">
|
|
38
38
|
<span>
|
|
39
39
|
<IconButton size="small" color="error" disabled={isDisabled} onClick={onDeleteItem}>
|
|
40
40
|
<RemoveCircleOutlineIcon />
|
package/src/components/FormComponents/RepeatItem/{DeleteItemButton.tsx → RemoveItemButton.tsx}
RENAMED
|
@@ -21,20 +21,20 @@ import IconButton from '@mui/material/IconButton';
|
|
|
21
21
|
import RemoveCircleOutlineIcon from '@mui/icons-material/RemoveCircleOutline';
|
|
22
22
|
import type { QuestionnaireResponseItemAnswer } from 'fhir/r4';
|
|
23
23
|
|
|
24
|
-
interface
|
|
24
|
+
interface RemoveItemButtonProps {
|
|
25
25
|
answer: QuestionnaireResponseItemAnswer | null;
|
|
26
26
|
numOfRepeatAnswers: number;
|
|
27
27
|
readOnly: boolean;
|
|
28
28
|
onDeleteAnswer: () => void;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
function
|
|
31
|
+
function RemoveItemButton(props: RemoveItemButtonProps) {
|
|
32
32
|
const { answer, numOfRepeatAnswers, readOnly, onDeleteAnswer } = props;
|
|
33
33
|
|
|
34
34
|
const isDisabled = answer === null || numOfRepeatAnswers === 1 || readOnly;
|
|
35
35
|
|
|
36
36
|
return (
|
|
37
|
-
<RepeatDeleteTooltip className="repeat-item-delete" title="
|
|
37
|
+
<RepeatDeleteTooltip className="repeat-item-delete" title="Remove item">
|
|
38
38
|
<span>
|
|
39
39
|
<IconButton size="small" color="error" disabled={isDisabled} onClick={onDeleteAnswer}>
|
|
40
40
|
<RemoveCircleOutlineIcon fontSize="small" />
|
|
@@ -44,4 +44,4 @@ function DeleteItemButton(props: DeleteItemButtonProps) {
|
|
|
44
44
|
);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
export default
|
|
47
|
+
export default RemoveItemButton;
|
|
@@ -29,7 +29,7 @@ import type {
|
|
|
29
29
|
PropsWithQrItemChangeHandler,
|
|
30
30
|
PropsWithShowMinimalViewAttribute
|
|
31
31
|
} from '../../../interfaces/renderProps.interface';
|
|
32
|
-
import
|
|
32
|
+
import RemoveItemButton from './RemoveItemButton';
|
|
33
33
|
import useReadOnly from '../../../hooks/useReadOnly';
|
|
34
34
|
|
|
35
35
|
interface RepeatFieldProps
|
|
@@ -71,7 +71,7 @@ function RepeatField(props: RepeatFieldProps) {
|
|
|
71
71
|
/>
|
|
72
72
|
</Box>
|
|
73
73
|
{showMinimalView ? null : (
|
|
74
|
-
<
|
|
74
|
+
<RemoveItemButton
|
|
75
75
|
answer={answer}
|
|
76
76
|
numOfRepeatAnswers={numOfRepeatAnswers}
|
|
77
77
|
readOnly={readOnly}
|
|
@@ -24,7 +24,7 @@ import type {
|
|
|
24
24
|
PropsWithQrItemChangeHandler,
|
|
25
25
|
PropsWithShowMinimalViewAttribute
|
|
26
26
|
} from '../../../interfaces/renderProps.interface';
|
|
27
|
-
import useQuestionnaireStore from '../../../stores
|
|
27
|
+
import { useQuestionnaireStore } from '../../../stores';
|
|
28
28
|
import SingleItemSwitcher from './SingleItemSwitcher';
|
|
29
29
|
import useHidden from '../../../hooks/useHidden';
|
|
30
30
|
import useReadOnly from '../../../hooks/useReadOnly';
|
|
@@ -43,7 +43,7 @@ function SingleItem(props: SingleItemProps) {
|
|
|
43
43
|
const { qItem, qrItem, isRepeated, isTabled, showMinimalView, parentIsReadOnly, onQrItemChange } =
|
|
44
44
|
props;
|
|
45
45
|
|
|
46
|
-
const updateEnableWhenItem = useQuestionnaireStore
|
|
46
|
+
const updateEnableWhenItem = useQuestionnaireStore.use.updateEnableWhenItem();
|
|
47
47
|
|
|
48
48
|
const handleQrItemChange = useCallback(
|
|
49
49
|
(newQrItem: QuestionnaireResponseItem) => {
|
|
@@ -18,32 +18,18 @@
|
|
|
18
18
|
import React, { useMemo, useState } from 'react';
|
|
19
19
|
|
|
20
20
|
import type { QuestionnaireItem, QuestionnaireResponseItem } from 'fhir/r4';
|
|
21
|
-
import Divider from '@mui/material/Divider';
|
|
22
|
-
import Paper from '@mui/material/Paper';
|
|
23
|
-
import Table from '@mui/material/Table';
|
|
24
|
-
import TableBody from '@mui/material/TableBody';
|
|
25
|
-
import TableCell from '@mui/material/TableCell';
|
|
26
|
-
import TableContainer from '@mui/material/TableContainer';
|
|
27
|
-
import TableHead from '@mui/material/TableHead';
|
|
28
|
-
import TableRow from '@mui/material/TableRow';
|
|
29
|
-
import Typography from '@mui/material/Typography';
|
|
30
|
-
import GroupTableRow from './GroupTableRow';
|
|
31
|
-
import { HeaderTableCell } from './Table.styles';
|
|
32
|
-
import { QGroupContainerBox } from '../../Box.styles';
|
|
33
21
|
import { mapQItemsIndex } from '../../../utils/mapItem';
|
|
34
22
|
import type {
|
|
35
23
|
PropsWithParentIsReadOnlyAttribute,
|
|
36
|
-
PropsWithQrRepeatGroupChangeHandler
|
|
24
|
+
PropsWithQrRepeatGroupChangeHandler,
|
|
25
|
+
PropsWithShowMinimalViewAttribute
|
|
37
26
|
} from '../../../interfaces/renderProps.interface';
|
|
38
|
-
import type { PropsWithShowMinimalViewAttribute } from '../../../interfaces/renderProps.interface';
|
|
39
27
|
import useInitialiseGroupTable from '../../../hooks/useInitialiseGroupTable';
|
|
40
28
|
import { nanoid } from 'nanoid';
|
|
41
|
-
import { createEmptyQrItem } from '../../../utils/qrItem';
|
|
42
|
-
import DeleteRowButton from './DeleteRowButton';
|
|
43
|
-
import LabelWrapper from '../ItemParts/ItemLabelWrapper';
|
|
44
|
-
import cloneDeep from 'lodash.clonedeep';
|
|
45
|
-
import AddRowButton from './AddRowButton';
|
|
46
29
|
import useReadOnly from '../../../hooks/useReadOnly';
|
|
30
|
+
import GroupTableView from './GroupTableView';
|
|
31
|
+
import { GroupTableRowModel } from '../../../interfaces/groupTable.interface';
|
|
32
|
+
import { getGroupTableItemsToUpdate } from '../../../utils/groupTable';
|
|
47
33
|
|
|
48
34
|
interface GroupTableProps
|
|
49
35
|
extends PropsWithQrRepeatGroupChangeHandler,
|
|
@@ -64,11 +50,16 @@ function GroupTable(props: GroupTableProps) {
|
|
|
64
50
|
onQrRepeatGroupChange
|
|
65
51
|
} = props;
|
|
66
52
|
|
|
53
|
+
// TODO come back to fix stuttering on dnd update
|
|
54
|
+
|
|
67
55
|
const readOnly = useReadOnly(qItem, parentIsReadOnly);
|
|
68
56
|
|
|
69
57
|
const initialisedGroupTables = useInitialiseGroupTable(qrItems);
|
|
70
58
|
|
|
71
59
|
const [tableRows, setTableRows] = useState(initialisedGroupTables);
|
|
60
|
+
const [selectedIds, setSelectedIds] = useState<string[]>(
|
|
61
|
+
initialisedGroupTables.map((row) => row.nanoId)
|
|
62
|
+
);
|
|
72
63
|
|
|
73
64
|
// Generate item labels as table headers
|
|
74
65
|
const qItems = qItem.item;
|
|
@@ -99,13 +90,11 @@ function GroupTable(props: GroupTableProps) {
|
|
|
99
90
|
setTableRows(updatedTableRows);
|
|
100
91
|
onQrRepeatGroupChange({
|
|
101
92
|
linkId: qItem.linkId,
|
|
102
|
-
qrItems: updatedTableRows
|
|
103
|
-
singleRow.qrItem ? [cloneDeep(singleRow.qrItem)] : []
|
|
104
|
-
)
|
|
93
|
+
qrItems: getGroupTableItemsToUpdate(updatedTableRows, selectedIds)
|
|
105
94
|
});
|
|
106
95
|
}
|
|
107
96
|
|
|
108
|
-
function
|
|
97
|
+
function handleRemoveRow(index: number) {
|
|
109
98
|
const updatedTableRows = [...tableRows];
|
|
110
99
|
|
|
111
100
|
updatedTableRows.splice(index, 1);
|
|
@@ -113,118 +102,80 @@ function GroupTable(props: GroupTableProps) {
|
|
|
113
102
|
setTableRows(updatedTableRows);
|
|
114
103
|
onQrRepeatGroupChange({
|
|
115
104
|
linkId: qItem.linkId,
|
|
116
|
-
qrItems: updatedTableRows
|
|
117
|
-
singleRow.qrItem ? [cloneDeep(singleRow.qrItem)] : []
|
|
118
|
-
)
|
|
105
|
+
qrItems: getGroupTableItemsToUpdate(updatedTableRows, selectedIds)
|
|
119
106
|
});
|
|
120
107
|
}
|
|
121
108
|
|
|
122
109
|
function handleAddRow() {
|
|
110
|
+
const newRowNanoId = nanoid();
|
|
123
111
|
setTableRows([
|
|
124
112
|
...tableRows,
|
|
125
113
|
{
|
|
126
|
-
nanoId:
|
|
114
|
+
nanoId: newRowNanoId,
|
|
127
115
|
qrItem: null
|
|
128
116
|
}
|
|
129
117
|
]);
|
|
118
|
+
setSelectedIds([...selectedIds, newRowNanoId]);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function handleSelectAll() {
|
|
122
|
+
// deselect all if all are selected, otherwise select all
|
|
123
|
+
const updatedTableIds =
|
|
124
|
+
selectedIds.length === tableRows.length ? [] : tableRows.map((tableRow) => tableRow.nanoId);
|
|
125
|
+
setSelectedIds(updatedTableIds);
|
|
126
|
+
onQrRepeatGroupChange({
|
|
127
|
+
linkId: qItem.linkId,
|
|
128
|
+
qrItems: getGroupTableItemsToUpdate(tableRows, updatedTableIds)
|
|
129
|
+
});
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
qItemsIndexMap={qItemsIndexMap}
|
|
160
|
-
parentIsReadOnly={parentIsReadOnly}
|
|
161
|
-
onQrItemChange={(newQrGroup) => handleRowChange(newQrGroup, index)}
|
|
162
|
-
/>
|
|
163
|
-
</TableRow>
|
|
164
|
-
);
|
|
165
|
-
})}
|
|
166
|
-
</TableBody>
|
|
167
|
-
</Table>
|
|
168
|
-
</TableContainer>
|
|
169
|
-
</QGroupContainerBox>
|
|
170
|
-
);
|
|
132
|
+
function handleSelectRow(nanoId: string) {
|
|
133
|
+
const updatedSelectedIds = [...selectedIds];
|
|
134
|
+
|
|
135
|
+
const index = updatedSelectedIds.indexOf(nanoId);
|
|
136
|
+
if (index === -1) {
|
|
137
|
+
updatedSelectedIds.push(nanoId);
|
|
138
|
+
} else {
|
|
139
|
+
updatedSelectedIds.splice(index, 1);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
setSelectedIds(updatedSelectedIds);
|
|
143
|
+
onQrRepeatGroupChange({
|
|
144
|
+
linkId: qItem.linkId,
|
|
145
|
+
qrItems: getGroupTableItemsToUpdate(tableRows, updatedSelectedIds)
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// TODO fix error message
|
|
150
|
+
// TODO add swc
|
|
151
|
+
// TODO add listener
|
|
152
|
+
|
|
153
|
+
function handleReorderRows(newTableRows: GroupTableRowModel[]) {
|
|
154
|
+
setTableRows(newTableRows);
|
|
155
|
+
onQrRepeatGroupChange({
|
|
156
|
+
linkId: qItem.linkId,
|
|
157
|
+
qrItems: getGroupTableItemsToUpdate(newTableRows, selectedIds)
|
|
158
|
+
});
|
|
171
159
|
}
|
|
172
160
|
|
|
173
161
|
return (
|
|
174
|
-
<
|
|
175
|
-
{
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
<TableHead>
|
|
192
|
-
<TableRow>
|
|
193
|
-
{itemLabels.map((itemLabel) => (
|
|
194
|
-
<HeaderTableCell key={itemLabel}>{itemLabel}</HeaderTableCell>
|
|
195
|
-
))}
|
|
196
|
-
<TableCell />
|
|
197
|
-
</TableRow>
|
|
198
|
-
</TableHead>
|
|
199
|
-
<TableBody>
|
|
200
|
-
{tableRows.map(({ nanoId, qrItem: nullableQrItem }, index) => {
|
|
201
|
-
const answeredQrItem = createEmptyQrItem(qItem);
|
|
202
|
-
if (nullableQrItem) {
|
|
203
|
-
answeredQrItem.item = nullableQrItem.item;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
return (
|
|
207
|
-
<TableRow key={nanoId}>
|
|
208
|
-
<GroupTableRow
|
|
209
|
-
qItem={qItem}
|
|
210
|
-
qrItem={answeredQrItem}
|
|
211
|
-
qItemsIndexMap={qItemsIndexMap}
|
|
212
|
-
parentIsReadOnly={parentIsReadOnly}
|
|
213
|
-
onQrItemChange={(newQrGroup) => handleRowChange(newQrGroup, index)}
|
|
214
|
-
/>
|
|
215
|
-
<DeleteRowButton
|
|
216
|
-
nullableQrItem={nullableQrItem}
|
|
217
|
-
numOfRows={tableRows.length}
|
|
218
|
-
readOnly={readOnly}
|
|
219
|
-
onDeleteItem={() => handleDeleteRow(index)}
|
|
220
|
-
/>
|
|
221
|
-
</TableRow>
|
|
222
|
-
);
|
|
223
|
-
})}
|
|
224
|
-
</TableBody>
|
|
225
|
-
</Table>
|
|
226
|
-
</TableContainer>
|
|
227
|
-
</QGroupContainerBox>
|
|
162
|
+
<GroupTableView
|
|
163
|
+
qItem={qItem}
|
|
164
|
+
qItemsIndexMap={qItemsIndexMap}
|
|
165
|
+
groupCardElevation={groupCardElevation}
|
|
166
|
+
readOnly={readOnly}
|
|
167
|
+
tableRows={tableRows}
|
|
168
|
+
selectedIds={selectedIds}
|
|
169
|
+
itemLabels={itemLabels}
|
|
170
|
+
showMinimalView={showMinimalView}
|
|
171
|
+
parentIsReadOnly={parentIsReadOnly}
|
|
172
|
+
onAddRow={handleAddRow}
|
|
173
|
+
onRowChange={handleRowChange}
|
|
174
|
+
onRemoveRow={handleRemoveRow}
|
|
175
|
+
onSelectRow={handleSelectRow}
|
|
176
|
+
onSelectAll={handleSelectAll}
|
|
177
|
+
onReorderRows={handleReorderRows}
|
|
178
|
+
/>
|
|
228
179
|
);
|
|
229
180
|
}
|
|
230
181
|
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2023 Commonwealth Scientific and Industrial Research
|
|
3
|
+
* Organisation (CSIRO) ABN 41 687 119 230.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import React from 'react';
|
|
19
|
+
import { createEmptyQrItem } from '../../../utils/qrItem';
|
|
20
|
+
import { QuestionnaireItem, QuestionnaireResponseItem } from 'fhir/r4';
|
|
21
|
+
import { GroupTableRowModel } from '../../../interfaces/groupTable.interface';
|
|
22
|
+
import {
|
|
23
|
+
PropsWithParentIsReadOnlyAttribute,
|
|
24
|
+
PropsWithShowMinimalViewAttribute
|
|
25
|
+
} from '../../../interfaces/renderProps.interface';
|
|
26
|
+
import GroupTableRow from './GroupTableRow';
|
|
27
|
+
import { DragDropContext, Droppable, DropResult } from 'react-beautiful-dnd';
|
|
28
|
+
import { reorderRows } from '../../../utils/groupTable';
|
|
29
|
+
import TableBody from '@mui/material/TableBody';
|
|
30
|
+
|
|
31
|
+
interface GroupTableBodyProps
|
|
32
|
+
extends PropsWithParentIsReadOnlyAttribute,
|
|
33
|
+
PropsWithShowMinimalViewAttribute {
|
|
34
|
+
tableQItem: QuestionnaireItem;
|
|
35
|
+
readOnly: boolean;
|
|
36
|
+
tableRows: GroupTableRowModel[];
|
|
37
|
+
selectedIds: string[];
|
|
38
|
+
qItemsIndexMap: Record<string, number>;
|
|
39
|
+
onRowChange: (newQrRow: QuestionnaireResponseItem, index: number) => void;
|
|
40
|
+
onRemoveRow: (index: number) => void;
|
|
41
|
+
onSelectRow: (nanoId: string) => void;
|
|
42
|
+
onReorderRows: (newTableRows: GroupTableRowModel[]) => void;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function GroupTableBody(props: GroupTableBodyProps) {
|
|
46
|
+
const {
|
|
47
|
+
tableQItem,
|
|
48
|
+
readOnly,
|
|
49
|
+
tableRows,
|
|
50
|
+
selectedIds,
|
|
51
|
+
qItemsIndexMap,
|
|
52
|
+
showMinimalView,
|
|
53
|
+
parentIsReadOnly,
|
|
54
|
+
onRowChange,
|
|
55
|
+
onRemoveRow,
|
|
56
|
+
onSelectRow,
|
|
57
|
+
onReorderRows
|
|
58
|
+
} = props;
|
|
59
|
+
|
|
60
|
+
function onDragEnd(result: DropResult) {
|
|
61
|
+
if (!result.destination) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (result.destination.index === result.source.index) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const reorderedRows = reorderRows(tableRows, result.source.index, result.destination.index);
|
|
70
|
+
|
|
71
|
+
onReorderRows(reorderedRows);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
<DragDropContext onDragEnd={onDragEnd}>
|
|
76
|
+
<Droppable droppableId="gtable_rows" direction="vertical">
|
|
77
|
+
{(droppableProvided, snapshot) => (
|
|
78
|
+
<TableBody ref={droppableProvided.innerRef} {...droppableProvided.droppableProps}>
|
|
79
|
+
{tableRows.map(({ nanoId, qrItem: nullableQrItem }, index) => {
|
|
80
|
+
const itemIsSelected = selectedIds.indexOf(nanoId) !== -1;
|
|
81
|
+
const answeredQrItem = createEmptyQrItem(tableQItem);
|
|
82
|
+
if (nullableQrItem) {
|
|
83
|
+
answeredQrItem.item = nullableQrItem.item;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<GroupTableRow
|
|
88
|
+
key={nanoId}
|
|
89
|
+
index={index}
|
|
90
|
+
nanoId={nanoId}
|
|
91
|
+
tableQItem={tableQItem}
|
|
92
|
+
answeredQrItem={answeredQrItem}
|
|
93
|
+
nullableQrItem={nullableQrItem}
|
|
94
|
+
readOnly={readOnly}
|
|
95
|
+
hoverDisabled={snapshot.isDraggingOver}
|
|
96
|
+
tableRows={tableRows}
|
|
97
|
+
itemIsSelected={itemIsSelected}
|
|
98
|
+
selectedIds={selectedIds}
|
|
99
|
+
qItemsIndexMap={qItemsIndexMap}
|
|
100
|
+
showMinimalView={showMinimalView}
|
|
101
|
+
parentIsReadOnly={parentIsReadOnly}
|
|
102
|
+
onRowChange={onRowChange}
|
|
103
|
+
onRemoveRow={onRemoveRow}
|
|
104
|
+
onSelectRow={onSelectRow}
|
|
105
|
+
/>
|
|
106
|
+
);
|
|
107
|
+
})}
|
|
108
|
+
{droppableProvided.placeholder}
|
|
109
|
+
</TableBody>
|
|
110
|
+
)}
|
|
111
|
+
</Droppable>
|
|
112
|
+
</DragDropContext>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export default GroupTableBody;
|