@openmrs/esm-form-engine-lib 4.1.1-pre.2404 → 4.1.1-pre.2408

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.
@@ -4,8 +4,11 @@ export const EncounterProviderAdapter = {
4
4
  gracefullySetSubmission(field, value, null);
5
5
  },
6
6
  getInitialValue: function(field, sourceObject, context) {
7
- const encounter = sourceObject ?? context.previousDomainObjectValue;
8
- return getLatestProvider(encounter)?.uuid;
7
+ const provider = getLatestProvider(sourceObject);
8
+ if (provider?.uuid) {
9
+ return provider.uuid;
10
+ }
11
+ return context.currentProvider?.uuid;
9
12
  },
10
13
  getPreviousValue: function(field, sourceObject, context) {
11
14
  const encounter = sourceObject ?? context.previousDomainObjectValue;
@@ -118,24 +118,22 @@ const UiSelectExtended = ({ field, errors, warnings, setFieldValue })=>{
118
118
  ]);
119
119
  useEffect(()=>{
120
120
  let ignore = false;
121
- if (value && !isDirty && dataSource && isSearchable && sessionMode !== 'enter' && !items.length) {
122
- // While in edit mode, search-based instances should fetch the initial item (previously selected value) to resolve its display property
121
+ if (value && !isDirty && dataSource && isSearchable && !items.length) {
122
+ // For search-based instances, fetch the initial item to resolve its display property
123
123
  setIsLoading(true);
124
- try {
125
- dataSource.fetchSingleItem(value).then((item)=>{
126
- if (!ignore) {
127
- setItems([
128
- dataSource.toUuidAndDisplay(item)
129
- ]);
130
- setIsLoading(false);
131
- }
132
- });
133
- } catch (error) {
124
+ dataSource.fetchSingleItem(value).then((item)=>{
125
+ if (!ignore) {
126
+ setItems([
127
+ dataSource.toUuidAndDisplay(item)
128
+ ]);
129
+ setIsLoading(false);
130
+ }
131
+ }).catch((error)=>{
134
132
  if (!ignore) {
135
133
  console.error(error);
136
134
  setIsLoading(false);
137
135
  }
138
- }
136
+ });
139
137
  }
140
138
  return ()=>{
141
139
  ignore = true;
@@ -143,7 +141,6 @@ const UiSelectExtended = ({ field, errors, warnings, setFieldValue })=>{
143
141
  }, [
144
142
  value,
145
143
  isDirty,
146
- sessionMode,
147
144
  dataSource,
148
145
  isSearchable,
149
146
  items
@@ -7,6 +7,10 @@ export class ProviderDataSource extends BaseOpenMRSDataSource {
7
7
  const { data } = await openmrsFetch(searchTerm ? `${url}&q=${searchTerm}` : url);
8
8
  return data?.results;
9
9
  }
10
+ async fetchSingleItem(uuid) {
11
+ const { data } = await openmrsFetch(`${restBaseUrl}/provider/${uuid}?v=custom:(uuid,display)`);
12
+ return data;
13
+ }
10
14
  constructor(){
11
15
  super(null);
12
16
  }
@@ -1 +1 @@
1
- {"version":3,"file":"encounter-provider-adapter.d.ts","sourceRoot":"","sources":["../../../src/adapters/encounter-provider-adapter.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,qBAAqB,EAE3B,MAAM,UAAU,CAAC;AAGlB,eAAO,MAAM,wBAAwB,EAAE,qBA6BtC,CAAC"}
1
+ {"version":3,"file":"encounter-provider-adapter.d.ts","sourceRoot":"","sources":["../../../src/adapters/encounter-provider-adapter.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,qBAAqB,EAE3B,MAAM,UAAU,CAAC;AAGlB,eAAO,MAAM,wBAAwB,EAAE,qBAgCtC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"ui-select-extended.component.d.ts","sourceRoot":"","sources":["../../../../../src/components/inputs/ui-select-extended/ui-select-extended.component.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4D,MAAM,OAAO,CAAC;AAYjF,OAAO,EAAmB,KAAK,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAO3E,QAAA,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,mBAAmB,CA0LnD,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
1
+ {"version":3,"file":"ui-select-extended.component.d.ts","sourceRoot":"","sources":["../../../../../src/components/inputs/ui-select-extended/ui-select-extended.component.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4D,MAAM,OAAO,CAAC;AAYjF,OAAO,EAAmB,KAAK,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAO3E,QAAA,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,mBAAmB,CA2LnD,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
@@ -1,6 +1,8 @@
1
+ import { type OpenmrsResource } from '@openmrs/esm-framework';
1
2
  import { BaseOpenMRSDataSource } from './data-source';
2
3
  export declare class ProviderDataSource extends BaseOpenMRSDataSource {
3
4
  constructor();
4
5
  fetchData(searchTerm: string, config?: Record<string, any>): Promise<any[]>;
6
+ fetchSingleItem(uuid: string): Promise<OpenmrsResource | null>;
5
7
  }
6
8
  //# sourceMappingURL=provider-datasource.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"provider-datasource.d.ts","sourceRoot":"","sources":["../../../src/datasources/provider-datasource.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAEtD,qBAAa,kBAAmB,SAAQ,qBAAqB;;IAKrD,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;CAMlF"}
1
+ {"version":3,"file":"provider-datasource.d.ts","sourceRoot":"","sources":["../../../src/datasources/provider-datasource.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzF,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAEtD,qBAAa,kBAAmB,SAAQ,qBAAqB;;IAKrD,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAO3E,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;CAIrE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-form-engine-lib",
3
- "version": "4.1.1-pre.2404",
3
+ "version": "4.1.1-pre.2408",
4
4
  "description": "React Form Engine for O3",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -13,8 +13,11 @@ export const EncounterProviderAdapter: FormFieldValueAdapter = {
13
13
  gracefullySetSubmission(field, value, null);
14
14
  },
15
15
  getInitialValue: function (field: FormField, sourceObject: OpenmrsResource, context: FormProcessorContextProps) {
16
- const encounter = sourceObject ?? context.previousDomainObjectValue;
17
- return getLatestProvider(encounter)?.uuid;
16
+ const provider = getLatestProvider(sourceObject);
17
+ if (provider?.uuid) {
18
+ return provider.uuid;
19
+ }
20
+ return context.currentProvider?.uuid;
18
21
  },
19
22
  getPreviousValue: function (
20
23
  field: FormField,
@@ -124,28 +124,29 @@ const UiSelectExtended: React.FC<FormFieldInputProps> = ({ field, errors, warnin
124
124
 
125
125
  useEffect(() => {
126
126
  let ignore = false;
127
- if (value && !isDirty && dataSource && isSearchable && sessionMode !== 'enter' && !items.length) {
128
- // While in edit mode, search-based instances should fetch the initial item (previously selected value) to resolve its display property
127
+ if (value && !isDirty && dataSource && isSearchable && !items.length) {
128
+ // For search-based instances, fetch the initial item to resolve its display property
129
129
  setIsLoading(true);
130
- try {
131
- dataSource.fetchSingleItem(value).then((item) => {
130
+ dataSource
131
+ .fetchSingleItem(value)
132
+ .then((item) => {
132
133
  if (!ignore) {
133
134
  setItems([dataSource.toUuidAndDisplay(item)]);
134
135
  setIsLoading(false);
135
136
  }
137
+ })
138
+ .catch((error) => {
139
+ if (!ignore) {
140
+ console.error(error);
141
+ setIsLoading(false);
142
+ }
136
143
  });
137
- } catch (error) {
138
- if (!ignore) {
139
- console.error(error);
140
- setIsLoading(false);
141
- }
142
- }
143
144
  }
144
145
 
145
146
  return () => {
146
147
  ignore = true;
147
148
  };
148
- }, [value, isDirty, sessionMode, dataSource, isSearchable, items]);
149
+ }, [value, isDirty, dataSource, isSearchable, items]);
149
150
 
150
151
  if (isLoading) {
151
152
  return <DropdownSkeleton />;
@@ -1,4 +1,4 @@
1
- import { openmrsFetch, restBaseUrl } from '@openmrs/esm-framework';
1
+ import { openmrsFetch, restBaseUrl, type OpenmrsResource } from '@openmrs/esm-framework';
2
2
  import { BaseOpenMRSDataSource } from './data-source';
3
3
 
4
4
  export class ProviderDataSource extends BaseOpenMRSDataSource {
@@ -12,4 +12,9 @@ export class ProviderDataSource extends BaseOpenMRSDataSource {
12
12
  const { data } = await openmrsFetch(searchTerm ? `${url}&q=${searchTerm}` : url);
13
13
  return data?.results;
14
14
  }
15
+
16
+ async fetchSingleItem(uuid: string): Promise<OpenmrsResource | null> {
17
+ const { data } = await openmrsFetch(`${restBaseUrl}/provider/${uuid}?v=custom:(uuid,display)`);
18
+ return data;
19
+ }
15
20
  }