Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(refactor) Replace usages of /ws/rest/v1/ with restBaseUrl #225

Merged
merged 2 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/components/dashboard/dashboard.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
usePagination,
useDebounce,
openmrsFetch,
restBaseUrl,
} from '@openmrs/esm-framework';
import { type KeyedMutator, preload } from 'swr';

Expand Down Expand Up @@ -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}
</ConfigurableLink>
Expand Down
20 changes: 10 additions & 10 deletions src/forms.resource.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -10,15 +10,15 @@ interface SavePayload {
}

export async function deleteClobdata(valueReference: string): Promise<FetchResponse<Schema>> {
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' },
});
return response;
}

export async function deleteForm(formUuid: string): Promise<FetchResponse<Record<string, never>>> {
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' },
});
Expand All @@ -29,7 +29,7 @@ export async function deleteResource(
formUuid: string,
resourceUuid: string,
): Promise<FetchResponse<Record<string, never>>> {
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' },
});
Expand All @@ -44,7 +44,7 @@ export async function uploadSchema(schema: Schema): Promise<string> {
body.append('file', schemaBlob);

const response = await window
.fetch(`${window.openmrsBase}/ws/rest/v1/clobdata`, {
.fetch(`${window.openmrsBase}/${restBaseUrl}/clobdata`, {
body,
method: 'POST',
})
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -121,7 +121,7 @@ export async function saveNewForm(
'Content-Type': 'application/json',
};

const response: FetchResponse<Form> = await openmrsFetch(`/ws/rest/v1/form`, {
const response: FetchResponse<Form> = await openmrsFetch(`${restBaseUrl}/form`, {
method: 'POST',
headers: headers,
body: body,
Expand All @@ -133,7 +133,7 @@ export async function saveNewForm(

export async function publishForm(uuid: string): Promise<FetchResponse<Form>> {
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,
Expand All @@ -143,7 +143,7 @@ export async function publishForm(uuid: string): Promise<FetchResponse<Form>> {

export async function unpublishForm(uuid: string): Promise<FetchResponse<Form>> {
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,
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useClobdata.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useConceptLookup.ts
Original file line number Diff line number Diff line change
@@ -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<Concept> } }, Error>(conceptId ? url : null, openmrsFetch);

Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useConceptName.ts
Original file line number Diff line number Diff line change
@@ -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);

Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useEncounterTypes.ts
Original file line number Diff line number Diff line change
@@ -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<EncounterType> } }, Error>(
url,
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useForm.ts
Original file line number Diff line number Diff line change
@@ -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`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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,
Expand Down
5 changes: 2 additions & 3 deletions src/hooks/useForms.ts
Original file line number Diff line number Diff line change
@@ -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<Form> } }, Error>(url, openmrsFetch);

Expand Down
Loading