From 775e57ee2623e8ed3cc048e668a9dc349eecdab2 Mon Sep 17 00:00:00 2001 From: jwnasambu Date: Wed, 28 Feb 2024 00:33:26 +0300 Subject: [PATCH 1/2] Replace usages of '/ws/rest/v1/' with restBaseUrl --- .../dashboard/dashboard.component.tsx | 3 ++- src/forms.resource.ts | 20 +++++++++---------- src/hooks/useClobdata.ts | 4 ++-- src/hooks/useConceptLookup.ts | 4 ++-- src/hooks/useConceptName.ts | 4 ++-- src/hooks/useEncounterTypes.ts | 4 ++-- src/hooks/useForm.ts | 4 ++-- src/hooks/useForms.ts | 5 ++--- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/components/dashboard/dashboard.component.tsx b/src/components/dashboard/dashboard.component.tsx index e730483..f28fdd3 100644 --- a/src/components/dashboard/dashboard.component.tsx +++ b/src/components/dashboard/dashboard.component.tsx @@ -38,6 +38,7 @@ import { usePagination, useDebounce, openmrsFetch, + restBaseUrl, } from '@openmrs/esm-framework'; import { type KeyedMutator, preload } from 'swr'; @@ -318,7 +319,7 @@ function FormsList({ forms, isValidating, mutate, t }: FormsListProps) { className={styles.link} to={editSchemaUrl} templateParams={{ formUuid: form?.uuid }} - onMouseEnter={() => void preload(`/ws/rest/v1/form/${form?.uuid}?v=full`, openmrsFetch)} + onMouseEnter={() => void preload(`${restBaseUrl}/form/${form?.uuid}?v=full`, openmrsFetch)} > {form.name} diff --git a/src/forms.resource.ts b/src/forms.resource.ts index 5d7640e..3ea8142 100644 --- a/src/forms.resource.ts +++ b/src/forms.resource.ts @@ -1,4 +1,4 @@ -import { openmrsFetch, type FetchResponse } from '@openmrs/esm-framework'; +import { openmrsFetch, type FetchResponse, restBaseUrl } from '@openmrs/esm-framework'; import type { Form, Schema } from './types'; interface SavePayload { @@ -10,7 +10,7 @@ interface SavePayload { } export async function deleteClobdata(valueReference: string): Promise> { - const response: FetchResponse = await openmrsFetch(`/ws/rest/v1/clobdata/${valueReference}`, { + const response: FetchResponse = await openmrsFetch(`${restBaseUrl}/clobdata/${valueReference}`, { method: 'DELETE', headers: { 'Content-Type': 'application/json' }, }); @@ -18,7 +18,7 @@ export async function deleteClobdata(valueReference: string): Promise>> { - const response: FetchResponse = await openmrsFetch(`/ws/rest/v1/form/${formUuid}`, { + const response: FetchResponse = await openmrsFetch(`${restBaseUrl}/form/${formUuid}`, { method: 'DELETE', headers: { 'Content-Type': 'application/json' }, }); @@ -29,7 +29,7 @@ export async function deleteResource( formUuid: string, resourceUuid: string, ): Promise>> { - const response: FetchResponse = await openmrsFetch(`/ws/rest/v1/form/${formUuid}/resource/${resourceUuid}`, { + const response: FetchResponse = await openmrsFetch(`${restBaseUrl}/form/${formUuid}/resource/${resourceUuid}`, { method: 'DELETE', headers: { 'Content-Type': 'application/json' }, }); @@ -44,7 +44,7 @@ export async function uploadSchema(schema: Schema): Promise { body.append('file', schemaBlob); const response = await window - .fetch(`${window.openmrsBase}/ws/rest/v1/clobdata`, { + .fetch(`${window.openmrsBase}/${restBaseUrl}/clobdata`, { body, method: 'POST', }) @@ -62,7 +62,7 @@ export async function getResourceUuid(formUuid: string, valueReference: string): valueReference: valueReference, }; - const response: FetchResponse = await openmrsFetch(`/ws/rest/v1/form/${formUuid}/resource`, { + const response: FetchResponse = await openmrsFetch(`${restBaseUrl}/form/${formUuid}/resource`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: body, @@ -88,7 +88,7 @@ export async function updateForm( }, }; - const response: FetchResponse = await openmrsFetch(`/ws/rest/v1/form/${formUuid}`, { + const response: FetchResponse = await openmrsFetch(`${restBaseUrl}/form/${formUuid}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: body, @@ -121,7 +121,7 @@ export async function saveNewForm( 'Content-Type': 'application/json', }; - const response: FetchResponse
= await openmrsFetch(`/ws/rest/v1/form`, { + const response: FetchResponse = await openmrsFetch(`${restBaseUrl}/form`, { method: 'POST', headers: headers, body: body, @@ -133,7 +133,7 @@ export async function saveNewForm( export async function publishForm(uuid: string): Promise> { const body = { published: true }; - const response: FetchResponse = await openmrsFetch(`/ws/rest/v1/form/${uuid}`, { + const response: FetchResponse = await openmrsFetch(`${restBaseUrl}/form/${uuid}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: body, @@ -143,7 +143,7 @@ export async function publishForm(uuid: string): Promise> { export async function unpublishForm(uuid: string): Promise> { const body = { published: false }; - const response: FetchResponse = await openmrsFetch(`/ws/rest/v1/form/${uuid}`, { + const response: FetchResponse = await openmrsFetch(`${restBaseUrl}/form/${uuid}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: body, diff --git a/src/hooks/useClobdata.ts b/src/hooks/useClobdata.ts index 1d74daf..cf9fc74 100644 --- a/src/hooks/useClobdata.ts +++ b/src/hooks/useClobdata.ts @@ -1,11 +1,11 @@ import useSWRImmutable from 'swr/immutable'; -import { openmrsFetch } from '@openmrs/esm-framework'; +import { openmrsFetch, restBaseUrl } from '@openmrs/esm-framework'; import type { Form, Schema } from '../types'; export const useClobdata = (form?: Form) => { const valueReferenceUuid = form?.resources?.find(({ name }) => name === 'JSON schema')?.valueReference; const formHasResources = form && form?.resources?.length > 0 && valueReferenceUuid; - const url = `/ws/rest/v1/clobdata/${valueReferenceUuid}`; + const url = `${restBaseUrl}/clobdata/${valueReferenceUuid}`; const { data, error, isLoading, isValidating, mutate } = useSWRImmutable<{ data: Schema }, Error>( formHasResources ? url : null, diff --git a/src/hooks/useConceptLookup.ts b/src/hooks/useConceptLookup.ts index 12cd5c0..30a15cd 100644 --- a/src/hooks/useConceptLookup.ts +++ b/src/hooks/useConceptLookup.ts @@ -1,9 +1,9 @@ import useSWR from 'swr'; -import { openmrsFetch } from '@openmrs/esm-framework'; +import { openmrsFetch, restBaseUrl } from '@openmrs/esm-framework'; import type { Concept } from '../types'; export function useConceptLookup(conceptId: string) { - const url = `/ws/rest/v1/concept?q=${conceptId}&v=full`; + const url = `${restBaseUrl}/concept?q=${conceptId}&v=full`; const { data, error } = useSWR<{ data: { results: Array } }, Error>(conceptId ? url : null, openmrsFetch); diff --git a/src/hooks/useConceptName.ts b/src/hooks/useConceptName.ts index 0b4c65f..048b87c 100644 --- a/src/hooks/useConceptName.ts +++ b/src/hooks/useConceptName.ts @@ -1,9 +1,9 @@ import useSWR from 'swr'; -import { openmrsFetch } from '@openmrs/esm-framework'; +import { openmrsFetch, restBaseUrl } from '@openmrs/esm-framework'; export function useConceptName(conceptId: string | undefined) { const customRepresentation = 'custom:(name:(display))'; - const url = `/ws/rest/v1/concept/${conceptId}?v=${customRepresentation}`; + const url = `${restBaseUrl}/concept/${conceptId}?v=${customRepresentation}`; const { data, error } = useSWR<{ data: { name: { display: string } } }, Error>(conceptId ? url : null, openmrsFetch); diff --git a/src/hooks/useEncounterTypes.ts b/src/hooks/useEncounterTypes.ts index 25d77cd..7541766 100644 --- a/src/hooks/useEncounterTypes.ts +++ b/src/hooks/useEncounterTypes.ts @@ -1,9 +1,9 @@ import useSWRImmutable from 'swr/immutable'; -import { openmrsFetch } from '@openmrs/esm-framework'; +import { openmrsFetch, restBaseUrl } from '@openmrs/esm-framework'; import type { EncounterType } from '../types'; export const useEncounterTypes = () => { - const url = `/ws/rest/v1/encountertype?v=custom:(uuid,name)`; + const url = `${restBaseUrl}/encountertype?v=custom:(uuid,name)`; const { data, error, isLoading } = useSWRImmutable<{ data: { results: Array } }, Error>( url, diff --git a/src/hooks/useForm.ts b/src/hooks/useForm.ts index dc038a1..1a5dfe1 100644 --- a/src/hooks/useForm.ts +++ b/src/hooks/useForm.ts @@ -1,9 +1,9 @@ import useSWR from 'swr/immutable'; -import { openmrsFetch } from '@openmrs/esm-framework'; +import { openmrsFetch, restBaseUrl } from '@openmrs/esm-framework'; import type { Form } from '../types'; export const useForm = (uuid: string) => { - const url = `/ws/rest/v1/form/${uuid}?v=full`; + const url = `${restBaseUrl}/${uuid}?v=full`; const { data, error, isLoading, isValidating, mutate } = useSWR<{ data: Form }, Error>( uuid ? url : null, diff --git a/src/hooks/useForms.ts b/src/hooks/useForms.ts index e187735..6c96298 100644 --- a/src/hooks/useForms.ts +++ b/src/hooks/useForms.ts @@ -1,10 +1,9 @@ import useSWR from 'swr'; -import { openmrsFetch } from '@openmrs/esm-framework'; +import { openmrsFetch, restBaseUrl } from '@openmrs/esm-framework'; import type { Form } from '../types'; export function useForms() { - const url = - '/ws/rest/v1/form?v=custom:(uuid,name,encounterType:(uuid,name),version,published,retired,resources:(uuid,name,dataType,valueReference))'; + const url = `${restBaseUrl}/form?v=custom:(uuid,name,encounterType:(uuid,name),version,published,retired,resources:(uuid,name,dataType,valueReference))`; const { data, error, isValidating, mutate } = useSWR<{ data: { results: Array } }, Error>(url, openmrsFetch); From 23ff6685bf57bdb93a65ed4129d14fa80542b47b Mon Sep 17 00:00:00 2001 From: jwnasambu Date: Wed, 28 Feb 2024 12:59:24 +0300 Subject: [PATCH 2/2] fix the missing string literal --- src/hooks/useForm.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hooks/useForm.ts b/src/hooks/useForm.ts index 1a5dfe1..bf4bd8f 100644 --- a/src/hooks/useForm.ts +++ b/src/hooks/useForm.ts @@ -3,7 +3,7 @@ import { openmrsFetch, restBaseUrl } from '@openmrs/esm-framework'; import type { Form } from '../types'; export const useForm = (uuid: string) => { - const url = `${restBaseUrl}/${uuid}?v=full`; + const url = `${restBaseUrl}/form/${uuid}?v=full`; const { data, error, isLoading, isValidating, mutate } = useSWR<{ data: Form }, Error>( uuid ? url : null,