-
Notifications
You must be signed in to change notification settings - Fork 124
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
Feat/fe/refactor/input #1174
Feat/fe/refactor/input #1174
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -41,6 +41,7 @@ import { logger } from "./Utils/Logger"; // Import the logger | |||||||||||||||||||||||||
import { networkService } from "./main"; | ||||||||||||||||||||||||||
import { Infrastructure } from "./Pages/Infrastructure"; | ||||||||||||||||||||||||||
import InfrastructureDetails from "./Pages/Infrastructure/Details"; | ||||||||||||||||||||||||||
import Test from "./Pages/test"; | ||||||||||||||||||||||||||
function App() { | ||||||||||||||||||||||||||
const AdminCheckedRegister = withAdminCheck(Register); | ||||||||||||||||||||||||||
const MonitorsWithAdminProp = withAdminProp(Monitors); | ||||||||||||||||||||||||||
|
@@ -89,6 +90,11 @@ function App() { | |||||||||||||||||||||||||
path="/" | ||||||||||||||||||||||||||
element={<HomeLayout />} | ||||||||||||||||||||||||||
> | ||||||||||||||||||||||||||
<Route | ||||||||||||||||||||||||||
path="/test" | ||||||||||||||||||||||||||
element={<Test />} | ||||||||||||||||||||||||||
/> | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
Comment on lines
+93
to
+97
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. Mom's spaghetti moment: Route needs protection! 🍝 The test route is currently exposed without any protection. Unlike other routes that use Apply this change to protect the route: <Route
path="/test"
- element={<Test />}
+ element={
+ process.env.NODE_ENV === 'development'
+ ? <ProtectedRoute Component={Test} />
+ : <Navigate to="/monitors" />
+ }
/> Also, consider moving this route closer to other development-only routes for better organization. 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||
<Route | ||||||||||||||||||||||||||
exact | ||||||||||||||||||||||||||
path="/" | ||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,7 @@ const Field = forwardRef( | |
error, | ||
disabled, | ||
hidden, | ||
className | ||
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. 🛠️ Refactor suggestion Yo dawg, let's talk about that className prop! 🍝 While adding the className prop is good for component flexibility, using it to control error visibility seems like an unexpected side effect. Consider separating these concerns. Consider these improvements:
- className={`${className ?? `field field-${type}`}`}
+ className={`field field-${type} ${className ?? ''}`} Also applies to: 228-228 |
||
}, | ||
ref | ||
) => { | ||
|
@@ -186,11 +186,11 @@ const Field = forwardRef( | |
), | ||
}} | ||
/> | ||
{ error && ( | ||
{error && ( | ||
<Typography | ||
component="span" | ||
className="input-error" | ||
hidden={className? true: false} | ||
hidden={className ? true : false} | ||
color={theme.palette.error.main} | ||
mt={theme.spacing(2)} | ||
sx={{ | ||
|
@@ -225,7 +225,7 @@ Field.propTypes = { | |
error: PropTypes.string, | ||
disabled: PropTypes.bool, | ||
hidden: PropTypes.bool, | ||
className: PropTypes.string | ||
className: PropTypes.string, | ||
}; | ||
|
||
export default Field; |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,60 @@ | ||||
import { Stack, Typography, InputAdornment, IconButton } from "@mui/material"; | ||||
import { useTheme } from "@mui/material/styles"; | ||||
import { useState } from "react"; | ||||
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. Yo dawg, you've got an unused import there! The -import { useState } from "react"; 📝 Committable suggestion
Suggested change
|
||||
import PropTypes from "prop-types"; | ||||
import VisibilityOff from "@mui/icons-material/VisibilityOff"; | ||||
import Visibility from "@mui/icons-material/Visibility"; | ||||
export const HttpAdornment = ({ https }) => { | ||||
const theme = useTheme(); | ||||
return ( | ||||
<Stack | ||||
direction="row" | ||||
alignItems="center" | ||||
height="100%" | ||||
sx={{ | ||||
borderRight: `solid 1px ${theme.palette.border.dark}`, | ||||
backgroundColor: theme.palette.background.accent, | ||||
pl: theme.spacing(6), | ||||
}} | ||||
> | ||||
<Typography | ||||
component="h5" | ||||
paddingRight={"var(--env-var-spacing-1-minus)"} | ||||
color={theme.palette.text.secondary} | ||||
sx={{ lineHeight: 1, opacity: 0.8 }} | ||||
> | ||||
{https ? "https" : "http"}:// | ||||
</Typography> | ||||
</Stack> | ||||
); | ||||
}; | ||||
|
||||
export const PasswordEndAdornment = ({ fieldType, setFieldType }) => { | ||||
const theme = useTheme(); | ||||
return ( | ||||
<InputAdornment position="end"> | ||||
<IconButton | ||||
aria-label="toggle password visibility" | ||||
onClick={() => setFieldType(fieldType === "password" ? "text" : "password")} | ||||
sx={{ | ||||
color: theme.palette.border.dark, | ||||
padding: theme.spacing(1), | ||||
"&:focus-visible": { | ||||
outline: `2px solid ${theme.palette.primary.main}`, | ||||
outlineOffset: `2px`, | ||||
}, | ||||
"& .MuiTouchRipple-root": { | ||||
pointerEvents: "none", | ||||
display: "none", | ||||
}, | ||||
}} | ||||
> | ||||
{fieldType === "password" ? <VisibilityOff /> : <Visibility />} | ||||
</IconButton> | ||||
</InputAdornment> | ||||
); | ||||
}; | ||||
Comment on lines
+32
to
+56
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. 🛠️ Refactor suggestion Lose yourself in the PropTypes, the moment, you better never let it go! The component is missing PropTypes validation for Add PropTypes: PasswordEndAdornment.propTypes = {
fieldType: PropTypes.oneOf(['password', 'text']).isRequired,
setFieldType: PropTypes.func.isRequired,
}; Optimize with memo: +import { memo } from 'react';
-export const PasswordEndAdornment = ({ fieldType, setFieldType }) => {
+export const PasswordEndAdornment = memo(({ fieldType, setFieldType }) => {
// ... component code ...
-};
+}); |
||||
|
||||
HttpAdornment.propTypes = { | ||||
https: PropTypes.bool.isRequired, | ||||
}; |
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.
💡 Codebase verification
Yo, this test route needs some protection sauce! 🍝
Looking at App.jsx, the test route is completely exposed without any ProtectedRoute wrapper, unlike other routes in the app. This is a security concern since it's testing sensitive form components.
🔗 Analysis chain
Yo dawg, we need to protect that test route! 🍝
The Test component import looks good, but considering this is for testing the refactored Field component, we should ensure it's not accessible in production.
Let's check if there are any environment checks:
Consider wrapping this import with an environment check:
The previous search didn't work because we need to first locate the test file. Let's check its actual content and the route definition to understand how it's being used and whether there are any existing protections.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 212
Script:
Length of output: 12427