@openmrs/esm-form-builder-app 2.0.2-pre.559 → 2.0.2-pre.568

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.
@@ -2,24 +2,24 @@ import React from "react";
2
2
  import { useDraggable } from "@dnd-kit/core";
3
3
  import { CSS } from "@dnd-kit/utilities";
4
4
  import { useTranslation } from "react-i18next";
5
- import { Button } from "@carbon/react";
6
- import { Edit, Replicate, TrashCan, Draggable } from "@carbon/react/icons";
5
+ import { Button, CopyButton } from "@carbon/react";
6
+ import { Draggable, Edit, TrashCan } from "@carbon/react/icons";
7
7
  import type { Question } from "../../types";
8
8
  import styles from "./draggable-question.scss";
9
9
 
10
10
  type DraggableQuestionProps = {
11
- allQuestions: Array<Question>;
12
11
  question: Question;
13
12
  pageIndex: number;
14
13
  sectionIndex: number;
15
14
  questionIndex: number;
16
- duplicateQuestion: (
15
+ handleDuplicateQuestion: (
17
16
  question: Question,
18
17
  pageId: number,
19
18
  sectionId: number
20
19
  ) => void;
21
20
  handleEditButtonClick: (question: Question) => void;
22
21
  handleDeleteButtonClick: (question: Question) => void;
22
+ questionCount: number;
23
23
  };
24
24
 
25
25
  export const DraggableQuestion: React.FC<DraggableQuestionProps> = ({
@@ -27,10 +27,10 @@ export const DraggableQuestion: React.FC<DraggableQuestionProps> = ({
27
27
  pageIndex,
28
28
  sectionIndex,
29
29
  questionIndex,
30
- duplicateQuestion,
30
+ handleDuplicateQuestion,
31
31
  handleDeleteButtonClick,
32
32
  handleEditButtonClick,
33
- allQuestions,
33
+ questionCount,
34
34
  }) => {
35
35
  const { t } = useTranslation();
36
36
  const draggableId = `question-${pageIndex}-${sectionIndex}-${questionIndex}`;
@@ -38,8 +38,9 @@ export const DraggableQuestion: React.FC<DraggableQuestionProps> = ({
38
38
  const { attributes, listeners, transform, isDragging, setNodeRef } =
39
39
  useDraggable({
40
40
  id: draggableId,
41
- disabled: allQuestions.length <= 1,
41
+ disabled: questionCount <= 1,
42
42
  });
43
+
43
44
  const style = {
44
45
  transform: CSS.Translate.toString(transform),
45
46
  };
@@ -60,40 +61,38 @@ export const DraggableQuestion: React.FC<DraggableQuestionProps> = ({
60
61
  <p className={styles.questionLabel}>{question.label}</p>
61
62
  </div>
62
63
  <div className={styles.buttonsContainer}>
63
- <Button
64
- kind="ghost"
65
- size="sm"
66
- enterDelayMs={200}
64
+ <CopyButton
65
+ align="top"
66
+ className="cds--btn--sm"
67
+ feedback={t("duplicated", "Duplicated") + "!"}
67
68
  iconDescription={t("duplicateQuestion", "Duplicate question")}
68
- onClick={() => {
69
- if (!isDragging) {
70
- duplicateQuestion(question, pageIndex, sectionIndex);
71
- }
72
- }}
73
- renderIcon={(props) => <Replicate size={16} {...props} />}
74
- hasIconOnly
69
+ kind="ghost"
70
+ onClick={() =>
71
+ !isDragging &&
72
+ handleDuplicateQuestion(question, pageIndex, sectionIndex)
73
+ }
75
74
  />
76
75
  <Button
77
- kind="ghost"
78
- size="sm"
79
- enterDelayMs={200}
76
+ enterDelayMs={300}
77
+ hasIconOnly
80
78
  iconDescription={t("editQuestion", "Edit question")}
79
+ kind="ghost"
81
80
  onClick={() => {
82
81
  if (!isDragging) {
83
82
  handleEditButtonClick(question);
84
83
  }
85
84
  }}
86
85
  renderIcon={(props) => <Edit size={16} {...props} />}
87
- hasIconOnly
86
+ size="md"
88
87
  />
89
88
  <Button
89
+ enterDelayMs={300}
90
90
  hasIconOnly
91
- enterDelayMs={200}
92
91
  iconDescription={t("deleteQuestion", "Delete question")}
93
92
  kind="ghost"
94
93
  onClick={handleDeleteButtonClick}
95
94
  renderIcon={(props) => <TrashCan size={16} {...props} />}
96
- size="sm"
95
+ size="md"
97
96
  />
98
97
  </div>
99
98
  </div>