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

intial changes new #1530

Open
wants to merge 12 commits into
base: console
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const CampaignCard = () => {
link: `/${window?.contextPath}/employee/campaign/boundary/home`,
roles: ROLES.CAMPAIGN_MANAGER,
// count: isLoading?"-":data
}
},
];

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
Expand Up @@ -29,7 +29,9 @@ const Checkboxes = ({
subQinitialQuestionData,
addComment,
handleOptionComment,
typeOfCall
}) => {
let dis = typeOfCall==="view"?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.

🛠️ Refactor suggestion

Simplify the dis variable declaration.

The current implementation can be improved for better readability and consistency with best practices:

  1. Use const instead of let as the variable is never reassigned.
  2. Simplify the boolean expression to avoid unnecessary use of a ternary operator.

Apply this change:

-  let dis = typeOfCall==="view"?true:false;
+  const dis = typeOfCall === "view";

This change addresses the following static analysis hints:

  • Unnecessary use of boolean literals in conditional expression.
  • Use of let for a variable that is only assigned once.
📝 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 dis = typeOfCall==="view"?true:false;
const dis = typeOfCall === "view";
🧰 Tools
🪛 Biome

[error] 34-34: 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)


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

'dis' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

return (
<div >
{options.map((item, index) => (
Expand All @@ -55,9 +57,11 @@ const Checkboxes = ({
t={t}
addComment={addComment}
handleOptionComment={handleOptionComment}
typeOfCall={typeOfCall}
/>
{item.optionComment && <FieldV1
// className="example"
disabled={dis}
type={"textarea"}
populators={{
resizeSmart:true
Expand All @@ -82,7 +86,7 @@ const Checkboxes = ({
}
</>
))}
<div>
{!dis && <div>
<Button
// className="custom-class"
icon="AddIcon"
Expand All @@ -94,15 +98,7 @@ const Checkboxes = ({
variation="teritiary"
textStyles={{width:'unset'}}
/>
{/* <button
className="unstyled-button link"
type="button"
disabled={(!createNewSurvey && formDisabled) || (isPartiallyEnabled ? !isPartiallyEnabled : formDisabled)}
onClick={() => addOption()}
>
{t("CS_COMMON_ADD_OPTION")}
</button> */}
</div>
</div>}
</div>
);
};
Expand All @@ -129,9 +125,11 @@ const CheckBoxOption = ({
t,
optionComment,
addComment,
handleOptionComment
handleOptionComment,
typeOfCall
}) => {
const [isFocused, setIsFocused] = useState(false);
let dis = typeOfCall==="view"?true:false;

// useEffect(() => {
// updateOption({ value: optionTitle, id: index });
Expand All @@ -141,23 +139,24 @@ const CheckBoxOption = ({
<div>
<div className="optioncheckboxwrapper" style={{justifyContent:"space-between", height:"3rem"}}>
<div style={{display:"flex"}}>
<CheckBox mainClassName="checkboxOptionVariant" label="" disable={isInputDisabled} />
<CheckBox mainClassName="checkboxOptionVariant" label="" disable={dis} />
<input
disabled={dis}
ref={inputRef}
type="text"
value={title}
onChange={(ev) => updateOption({ value: ev.target.value, id: index })}
onBlur={() => setIsFocused(false)}
onFocus={() => setIsFocused(true)}
className={isFocused ? "simple_editable-input" : "simple_readonly-input"}
maxLength={maxLength}
// maxLength={maxLength}
title={titleHover}
style={{ ...labelstyle }}
disabled={isPartiallyEnabled ? !isPartiallyEnabled : formDisabled}
// disabled={isPartiallyEnabled ? !isPartiallyEnabled : formDisabled}
/>
</div>
<div style={{display:"flex", gap:"1rem", alignItems:"center"}}>
{
{!dis &&
<>
<CheckBox
key={field.key}
Expand All @@ -181,7 +180,7 @@ const CheckBoxOption = ({
// isLabelFirst={true}
index={field.key}
/>} */}
{!disableDelete && (
{!dis && !disableDelete && (
// <div className="pointer" onClick={() => removeOption(index)}>
// <DustbinIcon />
// {t(`CAMPAIGN_DELETE_ROW_TEXT`)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useEffect, Fragment, useContext } from "react";
import { } from "@egovernments/digit-ui-react-components";
import { } from "@egovernments/digit-ui-react-components";
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove unnecessary empty import

The import statement at line 2 is empty, importing nothing from "@egovernments/digit-ui-react-components". This is unnecessary and can be removed to clean up the code.

Apply this diff to fix the issue:

-import { } from "@egovernments/digit-ui-react-components";
📝 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
import { } from "@egovernments/digit-ui-react-components";

import { useTranslation } from "react-i18next";
import { DustbinIcon } from "./icons/DustbinIcon";
import { PRIMARY_COLOR } from "../utils";
Expand All @@ -18,6 +18,7 @@ const FieldSelector = ({ type, name, value, onChange, placeholder = "", t, field
subQparent,
subQparentId,
subQinitialQuestionData,
typeOfCall
}) => {

const [options, setOptions] = useState(() => {
Expand All @@ -37,7 +38,7 @@ const FieldSelector = ({ type, name, value, onChange, placeholder = "", t, field
return [defaultOption];
}
});

useEffect(() => {
dispatchQuestionData({
type: "UPDATE_OPTIONS",
Expand Down Expand Up @@ -169,6 +170,7 @@ const FieldSelector = ({ type, name, value, onChange, placeholder = "", t, field
subQparent={subQparent}
subQparentId={subQparentId}
subQinitialQuestionData={subQinitialQuestionData}
typeOfCall={typeOfCall}
/>
);
break;
Expand All @@ -192,6 +194,7 @@ const FieldSelector = ({ type, name, value, onChange, placeholder = "", t, field
subQparent={subQparent}
subQparentId={subQparentId}
subQinitialQuestionData={subQinitialQuestionData}
typeOfCall={typeOfCall}
/>
);
break;
Expand All @@ -215,6 +218,7 @@ const FieldSelector = ({ type, name, value, onChange, placeholder = "", t, field
subQparent={subQparent}
subQparentId={subQparentId}
subQinitialQuestionData={subQinitialQuestionData}
typeOfCall={typeOfCall}
/>
);
break;
Expand All @@ -224,7 +228,7 @@ const FieldSelector = ({ type, name, value, onChange, placeholder = "", t, field
}
};

const CreateQuestion = ({ onSelect, className, level = 1, initialQuestionData, parent = null, parentId = null, optionId }) => {
const CreateQuestion = ({ onSelect, className, level = 1, initialQuestionData, parent = null, parentId = null, optionId, typeOfCall = null }) => {
const { t } = useTranslation();
const state = Digit.ULBService.getStateId();
const tenantId = Digit.ULBService.getCurrentTenantId();
Expand Down Expand Up @@ -323,24 +327,51 @@ const CreateQuestion = ({ onSelect, className, level = 1, initialQuestionData, p
});
};

const handleRequiredField = (id) => {
dispatchQuestionData({
type: "UPDATE_REQUIRED",
payload: {
id: id
}
})
}

const example = {
maxWidth: "100rem"
}

let dis = typeOfCall === "view" ? 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.

⚠️ Potential issue

Simplify assignment and use const instead of let

The variable dis is assigned using a ternary operator that returns a boolean value. You can simplify the assignment by directly assigning the boolean expression result. Since dis is never reassigned, use const instead of let.

Apply this diff to fix the issue:

-  let dis = typeOfCall === "view" ? true : false;
+  const dis = typeOfCall === "view";
📝 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 dis = typeOfCall === "view" ? true : false;
const dis = typeOfCall === "view";
🧰 Tools
🪛 Biome

[error] 343-343: 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)


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

'dis' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

return (
<React.Fragment>
{initialQuestionData
?.filter((i) => i.level === level && (i.parentId ? (i.parentId === parentId) : true))
?.filter((i) => i.level === level && (i.parentId ? (i.parentId === parentId) : true) && (i.level <= 3) && (i.isActive === true))
?.map((field, index) => {
return (
<Card type={"primary"} variant={"form"} className={`question-card-container ${className}`}>
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add a unique key prop to the Card component in the list

When rendering a list of elements using .map(), each element should have a unique key prop to help React identify which items have changed.

Apply this diff to fix the issue:

                 ?.map((field, index) => {
+                   return (
+                     <Card key={field.id} type={"primary"} variant={"form"} className={`question-card-container ${className}`}>
-                   return (
-                     <Card type={"primary"} variant={"form"} className={`question-card-container ${className}`}>
📝 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
<Card type={"primary"} variant={"form"} className={`question-card-container ${className}`}>
<Card key={field.id} type={"primary"} variant={"form"} className={`question-card-container ${className}`}>
🧰 Tools
🪛 Biome

[error] 350-350: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

<LabelFieldPair className="question-label-field" style={{ display: "block" }}>
<div className="question-label" style={{ height: "1.5rem", display: "flex", justifyContent: "space-between", width: "100%" }}>
<span style={{fontWeight:"700"}}>{`${t("QUESTION")} ${index + 1}`}</span>
{/* <span className="mandatory-span">*</span> */}
<div style={{ height: "1rem" }}>
<div className="question-label" style={{ height: "3rem", display: "flex", justifyContent: "space-between", width: "100%" }}>
<div style={{ display: "flex", gap: "1rem" }}>
<span style={{ fontWeight: "700", marginTop: "1rem" }}>{`${t("QUESTION")} ${index + 1}`}</span>
<div style={{ alignItems: "center" }}>
<CheckBox
disabled={dis}
// style={{height:"1rem", alignItems:"center", paddingBottom:"0.5rem"}}
key={field.key}
mainClassName={"checkboxOptionVariant"}
// disabled={optionDependency ? true : false}
label={t("REQUIRED")}
checked={field?.isRequired}
// onChange={handleRequiredField(field.id)}
onChange={() => handleRequiredField(field.id)}
// isLabelFirst={true}
index={field.key}
/>
</div>
</div>
{initialQuestionData?.length > 1 && (
{/* <span className="mandatory-span">*</span> */}
{/* <div style={{ height: "0.5rem" }}> */}
{/* </div> */}
{!dis && initialQuestionData?.length > 1 && (
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)

LGTM: Conditional rendering of delete button based on view mode.

The delete button is now correctly hidden when in view mode. This change improves the user experience by preventing accidental deletions when viewing questions.

For better readability, consider renaming the dis variable as suggested in the previous comment. The condition would then read as !isViewMode, which is more self-explanatory.

<>
<div className="separator"></div>
<div
Expand All @@ -359,7 +390,7 @@ const CreateQuestion = ({ onSelect, className, level = 1, initialQuestionData, p
}}
>
<DustbinIcon />
{t(`CAMPAIGN_DELETE_ROW_TEXT`)}
{t(`CAMPAIGN_DELETE_QUESTION`)}
</div>
</>
)}
Expand All @@ -376,16 +407,17 @@ const CreateQuestion = ({ onSelect, className, level = 1, initialQuestionData, p
className={"example"}
/> */}
<TextInput
isRequired={true}
className="tetxinput-example"
type={"text"}
// props={{ fieldStyle: example }}
name="title"
value={field?.title || ""}
onChange={(event) => handleUpdateField(event.target.value, "title", field.key, field.id)}
placeholder={"Type your question here"}
/>
<Dropdown
disabled={dis}
isRequired={true}
className="tetxinput-example"
type={"text"}
// props={{ fieldStyle: example }}
name="title"
value={field?.title || ""}
onChange={(event) => handleUpdateField(event.target.value, "title", field.key, field.id)}
placeholder={"Type your question here"}
/>
{!dis && <Dropdown
style={{ width: "20%" }}
t={t}
option={dataType}
Expand All @@ -395,7 +427,7 @@ const CreateQuestion = ({ onSelect, className, level = 1, initialQuestionData, p
handleUpdateField(value, "type", field.key, field.id);
}}
placeholder="Type"
/>
/>}
</div>
{field?.isRegex && (
<Dropdown
Expand Down Expand Up @@ -425,11 +457,13 @@ const CreateQuestion = ({ onSelect, className, level = 1, initialQuestionData, p
subQparent={field}
subQparentId={field.id}
subQinitialQuestionData={initialQuestionData}
typeOfCall={typeOfCall}
/>
)}
{
(field?.type?.code === "Short Answer") && (
<FieldV1
disabled="true"
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Use boolean value for disabled prop

The disabled prop should be assigned a boolean value. Use disabled={true} or simply disabled for correct behavior.

Apply this diff to fix the issue:

-          disabled="true"
+          disabled={true}
📝 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
disabled="true"
disabled={true}

className="example"
type={"textarea"}
populators={{
Expand All @@ -442,10 +476,8 @@ const CreateQuestion = ({ onSelect, className, level = 1, initialQuestionData, p
placeholder={""}
/>
)


}
{field.dependency && (
{!dis && field.dependency && (
<CreateQuestion
onSelect={onSelect}
className="subSection"
Expand All @@ -464,19 +496,20 @@ const CreateQuestion = ({ onSelect, className, level = 1, initialQuestionData, p
</Card>
);
})}
<div style={{ display: "flex", justifyContent: "center" }}>
<Button
variation="secondary"
label={t("ADD_QUESTION")}
className={"hover"}
// icon={<AddIcon styles={{ height: "1.5rem", width: "1.5rem" }} fill={PRIMARY_COLOR} />}
icon="Add"
iconFill=""
// onButtonClick={addMoreField}
onClick={()=>addMoreField()}
textStyles={{width:'unset'}}
/>
</div>
{!dis && <div style={{ display: "flex", justifyContent: "center" }}>
<Button
variation="secondary"
label={t("ADD_QUESTION")}
className={"hover"}
// icon={<AddIcon styles={{ height: "1.5rem", width: "1.5rem" }} fill={PRIMARY_COLOR} />}
icon="Add"
iconFill=""
// onButtonClick={addMoreField}
onClick={() => addMoreField()}
textStyles={{ width: 'unset' }}
/>
</div>
}
</React.Fragment>
);
};
Expand Down
Loading