From 42208100922c5e13810ab5ab17d058d16bd49dbd Mon Sep 17 00:00:00 2001 From: Nipun Arora Date: Wed, 6 Mar 2024 09:54:24 +0530 Subject: [PATCH] added hrms module --- .github/workflows/mfe-hrms-ui-docker.yml | 25 ++++++++++++++++--- micro-ui/web/lerna.json | 3 ++- micro-ui/web/package.json | 3 ++- .../core/src/modules/registerRemotes.js | 11 ++++++++ micro-ui/web/packages/core/webpack.dev.js | 2 +- micro-ui/web/packages/core/webpack.prod.js | 2 +- micro-ui/web/packages/hrms/docker/nginx.conf | 2 +- micro-ui/web/packages/hrms/package.json | 5 ++-- micro-ui/web/packages/hrms/public/index.html | 1 - micro-ui/web/packages/hrms/src/HRMSWrapper.js | 19 ++++++++++++++ .../web/packages/hrms/src/SingleSpaEntry.js | 25 +++++++++++++++++++ .../hrms/src/components/InboxFilter.js | 6 ++--- .../components/pageComponents/jurisdiction.js | 5 ++-- .../web/packages/hrms/src/pages/Response.js | 8 +++--- micro-ui/web/packages/hrms/src/pages/index.js | 8 +++--- micro-ui/web/packages/hrms/webpack.dev.js | 2 +- micro-ui/web/packages/hrms/webpack.prod.js | 6 ++--- 17 files changed, 104 insertions(+), 29 deletions(-) create mode 100644 micro-ui/web/packages/hrms/src/HRMSWrapper.js create mode 100644 micro-ui/web/packages/hrms/src/SingleSpaEntry.js diff --git a/.github/workflows/mfe-hrms-ui-docker.yml b/.github/workflows/mfe-hrms-ui-docker.yml index 501ffb10b47..11adf857a37 100644 --- a/.github/workflows/mfe-hrms-ui-docker.yml +++ b/.github/workflows/mfe-hrms-ui-docker.yml @@ -2,7 +2,7 @@ name: hrms ui service docker Image CI on: push: - branches: [ "mf-build-docker", "mf-stable" ] + branches: [ "mf-build-docker","mf-stable-common-module" ] pull_request: branches: [ "mf-build" ] @@ -14,19 +14,36 @@ jobs: steps: - uses: actions/checkout@v3 + with: + fetch-depth: 0 # Fetch all history for tags and branches + + - name: Set up environment variables + id: env + run: | + echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV + echo "ACTION_NUMBER=${GITHUB_RUN_NUMBER}" >> $GITHUB_ENV + echo "COMMIT_ID=${GITHUB_SHA: -8}" >> $GITHUB_ENV # Extract last 8 characters of SHA + - name: Build the Docker image + id: docker_build working-directory: ./micro-ui/web/packages/hrms - run: docker build . --file docker/Dockerfile --tag egovio/hrms-ui:latest + run: | + IMAGE_TAG=egovio/hrms-ui:${{ env.BRANCH_NAME }}-${{ env.COMMIT_ID }}-${{ env.ACTION_NUMBER }} + docker build . \ + --file docker/Dockerfile \ + --tag $IMAGE_TAG + echo "::set-output name=image_name::$IMAGE_TAG" - name: Login to Docker Hub and Push Docker Image working-directory: ./micro-ui/web/packages/hrms env: DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + IMAGE_NAME: ${{ steps.docker_build.outputs.image_name }} run: | # Authenticate with Docker Hub echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin # Push the image to Docker Hub - docker push egovio/hrms-ui:latest - + docker push $IMAGE_NAME + echo "Docker image pushed: $IMAGE_NAME" diff --git a/micro-ui/web/lerna.json b/micro-ui/web/lerna.json index 6aa29c27919..7fe41af7086 100644 --- a/micro-ui/web/lerna.json +++ b/micro-ui/web/lerna.json @@ -8,7 +8,8 @@ "packages/app1", "packages/common", "packages/pgr", - "packages/dss" + "packages/dss", + "packages/hrms" ], "command": { "run": { diff --git a/micro-ui/web/package.json b/micro-ui/web/package.json index 3bb2450a991..1b574c490c7 100644 --- a/micro-ui/web/package.json +++ b/micro-ui/web/package.json @@ -22,7 +22,8 @@ "packages/app1", "packages/common", "packages/pgr", - "packages/dss" + "packages/dss", + "packages/hrms" ], "scripts": { "build": "yarn lerna run build", diff --git a/micro-ui/web/packages/core/src/modules/registerRemotes.js b/micro-ui/web/packages/core/src/modules/registerRemotes.js index 458c716cd6e..57ade3e55ae 100644 --- a/micro-ui/web/packages/core/src/modules/registerRemotes.js +++ b/micro-ui/web/packages/core/src/modules/registerRemotes.js @@ -54,6 +54,17 @@ export default (queryClient) => { }, }); + registerApplication({ + name: "HRMS", + app: () => import("hrms/HRMSModule"), + activeWhen: `/${window.contextPath ? window.contextPath : "core-digit-ui"}/employee/hrms`, + customProps: { + title: "HRMS is running on host", + queryClient, + userType + }, + }); + start(); } diff --git a/micro-ui/web/packages/core/webpack.dev.js b/micro-ui/web/packages/core/webpack.dev.js index 7294f099c05..00d6e41fc24 100644 --- a/micro-ui/web/packages/core/webpack.dev.js +++ b/micro-ui/web/packages/core/webpack.dev.js @@ -43,7 +43,7 @@ module.exports = () => { // auth: "auth@http://localhost:8082/remoteEntry.js", // header: "header@http://localhost:8083/remoteEntry.js", // dashboard: "dashboard@http://localhost:8084/remoteEntry.js", - // hrms: "hrms@https://localhost:8085/remoteEntry.js", + hrms: "hrms@https://localhost:8085/remoteEntry.js", workbench: "workbench@https://localhost:8086/remoteEntry.js", common:"common@https://localhost:8090/remoteEntry.js", pgr:"pgr@https://localhost:8087/remoteEntry.js", diff --git a/micro-ui/web/packages/core/webpack.prod.js b/micro-ui/web/packages/core/webpack.prod.js index d4279d71af4..d0b32fe3189 100644 --- a/micro-ui/web/packages/core/webpack.prod.js +++ b/micro-ui/web/packages/core/webpack.prod.js @@ -19,7 +19,7 @@ module.exports = () => { // auth: `auth@${domain}/auth/remoteEntry.js`, // header: `header@${domain}/header/remoteEntry.js`, // dashboard: `dashboard@${domain}/dashboard/remoteEntry.js`, - // hrms: `hrms@${domain}/hrms/remoteEntry.js`, + hrms: `hrms@${domain}/hrms-ui/remoteEntry.js`, common: `common@${domain}/common-ui/remoteEntry.js`, pgr: `pgr@${domain}/pgr-ui/remoteEntry.js`, workbench : `workbench@${domain}/workbench-mfe/remoteEntry.js`, diff --git a/micro-ui/web/packages/hrms/docker/nginx.conf b/micro-ui/web/packages/hrms/docker/nginx.conf index 9d4ada9fdcb..d7b0029ac00 100644 --- a/micro-ui/web/packages/hrms/docker/nginx.conf +++ b/micro-ui/web/packages/hrms/docker/nginx.conf @@ -7,6 +7,6 @@ server { root /var/web; index index.html index.htm; - try_files $uri $uri/ /core/index.html; + try_files $uri $uri/ /hrms-ui/index.html; } } \ No newline at end of file diff --git a/micro-ui/web/packages/hrms/package.json b/micro-ui/web/packages/hrms/package.json index 22ccf2f947d..2dfb64a5dd1 100644 --- a/micro-ui/web/packages/hrms/package.json +++ b/micro-ui/web/packages/hrms/package.json @@ -23,12 +23,13 @@ "@babel/preset-env":"7.23.9" }, "dependencies": { + "single-spa-react": "^4.6.1", "react": "17.0.1", "react-dom": "17.0.1", "react-router-dom": "5.2.0", "rxjs": "6.6.3", - "@digit-ui/digit-ui-libraries-mfe": "1.0.7", - "@egovernments/digit-ui-react-components":"1.4.107", + "@digit-ui/digit-ui-libraries-mfe": "1.0.6", + "@egovernments/digit-ui-react-components":"1.4.106", "@digit-ui/digit-ui-module-core-base":"1.0.8", "react-hook-form": "6.15.8", "react-i18next": "11.16.2", diff --git a/micro-ui/web/packages/hrms/public/index.html b/micro-ui/web/packages/hrms/public/index.html index 266bc6968a7..c41b034230a 100644 --- a/micro-ui/web/packages/hrms/public/index.html +++ b/micro-ui/web/packages/hrms/public/index.html @@ -4,7 +4,6 @@ Hrms Page - { + initHRMSComponents(); + + return ( + + + + + + ); +}; + +export default App; \ No newline at end of file diff --git a/micro-ui/web/packages/hrms/src/SingleSpaEntry.js b/micro-ui/web/packages/hrms/src/SingleSpaEntry.js new file mode 100644 index 00000000000..59fda042cd9 --- /dev/null +++ b/micro-ui/web/packages/hrms/src/SingleSpaEntry.js @@ -0,0 +1,25 @@ +import React from "react"; +import ReactDOM from "react-dom"; +import singleSpaReact from "single-spa-react"; +import App from "./HRMSWrapper"; +const appLifeCycles = singleSpaReact({ + React, + ReactDOM, + rootComponent: App, + errorBoundary() { + // https://reactjs.org/docs/error-boundaries.html + return
This renders when a catastrophic error occurs
; + }, +}); + +export function bootstrap(props) { + return appLifeCycles.bootstrap(props); +} + +export function mount(props) { + return appLifeCycles.mount(props); +} + +export function unmount(props) { + return appLifeCycles.unmount(props); +} \ No newline at end of file diff --git a/micro-ui/web/packages/hrms/src/components/InboxFilter.js b/micro-ui/web/packages/hrms/src/components/InboxFilter.js index a221c2a57ef..6e192b2668a 100644 --- a/micro-ui/web/packages/hrms/src/components/InboxFilter.js +++ b/micro-ui/web/packages/hrms/src/components/InboxFilter.js @@ -38,7 +38,7 @@ const Filter = ({ searchParams, onFilterChange, onSearch, removeParam, ...props )[0]; }); const { isLoading, isError, errors, data: data, ...rest } = Digit.Hooks.hrms.useHrmsMDMS( - tenantId ? tenantId.code : searchParams?.tenantId, + tenantId ? tenantId?.code : searchParams?.tenantId, "egov-hrms", "HRMSRolesandDesignation" ); @@ -54,8 +54,8 @@ const Filter = ({ searchParams, onFilterChange, onSearch, removeParam, ...props }); useEffect(() => { - if (tenantId.code) { - setSearchParams({ ..._searchParams, tenantId: tenantId.code }); + if (tenantId?.code) { + setSearchParams({ ..._searchParams, tenantId: tenantId?.code }); } }, [tenantId]); diff --git a/micro-ui/web/packages/hrms/src/components/pageComponents/jurisdiction.js b/micro-ui/web/packages/hrms/src/components/pageComponents/jurisdiction.js index 91dd0663f30..11f545f7651 100644 --- a/micro-ui/web/packages/hrms/src/components/pageComponents/jurisdiction.js +++ b/micro-ui/web/packages/hrms/src/components/pageComponents/jurisdiction.js @@ -113,7 +113,7 @@ const Jurisdictions = ({ t, config, onSelect, userType, formData }) => { const [focusIndex, setFocusIndex] = useState(-1); function gethierarchylistdata() { - return data?.MdmsRes?.["egov-location"]["TenantBoundary"].map((ele) => ele.hierarchyType); + return data?.MdmsRes?.["egov-location"]["TenantBoundary"]?.map((ele) => ele.hierarchyType); } function getboundarydata() { @@ -173,8 +173,7 @@ function Jurisdiction({ const [Boundary, selectboundary] = useState([]); useEffect(() => { selectBoundaryType( - data?.MdmsRes?.["egov-location"]["TenantBoundary"] - .filter((ele) => { + data?.MdmsRes?.["egov-location"]["TenantBoundary"]?.filter((ele) => { return ele?.hierarchyType?.code == jurisdiction?.hierarchy?.code; }) .map((item) => { return { ...item.boundary, i18text: Digit.Utils.locale.convertToLocale(item.boundary.label, 'EGOV_LOCATION_BOUNDARYTYPE') } }) diff --git a/micro-ui/web/packages/hrms/src/pages/Response.js b/micro-ui/web/packages/hrms/src/pages/Response.js index d5af6e90c9c..77a8d1b2758 100644 --- a/micro-ui/web/packages/hrms/src/pages/Response.js +++ b/micro-ui/web/packages/hrms/src/pages/Response.js @@ -37,7 +37,7 @@ const Response = (props) => { const [mutationHappened, setMutationHappened, clear] = Digit.Hooks.useSessionStorage("EMPLOYEE_HRMS_MUTATION_HAPPENED", false); const [successData, setsuccessData, clearSuccessData] = Digit.Hooks.useSessionStorage("EMPLOYEE_HRMS_MUTATION_SUCCESS_DATA", false); const [errorInfo, setErrorInfo, clearError] = Digit.Hooks.useSessionStorage("EMPLOYEE_HRMS_ERROR_DATA", false); - const mutation = state.key === "UPDATE" ? Digit.Hooks.hrms.useHRMSUpdate(tenantId) : Digit.Hooks.hrms.useHRMSCreate(tenantId); + const mutation = state?.key === "UPDATE" ? Digit.Hooks.hrms.useHRMSUpdate(tenantId) : Digit.Hooks.hrms.useHRMSCreate(tenantId); const employeeCreateSession = Digit.Hooks.useSessionStorage("NEW_EMPLOYEE_CREATE", {}); const [sessionFormData,setSessionFormData, clearSessionFormData] = employeeCreateSession; @@ -63,7 +63,7 @@ const Response = (props) => { setMutationHappened(true); }; if (!mutationHappened ) { - if (state.key === "UPDATE") { + if (state?.key === "UPDATE") { mutation.mutate( { Employees: state.Employees, @@ -97,12 +97,12 @@ const Response = (props) => { - {t(DisplayText(state.action, mutation.isSuccess || !!successData, props.parentRoute.includes("employee"), t), t)} + {t(DisplayText(state?.action, mutation.isSuccess || !!successData, props.parentRoute.includes("employee"), t), t)} diff --git a/micro-ui/web/packages/hrms/src/pages/index.js b/micro-ui/web/packages/hrms/src/pages/index.js index 007518f74dc..6d4bc98d2b2 100644 --- a/micro-ui/web/packages/hrms/src/pages/index.js +++ b/micro-ui/web/packages/hrms/src/pages/index.js @@ -1,7 +1,7 @@ import { PrivateRoute } from "@egovernments/digit-ui-react-components"; import React,{ useEffect } from "react"; import { useTranslation } from "react-i18next"; -import { Link, Switch, useLocation } from "react-router-dom"; +import { Link, Switch, useLocation, BrowserRouter as Router } from "react-router-dom"; import { SVG } from "@egovernments/digit-ui-react-components"; const {SixFtApart,Rotate360}=SVG; @@ -33,8 +33,9 @@ const EmployeeApp = ({ path, url, userType }) => { },[location]); return ( - + +

@@ -53,8 +54,9 @@ const EmployeeApp = ({ path, url, userType }) => { } /> } />

+
+
-
); }; diff --git a/micro-ui/web/packages/hrms/webpack.dev.js b/micro-ui/web/packages/hrms/webpack.dev.js index bf6c49f95c1..864c0447283 100644 --- a/micro-ui/web/packages/hrms/webpack.dev.js +++ b/micro-ui/web/packages/hrms/webpack.dev.js @@ -41,7 +41,7 @@ module.exports = () => { name: "hrms", filename: "remoteEntry.js", exposes: { - "./HrmsModule": "./src/bootstrap", + "./HRMSModule": "./src/SingleSpaEntry", }, shared: packageJson.dependencies, }), diff --git a/micro-ui/web/packages/hrms/webpack.prod.js b/micro-ui/web/packages/hrms/webpack.prod.js index 951ce3fe29f..875fec5b04c 100644 --- a/micro-ui/web/packages/hrms/webpack.prod.js +++ b/micro-ui/web/packages/hrms/webpack.prod.js @@ -12,12 +12,12 @@ module.exports = () => { }, plugins: [ new ModuleFederationPlugin({ - name: "hrms-ui", + name: "hrms", filename: "remoteEntry.js", exposes: { - "./HrmsModule": "./src/bootstrap", + "./HRMSModule": "./src/SingleSpaEntry", }, - shared: packageJson.dependencies, //removed the shared logic for now will be enabled later for optimization + // shared: packageJson.dependencies, //removed the shared logic for now will be enabled later for optimization }), ], };