@openmrs/esm-form-engine-lib 2.1.0-pre.1443 → 2.1.0-pre.1464

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-form-engine-lib",
3
- "version": "2.1.0-pre.1443",
3
+ "version": "2.1.0-pre.1464",
4
4
  "description": "React Form Engine for O3",
5
5
  "browser": "dist/openmrs-esm-form-engine-lib.js",
6
6
  "main": "src/index.ts",
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { act, render, screen } from '@testing-library/react';
3
- import { userEvent } from '@testing-library/user-event';
3
+ import userEvent from '@testing-library/user-event'; // Correct import for userEvent
4
4
  import { type FetchResponse, openmrsFetch, usePatient, useSession } from '@openmrs/esm-framework';
5
5
  import { type FormSchema } from '../../../types';
6
6
  import { mockPatient } from '__mocks__/patient.mock';
@@ -31,7 +31,7 @@ jest.mock('../../../api', () => {
31
31
  });
32
32
 
33
33
  const renderForm = async () => {
34
- await act(() =>
34
+ await act(async () => {
35
35
  render(
36
36
  <FormEngine
37
37
  formJson={multiSelectFormSchema as unknown as FormSchema}
@@ -40,11 +40,11 @@ const renderForm = async () => {
40
40
  formSessionIntent={undefined}
41
41
  visit={visit}
42
42
  />,
43
- ),
44
- );
43
+ );
44
+ });
45
45
  };
46
46
 
47
- describe.skip('MultiSelect Component', () => {
47
+ describe('MultiSelect Component', () => {
48
48
  beforeEach(() => {
49
49
  mockOpenmrsFetch.mockResolvedValue({
50
50
  data: { results: [{ ...multiSelectFormSchema }] },
@@ -69,22 +69,20 @@ describe.skip('MultiSelect Component', () => {
69
69
  it('should disable checkbox option if the field value depends on evaluates the expression to true', async () => {
70
70
  const user = userEvent.setup();
71
71
  await renderForm();
72
-
73
72
  await user.click(screen.getByRole('combobox', { name: /Patient covered by NHIF/i }));
74
73
  await user.click(screen.getByRole('option', { name: /no/i }));
75
-
76
74
  await user.click(screen.getByText('Was this visit scheduled?'));
77
- expect(screen.getByRole('option', { name: /Unscheduled visit early/i })).toHaveAttribute('disabled');
75
+ const unscheduledVisitOption = screen.getByRole('option', { name: /Unscheduled visit early/i });
76
+ expect(unscheduledVisitOption).toHaveAttribute('disabled');
78
77
  });
79
78
 
80
79
  it('should enable checkbox option if the field value depends on evaluates the expression to false', async () => {
81
80
  const user = userEvent.setup();
82
81
  await renderForm();
83
-
84
82
  await user.click(screen.getByRole('combobox', { name: /patient covered by nhif/i }));
85
83
  await user.click(screen.getByRole('option', { name: /yes/i }));
86
-
87
84
  await user.click(screen.getByText('Was this visit scheduled?'));
88
- expect(screen.getByRole('option', { name: /Unscheduled visit early/i })).not.toHaveAttribute('disabled');
85
+ const unscheduledVisitOption = screen.getByRole('option', { name: /Unscheduled visit early/i });
86
+ expect(unscheduledVisitOption).not.toBeDisabled();
89
87
  });
90
88
  });
@@ -91,7 +91,12 @@ export const FormRenderer = ({ processorContext, initialValues, setIsLoadingForm
91
91
  />
92
92
  );
93
93
  }
94
- return <PageRenderer page={page} />;
94
+ return (
95
+ <PageRenderer
96
+ key={page.label}
97
+ page={page}
98
+ />
99
+ );
95
100
  })}
96
101
  </FormProvider>
97
102
  );
@@ -1,4 +1,4 @@
1
- import React, { useMemo } from 'react';
1
+ import React, { useMemo, useState } from 'react';
2
2
  import { type FormPage } from '../../../types';
3
3
  import { isTrue } from '../../../utils/boolean-utils';
4
4
  import { useTranslation } from 'react-i18next';
@@ -7,6 +7,7 @@ import { Waypoint } from 'react-waypoint';
7
7
  import styles from './page.renderer.scss';
8
8
  import { Accordion, AccordionItem } from '@carbon/react';
9
9
  import { useFormFactory } from '../../../provider/form-factory-provider';
10
+ import { ChevronDownIcon, ChevronUpIcon } from '@openmrs/esm-framework';
10
11
 
11
12
  interface PageRendererProps {
12
13
  page: FormPage;
@@ -15,32 +16,47 @@ interface PageRendererProps {
15
16
  function PageRenderer({ page }: PageRendererProps) {
16
17
  const { t } = useTranslation();
17
18
  const pageId = useMemo(() => page.label.replace(/\s/g, ''), [page.label]);
19
+ const [isCollapsed, setIsCollapsed] = useState(false);
18
20
 
19
21
  const { setCurrentPage } = useFormFactory();
20
22
  const visibleSections = page.sections.filter((section) => {
21
23
  const hasVisibleQuestions = section.questions.some((question) => !isTrue(question.isHidden));
22
24
  return !isTrue(section.isHidden) && hasVisibleQuestions;
23
25
  });
26
+
27
+ const toggleCollapse = () => setIsCollapsed(!isCollapsed);
28
+
24
29
  return (
25
30
  <div>
26
31
  <Waypoint onEnter={() => setCurrentPage(pageId)} topOffset="50%" bottomOffset="60%">
27
32
  <div className={styles.pageContent}>
28
- <div className={styles.pageHeader}>
29
- <p className={styles.pageTitle}>{t(page.label)}</p>
33
+ <div className={styles.pageHeader} onClick={toggleCollapse}>
34
+ <p className={styles.pageTitle}>
35
+ {t(page.label)}
36
+ <span className={styles.collapseIconWrapper}>
37
+ {isCollapsed ? (
38
+ <ChevronDownIcon className={styles.collapseIcon} aria-label="Expand" />
39
+ ) : (
40
+ <ChevronUpIcon className={styles.collapseIcon} aria-label="Collapse" />
41
+ )}
42
+ </span>
43
+ </p>
30
44
  </div>
31
- <Accordion>
32
- {visibleSections.map((section) => (
33
- <AccordionItem
34
- title={t(section.label)}
35
- open={true}
36
- className={styles.sectionContainer}
37
- key={`section-${section.label}`}>
38
- <div className={styles.formSection}>
39
- <SectionRenderer section={section} />
40
- </div>
41
- </AccordionItem>
42
- ))}
43
- </Accordion>
45
+ {!isCollapsed && (
46
+ <Accordion>
47
+ {visibleSections.map((section) => (
48
+ <AccordionItem
49
+ title={t(section.label)}
50
+ open={true}
51
+ className={styles.sectionContainer}
52
+ key={`section-${section.label}`}>
53
+ <div className={styles.formSection}>
54
+ <SectionRenderer section={section} />
55
+ </div>
56
+ </AccordionItem>
57
+ ))}
58
+ </Accordion>
59
+ )}
44
60
  </div>
45
61
  </Waypoint>
46
62
  </div>
@@ -1,13 +1,19 @@
1
1
  @use '@carbon/colors';
2
+ @use '@carbon/type';
2
3
 
3
4
  .pageContent:last-child > hr {
4
5
  display: none;
5
6
  }
6
7
 
7
8
  .pageHeader {
8
- display: flex;
9
- flex-direction: row;
10
- margin: 0.5rem 1rem;
9
+ cursor: pointer;
10
+ transition: background-color 0.1s;
11
+ border-radius: 1px;
12
+ padding: 0.5rem 1rem;
13
+
14
+ &:hover {
15
+ background-color: colors.$gray-20;
16
+ }
11
17
  }
12
18
 
13
19
  .pageTitle {
@@ -16,6 +22,16 @@
16
22
  line-height: 1.4;
17
23
  color: colors.$gray-100;
18
24
  width: 100%;
25
+ display: flex;
26
+ align-items: center;
27
+ justify-content: space-between;
28
+ margin: 0;
29
+ }
30
+
31
+ .collapseIcon {
32
+ fill: colors.$gray-70;
33
+ width: 1rem;
34
+ height: 1rem;
19
35
  }
20
36
 
21
37
  .sectionContainer > div {
@@ -118,4 +118,4 @@
118
118
 
119
119
  .toggleContainer {
120
120
  margin-bottom: 0.5rem;
121
- }
121
+ }