Skip to content

Commit ab20c96

Browse files
committed
refactor: Import types directly from @openmrs/esm-form-engine-lib
- Remove re-exported types from src/types.ts - Update all files to import FormField, FormPage, FormSection directly from @openmrs/esm-form-engine-lib - Keep only local types in src/types.ts (FormBuilderSchema, Form, Schema, Concept, etc.) - This eliminates redundant type re-exports and makes dependencies clearer
1 parent 1ed6588 commit ab20c96

File tree

7 files changed

+310
-365
lines changed

7 files changed

+310
-365
lines changed

src/components/interactive-builder/draggable/draggable-question.component.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ import { IconButton } from '@carbon/react';
66
import { Draggable, Edit, TrashCan, Copy } from '@carbon/react/icons';
77
import { showModal, ChevronDownIcon, ChevronUpIcon } from '@openmrs/esm-framework';
88
import MarkdownWrapper from '../markdown-wrapper/markdown-wrapper';
9-
import type { Question, Schema } from '@types';
9+
import type { FormField } from '@openmrs/esm-form-engine-lib';
10+
import type { Schema } from '@types';
1011
import styles from './draggable-question.scss';
1112

1213
interface DraggableQuestionProps {
13-
handleDuplicateQuestion: (question: Question, pageId: number, sectionId: number, questionId?: number) => void;
14+
handleDuplicateQuestion: (question: FormField, pageId: number, sectionId: number, questionId?: number) => void;
1415
onSchemaChange: (schema: Schema) => void;
1516
pageIndex: number;
16-
question: Question;
17+
question: FormField;
1718
questionCount: number;
1819
questionIndex: number;
1920
schema: Schema;

src/components/interactive-builder/interactive-builder.component.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import { showModal, showSnackbar } from '@openmrs/esm-framework';
1919
import DraggableQuestion from './draggable/draggable-question.component';
2020
import EditableValue from './editable/editable-value.component';
2121
import type { DragEndEvent } from '@dnd-kit/core';
22-
import type { FormSchema } from '@openmrs/esm-form-engine-lib';
23-
import type { Schema, Question } from '@types';
22+
import type { FormSchema, FormField } from '@openmrs/esm-form-engine-lib';
23+
import type { Schema } from '@types';
2424
import styles from './interactive-builder.scss';
2525

2626
interface ValidationError {
@@ -37,7 +37,7 @@ interface InteractiveBuilderProps {
3737
}
3838

3939
interface SubQuestionProps {
40-
question: Question;
40+
question: FormField;
4141
pageIndex: number;
4242
sectionIndex: number;
4343
questionIndex: number;
@@ -257,9 +257,9 @@ const InteractiveBuilder: React.FC<InteractiveBuilderProps> = ({
257257
);
258258

259259
const duplicateQuestion = useCallback(
260-
(question: Question, pageId: number, sectionId: number, questionId?: number) => {
260+
(question: FormField, pageId: number, sectionId: number, questionId?: number) => {
261261
try {
262-
const questionToDuplicate: Question = JSON.parse(JSON.stringify(question));
262+
const questionToDuplicate: FormField = JSON.parse(JSON.stringify(question));
263263
questionToDuplicate.id = questionToDuplicate.id + 'Duplicate';
264264

265265
if (Number.isInteger(questionId)) {
@@ -340,7 +340,7 @@ const InteractiveBuilder: React.FC<InteractiveBuilderProps> = ({
340340
pageIndex: number,
341341
sectionIndex: number,
342342
questionId: string | number,
343-
newQuestion: Question,
343+
newQuestion: FormField,
344344
): Schema {
345345
if (activeQuestion.type === 'question') {
346346
const newSchema = { ...schema };
@@ -419,7 +419,7 @@ const InteractiveBuilder: React.FC<InteractiveBuilderProps> = ({
419419
return errors || [];
420420
};
421421

422-
const getValidationError = (question: Question) => {
422+
const getValidationError = (question: FormField) => {
423423
const errorField: ValidationError = validationResponse.find(
424424
(error) =>
425425
error.field.label === question.label && error.field.id === question.id && error.field.type === question.type,

src/components/interactive-builder/modals/add-form-reference/add-form-reference.modal.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import {
1919
import { showSnackbar } from '@openmrs/esm-framework';
2020
import { useForms } from '@hooks/useForms';
2121
import { useClobdata } from '@hooks/useClobdata';
22-
import { type Form as FormType, type Schema, type FormPage, type FormSection, type FormField } from '@types';
22+
import type { FormPage, FormSection, FormField } from '@openmrs/esm-form-engine-lib';
23+
import { type Form as FormType, type Schema } from '@types';
2324
import styles from './add-form-reference.scss';
2425

2526
interface AddFormReferenceModalProps {

src/components/interactive-builder/modals/delete-question/delete-question.modal.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import React from 'react';
22
import { useTranslation } from 'react-i18next';
33
import { Button, ModalBody, ModalFooter, ModalHeader } from '@carbon/react';
44
import { showSnackbar } from '@openmrs/esm-framework';
5-
import type { Question, Schema } from '@types';
5+
import type { FormField } from '@openmrs/esm-form-engine-lib';
6+
import type { Schema } from '@types';
67

78
interface DeleteQuestionModal {
89
closeModal: () => void;
910
onSchemaChange: (schema: Schema) => void;
1011
pageIndex: number;
11-
question: Question;
12+
question: FormField;
1213
questionIndex: number;
1314
schema: Schema;
1415
sectionIndex: number;

src/resources/form-validator.resource.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { openmrsFetch, restBaseUrl } from '@openmrs/esm-framework';
2-
import type { Question, Schema } from '@types';
2+
import type { FormField } from '@openmrs/esm-form-engine-lib';
3+
import type { Schema } from '@types';
34
import type { ConfigObject } from '../config-schema';
45

56
interface Field {
@@ -32,7 +33,7 @@ export const handleFormValidation = async (
3233
const asyncTasks: Array<Promise<void>> = [];
3334

3435
parsedForm.pages?.forEach((page) =>
35-
page.sections?.forEach((section: { questions: Array<Question> }) =>
36+
page.sections?.forEach((section: { questions: Array<FormField> }) =>
3637
section.questions?.forEach((question) => {
3738
asyncTasks.push(
3839
handleQuestionValidation(question, errors, configObject, warnings),

src/types.ts

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,5 @@
11
import type { OpenmrsResource } from '@openmrs/esm-framework';
2-
import type {
3-
OpenmrsFormResource,
4-
FormField,
5-
ProgramState,
6-
ReferencedForm,
7-
RenderType,
8-
RequiredFieldProps,
9-
FormReference,
10-
OpenmrsEncounter,
11-
OpenmrsObs,
12-
SessionMode,
13-
PostSubmissionAction,
14-
FormSchema,
15-
FormPage,
16-
FormSection,
17-
FormQuestionOptions,
18-
QuestionAnswerOption,
19-
HideProps,
20-
DisableProps,
21-
RepeatOptions,
22-
} from '@openmrs/esm-form-engine-lib';
2+
import type { FormSchema, ProgramState } from '@openmrs/esm-form-engine-lib';
233
import type { AuditInfo } from './components/audit-details/audit-details.component';
244
import type { questionTypes } from '@constants';
255

@@ -75,26 +55,6 @@ export interface SchemaContextType {
7555
setSchema: (schema: Schema) => void;
7656
}
7757

78-
// Using FormPage from form-engine-lib instead of local Page
79-
export type Page = FormPage;
80-
// Export FormPage as well for direct imports
81-
export { FormPage };
82-
83-
// Using FormSection from form-engine-lib instead of local Section
84-
export type Section = FormSection;
85-
// Export FormSection as well for direct imports
86-
export { FormSection };
87-
88-
// Using FormField from form-engine-lib instead of local Question
89-
export type Question = FormField;
90-
// Export FormField as well for direct imports
91-
export { FormField };
92-
93-
// Using FormQuestionOptions from form-engine-lib instead of local QuestionOptions
94-
export type QuestionOptions = FormQuestionOptions;
95-
// Export FormQuestionOptions as well for direct imports
96-
export { FormQuestionOptions };
97-
9858
export interface Answer {
9959
concept: string;
10060
label: string;
@@ -142,25 +102,6 @@ export interface PersonAttributeType {
142102
};
143103
}
144104

145-
// Export the imported types directly
146-
export type {
147-
OpenmrsEncounter,
148-
OpenmrsObs,
149-
SessionMode,
150-
PostSubmissionAction,
151-
FormSchema,
152-
QuestionAnswerOption,
153-
HideProps,
154-
DisableProps,
155-
RepeatOptions,
156-
OpenmrsFormResource,
157-
RenderType,
158-
RequiredFieldProps,
159-
FormReference,
160-
ReferencedForm,
161-
ProgramState,
162-
};
163-
164105
export interface Program {
165106
uuid: string;
166107
name: string;

0 commit comments

Comments
 (0)