Skip to content

Libraries changes and cleanup (#245) #246

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

Open
wants to merge 1 commit into
base: develop-webpack
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 8 additions & 10 deletions webpack/libraries/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@egovernments/digit-ui-libraries",
"version": "1.8.1-upgrade.5",
"version": "1.8.1-upgrade.6",
"main": "dist/main.js",
"module": "dist/main.js",
"source": "src/index.js",
Expand All @@ -9,7 +9,7 @@
"dist"
],
"scripts": {
"start": "microbundle-crl watch --no-compress --format modern,cjs",
"start": "webpack serve --mode=production --open --hot",
"prepublish": "yarn build",
"example": "cd example && npm run start",
"build": "webpack --mode=production --node-env=production --config webpack.config.js",
Expand All @@ -18,12 +18,13 @@
"deploy": "gh-pages -d example/build"
},
"peerDependencies": {
"react": "19.0.0"
"react": "^19.0.0",
"react-dom": "^19.0.0",
"@tanstack/react-query": "^5.62.16"
},
"devDependencies": {
"gh-pages": "2.2.0",
"microbundle-crl": "0.13.11",
"react-dom": "19.0.0",
"react-scripts": "^4.0.1",
"sass": "^1.83.4",
"sass-loader": "^16.0.4",
Expand All @@ -33,25 +34,22 @@
"babel-loader": "8.0.0",
"cross-env": "7.0.3",
"lint-staged": "12.3.7",
"react": "19.0.0",
"webpack": "^5.97.1",
"webpack-cli": "^4.10.0"
},
"dependencies": {
"@tanstack/react-query": "^5.62.16",
"axios": "0.27.2",
"babel-preset-react": "6.24.1",
"date-fns": "2.28.0",
"dom-to-image": "2.6.0",
"html2canvas": "1.4.1",
"i18next": "19.9.2",
"i18next": "23.2.3",
"i18next-react-postprocessor": "3.0.7",
"pdfmake": "0.1.72",
"react": "19.0.0",
"react-i18next": "15.0.0",
"react-redux": "7.2.8",
"react-redux": "9.2.0",
"react-router-dom": "5.3.0",
"redux": "4.1.2",
"redux": "5.0.0",
"xlsx": "0.17.5",
"@egovernments/digit-ui-components": "0.0.2-beta.4-webpack.2",
"@egovernments/digit-ui-svg-components": "1.0.0-webpack.6"
Expand Down
13 changes: 7 additions & 6 deletions webpack/libraries/src/hooks/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { useQuery } from "@tanstack/react-query";
import { StoreService } from "../services/molecules/Store/service";

export const useStore = ({ stateCode, moduleCode, language ,modulePrefix = "rainmaker" }) => {
return useQuery(
['store', stateCode, moduleCode, language, modulePrefix], // queryKey
() => StoreService.defaultData(stateCode, moduleCode, language, modulePrefix), // query function
{
// You can add other options here if needed, such as `enabled`, `staleTime`, etc.
}
return useQuery({
queryKey : ['store', stateCode, moduleCode, language, modulePrefix], // queryKey
queryFn : () => StoreService.defaultData(stateCode, moduleCode, language, modulePrefix), // query function
// {
// // You can add other options here if needed, such as `enabled`, `staleTime`, etc.
// }
}
);
};

Expand Down
8 changes: 7 additions & 1 deletion webpack/libraries/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import mergeConfig from "./config/mergeConfig";
import { useStore } from "./services/index";
import { initI18n } from "./translations/index";
import { Request } from "./services/atoms/Utils/Request";
// ---
import { StoreService } from "./services/molecules/Store/service";
// ---

import { Storage, PersistantStorage } from "./services/atoms/Utils/Storage";
import { UploadServices } from "./services/atoms/UploadServices";
Expand Down Expand Up @@ -76,12 +79,15 @@ const initLibraries = () => {
setupLibraries("InboxGeneral", InboxGeneral);
setupLibraries("ShareFiles", ShareFiles);
setupLibraries("Contexts", Contexts);
setupLibraries("Hooks", Hooks);
// setupLibraries("Hooks", Hooks);
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Hooks setup disabled

The Hooks setup has been commented out, which seems to be part of the architectural change moving to StoreService. Ensure that all functionality previously handled by Hooks is now properly handled by StoreService or document this change as a potential breaking change.

Recommended checks:

  1. Verify if any existing components are still trying to use functionality from the Hooks module
  2. Confirm that StoreService covers all relevant functionality

🏁 Script executed:

#!/bin/bash
# Find components that might be importing or using Hooks directly
rg "import.*Hooks.*from" --type js --type jsx --type ts --type tsx
rg "Digit\.Hooks\." --type js --type jsx --type ts --type tsx

Length of output: 188


I'll generate new shell scripts that explicitly add file types for JSX/TSX so we can verify if any components still import or reference the Hooks module. Please run the following scripts and share the output to confirm if any references remain:

Once you run these commands, please verify whether any output is returned. If no references are found, it likely indicates that the Hooks module is indeed no longer in use. If there are references, you'll need to ensure that either those components are updated to use StoreService or the change is documented properly as a potential breaking change.


🏁 Script executed:

#!/bin/bash
# Adding custom file types for jsx and tsx before searching for Hooks references.

# Search for imports of Hooks (works with .js, .jsx, .ts, .tsx files)
rg --type-add 'jsx:*.jsx' --type-add 'tsx:*.tsx' -e "import.*Hooks.*from" .

# Search for explicit usage of Digit.Hooks (works with .js, .jsx, .ts, .tsx files)
rg --type-add 'jsx:*.jsx' --type-add 'tsx:*.tsx' -e "Digit\.Hooks\." .

Length of output: 25779


Action: Address Incomplete Hooks Migration

The Hooks setup in webpack/libraries/src/index.js is now disabled (see the commented out code), but our repository search reveals that many components continue to import and actively use Digit.Hooks (e.g., useCustomAPIHook, useQueryParams, useCustomMDMS, etc.) across various modules. This indicates that the architectural migration to StoreService may be incomplete.

Please ensure one of the following:

  • Fully migrate Hooks functionality: Update all components using Digit.Hooks to use StoreService where applicable.
  • Document the change as a breaking change: Clearly document which Hooks functionalities are deprecated and how their absence is handled or should be manually addressed by downstream consumers.

Key Points:

  • The file webpack/libraries/src/index.js (Line 82) contains the disabled setup:
      // setupLibraries("Hooks", Hooks);
  • Numerous components in both the React and Webpack directories still reference Digit.Hooks.*.

Please review all Hooks usage to confirm coverage by StoreService and update or document accordingly.

setupLibraries("Customizations", {});
setupLibraries("Utils", Utils);
setupLibraries("Download", Download);

setupLibraries("AccessControlService", AccessControlService);
//
setupLibraries("StoreServiceLib", StoreService);
//

return new Promise((resolve) => {
initI18n(resolve);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const LocalizationStore = {

updateResources: (locale, messages) => {
let locales = TransformArrayToObj(messages);
i18next.addResources(locale, "translations", locales);
window.i18next.addResources(locale, "translations", locales);
},
};

Expand Down
4 changes: 2 additions & 2 deletions webpack/libraries/src/services/elements/MDMS.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const initRequestBody = (tenantId) => ({
},
});

const getCriteria = (tenantId, moduleDetails) => {
const getCriteria = (tenantId="mz", moduleDetails) => {
return {
MdmsCriteria: {
tenantId,
Expand Down Expand Up @@ -1471,7 +1471,7 @@ const debouncedCall = ({ serviceName, url, data, useCache, params }, resolve, re
};

export const MdmsService = {
init: (stateCode) =>
init: (stateCode="mz") =>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

same here as well

ServiceRequest({
serviceName: "mdmsInit",
url: Urls.MDMS,
Expand Down
17 changes: 11 additions & 6 deletions webpack/libraries/src/services/molecules/Store/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const StoreService = {
uiHomePage: uiHomePage,
};
},
digitInitData: async (stateCode, enabledModules, modulePrefix) => {
digitInitData: async (stateCode="mz", enabledModules, modulePrefix) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we cant have hardcoded @purepiyush

const { MdmsRes } = await MdmsService.init(stateCode);
const stateInfo = MdmsRes["common-masters"]?.StateInfo?.[0] || {};
const uiHomePage = MdmsRes["common-masters"]?.uiHomePage?.[0] || {};
Expand Down Expand Up @@ -135,6 +135,7 @@ export const StoreService = {
uiHomePage: uiHomePage,
};
};

const initData = tenantConfigFetch
? await fetchTenantConfig()
: {
Expand Down Expand Up @@ -176,12 +177,16 @@ export const StoreService = {
}
// .filter((item) => !!moduleTenants.find((mt) => mt.code === item.code))
// .map((tenant) => ({ i18nKey: `TENANT_TENANTS_${tenant.code.replace(".", "_").toUpperCase()}`, ...tenant }));
try {
await LocalizationService.getLocale({
modules: [`${modulePrefix}-common`, `digit-ui`, `digit-tenants`, `${modulePrefix}-${stateCode.toLowerCase()}`],
locale: initData.selectedLanguage,
tenantId: stateCode,
});
} catch (error) {
console.error("LocalizationService.getLocale failed:", error);
}

await LocalizationService.getLocale({
modules: [`${modulePrefix}-common`, `digit-ui`, `digit-tenants`, `${modulePrefix}-${stateCode.toLowerCase()}`],
locale: initData.selectedLanguage,
tenantId: stateCode,
});
Storage.set("initData", initData);
initData.revenue_localities = revenue_localities;
initData.localities = localities;
Expand Down
3 changes: 2 additions & 1 deletion webpack/libraries/src/translations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const initI18n = (callback) => {
.use(initReactI18next)
.init(i18nextConfig(), () => {
window.i18next = i18next;
callback();
if (callback) callback();
});
};