-
Notifications
You must be signed in to change notification settings - Fork 14
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
32 dec 08 data validation in compliance #334
base: master
Are you sure you want to change the base?
32 dec 08 data validation in compliance #334
Conversation
WalkthroughThe pull request introduces significant enhancements to several components, including the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 2
🧹 Outside diff range and nitpick comments (3)
Clients/src/presentation/components/Inputs/Dropdowns/index.tsx (3)
52-52
: Remove unnecessaryconsole.log
statementThe
console.log
on line 52 seems to be a leftover from debugging and should be removed to clean up the console output.Apply this diff to remove it:
- console.log("🚀 ~ DropDowns ~ usersssssssssss:", users)
54-61
: RenamehandleChange
tohandleApproverChange
for clarityFor consistency with other handler functions (
handleOwnerChange
,handleReviewerChange
), consider renaminghandleChange
tohandleApproverChange
.Apply this diff to rename the function:
- const handleChange = (e: SelectChangeEvent<string | number>) => { + const handleApproverChange = (e: SelectChangeEvent<string | number>) => { const selectedValue = e.target.value; console.log("Selected value:", selectedValue); const selectedUser = users.find(user => user.id === selectedValue); console.log("Selected user:", selectedUser); setApprover(selectedValue); }; // Update the onChange prop in the Approver Select component <Select id="Approver" label="Approver:" value={approver || ""} - onChange={handleChange} + onChange={handleApproverChange} required items={users.map(user => ({ _id: user.id, name: user.name }))} sx={inputStyles} />
160-163
: Refactor user mapping to avoid code duplicationThe mapping of
users
to theitems
array is repeated for the Approver, Owner, and Reviewer selects. Consider extracting this mapping into a constant or function to adhere to the DRY (Don't Repeat Yourself) principle.Apply this diff to create a reusable
userItems
array:// After fetching and setting users setUsers(response.data); + // Create a reusable array for user items + const userItems = users.map(user => ({ + _id: user.id, + name: user.name, + })); // In the Approver Select component <Select id="Approver" label="Approver:" value={approver || ""} onChange={handleApproverChange} required - items={users.map(user => ({ - _id: user.id, - name: user.name - }))} + items={userItems} sx={inputStyles} /> // In the Owner Select component <Select id="Owner" label="Owner:" value={owner || ""} onChange={handleOwnerChange} required - items={users.map(user => ({ - _id: user.id, - name: user.name - }))} + items={userItems} sx={inputStyles} error={ownerError.hasError} helperText={ownerError.message} /> // In the Reviewer Select component <Select id="Reviewer" label="Reviewer:" value={reviewer || ""} onChange={handleReviewerChange} required - items={users.map(user => ({ - _id: user.id, - name: user.name - }))} + items={userItems} sx={inputStyles} error={reviewerError.hasError} helperText={reviewerError.message} />Also applies to: 193-195, 205-207
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (3)
Clients/src/presentation/components/Inputs/Dropdowns/index.tsx
(4 hunks)Clients/src/presentation/components/Inputs/Select/index.tsx
(8 hunks)Clients/src/presentation/components/Modals/Controlpane/index.tsx
(0 hunks)
💤 Files with no reviewable changes (1)
- Clients/src/presentation/components/Modals/Controlpane/index.tsx
useEffect(() => { | ||
const fetchUsers = async () => { | ||
const response = await getAllEntities({ routeUrl: "/users" }); | ||
setUsers(response.data); | ||
}; | ||
fetchUsers(); | ||
}, []); |
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
Add error handling for fetching user data
Currently, if the API call to fetch users fails, the component doesn't handle the error, which may lead to unexpected behavior or application crash. Consider adding error handling to manage API failures gracefully.
Apply this diff to handle errors:
const fetchUsers = async () => {
try {
const response = await getAllEntities({ routeUrl: "/users" });
setUsers(response.data);
+ } catch (error) {
+ // Handle the error appropriately
+ console.error("Failed to fetch users:", error);
+ // Optionally, set an error state or display a message to the user
+ }
};
Committable suggestion skipped: line range outside the PR's diff.
error?: boolean | string; | ||
helperText?: string; |
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.
Ensure error
prop is consistently a boolean
The error
prop is currently typed as boolean | string
, which may lead to unexpected behavior since MuiSelect
expects a boolean value for the error
prop. Passing a string may cause the error
prop to always evaluate to true
. Consider changing the type of error
to boolean
and adjust the error handling logic accordingly.
Apply this diff to correct the error
prop type and usage:
interface SelectProps {
id: string;
label?: string;
placeholder?: string;
isHidden?: boolean;
value: string | number;
items: { _id: string | number; name: string; email?: string }[];
isRequired?: boolean;
- error?: boolean | string;
+ error?: boolean;
helperText?: string;
onChange: (
event: SelectChangeEvent<string | number>,
child: React.ReactNode
) => void;
sx?: object;
getOptionValue?: (item: any) => any;
required?: boolean;
}
...
const Select: React.FC<SelectProps> = ({
// ...other props
error,
// ...other props
}) => {
// ...other code
- const isEmpty = required && (!value || value === "");
- const errorMessage = isEmpty ? "This field is required" : helperText;
+ const showError = error || (required && (!value || value === ""));
+ const errorMessage = showError ? helperText || "This field is required" : "";
return (
// ...other code
<MuiSelect
// ...other props
- error={isEmpty || error}
+ error={showError}
// ...other props
>
// ...other code
</MuiSelect>
{errorMessage && (
<Typography
component="span"
className="input-error"
color={theme.palette.status.error.text}
mt={theme.spacing(2)}
sx={{
opacity: 0.8,
fontSize: 11,
}}
>
{errorMessage}
</Typography>
)}
);
};
Also applies to: 73-75, 159-159
Looks good. ! |
Hello @melpsh Thank you for the nice code 🙏🏻 After that, we will move to the code review Regards |
Added Validation to compliance tracker inputs
Summary by CodeRabbit
New Features
Bug Fixes
Documentation