-
Notifications
You must be signed in to change notification settings - Fork 19
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
base: console
Are you sure you want to change the base?
intial changes new #1530
Changes from 8 commits
ed16dc8
1987af5
40ad68c
2daf550
f87c04b
1fe94c5
83283b0
36905ce
e467ab7
08ce819
bb447db
dcabfe4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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"; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove unnecessary empty import The import statement at line 2 is empty, importing nothing from Apply this diff to fix the issue: -import { } from "@egovernments/digit-ui-react-components"; 📝 Committable suggestion
Suggested change
|
||||||
import { useTranslation } from "react-i18next"; | ||||||
import { DustbinIcon } from "./icons/DustbinIcon"; | ||||||
import { PRIMARY_COLOR } from "../utils"; | ||||||
|
@@ -18,6 +18,7 @@ const FieldSelector = ({ type, name, value, onChange, placeholder = "", t, field | |||||
subQparent, | ||||||
subQparentId, | ||||||
subQinitialQuestionData, | ||||||
typeOfCall | ||||||
}) => { | ||||||
|
||||||
const [options, setOptions] = useState(() => { | ||||||
|
@@ -37,7 +38,7 @@ const FieldSelector = ({ type, name, value, onChange, placeholder = "", t, field | |||||
return [defaultOption]; | ||||||
} | ||||||
}); | ||||||
|
||||||
useEffect(() => { | ||||||
dispatchQuestionData({ | ||||||
type: "UPDATE_OPTIONS", | ||||||
|
@@ -169,6 +170,7 @@ const FieldSelector = ({ type, name, value, onChange, placeholder = "", t, field | |||||
subQparent={subQparent} | ||||||
subQparentId={subQparentId} | ||||||
subQinitialQuestionData={subQinitialQuestionData} | ||||||
typeOfCall={typeOfCall} | ||||||
/> | ||||||
); | ||||||
break; | ||||||
|
@@ -192,6 +194,7 @@ const FieldSelector = ({ type, name, value, onChange, placeholder = "", t, field | |||||
subQparent={subQparent} | ||||||
subQparentId={subQparentId} | ||||||
subQinitialQuestionData={subQinitialQuestionData} | ||||||
typeOfCall={typeOfCall} | ||||||
/> | ||||||
); | ||||||
break; | ||||||
|
@@ -215,6 +218,7 @@ const FieldSelector = ({ type, name, value, onChange, placeholder = "", t, field | |||||
subQparent={subQparent} | ||||||
subQparentId={subQparentId} | ||||||
subQinitialQuestionData={subQinitialQuestionData} | ||||||
typeOfCall={typeOfCall} | ||||||
/> | ||||||
); | ||||||
break; | ||||||
|
@@ -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(); | ||||||
|
@@ -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; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Simplify assignment and use The variable Apply this diff to fix the issue: - let dis = typeOfCall === "view" ? true : false;
+ const dis = typeOfCall === "view"; 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Biome
|
||||||
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}`}> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a unique When rendering a list of elements using 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
Suggested change
🧰 Tools🪛 Biome
|
||||||
<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 && ( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||||||
<> | ||||||
<div className="separator"></div> | ||||||
<div | ||||||
|
@@ -359,7 +390,7 @@ const CreateQuestion = ({ onSelect, className, level = 1, initialQuestionData, p | |||||
}} | ||||||
> | ||||||
<DustbinIcon /> | ||||||
{t(`CAMPAIGN_DELETE_ROW_TEXT`)} | ||||||
{t(`CAMPAIGN_DELETE_QUESTION`)} | ||||||
</div> | ||||||
</> | ||||||
)} | ||||||
|
@@ -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} | ||||||
|
@@ -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 | ||||||
|
@@ -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" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use boolean value for The Apply this diff to fix the issue: - disabled="true"
+ disabled={true} 📝 Committable suggestion
Suggested change
|
||||||
className="example" | ||||||
type={"textarea"} | ||||||
populators={{ | ||||||
|
@@ -442,10 +476,8 @@ const CreateQuestion = ({ onSelect, className, level = 1, initialQuestionData, p | |||||
placeholder={""} | ||||||
/> | ||||||
) | ||||||
|
||||||
|
||||||
} | ||||||
{field.dependency && ( | ||||||
{!dis && field.dependency && ( | ||||||
<CreateQuestion | ||||||
onSelect={onSelect} | ||||||
className="subSection" | ||||||
|
@@ -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> | ||||||
); | ||||||
}; | ||||||
|
There was a problem hiding this comment.
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:
const
instead oflet
as the variable is never reassigned.Apply this change:
This change addresses the following static analysis hints:
let
for a variable that is only assigned once.📝 Committable suggestion
🧰 Tools
🪛 Biome