@openmrs/esm-form-builder-app 2.0.2-pre.574 → 2.0.2-pre.586

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 (85) hide show
  1. package/README.md +43 -17
  2. package/dist/127.js +1 -1
  3. package/dist/127.js.map +1 -1
  4. package/dist/150.js +1 -1
  5. package/dist/150.js.map +1 -1
  6. package/dist/153.js +1 -1
  7. package/dist/153.js.map +1 -1
  8. package/dist/164.js +1 -1
  9. package/dist/256.js +1 -1
  10. package/dist/319.js +1 -1
  11. package/dist/447.js +1 -1
  12. package/dist/447.js.map +1 -1
  13. package/dist/515.js +2 -0
  14. package/dist/{773.js.LICENSE.txt → 515.js.LICENSE.txt} +9 -0
  15. package/dist/515.js.map +1 -0
  16. package/dist/527.js +1 -0
  17. package/dist/527.js.map +1 -0
  18. package/dist/574.js +1 -1
  19. package/dist/757.js +1 -1
  20. package/dist/788.js +1 -1
  21. package/dist/800.js +1 -1
  22. package/dist/800.js.map +1 -1
  23. package/dist/807.js +1 -1
  24. package/dist/833.js +1 -1
  25. package/dist/878.js +2 -0
  26. package/dist/{208.js.LICENSE.txt → 878.js.LICENSE.txt} +2 -1
  27. package/dist/878.js.map +1 -0
  28. package/dist/main.js +1 -1
  29. package/dist/main.js.map +1 -1
  30. package/dist/openmrs-esm-form-builder-app.js +1 -1
  31. package/dist/openmrs-esm-form-builder-app.js.buildmanifest.json +154 -175
  32. package/dist/openmrs-esm-form-builder-app.js.map +1 -1
  33. package/dist/routes.json +1 -1
  34. package/package.json +35 -32
  35. package/src/components/action-buttons/action-buttons.component.tsx +65 -101
  36. package/src/components/dashboard/dashboard.component.tsx +98 -174
  37. package/src/components/dashboard/dashboard.test.tsx +51 -81
  38. package/src/components/empty-state/empty-data-illustration.component.tsx +4 -16
  39. package/src/components/empty-state/empty-state.component.tsx +11 -15
  40. package/src/components/error-state/error-state.component.tsx +11 -13
  41. package/src/components/form-editor/form-editor.component.tsx +97 -128
  42. package/src/components/form-renderer/form-renderer.component.tsx +30 -41
  43. package/src/components/interactive-builder/add-question-modal.component.tsx +129 -167
  44. package/src/components/interactive-builder/delete-page-modal.component.tsx +24 -37
  45. package/src/components/interactive-builder/delete-question-modal.component.tsx +25 -47
  46. package/src/components/interactive-builder/delete-section-modal.component.tsx +24 -37
  47. package/src/components/interactive-builder/draggable-question.component.tsx +21 -34
  48. package/src/components/interactive-builder/droppable-container.component.tsx +5 -5
  49. package/src/components/interactive-builder/edit-question-modal.component.tsx +191 -233
  50. package/src/components/interactive-builder/editable-value.component.tsx +12 -17
  51. package/src/components/interactive-builder/interactive-builder.component.tsx +134 -184
  52. package/src/components/interactive-builder/new-form-modal.component.tsx +35 -49
  53. package/src/components/interactive-builder/page-modal.component.tsx +29 -45
  54. package/src/components/interactive-builder/question-modal.scss +7 -0
  55. package/src/components/interactive-builder/section-modal.component.tsx +29 -40
  56. package/src/components/interactive-builder/value-editor.component.tsx +11 -16
  57. package/src/components/modals/save-form-modal.component.tsx +112 -165
  58. package/src/components/pagination/index.ts +2 -2
  59. package/src/components/pagination/pagination.component.tsx +8 -13
  60. package/src/components/pagination/usePaginationInfo.ts +4 -9
  61. package/src/components/schema-editor/schema-editor.component.tsx +11 -17
  62. package/src/config-schema.ts +28 -30
  63. package/src/declarations.d.ts +4 -3
  64. package/src/form-builder-admin-card-link.component.tsx +7 -11
  65. package/src/forms.resource.ts +66 -87
  66. package/src/hooks/useClobdata.ts +10 -12
  67. package/src/hooks/useConceptLookup.ts +5 -8
  68. package/src/hooks/useConceptName.ts +6 -9
  69. package/src/hooks/useEncounterTypes.ts +8 -8
  70. package/src/hooks/useForm.ts +7 -7
  71. package/src/hooks/useForms.ts +5 -8
  72. package/src/index.ts +11 -23
  73. package/src/root.component.tsx +4 -4
  74. package/src/setup-tests.ts +1 -9
  75. package/src/test-helpers.tsx +8 -15
  76. package/src/types.ts +16 -8
  77. package/dist/208.js +0 -2
  78. package/dist/208.js.map +0 -1
  79. package/dist/536.js +0 -1
  80. package/dist/536.js.map +0 -1
  81. package/dist/62.js +0 -1
  82. package/dist/62.js.map +0 -1
  83. package/dist/773.js +0 -2
  84. package/dist/773.js.map +0 -1
  85. package/src/constants.ts +0 -3
@@ -1,5 +1,5 @@
1
- import React, { useState } from "react";
2
- import { useTranslation } from "react-i18next";
1
+ import React, { useState } from 'react';
2
+ import { useTranslation } from 'react-i18next';
3
3
  import {
4
4
  Button,
5
5
  ComposedModal,
@@ -10,26 +10,21 @@ import {
10
10
  ModalHeader,
11
11
  Stack,
12
12
  TextInput,
13
- } from "@carbon/react";
14
- import { showToast, showNotification } from "@openmrs/esm-framework";
15
- import type { Schema } from "../../types";
13
+ } from '@carbon/react';
14
+ import { showToast, showNotification } from '@openmrs/esm-framework';
15
+ import type { Schema } from '../../types';
16
16
 
17
- type NewFormModalProps = {
17
+ interface NewFormModalProps {
18
18
  schema: Schema;
19
19
  onSchemaChange: (schema: Schema) => void;
20
20
  onModalChange: (showModal: boolean) => void;
21
21
  showModal: boolean;
22
- };
22
+ }
23
23
 
24
- const NewFormModal: React.FC<NewFormModalProps> = ({
25
- schema,
26
- onSchemaChange,
27
- showModal,
28
- onModalChange,
29
- }) => {
24
+ const NewFormModal: React.FC<NewFormModalProps> = ({ schema, onSchemaChange, showModal, onModalChange }) => {
30
25
  const { t } = useTranslation();
31
- const [formName, setFormName] = useState("");
32
- const [formDescription, setFormDescription] = useState("");
26
+ const [formName, setFormName] = useState('');
27
+ const [formDescription, setFormDescription] = useState('');
33
28
 
34
29
  const updateSchema = (updates: Partial<Schema>) => {
35
30
  try {
@@ -37,18 +32,20 @@ const NewFormModal: React.FC<NewFormModalProps> = ({
37
32
  onSchemaChange(updatedSchema);
38
33
 
39
34
  showToast({
40
- title: t("success", "Success!"),
41
- kind: "success",
35
+ title: t('success', 'Success!'),
36
+ kind: 'success',
42
37
  critical: true,
43
- description: t("formCreated", "New form created"),
38
+ description: t('formCreated', 'New form created'),
44
39
  });
45
40
  } catch (error) {
46
- showNotification({
47
- title: t("errorCreatingForm", "Error creating form"),
48
- kind: "error",
49
- critical: true,
50
- description: error?.message,
51
- });
41
+ if (error instanceof Error) {
42
+ showNotification({
43
+ title: t('errorCreatingForm', 'Error creating form'),
44
+ kind: 'error',
45
+ critical: true,
46
+ description: error?.message,
47
+ });
48
+ }
52
49
  }
53
50
  };
54
51
 
@@ -64,41 +61,30 @@ const NewFormModal: React.FC<NewFormModalProps> = ({
64
61
  };
65
62
 
66
63
  return (
67
- <ComposedModal
68
- open={showModal}
69
- onClose={() => onModalChange(false)}
70
- preventCloseOnClickOutside
71
- >
72
- <ModalHeader title={t("createNewForm", "Create a new form")} />
73
- <Form onSubmit={(event) => event.preventDefault()}>
64
+ <ComposedModal open={showModal} onClose={() => onModalChange(false)} preventCloseOnClickOutside>
65
+ <ModalHeader title={t('createNewForm', 'Create a new form')} />
66
+ <Form onSubmit={(event: React.SyntheticEvent) => event.preventDefault()}>
74
67
  <ModalBody>
75
68
  <Stack gap={5}>
76
- <FormGroup legendText={""}>
69
+ <FormGroup legendText={''}>
77
70
  <TextInput
78
71
  id="formName"
79
- labelText={t("formName", "Form name")}
80
- placeholder={t(
81
- "formNamePlaceholder",
82
- "What the form is called in the system"
83
- )}
72
+ labelText={t('formName', 'Form name')}
73
+ placeholder={t('namePlaceholder', 'What the form is called in the system')}
84
74
  value={formName}
85
- onChange={(event: React.ChangeEvent<HTMLInputElement>) =>
86
- setFormName(event.target.value)
87
- }
75
+ onChange={(event: React.ChangeEvent<HTMLInputElement>) => setFormName(event.target.value)}
88
76
  />
89
77
  </FormGroup>
90
- <FormGroup legendText={""}>
78
+ <FormGroup legendText={''}>
91
79
  <TextInput
92
80
  id="formDescription"
93
- labelText={t("formDescription", "Form description")}
81
+ labelText={t('formDescription', 'Form description')}
94
82
  placeholder={t(
95
- "formDescriptionPlaceholder",
96
- "A short description of the form e.g. A form for collecting COVID-19 symptoms"
83
+ 'formDescriptionPlaceholder',
84
+ 'A short description of the form e.g. A form for collecting COVID-19 symptoms',
97
85
  )}
98
86
  value={formDescription}
99
- onChange={(event: React.ChangeEvent<HTMLInputElement>) =>
100
- setFormDescription(event.target.value)
101
- }
87
+ onChange={(event: React.ChangeEvent<HTMLInputElement>) => setFormDescription(event.target.value)}
102
88
  />
103
89
  </FormGroup>
104
90
  </Stack>
@@ -106,10 +92,10 @@ const NewFormModal: React.FC<NewFormModalProps> = ({
106
92
  </Form>
107
93
  <ModalFooter>
108
94
  <Button kind="secondary" onClick={() => onModalChange(false)}>
109
- {t("cancel", "Cancel")}
95
+ {t('cancel', 'Cancel')}
110
96
  </Button>
111
97
  <Button disabled={!formName} onClick={handleCreateForm}>
112
- <span>{t("createForm", "Create Form")}</span>
98
+ <span>{t('createForm', 'Create Form')}</span>
113
99
  </Button>
114
100
  </ModalFooter>
115
101
  </ComposedModal>
@@ -1,33 +1,19 @@
1
- import React, { useState } from "react";
2
- import { useTranslation } from "react-i18next";
3
- import {
4
- Button,
5
- ComposedModal,
6
- Form,
7
- FormGroup,
8
- ModalBody,
9
- ModalFooter,
10
- ModalHeader,
11
- TextInput,
12
- } from "@carbon/react";
13
- import { showToast, showNotification } from "@openmrs/esm-framework";
14
- import type { Schema } from "../../types";
1
+ import React, { useState } from 'react';
2
+ import { useTranslation } from 'react-i18next';
3
+ import { Button, ComposedModal, Form, FormGroup, ModalBody, ModalFooter, ModalHeader, TextInput } from '@carbon/react';
4
+ import { showToast, showNotification } from '@openmrs/esm-framework';
5
+ import type { Schema } from '../../types';
15
6
 
16
- type PageModalProps = {
7
+ interface PageModalProps {
17
8
  schema: Schema;
18
9
  onSchemaChange: (schema: Schema) => void;
19
10
  showModal: boolean;
20
11
  onModalChange: (showModal: boolean) => void;
21
- };
12
+ }
22
13
 
23
- const PageModal: React.FC<PageModalProps> = ({
24
- schema,
25
- onSchemaChange,
26
- showModal,
27
- onModalChange,
28
- }) => {
14
+ const PageModal: React.FC<PageModalProps> = ({ schema, onSchemaChange, showModal, onModalChange }) => {
29
15
  const { t } = useTranslation();
30
- const [pageTitle, setPageTitle] = useState("");
16
+ const [pageTitle, setPageTitle] = useState('');
31
17
 
32
18
  const handleUpdatePageTitle = () => {
33
19
  updatePages();
@@ -43,49 +29,47 @@ const PageModal: React.FC<PageModalProps> = ({
43
29
  });
44
30
 
45
31
  onSchemaChange({ ...schema });
46
- setPageTitle("");
32
+ setPageTitle('');
47
33
  }
48
34
  showToast({
49
- title: t("success", "Success!"),
50
- kind: "success",
35
+ title: t('success', 'Success!'),
36
+ kind: 'success',
51
37
  critical: true,
52
- description: t("pageCreated", "New page created"),
38
+ description: t('pageCreated', 'New page created'),
53
39
  });
54
40
  } catch (error) {
55
- showNotification({
56
- title: t("errorCreatingPage", "Error creating page"),
57
- kind: "error",
58
- critical: true,
59
- description: error?.message,
60
- });
41
+ if (error instanceof Error) {
42
+ showNotification({
43
+ title: t('errorCreatingPage', 'Error creating page'),
44
+ kind: 'error',
45
+ critical: true,
46
+ description: error?.message,
47
+ });
48
+ }
61
49
  }
62
50
  };
63
51
 
64
52
  return (
65
- <ComposedModal
66
- open={showModal}
67
- onClose={() => onModalChange(false)}
68
- preventCloseOnClickOutside
69
- >
70
- <ModalHeader title={t("createNewPage", "Create a new page")} />
71
- <Form onSubmit={(event) => event.preventDefault()}>
53
+ <ComposedModal open={showModal} onClose={() => onModalChange(false)} preventCloseOnClickOutside>
54
+ <ModalHeader title={t('createNewPage', 'Create a new page')} />
55
+ <Form onSubmit={(event: React.SyntheticEvent) => event.preventDefault()}>
72
56
  <ModalBody>
73
- <FormGroup legendText={""}>
57
+ <FormGroup legendText={''}>
74
58
  <TextInput
75
59
  id="pageTitle"
76
- labelText={t("enterPageTitle", "Enter a title for your new page")}
60
+ labelText={t('enterPageTitle', 'Enter a title for your new page')}
77
61
  value={pageTitle}
78
- onChange={(event) => setPageTitle(event.target.value)}
62
+ onChange={(event: React.ChangeEvent<HTMLInputElement>) => setPageTitle(event.target.value)}
79
63
  />
80
64
  </FormGroup>
81
65
  </ModalBody>
82
66
  </Form>
83
67
  <ModalFooter>
84
68
  <Button onClick={() => onModalChange(false)} kind="secondary">
85
- {t("cancel", "Cancel")}
69
+ {t('cancel', 'Cancel')}
86
70
  </Button>
87
71
  <Button disabled={!pageTitle} onClick={handleUpdatePageTitle}>
88
- <span>{t("save", "Save")}</span>
72
+ <span>{t('save', 'Save')}</span>
89
73
  </Button>
90
74
  </ModalFooter>
91
75
  </ComposedModal>
@@ -104,3 +104,10 @@
104
104
  width: 100%;
105
105
  }
106
106
  }
107
+
108
+ .error {
109
+ width: 100%;
110
+ max-width: unset;
111
+ padding: '0rem';
112
+ margin-bottom: 1rem;
113
+ }
@@ -1,26 +1,17 @@
1
- import React, { useState } from "react";
2
- import { useTranslation } from "react-i18next";
3
- import {
4
- Button,
5
- ComposedModal,
6
- Form,
7
- FormGroup,
8
- ModalBody,
9
- ModalFooter,
10
- ModalHeader,
11
- TextInput,
12
- } from "@carbon/react";
13
- import { showToast, showNotification } from "@openmrs/esm-framework";
14
- import type { Schema } from "../../types";
1
+ import React, { useState } from 'react';
2
+ import { useTranslation } from 'react-i18next';
3
+ import { Button, ComposedModal, Form, FormGroup, ModalBody, ModalFooter, ModalHeader, TextInput } from '@carbon/react';
4
+ import { showToast, showNotification } from '@openmrs/esm-framework';
5
+ import type { Schema } from '../../types';
15
6
 
16
- type SectionModalProps = {
7
+ interface SectionModalProps {
17
8
  schema: Schema;
18
9
  onSchemaChange: (schema: Schema) => void;
19
10
  pageIndex: number;
20
11
  resetIndices: () => void;
21
12
  showModal: boolean;
22
13
  onModalChange: (showModal: boolean) => void;
23
- };
14
+ }
24
15
 
25
16
  const SectionModal: React.FC<SectionModalProps> = ({
26
17
  schema,
@@ -31,7 +22,7 @@ const SectionModal: React.FC<SectionModalProps> = ({
31
22
  onModalChange,
32
23
  }) => {
33
24
  const { t } = useTranslation();
34
- const [sectionTitle, setSectionTitle] = useState("");
25
+ const [sectionTitle, setSectionTitle] = useState('');
35
26
 
36
27
  const handleUpdatePageSections = () => {
37
28
  updateSections();
@@ -42,54 +33,52 @@ const SectionModal: React.FC<SectionModalProps> = ({
42
33
  try {
43
34
  schema.pages[pageIndex]?.sections?.push({
44
35
  label: sectionTitle,
45
- isExpanded: "true",
36
+ isExpanded: 'true',
46
37
  questions: [],
47
38
  });
48
39
  onSchemaChange({ ...schema });
49
- setSectionTitle("");
40
+ setSectionTitle('');
50
41
  resetIndices();
51
42
 
52
43
  showToast({
53
- title: t("success", "Success!"),
54
- kind: "success",
44
+ title: t('success', 'Success!'),
45
+ kind: 'success',
55
46
  critical: true,
56
- description: t("sectionCreated", "New section created"),
47
+ description: t('sectionCreated', 'New section created'),
57
48
  });
58
49
  } catch (error) {
59
- showNotification({
60
- title: t("errorCreatingSection", "Error creating section"),
61
- kind: "error",
62
- critical: true,
63
- description: error?.message,
64
- });
50
+ if (error instanceof Error) {
51
+ showNotification({
52
+ title: t('errorCreatingSection', 'Error creating section'),
53
+ kind: 'error',
54
+ critical: true,
55
+ description: error?.message,
56
+ });
57
+ }
65
58
  }
66
59
  };
67
60
 
68
61
  return (
69
- <ComposedModal
70
- open={showModal}
71
- onClose={() => onModalChange(false)}
72
- preventCloseOnClickOutside
73
- >
74
- <ModalHeader title={t("createNewSection", "Create a new section")} />
75
- <Form onSubmit={(event) => event.preventDefault()}>
62
+ <ComposedModal open={showModal} onClose={() => onModalChange(false)} preventCloseOnClickOutside>
63
+ <ModalHeader title={t('createNewSection', 'Create a new section')} />
64
+ <Form onSubmit={(event: React.SyntheticEvent) => event.preventDefault()}>
76
65
  <ModalBody>
77
- <FormGroup legendText={""}>
66
+ <FormGroup legendText={''}>
78
67
  <TextInput
79
68
  id="sectionTitle"
80
- labelText={t("enterSectionTitle", "Enter a section title")}
69
+ labelText={t('enterSectionTitle', 'Enter a section title')}
81
70
  value={sectionTitle}
82
- onChange={(event) => setSectionTitle(event.target.value)}
71
+ onChange={(event: React.ChangeEvent<HTMLInputElement>) => setSectionTitle(event.target.value)}
83
72
  />
84
73
  </FormGroup>
85
74
  </ModalBody>
86
75
  </Form>
87
76
  <ModalFooter>
88
77
  <Button onClick={() => onModalChange(false)} kind="secondary">
89
- {t("cancel", "Cancel")}
78
+ {t('cancel', 'Cancel')}
90
79
  </Button>
91
80
  <Button disabled={!sectionTitle} onClick={handleUpdatePageSections}>
92
- <span>{t("save", "Save")}</span>
81
+ <span>{t('save', 'Save')}</span>
93
82
  </Button>
94
83
  </ModalFooter>
95
84
  </ComposedModal>
@@ -1,23 +1,18 @@
1
- import React, { useState } from "react";
2
- import { useTranslation } from "react-i18next";
3
- import { Button, TextInput } from "@carbon/react";
4
- import { Close, Save } from "@carbon/react/icons";
5
- import styles from "./value-editor.scss";
1
+ import React, { useState } from 'react';
2
+ import { useTranslation } from 'react-i18next';
3
+ import { Button, TextInput } from '@carbon/react';
4
+ import { Close, Save } from '@carbon/react/icons';
5
+ import styles from './value-editor.scss';
6
6
 
7
- type ValueEditorProps = {
7
+ interface ValueEditorProps {
8
8
  id: string;
9
9
  handleCancel: () => void;
10
10
  handleSave: (value: string) => void;
11
11
  onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
12
12
  value: string;
13
- };
13
+ }
14
14
 
15
- const ValueEditor: React.FC<ValueEditorProps> = ({
16
- id,
17
- handleCancel,
18
- handleSave,
19
- value,
20
- }) => {
15
+ const ValueEditor: React.FC<ValueEditorProps> = ({ id, handleCancel, handleSave, value }) => {
21
16
  const { t } = useTranslation();
22
17
  const [tmpValue, setTmpValue] = useState(value);
23
18
 
@@ -27,7 +22,7 @@ const ValueEditor: React.FC<ValueEditorProps> = ({
27
22
  id={id}
28
23
  labelText=""
29
24
  value={tmpValue}
30
- onChange={(event) => setTmpValue(event.target.value)}
25
+ onChange={(event: React.ChangeEvent<HTMLInputElement>) => setTmpValue(event.target.value)}
31
26
  />
32
27
  <div className={styles.actionButtons}>
33
28
  <Button
@@ -36,7 +31,7 @@ const ValueEditor: React.FC<ValueEditorProps> = ({
36
31
  kind="primary"
37
32
  onClick={() => handleSave(tmpValue)}
38
33
  >
39
- {t("saveButtonText", "Save")}
34
+ {t('saveButtonText', 'Save')}
40
35
  </Button>
41
36
  <Button
42
37
  size="md"
@@ -44,7 +39,7 @@ const ValueEditor: React.FC<ValueEditorProps> = ({
44
39
  kind="secondary"
45
40
  onClick={handleCancel}
46
41
  >
47
- {t("cancelButtonText", "Cancel")}
42
+ {t('cancelButtonText', 'Cancel')}
48
43
  </Button>
49
44
  </div>
50
45
  </>