Skip to content

Commit

Permalink
Remove deprecated types
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmale committed Aug 6, 2024
1 parent 26e319c commit 06300f4
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 153 deletions.
46 changes: 1 addition & 45 deletions src/components/repeat/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { cloneDeep } from 'lodash-es';
import { type FormField, type OpenmrsEncounter, type SubmissionHandler } from '../../types';
import { type FormField } from '../../types';
import { type OpenmrsResource } from '@openmrs/esm-framework';
import { isEmpty } from '../../validators/form-validator';
import { clearSubmission } from '../../utils/common-utils';
import { assignedObsIds } from '../../adapters/obs-adapter';
import { assignedOrderIds } from '../../adapters/orders-adapter';

export function cloneRepeatField(srcField: FormField, value: OpenmrsResource, idSuffix: number) {
const originalGroupMembersIds: string[] = [];
Expand Down Expand Up @@ -68,45 +66,3 @@ export function disableRepeatAddButton(limit: string | number, counter: number)
}
return counter >= repeatLimit;
}

export function hydrateRepeatField(
field: FormField,
formFields: FormField[],
encounter: OpenmrsEncounter,
initialValues: Record<string, any>,
formFieldHandlers: Record<string, SubmissionHandler>,
) {
let counter = 1;
const unMappedGroups = encounter.obs.filter(
(obs) =>
obs.concept.uuid === field.questionOptions.concept &&
obs.uuid != field.meta.previousValue?.uuid &&
!assignedObsIds.includes(obs.uuid),
);
const unMappedOrders = encounter.orders.filter((order) => {
const availableOrderables = field.questionOptions.answers?.map((answer) => answer.concept) || [];
return availableOrderables.includes(order.concept?.uuid) && !assignedOrderIds.includes(order.uuid);
});
if (field.type === 'testOrder') {
return unMappedOrders
.filter((order) => !order.voided)
.map((order) => {
const clone = cloneRepeatField(field, order, counter++);
initialValues[clone.id] = formFieldHandlers[field.type].getInitialValue({ orders: [order] }, clone, formFields);
return clone;
});
}
// handle obs groups
return unMappedGroups.flatMap((group) => {
const clone = cloneRepeatField(field, group, counter++);
clone.questions.forEach((childField) => {
initialValues[childField.id] = formFieldHandlers[field.type].getInitialValue(
{ obs: [group] },
childField,
formFields,
);
});
assignedObsIds.push(group.uuid);
return [clone, ...clone.questions];
});
}
2 changes: 0 additions & 2 deletions src/form-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
type OpenmrsEncounter,
type PatientIdentifier,
type SessionMode,
type SubmissionHandler,
} from './types';

type FormContextProps = {
Expand All @@ -19,7 +18,6 @@ type FormContextProps = {
isSubmitting: boolean;
layoutType?: LayoutType;
workspaceLayout?: 'minimized' | 'maximized';
formFieldHandlers: Record<string, SubmissionHandler>;
};

export interface EncounterContext {
Expand Down

This file was deleted.

42 changes: 0 additions & 42 deletions src/registry/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ import {
type DataSource,
type FormFieldValidator,
type FormSchemaTransformer,
type FormFieldProps,
type PostSubmissionAction,
type SubmissionHandler,
} from '../types';
import { getGlobalStore } from '@openmrs/esm-framework';
import { FormsStore } from '../constants';
import { inbuiltControls } from './inbuilt-components/inbuiltControls';
import { inbuiltFieldSubmissionHandlers } from './inbuilt-components/inbuiltFieldSubmissionHandlers';
import { inbuiltValidators } from './inbuilt-components/inbuiltValidators';
import { inbuiltDataSources } from './inbuilt-components/inbuiltDataSources';
import { getControlTemplate } from './inbuilt-components/control-templates';
Expand Down Expand Up @@ -42,13 +39,6 @@ export interface CustomControlRegistration extends ComponentRegistration<React.C
alias?: string;
}

/**
* @deprecated
*/
export interface FieldSubmissionHandlerRegistration extends ComponentRegistration<SubmissionHandler> {
type: string;
}

export interface FieldValueAdapterRegistration extends ComponentRegistration<FormFieldValueAdapter> {
type: string;
}
Expand All @@ -57,7 +47,6 @@ export interface FormsRegistryStoreState {
controls: CustomControlRegistration[];
fieldValidators: ComponentRegistration<FormFieldValidator>[];
fieldValueAdapters: FieldValueAdapterRegistration[];
fieldSubmissionHandlers: FieldSubmissionHandlerRegistration[];
postSubmissionActions: ComponentRegistration<PostSubmissionAction>[];
dataSources: ComponentRegistration<DataSource<any>>[];
expressionHelpers: Record<string, Function>;
Expand All @@ -67,8 +56,6 @@ export interface FormsRegistryStoreState {
interface FormRegistryCache {
validators: Record<string, FormFieldValidator>;
controls: Record<string, React.ComponentType<FormFieldInputProps>>;
// @deprecated
fieldSubmissionHandlers: Record<string, SubmissionHandler>;
fieldValueAdapters: Record<string, FormFieldValueAdapter>;
postSubmissionActions: Record<string, PostSubmissionAction>;
dataSources: Record<string, DataSource<any>>;
Expand All @@ -79,7 +66,6 @@ const registryCache: FormRegistryCache = {
validators: {},
controls: {},
fieldValueAdapters: {},
fieldSubmissionHandlers: {},
postSubmissionActions: {},
dataSources: {},
formSchemaTransformers: {},
Expand All @@ -95,13 +81,6 @@ export function registerPostSubmissionAction(registration: ComponentRegistration
getFormsStore().postSubmissionActions.push(registration);
}

/**
* @deprecated
*/
export function registerFieldSubmissionHandler(registration: FieldSubmissionHandlerRegistration) {
getFormsStore().fieldSubmissionHandlers.push(registration);
}

export function registerFieldValueAdapter(registration: FieldValueAdapterRegistration) {
getFormsStore().fieldValueAdapters.push(registration);
}
Expand Down Expand Up @@ -169,26 +148,6 @@ export async function getRegisteredFieldValueAdapter(type: string): Promise<Form
return adapter;
}

/**
* @deprecated
* A convinience function that returns the appropriate submission handler for a given type.
*/
export async function getRegisteredFieldSubmissionHandler(type: string): Promise<SubmissionHandler> {
if (registryCache.fieldSubmissionHandlers[type]) {
return registryCache.fieldSubmissionHandlers[type];
}
let handler = inbuiltFieldSubmissionHandlers.find((handler) => handler.type === type)?.component;
// if undefined, try serching through the registered custom handlers
if (!handler) {
const handlerImport = await getFormsStore()
.fieldSubmissionHandlers.find((handler) => handler.type === type)
?.load?.();
handler = handlerImport?.default;
}
registryCache.fieldSubmissionHandlers[type] = handler;
return handler;
}

export async function getRegisteredFormSchemaTransformers(): Promise<FormSchemaTransformer[]> {
const transformers = [];

Expand Down Expand Up @@ -296,7 +255,6 @@ function getFormsStore(): FormsRegistryStoreState {
expressionHelpers: {},
fieldValidators: [],
fieldValueAdapters: [],
fieldSubmissionHandlers: [],
dataSources: [],
formSchemaTransformers: [],
}).getState();
Expand Down
38 changes: 0 additions & 38 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,44 +65,6 @@ export interface FormFieldValueAdapter {
tearDown: () => void;
}

/**
* @deprecated
* TODO: Remove this interface
*/
export interface SubmissionHandler {
/**
* Abstraction of the extraction of initial field value from an `encounter`
*
* @returns the `initialValue`
*/
getInitialValue: (
encounter: OpenmrsEncounter,
field: FormField,
allFormFields?: Array<FormField>,
context?: any,
) => {};

/**
* Handles field submission.
*
* @should Construct a new submission value, edit and handle deletion by voiding.
* @returns the `submissionValue`
*/
handleFieldSubmission: (field: FormField, value: any, context: any) => {};

/**
* Extracts value to be displayed while in `view` mode
*
* @returns the `displayValue`
*/
getDisplayValue: (field: FormField, value: any) => any;

/**
* Fetches the previous value for a form field
*/
getPreviousValue?: (field: FormField, encounter: OpenmrsEncounter, allFormFields: Array<FormField>) => any;
}

export interface DataSource<T> {
/**
* Fetches arbitrary data from a data source
Expand Down
18 changes: 0 additions & 18 deletions src/types/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,24 +88,6 @@ export interface FormField {
meta?: QuestionMetaProps;
}

/**
* @deprecated
*/
export interface FormFieldProps {
question: FormField;
onChange: (
fieldName: string,
value: any,
setErrors: (errors: Array<ValidationResult>) => void,
setWarnings: (warnings: Array<ValidationResult>) => void,
isUnspecified?: boolean,
) => void;
handler: any;
// This is of util to components defined out of the engine
useField?: (fieldId: string) => any;
previousValue?: string | number | Date | boolean | any[];
}

export interface FormFieldInputProps {
value: any;
field: FormField;
Expand Down

0 comments on commit 06300f4

Please sign in to comment.