Skip to content

Commit

Permalink
UI Custiomizations fix (#1509)
Browse files Browse the repository at this point in the history
* Update createUpdatePlanProject.js

* updatd ui customizations
  • Loading branch information
nipunarora-eGov authored Oct 11, 2024
1 parent 159e7da commit 13cd94a
Show file tree
Hide file tree
Showing 2 changed files with 173 additions and 10 deletions.
179 changes: 172 additions & 7 deletions health/micro-ui/web/micro-ui-internals/example/src/UICustomizations.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Link } from "react-router-dom";
import _ from "lodash";
import { useLocation, useHistory } from "react-router-dom";
import { useParams } from "react-router-dom";

import { useLocation, useHistory,Link,useParams } from "react-router-dom";
import React from "react";
import { Dropdown } from "@egovernments/digit-ui-components";
//create functions here based on module name set in mdms(eg->SearchProjectConfig)
//how to call these -> Digit?.Customizations?.[masterName]?.[moduleName]
// these functions will act as middlewares
Expand Down Expand Up @@ -764,7 +763,7 @@ export const UICustomizations = {
}
},
},
SearchMicroplan: {
MicroplanSearchConfig: {
preProcess: (data, additionalDetails) => {
const { name, status } = data?.state?.searchForm || {};

Expand All @@ -778,12 +777,178 @@ export const UICustomizations = {
// delete data.body.PlanConfigurationSearchCriteria.pagination
data.body.PlanConfigurationSearchCriteria.status = status?.status;
cleanObject(data.body.PlanConfigurationSearchCriteria);

return data;
},
additionalCustomizations: (row, key, column, value, t, searchResult) => {
if (key === "CAMPAIGN_DATE") {
return `${Digit.DateUtils.ConvertEpochToDate(value)} - ${Digit.DateUtils.ConvertEpochToDate(row?.CampaignDetails?.endDate)}`;
if (key === "Actions") {
return (
<Dropdown
option={[
{ code: "1", name: "Edit Setup" },
{ code: "2", name: "Duplicate Setup" },
{ code: "3", name: "View Summary" },
]}
select={(e) => { console.log(e, "event") }}
optionKey={"name"}
selected={{ code: "1", name: "Actions" }}
></Dropdown>
// <p>$${value}</p>

);
}

if (key === "Name of the Microplan") {
if (value && value !== "NA") {

return (
<div
style={{
maxWidth: '15rem', // Set the desired maximum width
wordWrap: 'break-word', // Allows breaking within words
whiteSpace: 'normal', // Ensures text wraps normally
overflowWrap: 'break-word' // Break long words at the edge
}}
>
<p>{value}</p>
</div>
)
} else {
return (
<div>
<p>NA</p>
</div>
)
}

}

},
},

UserManagementConfig: {

customValidationCheck: (data) => {
const { phone } = data;
const mobileRegex = /^[0-9]{10}$/;

// Allow empty mobile number
if (!phone || phone.trim() === "") {
return false;
}

// Check if phone matches the regex
if (!mobileRegex.test(phone)) {
return { error: true, label: "INVALID_MOBILE_NUMBER" }; // Return an error message if invalid
}

return false;
},
preProcess: (data, additionalDetails) => {

const { phone, name } = data?.state?.searchForm || {}
const { sortOrder } = data?.state?.filterForm || {}
let { roleschosen } = data?.state?.filterForm || []

if (!roleschosen) {
roleschosen = {}
}
// if(Object.keys(roleschosen).length === 0){
// for(const obj of additionalDetails["microplanData"]){

// roleschosen[obj["roleCode"]]=true;

// }
// }

let rolesString = '';
if (roleschosen) {
rolesString = Object.keys(roleschosen).filter(role => roleschosen[role] === true).join(',');
}



data.params.names = name;

data.params.phone = phone;

data.params.roles = rolesString;
data.params.tenantId = Digit.ULBService.getCurrentTenantId();
cleanObject(data.params);
delete data.params.roleschosen;
delete data.params.name;


return data
},

rolesForFilter: (props) => {
const userInfo = Digit.UserService.getUser();
const tenantId = Digit.ULBService.getCurrentTenantId();

return {
params: {},
url: '/mdms-v2/v2/_search', //mdms fetch from

body: {
MdmsCriteria: {
tenantId: Digit.ULBService.getCurrentTenantId(),
filters: {},
schemaCode: "hcm-microplanning.rolesForMicroplan",
limit: 10,
offset: 0
}

},
config: {
enabled: true,
select: (data) => {
const roles = data?.mdms.map(item => {
return (
{
roleCode: item.data.roleCode,
i18nKey: Digit.Utils.locale.getTransformedLocale(`MP_ROLE_${item.data.roleCode}`)

}
)
})

return roles
},
},
// changeQueryName:"setPlantUsersInboxDropdown"
}
},




additionalCustomizations: (row, key, column, value, t, searchResult) => {


if (key === "Role") {

if (value && value !== "NA") {

return (
<div>
{value.map((item, index) => (
<span key={index} className="dm-code">
{Digit.Utils.locale.getTransformedLocale(`MP_ROLE_${item.code}`)}
{index < value.length - 1 && ", "}
</span>
))}
</div>
);
}

}else{
return(
<div>NA</div>
)
}

},

}
};
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { Link } from "react-router-dom";
import _ from "lodash";
import { useLocation, useHistory,Link,useParams } from "react-router-dom";
import React from "react";
import { Dropdown } from "@egovernments/digit-ui-components";


//create functions here based on module name set in mdms(eg->SearchProjectConfig)
//how to call these -> Digit?.Customizations?.[masterName]?.[moduleName]
// these functions will act as middlewares
Expand Down

0 comments on commit 13cd94a

Please sign in to comment.