-
Notifications
You must be signed in to change notification settings - Fork 19
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
Hrms bounday service #1544
base: master
Are you sure you want to change the base?
Hrms bounday service #1544
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,12 +1,12 @@ | ||||||
import { useQuery } from 'react-query'; | ||||||
import { LocationService } from "../services/elements/Location"; | ||||||
|
||||||
const useLocation = (tenantId, locationType, config = {}) => { | ||||||
const useLocation = (tenantId, locationType, config = {},includeChildren,includeParents) => { | ||||||
switch(locationType) { | ||||||
case 'Locality': | ||||||
return useQuery(["LOCALITY_DETAILS", tenantId ], () => LocationService.getLocalities(tenantId), config); | ||||||
case 'Ward': | ||||||
return useQuery(["WARD_DETAILS", tenantId ], () => LocationService.getWards(tenantId), config); | ||||||
return useQuery(["WARD_DETAILS", tenantId], () => LocationService.getWards(tenantId,includeChildren,includeParents), config); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update the query key to include new parameters for proper caching. The 'Ward' case has been correctly updated to pass the new To ensure proper caching behavior with React Query, update the query key to include the new parameters: - return useQuery(["WARD_DETAILS", tenantId], () => LocationService.getWards(tenantId,includeChildren,includeParents), config);
+ return useQuery(["WARD_DETAILS", tenantId, includeChildren, includeParents], () => LocationService.getWards(tenantId, includeChildren, includeParents), config); This change will ensure that React Query creates separate cache entries for different combinations of 📝 Committable suggestion
Suggested change
|
||||||
default: | ||||||
break | ||||||
} | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
const mdmsV1Path = window?.globalConfigs?.getConfig("MDMS_V1_CONTEXT_PATH") || "egov-mdms-service"; | ||
const mdmsV2Path = window?.globalConfigs?.getConfig("MDMS_V2_CONTEXT_PATH") || "mdms-v2"; | ||
const boundarySearchPath = window?.globalConfigs?.getConfig("BOUNDARY_CONTEXT") || "boundary-service/boundary-relationships/_search?"; | ||
const hierarchyType = window?.globalConfigs?.getConfig("HIERARCHY_TYPE") || "hierarchyType=ADMIN"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) LGTM: Well-implemented configuration constant with a minor suggestion. The const hierarchyType = window?.globalConfigs?.getConfig("HIERARCHY_TYPE") || "ADMIN"; Then, when using this constant, you can add the "hierarchyType=" prefix: `hierarchyType=${hierarchyType}` This approach separates the configuration value from its usage, potentially making it more flexible for future changes. |
||
|
||
const Urls = { | ||
MDMS_V2:`/${mdmsV2Path}/v1/_search`, | ||
MDMS: `/${mdmsV1Path}/v1/_search`, | ||
WorkFlow: `/egov-workflow-v2/egov-wf/businessservice/_search`, | ||
WorkFlowProcessSearch: `/egov-workflow-v2/egov-wf/process/_search`, | ||
localization: `/localization/messages/v1/_search`, | ||
location: { | ||
localities: `/egov-location/location/v11/boundarys/_search?hierarchyTypeCode=ADMIN&boundaryType=Locality`, | ||
wards: `/egov-location/location/v11/boundarys/_search?hierarchyTypeCode=ADMIN&boundaryType=Ward`, | ||
revenue_localities: `/egov-location/location/v11/boundarys/_search?hierarchyTypeCode=REVENUE&boundaryType=Locality`, | ||
localities: `/${boundarySearchPath}includeChildren=true&${hierarchyType}&boundaryType=locality`, | ||
wards: `/${boundarySearchPath}includeChildren=true&${hierarchyType}&boundaryType=Ward&includeParents=true`, | ||
revenue_localities: `/boundary-service/boundary-relationships/_search?hierarchyType=REVENUE&boundaryType=locality`, | ||
}, | ||
|
||
pgr_search: `/pgr-services/v2/request/_search`, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,11 +19,11 @@ export const LocationService = { | |
}); | ||
return response; | ||
}, | ||
getWards: (tenantId) => { | ||
getWards: (tenantId,includeChildren,includeParents) => { | ||
return ServiceRequest({ | ||
serviceName: "getWards", | ||
url: Urls.location.wards, | ||
params: { tenantId: tenantId }, | ||
params: { tenantId: tenantId,includeChildren: includeChildren, includeParents}, | ||
useCache: true, | ||
}); | ||
Comment on lines
+22
to
28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Update The changes to the Apply this diff to fix the getWards: (tenantId,includeChildren,includeParents) => {
return ServiceRequest({
serviceName: "getWards",
url: Urls.location.wards,
- params: { tenantId: tenantId,includeChildren: includeChildren, includeParents},
+ params: { tenantId, includeChildren, includeParents },
useCache: true,
});
} This change ensures that:
Consider adding spaces after commas in the method signature for better readability: getWards: (tenantId, includeChildren, includeParents) => { |
||
} | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -112,8 +112,22 @@ const Jurisdictions = ({ t, config, onSelect, userType, formData }) => { | |||||||||||||||||||||||||||||||||||||||||||||
let boundaryTypeoption = []; | ||||||||||||||||||||||||||||||||||||||||||||||
const [focusIndex, setFocusIndex] = useState(-1); | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
const { isBoundaryServiceLoading, data: hierarchyOptions } = Digit.Hooks.useLocation( | ||||||||||||||||||||||||||||||||||||||||||||||
tenantId, | ||||||||||||||||||||||||||||||||||||||||||||||
"Ward", | ||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||
select: (data) => { | ||||||||||||||||||||||||||||||||||||||||||||||
return data; | ||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||
true | ||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+115
to
+125
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Simplify the The Apply this diff to simplify the code: const { isBoundaryServiceLoading, data: hierarchyOptions } = Digit.Hooks.useLocation(
tenantId,
"Ward",
- {
- select: (data) => {
- return data;
- },
- },
true
); 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
function gethierarchylistdata() { | ||||||||||||||||||||||||||||||||||||||||||||||
return data?.MdmsRes?.["egov-location"]["TenantBoundary"].map((ele) => ele.hierarchyType); | ||||||||||||||||||||||||||||||||||||||||||||||
return hierarchyOptions?.TenantBoundary?.map((ele) => ({ | ||||||||||||||||||||||||||||||||||||||||||||||
code: ele.hierarchyType, | ||||||||||||||||||||||||||||||||||||||||||||||
name: ele.hierarchyType | ||||||||||||||||||||||||||||||||||||||||||||||
})); | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
function getboundarydata() { | ||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -124,7 +138,7 @@ const Jurisdictions = ({ t, config, onSelect, userType, formData }) => { | |||||||||||||||||||||||||||||||||||||||||||||
return data?.MdmsRes?.["ACCESSCONTROL-ROLES"].roles.map(role => { return { code: role.code, name: role?.name ? role?.name : " " , labelKey: 'ACCESSCONTROL_ROLES_ROLES_' + role.code } }); | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
if (isLoading) { | ||||||||||||||||||||||||||||||||||||||||||||||
if (isLoading || isBoundaryServiceLoading) { | ||||||||||||||||||||||||||||||||||||||||||||||
return <Loader />; | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
return ( | ||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -148,6 +162,7 @@ const Jurisdictions = ({ t, config, onSelect, userType, formData }) => { | |||||||||||||||||||||||||||||||||||||||||||||
getboundarydata={getboundarydata} | ||||||||||||||||||||||||||||||||||||||||||||||
getroledata={getroledata} | ||||||||||||||||||||||||||||||||||||||||||||||
handleRemoveUnit={handleRemoveUnit} | ||||||||||||||||||||||||||||||||||||||||||||||
hierarchyOptions={hierarchyOptions} | ||||||||||||||||||||||||||||||||||||||||||||||
/> | ||||||||||||||||||||||||||||||||||||||||||||||
))} | ||||||||||||||||||||||||||||||||||||||||||||||
<label onClick={handleAddUnit} className="link-label" style={{ width: "12rem" }}> | ||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -168,18 +183,19 @@ function Jurisdiction({ | |||||||||||||||||||||||||||||||||||||||||||||
getroledata, | ||||||||||||||||||||||||||||||||||||||||||||||
roleoption, | ||||||||||||||||||||||||||||||||||||||||||||||
index, | ||||||||||||||||||||||||||||||||||||||||||||||
hierarchyOptions | ||||||||||||||||||||||||||||||||||||||||||||||
}) { | ||||||||||||||||||||||||||||||||||||||||||||||
const [BoundaryType, selectBoundaryType] = useState([]); | ||||||||||||||||||||||||||||||||||||||||||||||
const [Boundary, selectboundary] = useState([]); | ||||||||||||||||||||||||||||||||||||||||||||||
useEffect(() => { | ||||||||||||||||||||||||||||||||||||||||||||||
selectBoundaryType( | ||||||||||||||||||||||||||||||||||||||||||||||
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') } }) | ||||||||||||||||||||||||||||||||||||||||||||||
const filteredBoundaryTypes = hierarchyOptions?.TenantBoundary?.filter((ele) => ele.hierarchyType === jurisdiction?.hierarchy?.code).map( | ||||||||||||||||||||||||||||||||||||||||||||||
(item) => ({ | ||||||||||||||||||||||||||||||||||||||||||||||
...item.boundary[0], | ||||||||||||||||||||||||||||||||||||||||||||||
i18text: Digit.Utils.locale.convertToLocale(item.boundary[0].boundaryType, "EGOV_LOCATION_BOUNDARYTYPE"), | ||||||||||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||
}, [jurisdiction?.hierarchy, data?.MdmsRes]); | ||||||||||||||||||||||||||||||||||||||||||||||
selectBoundaryType(filteredBoundaryTypes); | ||||||||||||||||||||||||||||||||||||||||||||||
}, [jurisdiction?.hierarchy, hierarchyOptions]); | ||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+191
to
+198
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure safe access to In the mapping function within the Apply this diff to add safety checks: useEffect(() => {
const filteredBoundaryTypes = hierarchyOptions?.TenantBoundary?.filter(
(ele) => ele.hierarchyType === jurisdiction?.hierarchy?.code
).map((item) => {
+ if (!item.boundary || item.boundary.length === 0) {
+ return null; // or handle the case accordingly
+ }
return {
...item.boundary[0],
i18text: Digit.Utils.locale.convertToLocale(item.boundary[0].boundaryType, "EGOV_LOCATION_BOUNDARYTYPE"),
};
}).filter(Boolean);
selectBoundaryType(filteredBoundaryTypes);
}, [jurisdiction?.hierarchy, hierarchyOptions]); 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
const tenant = Digit.ULBService.getCurrentTenantId(); | ||||||||||||||||||||||||||||||||||||||||||||||
useEffect(() => { | ||||||||||||||||||||||||||||||||||||||||||||||
selectboundary(data?.MdmsRes?.tenant?.tenants.filter(city => city.code != Digit.ULBService.getStateId()).map(city => { return { ...city, i18text: Digit.Utils.locale.getCityLocale(city.code) } })); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,15 +21,15 @@ const LocationDropdownWrapper = ({populators,formData,props,inputRef,errors,setV | |
const wards = [] | ||
const localities = {} | ||
data?.TenantBoundary[0]?.boundary.forEach((item) => { | ||
localities[item?.code] = item?.children.map(item => ({ code: item.code, name: item.name, i18nKey: `${headerLocale}_ADMIN_${item?.code}`, label: item?.label })) | ||
wards.push({ code: item.code, name: item.name, i18nKey: `${headerLocale}_ADMIN_${item?.code}` }) | ||
localities[item?.code] = item?.children.map(item => ({ code: item.code, name: t(`${headerLocale}_ADMIN_${item?.code}`), i18nKey: `${headerLocale}_ADMIN_${item?.code}`, label: item?.label })) | ||
wards.push({ code: item.code, name: t(`${headerLocale}_ADMIN_${item?.code}`), i18nKey: `${headerLocale}_ADMIN_${item?.code}` }) | ||
Comment on lines
+24
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) LGTM! Consider extracting the translation key construction. The changes correctly implement localization for ward and locality names using the To improve readability, consider extracting the translation key construction into a separate function: const getTranslationKey = (code) => `${headerLocale}_ADMIN_${code}`;
// Then use it like this:
localities[item?.code] = item?.children.map(item => ({
code: item.code,
name: t(getTranslationKey(item?.code)),
i18nKey: getTranslationKey(item?.code),
label: item?.label
}));
wards.push({
code: item.code,
name: t(getTranslationKey(item?.code)),
i18nKey: getTranslationKey(item?.code)
}); This would make the code more DRY and easier to maintain. |
||
}); | ||
|
||
return { | ||
wards, localities | ||
} | ||
} | ||
}); | ||
},true); | ||
|
||
|
||
useEffect(() => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding default values for new parameters to maintain backward compatibility.
The function signature has been updated to include two new parameters,
includeChildren
andincludeParents
. While this change allows for more flexibility, it could potentially break existing code that calls this function without providing these new parameters.To maintain backward compatibility, consider adding default values for these new parameters:
This change would ensure that existing calls to
useLocation
continue to work as before, while still allowing the new functionality to be used when needed.📝 Committable suggestion