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

fixed product chip and summary issue #1941

Merged
merged 1 commit into from
Nov 29, 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 @@ -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" />
Comment on lines 13 to +15
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Consider adding integrity hashes for enhanced security

The CSS resources are loaded from unpkg.com without integrity hashes. Consider adding integrity checks to prevent supply chain attacks.

Example format:

-  <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" 
+        integrity_no="sha384-[hash]" 
+        crossorigin="anonymous" />

Committable suggestion skipped: line range outside the PR's diff.


<!-- 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;
Comment on lines +202 to +203
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Use const instead of let for variables that are not reassigned

The variables currentCycleIndex and currentCycle are declared with let but never reassigned after their initial assignment. Declaring them with const improves code readability and clearly indicates that these variables are constants.

Suggested fix:

     const reversedData = [];
-    let currentCycleIndex = null;
-    let currentCycle = null;
+    const currentCycleIndex = null;
+    const currentCycle = null;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let currentCycleIndex = null;
let currentCycle = null;
const currentCycleIndex = null;
const currentCycle = null;
🧰 Tools
🪛 Biome (1.9.4)

[error] 202-202: This let declares a variable that is only assigned once.

'currentCycleIndex' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


[error] 203-203: This let declares a variable that is only assigned once.

'currentCycle' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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 = [];
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Use const instead of let for attributes since it's not reassigned

The variable attributes is initialized but not reassigned. Using const is preferred for variables that remain constant to enhance code clarity.

Suggested fix:

-    let attributes = [];
+    const attributes = [];
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let attributes = [];
const attributes = [];
🧰 Tools
🪛 Biome (1.9.4)

[error] 228-228: This let declares a variable that is only assigned once.

'attributes' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


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;
}
Comment on lines +199 to +324
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Consider refactoring reverseDeliveryRemap into smaller functions

The reverseDeliveryRemap function is quite lengthy and contains complex nested logic. Refactoring it into smaller, modular functions can improve readability, maintainability, and facilitate easier testing.

🧰 Tools
🪛 Biome (1.9.4)

[error] 202-202: This let declares a variable that is only assigned once.

'currentCycleIndex' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


[error] 203-203: This let declares a variable that is only assigned once.

'currentCycle' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


[error] 228-228: This let declares a variable that is only assigned once.

'attributes' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)


// 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" />
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Consider documenting the CSS changes.

To help with future maintenance, consider documenting the specific product chip and summary issues that were fixed in this CSS version update.


💡 Codebase verification

Package version 0.1.53 is not accessible on unpkg CDN

The specified CSS package version @egovernments/[email protected] returns a 404 error, indicating that this version has not been published or is not accessible through the unpkg CDN. This needs to be addressed before merging the PR.

  • Ensure the package @egovernments/digit-ui-health-css version 0.1.53 is published to npm
  • Consider reverting to the previous working version (0.1.52) until the new version is published
🔗 Analysis chain

LGTM! Verify the package accessibility.

The CSS version update appears to be related to fixing product chip and summary issues.

Let's verify that the updated package exists and is accessible:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the health CSS package version exists and is accessible
# Expected: HTTP 200 status code if the package exists and is accessible

curl -I "https://unpkg.com/@egovernments/[email protected]/dist/index.css"

Length of output: 889

<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#00bcd1" />
<title>DIGIT HCM</title>
Expand Down