Skip to content

Commit

Permalink
fixed product chip and summary issue (#1941)
Browse files Browse the repository at this point in the history
fixed productchip and summary issue
  • Loading branch information
Bhavya-egov authored Nov 29, 2024
1 parent 134ae7c commit 61dd04e
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<title>DIGIT</title>
<link rel="stylesheet" href="https://unpkg.com/@egovernments/[email protected]/dist/index.css" />
<link rel="stylesheet" href="https://unpkg.com/@egovernments/[email protected]/dist/index.css" />
<link rel="stylesheet" href="https://unpkg.com/@egovernments/[email protected].52/dist/index.css" />
<link rel="stylesheet" href="https://unpkg.com/@egovernments/[email protected].53/dist/index.css" />

<!-- added below css for hcm-workbench module inclusion-->
<!-- <link rel="stylesheet" href="https://unpkg.com/@egovernments/[email protected]/dist/index.css" /> -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@egovernments/digit-ui-health-css",
"version": "0.1.52",
"version": "0.1.53",
"license": "MIT",
"main": "dist/index.css",
"author": "Jagankumar <[email protected]>",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@
}
.add-rule-btn {
margin: auto;
margin-bottom: 1rem;
h2 {
font-family: Roboto;
font-size: 1rem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ input[type="date"]::-webkit-calendar-picker-indicator {
.campaign-preview-edit-container {
display: flex;
gap: 1rem;
cursor: pointer;

span {
color: theme(digitv2.lightTheme.primary);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,95 +80,6 @@ function loopAndReturn(dataa, t) {
return format;
}

function reverseDeliveryRemap(data, t) {
if (!data) return null;
const reversedData = [];
let currentCycleIndex = null;
let currentCycle = null;

const operatorMapping = {
"<=": "LESS_THAN_EQUAL_TO",
">=": "GREATER_THAN_EQUAL_TO",
"<": "LESS_THAN",
">": "GREATER_THAN",
"==": "EQUAL_TO",
"!=": "NOT_EQUAL_TO",
IN_BETWEEN: "IN_BETWEEN",
};

const cycles = data?.[0]?.cycles || [];
const mapProductVariants = (productVariants) => {
return productVariants.map((variant, key) => ({
key: key + 1,
count: 1,
value: variant.productVariantId,
name: variant.name,
}));
};

const parseConditionAndCreateRules = (condition, ruleKey, products) => {
const conditionParts = condition.split("and").map((part) => part.trim());
let attributes = [];

conditionParts.forEach((part) => {
const parts = part.split(" ").filter(Boolean);

// Handle "IN_BETWEEN" operator
if (parts.length === 5 && (parts[1] === "<=" || parts[1] === "<") && (parts[3] === "<" || parts[3] === "<=")) {
const toValue = parts[0];
const fromValue = parts[4];
attributes.push({
key: attributes.length + 1,
operator: { code: operatorMapping["IN_BETWEEN"] },
attribute: { code: parts[2] },
fromValue,
toValue,
});
} else {
const match = part.match(/(.*?)\s*(<=|>=|<|>|==|!=)\s*(.*)/);
if (match) {
const attributeCode = match[1].trim();
const operatorSymbol = match[2].trim();
const value = match[3].trim();
attributes.push({
key: attributes.length + 1,
value,
operator: { code: operatorMapping[operatorSymbol] },
attribute: { code: attributeCode },
});
}
}
});
return [{
ruleKey: ruleKey + 1,
delivery: {},
products,
attributes,
}];
};
const mapDoseCriteriaToDeliveryRules = (doseCriteria) => {
return doseCriteria?.flatMap((criteria, ruleKey) => {
const products = mapProductVariants(criteria.ProductVariants);
return parseConditionAndCreateRules(criteria.condition, ruleKey, products);
});
};

const mapDeliveries = (deliveries) => {
return deliveries?.map((delivery, deliveryIndex) => ({
active: deliveryIndex === 0,
deliveryIndex: String(deliveryIndex + 1),
deliveryRules: mapDoseCriteriaToDeliveryRules(delivery.doseCriteria),
}));
};

const transformedCycles = cycles.map((cycle) => ({
active: true,
cycleIndex: String(cycle.id),
deliveries: mapDeliveries(cycle.deliveries),
}));

return transformedCycles;
}

function boundaryDataGrp(boundaryData) {
// Create an empty object to hold grouped data by type
Expand Down Expand Up @@ -285,6 +196,133 @@ const CampaignSummary = (props) => {
window.dispatchEvent(new Event("checking"));
}, [key]);

function reverseDeliveryRemap(data, t) {
if (!data) return null;
const reversedData = [];
let currentCycleIndex = null;
let currentCycle = null;

const operatorMapping = {
"<=": "LESS_THAN_EQUAL_TO",
">=": "GREATER_THAN_EQUAL_TO",
"<": "LESS_THAN",
">": "GREATER_THAN",
"==": "EQUAL_TO",
"!=": "NOT_EQUAL_TO",
IN_BETWEEN: "IN_BETWEEN",
};

const cycles = data?.[0]?.cycles || [];
const mapProductVariants = (productVariants) => {
return productVariants.map((variant, key) => ({
key: key + 1,
count: 1,
value: variant.productVariantId,
name: variant.name,
}));
};

const parseConditionAndCreateRules = (condition, ruleKey, products) => {
// const conditionParts = condition.split("and").map((part) => part.trim());
// let attributes = [];
let attributes = [];

if (isPreview) {
// Handle preview condition `3<=ageandage<11` or `3 <= Age < 11` in "IN_BETWEEN" style
const inBetweenMatch = condition.match(/(\d+)(<=|<|>=|>)(\w+)and(\w+)(<=|<|>=|>)(\d+)/);
if (inBetweenMatch) {
const toValue = inBetweenMatch[1].trim();
const fromValue = inBetweenMatch[6].trim();
const attributeCode = inBetweenMatch[3].trim();

attributes.push({
key: attributes.length + 1,
operator: { code: "IN_BETWEEN" },
attribute: { code: attributeCode },
fromValue,
toValue,
});
} else {
// Handle regular conditions in preview mode
const conditionParts = condition.split("and").map((part) => part.trim());
conditionParts.forEach((part) => {
const match = part.match(/(.*?)\s*(<=|>=|<|>|==|!=)\s*(.*)/);
if (match) {
const attributeCode = match[1].trim();
const operatorSymbol = match[2].trim();
const value = match[3].trim();
attributes.push({
key: attributes.length + 1,
value,
operator: { code: operatorMapping[operatorSymbol] },
attribute: { code: attributeCode },
});
}
});
}
} else {
const conditionParts = condition.split("and").map((part) => part.trim());
conditionParts.forEach((part) => {
const parts = part.split(" ").filter(Boolean);

// Handle "IN_BETWEEN" operator
if (parts.length === 5 && (parts[1] === "<=" || parts[1] === "<") && (parts[3] === "<" || parts[3] === "<=")) {
const toValue = parts[0];
const fromValue = parts[4];
attributes.push({
key: attributes.length + 1,
operator: { code: operatorMapping["IN_BETWEEN"] },
attribute: { code: parts[2] },
fromValue,
toValue,
});
} else {
const match = part.match(/(.*?)\s*(<=|>=|<|>|==|!=)\s*(.*)/);
if (match) {
const attributeCode = match[1].trim();
const operatorSymbol = match[2].trim();
const value = match[3].trim();
attributes.push({
key: attributes.length + 1,
value,
operator: { code: operatorMapping[operatorSymbol] },
attribute: { code: attributeCode },
});
}
}
});
}
return [{
ruleKey: ruleKey + 1,
delivery: {},
products,
attributes,
}];
};
const mapDoseCriteriaToDeliveryRules = (doseCriteria) => {
return doseCriteria?.flatMap((criteria, ruleKey) => {
const products = mapProductVariants(criteria.ProductVariants);
return parseConditionAndCreateRules(criteria.condition, ruleKey, products);
});
};

const mapDeliveries = (deliveries) => {
return deliveries?.map((delivery, deliveryIndex) => ({
active: deliveryIndex === 0,
deliveryIndex: String(deliveryIndex + 1),
deliveryRules: mapDoseCriteriaToDeliveryRules(delivery.doseCriteria),
}));
};

const transformedCycles = cycles.map((cycle) => ({
active: true,
cycleIndex: String(cycle.id),
deliveries: mapDeliveries(cycle.deliveries),
}));

return transformedCycles;
}

// useEffect(() => {
// if (props?.props?.summaryErrors) {
// if (props?.props?.summaryErrors?.deliveryErrors) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ const AddDeliveryRule = ({ targetedData, deliveryRules, setDeliveryRules, index,
<div className="product-tag-container digit-tag-container">
{delivery?.products?.length > 0 &&
delivery?.products?.map((i) => {
return i?.value && i?.count ? (
return i?.value && i?.quantity ? (
<Chip key={i.key} text={i?.name} onClick={() => removeProduct(i)} className="multiselectdropdown-tag" hideClose={false} />
) : null;
})}
Expand Down
2 changes: 1 addition & 1 deletion health/micro-ui/web/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<link rel="stylesheet" href="https://unpkg.com/@egovernments/[email protected]/dist/index.css" />
<link rel="stylesheet" href="https://unpkg.com/@egovernments/[email protected]/dist/index.css" />
<!-- added below css for hcm-workbench module inclusion-->
<link rel="stylesheet" href="https://unpkg.com/@egovernments/[email protected].52/dist/index.css" />
<link rel="stylesheet" href="https://unpkg.com/@egovernments/[email protected].53/dist/index.css" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#00bcd1" />
<title>DIGIT HCM</title>
Expand Down

0 comments on commit 61dd04e

Please sign in to comment.