@openmrs/esm-form-engine-lib 3.0.1-pre.1652 → 3.0.1-pre.1661

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": "3.0.1-pre.1652",
3
+ "version": "3.0.1-pre.1661",
4
4
  "description": "React Form Engine for O3",
5
5
  "browser": "dist/openmrs-esm-form-engine-lib.js",
6
6
  "main": "src/index.ts",
@@ -28,6 +28,7 @@ const formContext = {
28
28
  formFieldAdapters: null,
29
29
  formFieldValidators: null,
30
30
  customDependencies: null,
31
+ deletedFields: [],
31
32
  getFormField: jest.fn(),
32
33
  addFormField: jest.fn(),
33
34
  updateFormField: jest.fn(),
@@ -36,6 +37,7 @@ const formContext = {
36
37
  removeInvalidField: jest.fn(),
37
38
  setInvalidFields: jest.fn(),
38
39
  setForm: jest.fn(),
40
+ setDeletedFields: jest.fn(),
39
41
  } as FormContextProps;
40
42
 
41
43
  describe('ObsAdapter - transformFieldValue', () => {
@@ -30,6 +30,7 @@ const formContext = {
30
30
  customDependencies: {
31
31
  patientPrograms: [],
32
32
  },
33
+ deletedFields: [],
33
34
  getFormField: jest.fn(),
34
35
  addFormField: jest.fn(),
35
36
  updateFormField: jest.fn(),
@@ -38,6 +39,7 @@ const formContext = {
38
39
  removeInvalidField: jest.fn(),
39
40
  setInvalidFields: jest.fn(),
40
41
  setForm: jest.fn(),
42
+ setDeletedFields: jest.fn(),
41
43
  } as FormContextProps;
42
44
 
43
45
  const field = {
@@ -169,13 +169,6 @@ const UiSelectExtended: React.FC<FormFieldInputProps> = ({ field, errors, warnin
169
169
  itemToString={(item) => item?.display}
170
170
  selectedItem={selectedItem}
171
171
  placeholder={isSearchable ? t('search', 'Search') + '...' : null}
172
- shouldFilterItem={({ item, inputValue }) => {
173
- if (!inputValue) {
174
- // Carbon's initial call at component mount
175
- return true;
176
- }
177
- return item.display?.toLowerCase().includes(inputValue.toLowerCase());
178
- }}
179
172
  onChange={({ selectedItem }) => {
180
173
  isProcessingSelection.current = true;
181
174
  setFieldValue(selectedItem?.uuid);
@@ -252,18 +252,27 @@ describe('UiSelectExtended', () => {
252
252
  );
253
253
  });
254
254
 
255
- it('should filter items based on user input', async () => {
255
+ it('should display all items regardless of user input', async () => {
256
256
  await act(async () => {
257
257
  renderForm();
258
258
  });
259
259
 
260
- const transferLocationSelect = await findSelectInput(screen, 'Transfer Location');
260
+ const transferLocationSelect = await findSelectInput(screen, 'Transfer Location');
261
+ // Open the dropdown
261
262
  await user.click(transferLocationSelect);
263
+
264
+ // Verify all items are displayed initially
265
+ expect(screen.getByText('Kololo')).toBeInTheDocument();
266
+ expect(screen.getByText('Naguru')).toBeInTheDocument();
267
+ expect(screen.getByText('Muyenga')).toBeInTheDocument();
268
+
269
+ // Type input
262
270
  await user.type(transferLocationSelect, 'Nag');
263
-
271
+
272
+ // Verify all items are still displayed
273
+ expect(screen.getByText('Kololo')).toBeInTheDocument();
264
274
  expect(screen.getByText('Naguru')).toBeInTheDocument();
265
- expect(screen.queryByText('Kololo')).not.toBeInTheDocument();
266
- expect(screen.queryByText('Muyenga')).not.toBeInTheDocument();
275
+ expect(screen.getByText('Muyenga')).toBeInTheDocument();
267
276
  });
268
277
  });
269
278
 
@@ -37,7 +37,7 @@ export const FormRenderer = ({
37
37
  formState: { isDirty },
38
38
  } = methods;
39
39
 
40
- const [{ formFields, invalidFields, formJson }, dispatch] = useReducer(formStateReducer, {
40
+ const [{ formFields, invalidFields, formJson, deletedFields }, dispatch] = useReducer(formStateReducer, {
41
41
  ...initialState,
42
42
  formFields: evaluatedFields,
43
43
  formJson: evaluatedFormJson,
@@ -52,6 +52,7 @@ export const FormRenderer = ({
52
52
  addInvalidField,
53
53
  removeInvalidField,
54
54
  setForm,
55
+ setDeletedFields,
55
56
  } = useFormStateHelpers(dispatch, formFields);
56
57
 
57
58
  useEffect(() => {
@@ -75,6 +76,7 @@ export const FormRenderer = ({
75
76
  formFields,
76
77
  formJson,
77
78
  invalidFields,
79
+ deletedFields,
78
80
  addFormField,
79
81
  updateFormField,
80
82
  getFormField,
@@ -83,8 +85,9 @@ export const FormRenderer = ({
83
85
  addInvalidField,
84
86
  removeInvalidField,
85
87
  setForm,
88
+ setDeletedFields,
86
89
  };
87
- }, [processorContext, workspaceLayout, methods, formFields, formJson, invalidFields]);
90
+ }, [processorContext, workspaceLayout, methods, formFields, formJson, invalidFields, deletedFields]);
88
91
 
89
92
  useEffect(() => {
90
93
  registerForm(formJson.name, isSubForm, context);
@@ -4,6 +4,7 @@ type FormState = {
4
4
  formFields: FormField[];
5
5
  invalidFields: FormField[];
6
6
  formJson: FormSchema;
7
+ deletedFields: FormField[];
7
8
  };
8
9
 
9
10
  type Action =
@@ -15,12 +16,14 @@ type Action =
15
16
  | { type: 'ADD_INVALID_FIELD'; value: FormField }
16
17
  | { type: 'REMOVE_INVALID_FIELD'; value: string }
17
18
  | { type: 'CLEAR_INVALID_FIELDS' }
18
- | { type: 'SET_FORM_JSON'; value: any };
19
+ | { type: 'SET_FORM_JSON'; value: any }
20
+ | { type: 'SET_DELETED_FIELDS'; value: FormField[] };
19
21
 
20
22
  const initialState: FormState = {
21
23
  formFields: [],
22
24
  invalidFields: [],
23
25
  formJson: null,
26
+ deletedFields: [],
24
27
  };
25
28
 
26
29
  const formStateReducer = (state: FormState, action: Action): FormState => {
@@ -46,6 +49,8 @@ const formStateReducer = (state: FormState, action: Action): FormState => {
46
49
  return { ...state, invalidFields: [] };
47
50
  case 'SET_FORM_JSON':
48
51
  return { ...state, formJson: action.value };
52
+ case 'SET_DELETED_FIELDS':
53
+ return { ...state, deletedFields: action.value };
49
54
  default:
50
55
  return state;
51
56
  }
@@ -32,6 +32,8 @@ const Repeat: React.FC<FormFieldInputProps> = ({ field }) => {
32
32
  methods: { getValues, setValue },
33
33
  addFormField,
34
34
  removeFormField,
35
+ deletedFields,
36
+ setDeletedFields,
35
37
  } = context;
36
38
 
37
39
  useEffect(() => {
@@ -113,6 +115,7 @@ const Repeat: React.FC<FormFieldInputProps> = ({ field }) => {
113
115
  clearSubmission(field);
114
116
  }
115
117
  setRows(rows.filter((q) => q.id !== field.id));
118
+ setDeletedFields([...deletedFields, field]);
116
119
  removeFormField(field.id);
117
120
  };
118
121
 
@@ -54,6 +54,10 @@ export function useFormStateHelpers(dispatch: Dispatch<Action>, formFields: Form
54
54
  dispatch({ type: 'SET_FORM_JSON', value: updateFormSectionReferences(formJson) });
55
55
  }, []);
56
56
 
57
+ const setDeletedFields = useCallback((fields: FormField[]) => {
58
+ dispatch({ type: 'SET_DELETED_FIELDS', value: fields });
59
+ }, []);
60
+
57
61
  return {
58
62
  addFormField,
59
63
  updateFormField,
@@ -63,5 +67,6 @@ export function useFormStateHelpers(dispatch: Dispatch<Action>, formFields: Form
63
67
  addInvalidField,
64
68
  removeInvalidField,
65
69
  setForm,
70
+ setDeletedFields,
66
71
  };
67
72
  }
@@ -25,10 +25,11 @@ export function prepareEncounter(
25
25
  encounterProvider: string,
26
26
  location: string,
27
27
  ) {
28
- const { patient, formJson, domainObjectValue: encounter, formFields, visit } = context;
28
+ const { patient, formJson, domainObjectValue: encounter, formFields, visit, deletedFields } = context;
29
+ const allFormFields = [...formFields, ...deletedFields];
29
30
  const obsForSubmission = [];
30
- prepareObs(obsForSubmission, formFields);
31
- const ordersForSubmission = prepareOrders(formFields);
31
+ prepareObs(obsForSubmission, allFormFields);
32
+ const ordersForSubmission = prepareOrders(allFormFields);
32
33
  let encounterForSubmission: OpenmrsEncounter = {};
33
34
 
34
35
  if (encounter) {
@@ -7,6 +7,7 @@ export interface FormContextProps extends FormProcessorContextProps {
7
7
  methods: UseFormReturn<any>;
8
8
  workspaceLayout: 'minimized' | 'maximized';
9
9
  isSubmitting?: boolean;
10
+ deletedFields: FormField[];
10
11
  getFormField?: (field: string) => FormField;
11
12
  addFormField?: (field: FormField) => void;
12
13
  updateFormField?: (field: FormField) => void;
@@ -15,6 +16,7 @@ export interface FormContextProps extends FormProcessorContextProps {
15
16
  removeInvalidField?: (fieldId: string) => void;
16
17
  setInvalidFields?: (fields: FormField[]) => void;
17
18
  setForm?: (formJson: FormSchema) => void;
19
+ setDeletedFields?: (fields: FormField[]) => void;
18
20
  }
19
21
 
20
22
  export interface FormProviderProps extends FormContextProps {