Skip to content
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

Microplan search #1356

Merged
merged 2 commits into from
Sep 5, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const MicroplanCard = () => {
};
};

let links = [generateLink("SETUP_MICROLAN","setup-microplan")];
let links = [generateLink("SETUP_MICROCLAN","setup-microplan"),generateLink("SEARCH_MICROPLANS","microplan-search")];

links = links.filter((link) => (link?.roles && link?.roles?.length > 0 ? Digit.Utils.didEmployeeHasAtleastOneRole(link?.roles) : true));

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@


// default values of search input component
const defaultSearchValues = {
Copy link
Contributor

Choose a reason for hiding this comment

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

why this is required?

microplanName: "",

};


//config for tab search sceeen
export const TabSearchconfig = {
// moduleName: "commonCampaignUiConfig",
showTab: true, // setting true will enable tab screen
TabSearchconfig: [ // all tab config should be added in json array
{
label: "ALL",
type: "search",
apiDetails: {
serviceName: "/plan-service/config/_search", //! Note
requestParam: {},
requestBody: {},
masterName: "commonUiConfig",
moduleName: "MicroplanSearchConfig",
minParametersForSearchForm: 0,
tableFormJsonPath: "requestBody.PlanConfigurationSearchCriteria.pagination",
// filterFormJsonPath: "requestBody.MdmsCriteria.customs",
searchFormJsonPath: "requestBody.PlanConfigurationSearchCriteria",
},

sections: {
search: {
uiConfig: {
formClassName: "custom-both-clear-search",
primaryLabel: "ES_COMMON_SEARCH",
secondaryLabel: "ES_COMMON_CLEAR_SEARCH",
minReqFields: 0,
defaultValues: defaultSearchValues, // Set default values for search fields
fields: [
{
label: "Name of the microplan",
isMandatory: false,
key: "microplanName",
type: "text",
populators: {
name: "microplanName",
error: "Required",
validation: { pattern: /^[A-Za-z]+$/i },
},
},
// {
// label: "Phone number",
// isMandatory: false,
// key: "Phone number",
// type: "number",
// disable: false,
// populators: { name: "mobileNumber", error: "sample error message", validation: { min: 0, max: 999999999 } },
// },
// {
// label: "Individual Id ",
// isMandatory: false,
// type: "text",
// disable: false,
// populators: {
// name: "individualId",
// },
// },
],
},

show: true,
},
searchResult: {
uiConfig: {
columns: [
{
label: "Name of the Microplan",
jsonPath: "name",
additionalCustomization:true
},

{
label: "Microplan Status",
jsonPath: "status",
},
{
label: "Campaign Disease",
jsonPath: "CampaignDetails.campaignName",
},
{
label:"Camapaign Type",
jsonPath:"CampaignDetails.startDate"
},
{
label:"Distribution Strategy",
jsonPath:" proposalDate"
},
{
label:"Actions",
jsonPath:"",
additionalCustomization:true
}
],
resultsJsonPath: "PlanConfiguration",

enableColumnSort: true,
// resultsJsonPath: "mdms",
},
show: true,
},
// customHookName: "microplanv1.useSavedMicroplans", //! Note

},
customHookName:"microplanv1.useSavedMicroplans"
},


{label: "DRAFTED_SETUP"},
{label: "EXECUTION_TO_BE_DONE",},
{label:"EXECUTION_IN_PROGRESS"},
{label:"MICROPLAN_EXECUTED"}

],
};



Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Link, useHistory } from "react-router-dom";
import _ from "lodash";
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]
Expand All @@ -10,108 +12,90 @@ const businessServiceMap = {};

const inboxModuleNameMap = {};

function cleanObject(obj) {
for (const key in obj) {
if (Object.hasOwn(obj, key)) {
if (Array.isArray(obj[key])) {
if (obj[key].length === 0) {
delete obj[key];
}
} else if (
obj[key] === undefined ||
obj[key] === null ||
obj[key] === false ||
obj[key] === "" || // Check for empty string
(typeof obj[key] === "object" && Object.keys(obj[key]).length === 0)
) {
delete obj[key];
}
}
}
return obj;
}

export const UICustomizations = {
SearchPucarConfig: {
customValidationCheck: (data) => {
//checking both to and from date are present
const { createdFrom, createdTo } = data;
if ((createdFrom === "" && createdTo !== "") || (createdFrom !== "" && createdTo === ""))
return { warning: true, label: "ES_COMMON_ENTER_DATE_RANGE" };

return false;
},
preProcess: (data) => {
// data.params = { ...data.params, tenantId: Digit.ULBService.getCurrentTenantId() };

// let requestBody = { ...data.body.Individual };
// const pathConfig = {
// name: "name.givenName",
// };
// const dateConfig = {
// createdFrom: "daystart",
// createdTo: "dayend",
// };
// const selectConfig = {
// wardCode: "wardCode[0].code",
// socialCategory: "socialCategory.code",
// };
// const textConfig = ["name", "individualId"];
// let Individual = Object.keys(requestBody)
// .map((key) => {
// if (selectConfig[key]) {
// requestBody[key] = _.get(requestBody, selectConfig[key], null);
// } else if (typeof requestBody[key] == "object") {
// requestBody[key] = requestBody[key]?.code;
// } else if (textConfig?.includes(key)) {
// requestBody[key] = requestBody[key]?.trim();
// }
// return key;
// })
// .filter((key) => requestBody[key])
// .reduce((acc, curr) => {
// if (pathConfig[curr]) {
// _.set(acc, pathConfig[curr], requestBody[curr]);
// } else if (dateConfig[curr] && dateConfig[curr]?.includes("day")) {
// _.set(acc, curr, Digit.Utils.date.convertDateToEpoch(requestBody[curr], dateConfig[curr]));
// } else {
// _.set(acc, curr, requestBody[curr]);
// }
// return acc;
// }, {});

// data.body.Individual = { ...Individual };
console.log(data,"data");
return data;
},
additionalCustomizations: (row, key, column, value, t, searchResult) => {
//here we can add multiple conditions
//like if a cell is link then we return link
//first we can identify which column it belongs to then we can return relevant result
switch (key) {
case "MASTERS_WAGESEEKER_ID":
return (
<span className="link">
<Link to={`/${window.contextPath}/employee/masters/view-wageseeker?tenantId=${row?.tenantId}&individualId=${value}`}>
{String(value ? (column.translate ? t(column.prefix ? `${column.prefix}${value}` : value) : value) : t("ES_COMMON_NA"))}
</Link>
</span>
);

case "MASTERS_SOCIAL_CATEGORY":
return value ? <span style={{ whiteSpace: "nowrap" }}>{String(t(`MASTERS_${value}`))}</span> : t("ES_COMMON_NA");

case "CORE_COMMON_PROFILE_CITY":
return value ? <span style={{ whiteSpace: "nowrap" }}>{String(t(Digit.Utils.locale.getCityLocale(value)))}</span> : t("ES_COMMON_NA");

case "MASTERS_WARD":
return value ? (
<span style={{ whiteSpace: "nowrap" }}>{String(t(Digit.Utils.locale.getMohallaLocale(value, row?.tenantId)))}</span>
) : (
t("ES_COMMON_NA")
);

MicroplanSearchConfig: {
preProcess: (data, additionalDetails) => {
const { name, status } = data?.state?.searchForm || {};

data.body.PlanConfigurationSearchCriteria = {};
data.body.PlanConfigurationSearchCriteria.limit = data?.state?.tableForm?.limit;
// data.body.PlanConfigurationSearchCriteria.limit = 10
data.body.PlanConfigurationSearchCriteria.offset = data?.state?.tableForm?.offset;
data.body.PlanConfigurationSearchCriteria.name = name;
data.body.PlanConfigurationSearchCriteria.tenantId = Digit.ULBService.getCurrentTenantId();
data.body.PlanConfigurationSearchCriteria.userUuid = Digit.UserService.getUser().info.uuid;
// delete data.body.PlanConfigurationSearchCriteria.pagination
data.body.PlanConfigurationSearchCriteria.status = status?.status;
cleanObject(data.body.PlanConfigurationSearchCriteria);

case "MASTERS_LOCALITY":
return value ? (
<span style={{ whiteSpace: "break-spaces" }}>{String(t(Digit.Utils.locale.getMohallaLocale(value, row?.tenantId)))}</span>
) : (
t("ES_COMMON_NA")
);
default:
return t("ES_COMMON_NA");
}
},
MobileDetailsOnClick: (row, tenantId) => {
let link;
Object.keys(row).map((key) => {
if (key === "MASTERS_WAGESEEKER_ID")
link = `/${window.contextPath}/employee/masters/view-wageseeker?tenantId=${tenantId}&wageseekerId=${row[key]}`;
});
return link;
},
additionalValidations: (type, data, keys) => {
if (type === "date") {
return data[keys.start] && data[keys.end] ? () => new Date(data[keys.start]).getTime() <= new Date(data[keys.end]).getTime() : true;
}
},
},
return data;
},
additionalCustomizations: (row, key, column, value, t, searchResult) => {
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>
)
}

}

},
},

};
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Header, InboxSearchComposer } from "@egovernments/digit-ui-react-components";
import React, { useState, useEffect } from "react";
import { useTranslation } from "react-i18next";
import { TabSearchconfig } from '../../configs/MicroplanSearchConfig'



const defaultSearchValues = {

};

const MicroplanSearch = () => {
const { t } = useTranslation();
const [defaultValues, setDefaultValues] = useState(defaultSearchValues); // State to hold default values for search fields
const [config, setConfig] = useState(TabSearchconfig?.TabSearchconfig?.[0]); // initially setting first index config as default from jsonarray
const [tabData, setTabData] = useState(
TabSearchconfig?.TabSearchconfig?.map((configItem, index) => ({ key: index, label: configItem.label, active: index === 0 ? true : false }))
); // setting number of tab component and making first index enable as default
useEffect(() => {
// Set default values when component mounts
setDefaultValues(defaultSearchValues);
}, []);

const onTabChange = (n) => {

setTabData((prev) => prev.map((i, c) => ({ ...i, active: c === n ? true : false }))); //setting tab enable which is being clicked
// setConfig(TabSearchconfig?.TabSearchconfig?.[n]);// as per tab number filtering the config
const url = new URL(window.location.href);
url.searchParams.set("tabId", `${n}`);
window.history.replaceState({}, "", url);

};
return (
<React.Fragment>

<Header styles={{ fontSize: "32px" }}>{t(config?.label)}</Header>
<div className="inbox-search-wrapper">
{/* Pass defaultValues as props to InboxSearchComposer */}
<InboxSearchComposer
configs={config}
defaultValues={defaultValues}
showTab={true}
tabData={tabData}
onTabChange={onTabChange} //!activated ion tabChange
></InboxSearchComposer>
</div>
</React.Fragment>
);
};
export default MicroplanSearch;
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const SetupMicroplan = () => {
}, [params]);

const onSubmit = (formData) => {
debugger

//run validations
// setIsSubmittting to true -> to run inline validations within the components
setIsSubmitting(true);
Expand Down
Loading