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

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 (86) 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/draggable-question.scss +2 -2
  49. package/src/components/interactive-builder/droppable-container.component.tsx +5 -5
  50. package/src/components/interactive-builder/edit-question-modal.component.tsx +191 -233
  51. package/src/components/interactive-builder/editable-value.component.tsx +12 -17
  52. package/src/components/interactive-builder/interactive-builder.component.tsx +134 -184
  53. package/src/components/interactive-builder/new-form-modal.component.tsx +35 -49
  54. package/src/components/interactive-builder/page-modal.component.tsx +29 -45
  55. package/src/components/interactive-builder/question-modal.scss +7 -0
  56. package/src/components/interactive-builder/section-modal.component.tsx +29 -40
  57. package/src/components/interactive-builder/value-editor.component.tsx +11 -16
  58. package/src/components/modals/save-form-modal.component.tsx +112 -165
  59. package/src/components/pagination/index.ts +2 -2
  60. package/src/components/pagination/pagination.component.tsx +8 -13
  61. package/src/components/pagination/usePaginationInfo.ts +4 -9
  62. package/src/components/schema-editor/schema-editor.component.tsx +11 -17
  63. package/src/config-schema.ts +28 -30
  64. package/src/declarations.d.ts +4 -3
  65. package/src/form-builder-admin-card-link.component.tsx +7 -11
  66. package/src/forms.resource.ts +66 -87
  67. package/src/hooks/useClobdata.ts +10 -12
  68. package/src/hooks/useConceptLookup.ts +5 -8
  69. package/src/hooks/useConceptName.ts +6 -9
  70. package/src/hooks/useEncounterTypes.ts +8 -8
  71. package/src/hooks/useForm.ts +7 -7
  72. package/src/hooks/useForms.ts +5 -8
  73. package/src/index.ts +11 -23
  74. package/src/root.component.tsx +4 -4
  75. package/src/setup-tests.ts +1 -9
  76. package/src/test-helpers.tsx +8 -15
  77. package/src/types.ts +16 -8
  78. package/dist/208.js +0 -2
  79. package/dist/208.js.map +0 -1
  80. package/dist/536.js +0 -1
  81. package/dist/536.js.map +0 -1
  82. package/dist/62.js +0 -1
  83. package/dist/62.js.map +0 -1
  84. package/dist/773.js +0 -2
  85. package/dist/773.js.map +0 -1
  86. package/src/constants.ts +0 -3
@@ -1,16 +1,10 @@
1
- import React from "react";
2
- import { useTranslation } from "react-i18next";
3
- import {
4
- Button,
5
- ComposedModal,
6
- ModalBody,
7
- ModalFooter,
8
- ModalHeader,
9
- } from "@carbon/react";
10
- import { showNotification, showToast } from "@openmrs/esm-framework";
11
- import type { Schema } from "../../types";
1
+ import React from 'react';
2
+ import { useTranslation } from 'react-i18next';
3
+ import { Button, ComposedModal, ModalBody, ModalFooter, ModalHeader } from '@carbon/react';
4
+ import { showNotification, showToast } from '@openmrs/esm-framework';
5
+ import type { Schema } from '../../types';
12
6
 
13
- type DeleteQuestionModal = {
7
+ interface DeleteQuestionModal {
14
8
  onModalChange: (showModal: boolean) => void;
15
9
  onSchemaChange: (schema: Schema) => void;
16
10
  resetIndices: () => void;
@@ -19,7 +13,7 @@ type DeleteQuestionModal = {
19
13
  questionIndex: number;
20
14
  schema: Schema;
21
15
  showModal: boolean;
22
- };
16
+ }
23
17
 
24
18
  const DeleteQuestionModal: React.FC<DeleteQuestionModal> = ({
25
19
  onModalChange,
@@ -33,56 +27,40 @@ const DeleteQuestionModal: React.FC<DeleteQuestionModal> = ({
33
27
  }) => {
34
28
  const { t } = useTranslation();
35
29
 
36
- const deleteQuestion = (
37
- pageIndex: number,
38
- sectionIndex: number,
39
- questionIndex: number
40
- ) => {
30
+ const deleteQuestion = (pageIndex: number, sectionIndex: number, questionIndex: number) => {
41
31
  try {
42
- schema.pages[pageIndex].sections[sectionIndex].questions.splice(
43
- questionIndex,
44
- 1
45
- );
32
+ schema.pages[pageIndex].sections[sectionIndex].questions.splice(questionIndex, 1);
46
33
 
47
34
  onSchemaChange({ ...schema });
48
35
  resetIndices();
49
36
 
50
37
  showToast({
51
- title: t("success", "Success!"),
52
- kind: "success",
38
+ title: t('success', 'Success!'),
39
+ kind: 'success',
53
40
  critical: true,
54
- description: t("QuestionDeleted", "Question deleted"),
41
+ description: t('QuestionDeleted', 'Question deleted'),
55
42
  });
56
43
  } catch (error) {
57
- showNotification({
58
- title: t("errorDeletingQuestion", "Error deleting question"),
59
- kind: "error",
60
- critical: true,
61
- description: error?.message,
62
- });
44
+ if (error instanceof Error) {
45
+ showNotification({
46
+ title: t('errorDeletingQuestion', 'Error deleting question'),
47
+ kind: 'error',
48
+ critical: true,
49
+ description: error?.message,
50
+ });
51
+ }
63
52
  }
64
53
  };
65
54
 
66
55
  return (
67
- <ComposedModal
68
- open={showModal}
69
- onClose={() => onModalChange(false)}
70
- preventCloseOnClickOutside
71
- >
72
- <ModalHeader
73
- title={t(
74
- "deleteQuestionConfirmation",
75
- "Are you sure you want to delete this question?"
76
- )}
77
- />
56
+ <ComposedModal open={showModal} onClose={() => onModalChange(false)} preventCloseOnClickOutside>
57
+ <ModalHeader title={t('deleteQuestionConfirmation', 'Are you sure you want to delete this question?')} />
78
58
  <ModalBody>
79
- <p>
80
- {t("deleteQuestionExplainerText", "This action cannot be undone.")}
81
- </p>
59
+ <p>{t('deleteQuestionExplainerText', 'This action cannot be undone.')}</p>
82
60
  </ModalBody>
83
61
  <ModalFooter>
84
62
  <Button kind="secondary" onClick={() => onModalChange(false)}>
85
- {t("cancel", "Cancel")}
63
+ {t('cancel', 'Cancel')}
86
64
  </Button>
87
65
  <Button
88
66
  kind="danger"
@@ -91,7 +69,7 @@ const DeleteQuestionModal: React.FC<DeleteQuestionModal> = ({
91
69
  onModalChange(false);
92
70
  }}
93
71
  >
94
- <span>{t("deleteQuestion", "Delete question")}</span>
72
+ <span>{t('deleteQuestion', 'Delete question')}</span>
95
73
  </Button>
96
74
  </ModalFooter>
97
75
  </ComposedModal>
@@ -1,16 +1,10 @@
1
- import React from "react";
2
- import { useTranslation } from "react-i18next";
3
- import {
4
- Button,
5
- ComposedModal,
6
- ModalBody,
7
- ModalFooter,
8
- ModalHeader,
9
- } from "@carbon/react";
10
- import { showNotification, showToast } from "@openmrs/esm-framework";
11
- import type { Schema } from "../../types";
1
+ import React from 'react';
2
+ import { useTranslation } from 'react-i18next';
3
+ import { Button, ComposedModal, ModalBody, ModalFooter, ModalHeader } from '@carbon/react';
4
+ import { showNotification, showToast } from '@openmrs/esm-framework';
5
+ import type { Schema } from '../../types';
12
6
 
13
- type DeleteSectionModal = {
7
+ interface DeleteSectionModal {
14
8
  onModalChange: (showModal: boolean) => void;
15
9
  onSchemaChange: (schema: Schema) => void;
16
10
  resetIndices: () => void;
@@ -18,7 +12,7 @@ type DeleteSectionModal = {
18
12
  sectionIndex: number;
19
13
  schema: Schema;
20
14
  showModal: boolean;
21
- };
15
+ }
22
16
 
23
17
  const DeleteSectionModal: React.FC<DeleteSectionModal> = ({
24
18
  onModalChange,
@@ -39,44 +33,37 @@ const DeleteSectionModal: React.FC<DeleteSectionModal> = ({
39
33
  resetIndices();
40
34
 
41
35
  showToast({
42
- title: t("success", "Success!"),
43
- kind: "success",
36
+ title: t('success', 'Success!'),
37
+ kind: 'success',
44
38
  critical: true,
45
- description: t("SectionDeleted", "Section deleted"),
39
+ description: t('SectionDeleted', 'Section deleted'),
46
40
  });
47
41
  } catch (error) {
48
- showNotification({
49
- title: t("errorDeletingSection", "Error deleting section"),
50
- kind: "error",
51
- critical: true,
52
- description: error?.message,
53
- });
42
+ if (error instanceof Error) {
43
+ showNotification({
44
+ title: t('errorDeletingSection', 'Error deleting section'),
45
+ kind: 'error',
46
+ critical: true,
47
+ description: error?.message,
48
+ });
49
+ }
54
50
  }
55
51
  };
56
52
 
57
53
  return (
58
- <ComposedModal
59
- open={showModal}
60
- onClose={() => onModalChange(false)}
61
- preventCloseOnClickOutside
62
- >
63
- <ModalHeader
64
- title={t(
65
- "deleteSectionConfirmation",
66
- "Are you sure you want to delete this section?"
67
- )}
68
- />
54
+ <ComposedModal open={showModal} onClose={() => onModalChange(false)} preventCloseOnClickOutside>
55
+ <ModalHeader title={t('deleteSectionConfirmation', 'Are you sure you want to delete this section?')} />
69
56
  <ModalBody>
70
57
  <p>
71
58
  {t(
72
- "deleteSectionExplainerText",
73
- "Deleting this section will delete all the questions associated with it. This action cannot be undone."
59
+ 'deleteSectionExplainerText',
60
+ 'Deleting this section will delete all the questions associated with it. This action cannot be undone.',
74
61
  )}
75
62
  </p>
76
63
  </ModalBody>
77
64
  <ModalFooter>
78
65
  <Button kind="secondary" onClick={() => onModalChange(false)}>
79
- {t("cancel", "Cancel")}
66
+ {t('cancel', 'Cancel')}
80
67
  </Button>
81
68
  <Button
82
69
  kind="danger"
@@ -85,7 +72,7 @@ const DeleteSectionModal: React.FC<DeleteSectionModal> = ({
85
72
  onModalChange(false);
86
73
  }}
87
74
  >
88
- <span>{t("deleteSection", "Delete section")}</span>
75
+ <span>{t('deleteSection', 'Delete section')}</span>
89
76
  </Button>
90
77
  </ModalFooter>
91
78
  </ComposedModal>
@@ -1,26 +1,22 @@
1
- import React from "react";
2
- import { useDraggable } from "@dnd-kit/core";
3
- import { CSS } from "@dnd-kit/utilities";
4
- import { useTranslation } from "react-i18next";
5
- import { Button, CopyButton } from "@carbon/react";
6
- import { Draggable, Edit, TrashCan } from "@carbon/react/icons";
7
- import type { Question } from "../../types";
8
- import styles from "./draggable-question.scss";
1
+ import React from 'react';
2
+ import { useDraggable } from '@dnd-kit/core';
3
+ import { CSS } from '@dnd-kit/utilities';
4
+ import { useTranslation } from 'react-i18next';
5
+ import { Button, CopyButton } from '@carbon/react';
6
+ import { Draggable, Edit, TrashCan } from '@carbon/react/icons';
7
+ import type { Question } from '../../types';
8
+ import styles from './draggable-question.scss';
9
9
 
10
- type DraggableQuestionProps = {
10
+ interface DraggableQuestionProps {
11
11
  question: Question;
12
12
  pageIndex: number;
13
13
  sectionIndex: number;
14
14
  questionIndex: number;
15
- handleDuplicateQuestion: (
16
- question: Question,
17
- pageId: number,
18
- sectionId: number
19
- ) => void;
15
+ handleDuplicateQuestion: (question: Question, pageId: number, sectionId: number) => void;
20
16
  handleEditButtonClick: (question: Question) => void;
21
17
  handleDeleteButtonClick: (question: Question) => void;
22
18
  questionCount: number;
23
- };
19
+ }
24
20
 
25
21
  export const DraggableQuestion: React.FC<DraggableQuestionProps> = ({
26
22
  question,
@@ -35,11 +31,10 @@ export const DraggableQuestion: React.FC<DraggableQuestionProps> = ({
35
31
  const { t } = useTranslation();
36
32
  const draggableId = `question-${pageIndex}-${sectionIndex}-${questionIndex}`;
37
33
 
38
- const { attributes, listeners, transform, isDragging, setNodeRef } =
39
- useDraggable({
40
- id: draggableId,
41
- disabled: questionCount <= 1,
42
- });
34
+ const { attributes, listeners, transform, isDragging, setNodeRef } = useDraggable({
35
+ id: draggableId,
36
+ disabled: questionCount <= 1,
37
+ });
43
38
 
44
39
  const style = {
45
40
  transform: CSS.Translate.toString(transform),
@@ -50,12 +45,7 @@ export const DraggableQuestion: React.FC<DraggableQuestionProps> = ({
50
45
  return (
51
46
  <div className={dragStyles} style={style}>
52
47
  <div className={styles.iconAndName}>
53
- <div
54
- className={styles.dragIconContainer}
55
- ref={setNodeRef}
56
- {...attributes}
57
- {...listeners}
58
- >
48
+ <div className={styles.dragIconContainer} ref={setNodeRef} {...attributes} {...listeners}>
59
49
  <Draggable className={styles.dragIcon} size={16} />
60
50
  </div>
61
51
  <p className={styles.questionLabel}>{question.label}</p>
@@ -64,18 +54,15 @@ export const DraggableQuestion: React.FC<DraggableQuestionProps> = ({
64
54
  <CopyButton
65
55
  align="top"
66
56
  className="cds--btn--sm"
67
- feedback={t("duplicated", "Duplicated") + "!"}
68
- iconDescription={t("duplicateQuestion", "Duplicate question")}
57
+ feedback={t('duplicated', 'Duplicated') + '!'}
58
+ iconDescription={t('duplicateQuestion', 'Duplicate question')}
69
59
  kind="ghost"
70
- onClick={() =>
71
- !isDragging &&
72
- handleDuplicateQuestion(question, pageIndex, sectionIndex)
73
- }
60
+ onClick={() => !isDragging && handleDuplicateQuestion(question, pageIndex, sectionIndex)}
74
61
  />
75
62
  <Button
76
63
  enterDelayMs={300}
77
64
  hasIconOnly
78
- iconDescription={t("editQuestion", "Edit question")}
65
+ iconDescription={t('editQuestion', 'Edit question')}
79
66
  kind="ghost"
80
67
  onClick={() => {
81
68
  if (!isDragging) {
@@ -88,7 +75,7 @@ export const DraggableQuestion: React.FC<DraggableQuestionProps> = ({
88
75
  <Button
89
76
  enterDelayMs={300}
90
77
  hasIconOnly
91
- iconDescription={t("deleteQuestion", "Delete question")}
78
+ iconDescription={t('deleteQuestion', 'Delete question')}
92
79
  kind="ghost"
93
80
  onClick={handleDeleteButtonClick}
94
81
  renderIcon={(props) => <TrashCan size={16} {...props} />}
@@ -33,14 +33,14 @@
33
33
  cursor: pointer;
34
34
 
35
35
  :hover {
36
- background-color: colors.$white-0;
36
+ background-color: colors.$gray-20;
37
37
  }
38
38
  }
39
39
 
40
40
  .dragIcon {
41
41
  margin: 0 layout.$spacing-03;
42
42
  padding: 0.25rem;
43
- color: colors.$gray-50;
43
+ color: colors.$gray-80;
44
44
  margin-top: 0.25rem;
45
45
  width: 1.5rem;
46
46
  height: 1.5rem;
@@ -1,10 +1,10 @@
1
- import React from "react";
2
- import { useDroppable } from "@dnd-kit/core";
1
+ import React from 'react';
2
+ import { useDroppable } from '@dnd-kit/core';
3
3
 
4
- type DroppableProps = {
4
+ interface DroppableProps {
5
5
  id: string;
6
6
  children: React.ReactNode;
7
- };
7
+ }
8
8
 
9
9
  export function Droppable({ id, children }: DroppableProps) {
10
10
  const { isOver, setNodeRef } = useDroppable({
@@ -12,7 +12,7 @@ export function Droppable({ id, children }: DroppableProps) {
12
12
  });
13
13
 
14
14
  const style = {
15
- border: `1px solid ${isOver ? "#005d5d" : "transparent"}`,
15
+ border: `1px solid ${isOver ? '#005d5d' : 'transparent'}`,
16
16
  };
17
17
 
18
18
  return (