Skip to content

Refactor: Remove legacy components and migrate to TypeScript - #35

Open
vinothkumar-onyx wants to merge 8 commits into
3.1.2from
migration/typescript-vite-testing-setup
Open

Refactor: Remove legacy components and migrate to TypeScript#35
vinothkumar-onyx wants to merge 8 commits into
3.1.2from
migration/typescript-vite-testing-setup

Conversation

@vinothkumar-onyx

@vinothkumar-onyx vinothkumar-onyx commented Sep 16, 2025

Copy link
Copy Markdown
Collaborator

This pull request makes significant changes to modernize the build system, deployment, and environment configuration for the eCRNow-UI project. The main updates include migrating from Create React App to Vite, overhauling Docker and Nginx configuration, and updating documentation to reflect the new workflows. Several legacy files and configurations are removed, and new mock/test resources are added.

Build System and Tooling Modernization:

  • Migrated the project from Create React App to Vite, updating scripts in package.json and adding Vite-specific dependencies. The build, development, and test commands now use Vite and Vitest instead of react-scripts and Jest.
  • Added a new .env.example with Vite-compatible environment variables, replacing the old env.example that used React's naming conventions. [1] [2]
  • Updated the main HTML entry point to a new index.html for Vite, replacing the previous CRA-style public/index.html. [1] [2]

Docker and Deployment Changes:

  • Replaced the old Docker setup with a new multi-stage Dockerfile (root-level), which builds the app with Node, then serves it with Nginx. The Nginx configuration and Docker Compose files are updated or removed to match the new structure. [1] [2] [3] [4]
  • Removed outdated Docker and deployment documentation, and updated or added new instructions for building and deploying with the new setup. [1] [2] [3]

Mock and Testing Resources:

  • Added mock server files and example data for local testing, including mock/db.json, mock/json-server.json, mock/routes.json, and mock/server.js. [1] [2] [3] [4]
  • Added a sample db.json for API testing and local development.

Styling Improvements:

  • Updated src/App.css to add new CSS variables and improved form validation styles, aligning with the new primary color and validation feedback.

Summary of Most Important Changes

Build System and Environment Configuration:

  • Migrated from Create React App to Vite, updating scripts and dependencies in package.json, and switching environment variable usage to Vite's conventions (e.g., VITE_ECR_BASE_URL). [1] [2] [3]
  • Replaced public/index.html with a new Vite-compatible index.html. [1] [2]

Docker and Deployment:

  • Introduced a new multi-stage Dockerfile at the project root for building and serving the app with Nginx, and updated Nginx configuration accordingly. [1] [2]
  • Removed old Docker Compose and Dockerfile setup, and deprecated related documentation. [1] [2] [3] [4]

Documentation:

  • Added and updated documentation for separating UI from backend, building, and deploying the UI independently (including Maven/Tomcat instructions).

Mock and Testing:

  • Added mock server and test data files to support local development and API testing. [1] [2] [3] [4] [5]

Styling:

  • Improved form validation and color theming in src/App.css.

nbashyam and others added 2 commits April 22, 2025 15:32
- Deleted KAR, PublicHealthAuthority, and PublicHealthAuthorityList components.
- Removed index.js and replaced with main.tsx for Vite compatibility.
- Introduced serviceWorker.ts for service worker registration.
- Added TypeScript configuration (tsconfig.json) and Vite configuration (vite.config.ts).
- Updated withRouter to TypeScript.
- Added setupTests.ts for testing library setup.
Copilot AI review requested due to automatic review settings September 16, 2025 06:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request refactors the application by removing legacy components and migrating to TypeScript with Vite. The refactoring modernizes the codebase by replacing Create React App with Vite, converting JavaScript components to TypeScript, and removing outdated components.

Key changes include:

  • Removed legacy JavaScript components (KAR, PublicHealthAuthority, PublicHealthAuthorityList)
  • Replaced index.js with main.tsx for Vite compatibility
  • Converted withRouter helper from JavaScript to TypeScript
  • Added TypeScript configurations and reusable form components

Reviewed Changes

Copilot reviewed 83 out of 98 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
vite.config.ts Vite configuration with React plugin and test setup
src/withRouter.tsx TypeScript version of router HOC
src/setupTests.ts Test environment setup for TypeScript
src/serviceWorker.ts Migrated service worker with TypeScript
src/main.tsx New TypeScript entry point replacing index.js

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread src/serviceWorker.ts Outdated
Comment thread src/serviceWorker.ts
onUpdate?: (registration: ServiceWorkerRegistration) => void;
};

const isLocalhost = Boolean(

Copilot AI Sep 16, 2025

Copy link

Choose a reason for hiding this comment

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

The old isLocalhost code is commented out instead of being removed, creating duplicate logic. Remove the commented-out code block (lines 13-135) to maintain code cleanliness.

Copilot uses AI. Check for mistakes.
Comment thread src/Components/HealthCareSettings/HealthCareSettings.tsx Outdated
Comment thread src/main.tsx Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 84 out of 99 changed files in this pull request and generated 5 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread src/serviceWorker.ts
Comment on lines +16 to +23
const publicUrl = new URL(process.env.PUBLIC_URL!, window.location.href);

if (publicUrl.origin !== window.location.origin) {
return;
}

window.addEventListener("load", () => {
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;

Copilot AI Sep 16, 2025

Copy link

Choose a reason for hiding this comment

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

Using non-null assertion operator (!) on process.env.PUBLIC_URL without checking if it exists could cause runtime errors. The environment variable might be undefined in some environments.

Suggested change
const publicUrl = new URL(process.env.PUBLIC_URL!, window.location.href);
if (publicUrl.origin !== window.location.origin) {
return;
}
window.addEventListener("load", () => {
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
const publicUrlValue = process.env.PUBLIC_URL || '/';
const publicUrl = new URL(publicUrlValue, window.location.href);
if (publicUrl.origin !== window.location.origin) {
return;
}
window.addEventListener("load", () => {
const swUrl = `${publicUrlValue}/service-worker.js`;

Copilot uses AI. Check for mistakes.
Comment thread vite.config.ts
reporter: ["text", "html"],
exclude: [
"src/Services/AxiosConfig.ts",
"./vite.config.ts",

Copilot AI Sep 16, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] Including the Vite config file itself in the test coverage exclusion list is unnecessary since Vite configuration files are not typically part of test coverage analysis.

Suggested change
"./vite.config.ts",

Copilot uses AI. Check for mistakes.
Comment thread src/Components/HealthCareSettings/HealthCareSettings.tsx Outdated
}

function handleUsernameChange(e: ChangeEvent<HTMLInputElement>): void {
const value = e.target.value.replace(/\s/g, "");

Copilot AI Sep 16, 2025

Copy link

Choose a reason for hiding this comment

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

Automatically removing all spaces from username and password inputs without user notification could lead to confusion if users intentionally include spaces. Consider providing visual feedback or validation messages instead.

Copilot uses AI. Check for mistakes.
return;
}
function handlePasswordChange(e: ChangeEvent<HTMLInputElement>): void {
const value = e.target.value.replace(/\s/g, "");

Copilot AI Sep 16, 2025

Copy link

Choose a reason for hiding this comment

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

Automatically removing all spaces from username and password inputs without user notification could lead to confusion if users intentionally include spaces. Consider providing visual feedback or validation messages instead.

Copilot uses AI. Check for mistakes.
@vinothkumar-onyx
vinothkumar-onyx changed the base branch from main to 3.1.2 October 16, 2025 05:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 84 out of 99 changed files in this pull request and generated 5 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread src/withRouter.tsx
Comment on lines +1 to +2
import { useNavigate } from "react-router-dom";
import React from "react";

Copilot AI Oct 16, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] The React import should come before the react-router-dom import for better organization and consistency with typical React import ordering conventions.

Suggested change
import { useNavigate } from "react-router-dom";
import React from "react";
import React from "react";
import { useNavigate } from "react-router-dom";

Copilot uses AI. Check for mistakes.
Comment on lines +168 to +170
setTimeout(() => {
localStorage.removeItem("logoutSuccess");
}, 1000);

Copilot AI Oct 16, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] The hardcoded 1000ms timeout should be extracted to a named constant for better maintainability and to make the timing intention clearer.

Copilot uses AI. Check for mistakes.
Comment on lines +179 to +180
setTimeout(() => {
localStorage.removeItem("sessionExpired");

Copilot AI Oct 16, 2025

Copy link

Choose a reason for hiding this comment

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

The timeout value 181 appears to be missing a closing parenthesis and the value seems arbitrary. This should be consistent with other timeout values and properly closed.

Copilot uses AI. Check for mistakes.
Comment on lines +18 to +35
onChange={(e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement>) => {
if (
type === "number" &&
min !== undefined &&
e.target.value !== "" &&
!isNaN(parseFloat(e.target.value)) &&
parseFloat(e.target.value) < min
) {
const target = { ...e.target, value: String(min) };
const syntheticEvent = {
...e,
target,
} as React.ChangeEvent<HTMLInputElement | HTMLSelectElement>;
onChange(syntheticEvent);
return;
}
onChange(e);
}}

Copilot AI Oct 16, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] The synthetic event creation is complex and could be extracted to a separate helper function for better readability and testability.

Copilot uses AI. Check for mistakes.
Comment thread vite.config.ts
Comment on lines +4 to +10
import * as path from "path";

export default defineConfig({
plugins: [react()],
resolve: {
alias: {
"@": path.resolve(__dirname, "src"),

Copilot AI Oct 16, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] Using import * as path is unnecessary when you only need the resolve method. Consider using import { resolve } from "path" for more specific imports.

Suggested change
import * as path from "path";
export default defineConfig({
plugins: [react()],
resolve: {
alias: {
"@": path.resolve(__dirname, "src"),
import { resolve } from "path";
export default defineConfig({
plugins: [react()],
resolve: {
alias: {
"@": resolve(__dirname, "src"),

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants