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

HCMPRE 154 #1186

Merged
merged 4 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion micro-ui/web/micro-ui-internals/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@egovernments/digit-ui-libraries": "1.8.2-beta.5",
"@egovernments/digit-ui-module-workbench": "1.0.2-beta.3",
"@egovernments/digit-ui-components": "0.0.2-beta.18",
"@egovernments/digit-ui-module-core": "1.8.2-beta.8",
"@egovernments/digit-ui-module-core": "1.8.2-beta.9",
"@egovernments/digit-ui-module-utilities": "1.0.1-beta.30",
"@egovernments/digit-ui-react-components": "1.8.2-beta.11",
"@egovernments/digit-ui-module-hcmworkbench":"0.0.38",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
rel="stylesheet"
href="https://unpkg.com/@egovernments/[email protected]/dist/index.css"
/> -->
<link rel="stylesheet" href="https://unpkg.com/@egovernments/[email protected].6/dist/index.css" />
<link rel="stylesheet" href="https://unpkg.com/@egovernments/[email protected].7/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]/dist/index.css" />
<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
Expand Up @@ -550,3 +550,6 @@ tbody {
min-width: 8.6rem;
}
}
.digit-card-component.bannerCard.removeBottomMargin.languageSelection{
width: unset;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const BoundaryWithDate = ({ project, props, onSelect, dateReducerDispatch, canDe
}, [project]);

const handleDateChange = ({ date, endDate = false, cycleDate = false, cycleIndex }) => {
if (typeof date === "undefined") {
return null;
}
if (!endDate) {
dateReducerDispatch({
type: "START_DATE",
Expand All @@ -44,6 +47,9 @@ const BoundaryWithDate = ({ project, props, onSelect, dateReducerDispatch, canDe
};

const handleCycleDateChange = ({ date, endDate = false, cycleIndex }) => {
if (typeof date === "undefined") {
return null;
}
if (!endDate) {
dateReducerDispatch({
type: "CYCLE_START_DATE",
Expand All @@ -54,7 +60,7 @@ const BoundaryWithDate = ({ project, props, onSelect, dateReducerDispatch, canDe
});
} else {
dateReducerDispatch({
type: "CYCYLE_END_DATE",
type: "CYCLE_END_DATE",
date: date,
item: project,
cycleIndex: cycleIndex,
Expand Down Expand Up @@ -96,7 +102,7 @@ const BoundaryWithDate = ({ project, props, onSelect, dateReducerDispatch, canDe
}
onChange={(d) => {
handleDateChange({
date: d,
date: d?.target?.value,
});
}}
/>
Expand All @@ -116,7 +122,7 @@ const BoundaryWithDate = ({ project, props, onSelect, dateReducerDispatch, canDe
}}
onChange={(d) => {
handleDateChange({
date: d,
date: d?.target?.value,
endDate: true,
});
}}
Expand All @@ -138,26 +144,23 @@ const BoundaryWithDate = ({ project, props, onSelect, dateReducerDispatch, canDe
nonEditable={item?.startDate?.length > 0 && today > item?.startDate ? true : false}
value={item?.startDate}
placeholder={t("HCM_START_DATE")}
populators={
today >= item?.startDate
? {}
: {
validation: {
min:
index > 0
? cycleDates?.find((j) => j.cycleIndex == index)?.endDate &&
new Date(new Date(cycleDates?.find((j) => j.cycleIndex == index)?.endDate)?.getTime() + 86400000)
?.toISOString()
?.split("T")?.[0]
: startDate,
max: endDate,
},
}
}
populators={{
validation: {
min:
index > 0 && !isNaN(new Date(cycleDates?.find((j) => j.cycleIndex == index)?.endDate)?.getTime())
? new Date(new Date(cycleDates?.find((j) => j.cycleIndex == index)?.endDate)?.getTime() + ONE_DAY_IN_MS)
?.toISOString()
?.split("T")?.[0]
: today >= startDate
? today
: startDate,
max: endDate,
},
}}
onChange={(d) => {
// setStartValidation(true);
handleCycleDateChange({
date: d,
date: d?.target?.value,
cycleIndex: item?.cycleIndex,
});
}}
Expand All @@ -170,17 +173,19 @@ const BoundaryWithDate = ({ project, props, onSelect, dateReducerDispatch, canDe
placeholder={t("HCM_END_DATE")}
populators={{
validation: {
min: cycleDates?.find((j) => j.cycleIndex == index + 1)?.startDate
? new Date(new Date(cycleDates?.find((j) => j.cycleIndex == index + 1)?.startDate)?.getTime() + 86400000)
min: !isNaN(new Date(cycleDates?.find((j) => j.cycleIndex == index + 1)?.startDate)?.getTime())
? new Date(new Date(cycleDates?.find((j) => j.cycleIndex == index + 1)?.startDate)?.getTime() + ONE_DAY_IN_MS)
?.toISOString()
?.split("T")?.[0]
: null,
: today >= startDate
? today
: startDate,
max: endDate,
},
}}
onChange={(d) => {
handleCycleDateChange({
date: d,
date: d?.target?.value,
endDate: true,
cycleIndex: item?.cycleIndex,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const reducer = (state, action) => {
return item;
});
break;
case "CYCYLE_END_DATE":
case "CYCLE_END_DATE":
const cycleEndRemap = action?.cycles?.map((item, index) => {
if (item?.id === action?.cycleIndex) {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const reducer = (state, action) => {
if (item?.id === action?.cycleIndex) {
return {
...item,
startDate: Digit.Utils.pt.convertDateToEpoch(action?.date, "dayStart"),
startDate: Digit.Utils.pt.convertDateToEpoch(typeof action?.date === "string" ? action?.date : null, "dayStart"),
};
}
return item;
Expand All @@ -46,7 +46,7 @@ const reducer = (state, action) => {
},
};
break;
case "CYCYLE_END_DATE":
case "CYCLE_END_DATE":
const cycleEndRemap = action?.cycles?.map((item, index) => {
if (item?.id === action?.cycleIndex) {
return {
Expand Down Expand Up @@ -116,14 +116,16 @@ const DateAndCycleUpdate = ({ onSelect, formData, ...props }) => {

useEffect(() => {
if (dateReducer) {
setStartDate(Digit.Utils.date.getDate(dateReducer?.startDate));
setEndDate(Digit.Utils.date.getDate(dateReducer?.endDate));
setStartDate(dateReducer?.startDate ? Digit.Utils.date.getDate(dateReducer?.startDate) : "");
setEndDate(dateReducer?.endDate ? Digit.Utils.date.getDate(dateReducer?.endDate) : "");
if (dateReducer?.additionalDetails?.projectType?.cycles?.length > 0) {
const cycleDateData = dateReducer?.additionalDetails?.projectType?.cycles?.map((cycle) => ({
cycleIndex: cycle.id,
startDate: Digit.Utils.date.getDate(cycle.startDate),
endDate: Digit.Utils.date.getDate(cycle.endDate),
}));
const cycleDateData = dateReducer?.additionalDetails?.projectType?.cycles?.map((cycle) => {
return {
cycleIndex: cycle.id,
startDate: cycle.startDate ? Digit.Utils.date.getDate(cycle.startDate) : "",
endDate: cycle.endDate ? Digit.Utils.date.getDate(cycle.endDate) : "",
};
});
setCycleDates(cycleDateData);
}
}
Expand All @@ -139,7 +141,7 @@ const DateAndCycleUpdate = ({ onSelect, formData, ...props }) => {
}, [isLoading, projectData]);

const handleDateChange = ({ date, endDate = false, cycleDate = false, cycleIndex }) => {
if (!date || date <= today) {
if (typeof date === "undefined") {
return null;
}
if (!endDate) {
Expand All @@ -158,7 +160,7 @@ const DateAndCycleUpdate = ({ onSelect, formData, ...props }) => {
};

const handleCycleDateChange = ({ date, endDate = false, cycleIndex }) => {
if (!date || date <= today) {
if (typeof date === "undefined") {
return null;
}
if (!endDate) {
Expand All @@ -171,7 +173,7 @@ const DateAndCycleUpdate = ({ onSelect, formData, ...props }) => {
});
} else {
dateReducerDispatch({
type: "CYCYLE_END_DATE",
type: "CYCLE_END_DATE",
date: date,
item: dateReducer,
cycleIndex: cycleIndex,
Expand All @@ -182,17 +184,18 @@ const DateAndCycleUpdate = ({ onSelect, formData, ...props }) => {
return (
<Card className={"boundary-with-container"}>
<Header className="header">{t(`UPDATE_DATE_AND_CYCLE_HEADER`)}</Header>
<LabelFieldPair style={{ display: "grid", gridTemplateColumns: "13rem 2fr", alignItems: "start" }}>
<LabelFieldPair style={{ display: "grid", gridTemplateColumns: "13rem 2fr", alignItems: "start", gap: "1rem" }}>
<div className="campaign-dates">
<p>{t(`HCM_CAMPAIGN_DATES`)}</p>
<span className="mandatory-date">*</span>
</div>
<div className="date-field-container">
<FieldV1
required={true}
withoutLabel={true}
type="date"
value={startDate}
nonEditable={today >= startDate ? true : false}
nonEditable={startDate && startDate?.length > 0 && today >= startDate ? true : false}
Comment on lines +194 to +198
Copy link
Contributor

Choose a reason for hiding this comment

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

Simplify the nonEditable property check.

The use of boolean literals in the conditional expression is unnecessary. Simplify the code by directly assigning the result.

- nonEditable={startDate && startDate?.length > 0 && today >= startDate ? true : false}
+ nonEditable={startDate && startDate?.length > 0 && today >= startDate}
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
required={true}
withoutLabel={true}
type="date"
value={startDate}
nonEditable={today >= startDate ? true : false}
nonEditable={startDate && startDate?.length > 0 && today >= startDate ? true : false}
required={true}
withoutLabel={true}
type="date"
value={startDate}
nonEditable={startDate && startDate?.length > 0 && today >= startDate}
Tools
Biome

[error] 198-198: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

placeholder={t("HCM_START_DATE")}
populators={
today >= startDate
Expand All @@ -205,31 +208,28 @@ const DateAndCycleUpdate = ({ onSelect, formData, ...props }) => {
}
onChange={(d) => {
handleDateChange({
date: d,
date: d?.target?.value,
});
}}
/>
<FieldV1
required={true}
withoutLabel={true}
type="date"
value={endDate}
nonEditable={today >= endDate ? true : false}
nonEditable={endDate && endDate?.length > 0 && today >= endDate ? true : false}
Copy link
Contributor

Choose a reason for hiding this comment

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

Simplify the nonEditable property check.

The use of boolean literals in the conditional expression is unnecessary. Simplify the code by directly assigning the result.

- nonEditable={endDate && endDate?.length > 0 && today >= endDate ? true : false}
+ nonEditable={endDate && endDate?.length > 0 && today >= endDate}
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
nonEditable={endDate && endDate?.length > 0 && today >= endDate ? true : false}
nonEditable={endDate && endDate?.length > 0 && today >= endDate}
Tools
Biome

[error] 220-220: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

placeholder={t("HCM_END_DATE")}
populators={
today >= endDate
? {}
: {
validation: {
min:
startDate && startDate > today
? Digit.Utils.date.getDate(new Date(startDate).getTime() + 2 * ONE_DAY_IN_MS)
: Digit.Utils.date.getDate(Date.now() + 2 * ONE_DAY_IN_MS),
},
}
}
populators={{
validation: {
min:
startDate && startDate > today
? Digit.Utils.date.getDate(new Date(startDate).getTime() + 2 * ONE_DAY_IN_MS)
: Digit.Utils.date.getDate(Date.now() + 2 * ONE_DAY_IN_MS),
},
}}
onChange={(d) => {
handleDateChange({
date: d,
date: d?.target?.value,
endDate: true,
});
}}
Expand All @@ -246,57 +246,55 @@ const DateAndCycleUpdate = ({ onSelect, formData, ...props }) => {
</div>
<div className="date-field-container">
<FieldV1
required={true}
withoutLabel={true}
type="date"
value={item?.startDate}
nonEditable={today >= item?.startDate ? true : false}
nonEditable={item?.startDate && item?.startDate?.length > 0 && today >= item?.startDate ? true : false}
Copy link
Contributor

Choose a reason for hiding this comment

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

Simplify the nonEditable property check.

The use of boolean literals in the conditional expression is unnecessary. Simplify the code by directly assigning the result.

- nonEditable={item?.startDate && item?.startDate?.length > 0 && today >= item?.startDate ? true : false}
+ nonEditable={item?.startDate && item?.startDate?.length > 0 && today >= item?.startDate}
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
nonEditable={item?.startDate && item?.startDate?.length > 0 && today >= item?.startDate ? true : false}
nonEditable={item?.startDate && item?.startDate?.length > 0 && today >= item?.startDate}
Tools
Biome

[error] 253-253: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

placeholder={t("HCM_START_DATE")}
populators={
today >= item?.startDate
? {}
: {
validation: {
min:
index > 0
? new Date(new Date(cycleDates?.find((j) => j.cycleIndex == index)?.endDate)?.getTime() + 86400000)
?.toISOString()
?.split("T")?.[0]
: startDate,
max: endDate,
},
}
}
populators={{
validation: {
min:
index > 0 && !isNaN(new Date(cycleDates?.find((j) => j.cycleIndex == index)?.endDate)?.getTime())
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace isNaN with Number.isNaN.

The use of isNaN is unsafe as it attempts a type coercion. Use Number.isNaN instead.

- index > 0 && !isNaN(new Date(cycleDates?.find((j) => j.cycleIndex == index)?.endDate)?.getTime())
+ index > 0 && !Number.isNaN(new Date(cycleDates?.find((j) => j.cycleIndex == index)?.endDate)?.getTime())
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
index > 0 && !isNaN(new Date(cycleDates?.find((j) => j.cycleIndex == index)?.endDate)?.getTime())
index > 0 && !Number.isNaN(new Date(cycleDates?.find((j) => j.cycleIndex == index)?.endDate)?.getTime())
Tools
Biome

[error] 258-258: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.

See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.

(lint/suspicious/noGlobalIsNan)

? new Date(new Date(cycleDates?.find((j) => j.cycleIndex == index)?.endDate)?.getTime() + ONE_DAY_IN_MS)
?.toISOString()
?.split("T")?.[0]
: today >= startDate
? today
: startDate,
max: endDate,
},
}}
onChange={(d) => {
// setStartValidation(true);
handleCycleDateChange({
date: d,
date: d?.target?.value,
cycleIndex: item?.cycleIndex,
});
}}
/>
<FieldV1
required={true}
withoutLabel={true}
type="date"
value={item?.endDate}
nonEditable={today >= item?.endDate ? true : false}
nonEditable={item?.endDate && item?.endDate?.length > 0 && today >= item?.endDate ? true : false}
Copy link
Contributor

Choose a reason for hiding this comment

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

Simplify the nonEditable property check.

The use of boolean literals in the conditional expression is unnecessary. Simplify the code by directly assigning the result.

- nonEditable={item?.endDate && item?.endDate?.length > 0 && today >= item?.endDate ? true : false}
+ nonEditable={item?.endDate && item?.endDate?.length > 0 && today >= item?.endDate}
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
nonEditable={item?.endDate && item?.endDate?.length > 0 && today >= item?.endDate ? true : false}
nonEditable={item?.endDate && item?.endDate?.length > 0 && today >= item?.endDate}
Tools
Biome

[error] 281-281: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

placeholder={t("HCM_END_DATE")}
populators={
today >= item?.endDate
? {}
: {
validation: {
min: cycleDates?.find((j) => j.cycleIndex == index + 1)?.startDate
? new Date(new Date(cycleDates?.find((j) => j.cycleIndex == index + 1)?.startDate)?.getTime() + 86400000)
?.toISOString()
?.split("T")?.[0]
: null,
max: endDate,
},
}
}
populators={{
validation: {
min: !isNaN(new Date(cycleDates?.find((j) => j.cycleIndex == index + 1)?.startDate)?.getTime())
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace isNaN with Number.isNaN.

The use of isNaN is unsafe as it attempts a type coercion. Use Number.isNaN instead.

- min: !isNaN(new Date(cycleDates?.find((j) => j.cycleIndex == index + 1)?.startDate)?.getTime())
+ min: !Number.isNaN(new Date(cycleDates?.find((j) => j.cycleIndex == index + 1)?.startDate)?.getTime())
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
min: !isNaN(new Date(cycleDates?.find((j) => j.cycleIndex == index + 1)?.startDate)?.getTime())
min: !Number.isNaN(new Date(cycleDates?.find((j) => j.cycleIndex == index + 1)?.startDate)?.getTime())
Tools
Biome

[error] 285-285: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.

See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.

(lint/suspicious/noGlobalIsNan)

? new Date(new Date(cycleDates?.find((j) => j.cycleIndex == index + 1)?.startDate)?.getTime() + ONE_DAY_IN_MS)
?.toISOString()
?.split("T")?.[0]
: today >= startDate
? today
: startDate,
max: endDate,
},
}}
onChange={(d) => {
handleCycleDateChange({
date: d,
date: d?.target?.value,
endDate: true,
cycleIndex: item?.cycleIndex,
});
Expand Down
Loading