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 #13

Merged
merged 4 commits into from
Mar 7, 2024

Conversation

jwnasambu
Copy link
Contributor

@jwnasambu jwnasambu commented Feb 27, 2024

Requirements

  • This PR has a title that briefly describes the work done including a conventional commit type prefix and a Jira ticket number if applicable. See existing PR titles for inspiration.

For changes to apps

If applicable

  • My work includes tests or is validated by existing tests.

Summary

Change all instances of the hard-coded API base URL '/ws/rest/v1/' to use the restBaseUrl variable instead. To enhances maintainability and flexibility of the API base URL configuration.

Screenshots

N/A

Related Issue

https://openmrs.atlassian.net/browse/O3-2815

Other

@@ -46,7 +46,7 @@ const BillWaiverForm: React.FC<BillWaiverFormProps> = ({ bill, lineItems, setPat
isLowContrast: true,
});
setPatientUuid('');
mutate((key) => typeof key === 'string' && key.startsWith('/ws/rest/v1/cashier/bill?v=full'), undefined, {
mutate((key) => typeof key === 'string' && key.startsWith('${restBaseUrl}/cashier/bill?v=full'), undefined, {
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
mutate((key) => typeof key === 'string' && key.startsWith('${restBaseUrl}/cashier/bill?v=full'), undefined, {
mutate((key) => typeof key === 'string' && key.startsWith(`${restBaseUrl}/cashier/bill?v=full`), undefined, {

@@ -33,7 +33,7 @@ export function useServiceTypes() {
}

export const usePaymentModes = () => {
const url = `/ws/rest/v1/cashier/paymentMode`;
const url = `${restBaseUrl}cashier/paymentMode`;
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}cashier/paymentMode`;
const url = `${restBaseUrl}/cashier/paymentMode`;

@@ -15,7 +16,7 @@ async function globalSetup() {
const token = Buffer.from(`${process.env.E2E_USER_ADMIN_USERNAME}:${process.env.E2E_USER_ADMIN_PASSWORD}`).toString(
'base64',
);
await requestContext.post(`${process.env.E2E_BASE_URL}/ws/rest/v1/session`, {
await requestContext.post(`${process.env.E2E_BASE_URL}${restBaseUrl}/session`, {
Copy link
Member

Choose a reason for hiding this comment

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

Don't change the occurrences in the e2e directory.

@denniskigen denniskigen changed the title (refactor)Replace usages of '/ws/rest/v1/' with restBaseUrl (refactor) Replace usages of /ws/rest/v1/ with restBaseUrl Feb 27, 2024
@CynthiaKamau
Copy link
Contributor

Thanks @jwnasambu for this, quick question, is the restBaseUrl respresenting /ws/rest/v1/ or ws/rest/v1/

@jwnasambu
Copy link
Contributor Author

@CynthiaKamau Thanks for the good question. In my understanding restBaseUrl is representing /ws/rest/v1/ since its an absolute path starting from the root of the domain and not ws/rest/v1/ which is a relative path that dependent on the current location. Kindly help me understand more dear. My tests I have been looking at the desired behavior and the structure of the web application or API.

@CynthiaKamau
Copy link
Contributor

@CynthiaKamau Thanks for the good question. In my understanding restBaseUrl is representing /ws/rest/v1/ since its an absolute path starting from the root of the domain and not ws/rest/v1/ which is a relative path that dependent on the current location. Kindly help me understand more dear. My tests I have been looking at the desired behavior and the structure of the web application or API.

Thats fine @jwnasambu , kindly fix the conflicts then we can merge this in

@@ -18,7 +18,7 @@ const PrintReceipt: React.FC<PrintReceiptProps> = ({ billId }) => {
renderIcon={(props) => <Printer size={24} {...props} />}>
<ConfigurableLink
className={styles.configurableLink}
to={`\${openmrsBase}/ws/rest/v1/cashier/receipt?billId=${billId}`}>
to={`\${openmrsBase}/${restBaseUrl}/cashier/receipt?billId=${billId}`}>
Copy link
Contributor

Choose a reason for hiding this comment

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

to={\${openmrsBase}${restBaseUrl}/cashier/receipt?billId=${billId}}>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@CynthiaKamau Thanks for the review! Let me fix and ping you shortly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

to={\${openmrsBase}${restBaseUrl}/cashier/receipt?billId=${billId}}>

@CynthiaKamau by removing the backticks, we will lose the ability to use template literals and expressions directly within the string. In this case:

  • ${openmrsBase} and ${restBaseUrl} won't be evaluated as variables; they will be treated as literal strings.
  • ${billId} won't be evaluated either; it will be treated as a literal string.

As a result, the final value of the to attribute would be the concatenation of the literal strings, and the variable names won't be replaced with their actual values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@CynthiaKamau I have fixed the merge conflict and part of the proposed changes.

Copy link
Member

@pirupius pirupius left a comment

Choose a reason for hiding this comment

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

Thanks @jwnasambu for this

@pirupius pirupius merged commit e0a4628 into openmrs:main Mar 7, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants