-
Notifications
You must be signed in to change notification settings - Fork 1
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
Minor fixes #107
base: main
Are you sure you want to change the base?
Minor fixes #107
Changes from 2 commits
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,7 @@ | ||
import Box from '@mui/material/Box'; | ||
import { JSX } from 'react'; | ||
|
||
import { StyledButton } from '@/app/components/StyledButton'; | ||
import { | ||
camelCaseToFlat, | ||
getSection, | ||
|
@@ -520,6 +522,57 @@ const rows: TRow<TComposition>[] = [ | |
) as JSX.Element[][], | ||
}, | ||
}, | ||
{ | ||
type: 'row', | ||
config: { | ||
label: '', | ||
render: ({ text }) => { | ||
const toggleInfo = () => { | ||
const infoDiv = document.getElementById('composition-generated'); | ||
|
||
if (!infoDiv) { | ||
return null; | ||
} | ||
|
||
if (infoDiv.style.display === 'none') { | ||
infoDiv.style.display = 'block'; | ||
} else { | ||
infoDiv.style.display = 'none'; | ||
} | ||
return null; | ||
}; | ||
Comment on lines
+530
to
+543
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. Replace DOM manipulation with React state management. The current implementation uses direct DOM manipulation which goes against React's principles and could lead to synchronization issues. Consider using React's useState hook: -const toggleInfo = () => {
- const infoDiv = document.getElementById('composition-generated');
-
- if (!infoDiv) {
- return null;
- }
-
- if (infoDiv.style.display === 'none') {
- infoDiv.style.display = 'block';
- } else {
- infoDiv.style.display = 'none';
- }
- return null;
-};
+const [isVisible, setIsVisible] = useState(false);
+const toggleInfo = () => setIsVisible(!isVisible);
|
||
|
||
return ( | ||
<Box | ||
sx={{ | ||
padding: '20px 0px', | ||
width: '100%', | ||
'& table': { | ||
width: '100%', | ||
borderCollapse: 'collapse', | ||
marginBottom: '20px', | ||
'& th, & td': { | ||
border: '1px solid gray', | ||
padding: '8px', | ||
textAlign: 'left', | ||
}, | ||
}, | ||
}} | ||
> | ||
Comment on lines
+546
to
+561
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 Extract styles to a styled component. Inline styles should be moved to styled components for better maintainability and reusability. Consider creating a styled component: const StyledBox = styled(Box)(({ theme }) => ({
padding: '20px 0px',
width: '100%',
'& table': {
width: '100%',
borderCollapse: 'collapse',
marginBottom: '20px',
'& th, & td': {
border: '1px solid gray',
padding: '8px',
textAlign: 'left',
},
},
})); Then use it in your component: -<Box
- sx={{
- padding: '20px 0px',
- width: '100%',
- '& table': {
- width: '100%',
- borderCollapse: 'collapse',
- marginBottom: '20px',
- '& th, & td': {
- border: '1px solid gray',
- padding: '8px',
- textAlign: 'left',
- },
- },
- }}
->
+<StyledBox> |
||
<StyledButton size="small" variant="contained" onClick={toggleInfo}> | ||
Toggle Generated | ||
</StyledButton> | ||
Comment on lines
+562
to
+564
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. Enhance button accessibility. The toggle button lacks proper accessibility attributes. Add ARIA attributes to improve accessibility: -<StyledButton size="small" variant="contained" onClick={toggleInfo}>
+<StyledButton
+ size="small"
+ variant="contained"
+ onClick={toggleInfo}
+ aria-expanded={isVisible}
+ aria-controls="composition-generated"
+>
Toggle Generated
</StyledButton>
|
||
<div | ||
dangerouslySetInnerHTML={{ __html: text.div }} | ||
className="extra-info" | ||
id="composition-generated" | ||
style={{ display: 'none' }} | ||
/> | ||
Comment on lines
+565
to
+570
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. Security Risk: Unsafe HTML rendering. Using dangerouslySetInnerHTML with unsanitized content exposes the application to XSS attacks. Consider using a sanitization library like DOMPurify: +import DOMPurify from 'dompurify';
-<div
- dangerouslySetInnerHTML={{ __html: text.div }}
- className="extra-info"
- id="composition-generated"
- style={{ display: 'none' }}
-/>
+<div
+ dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(text.div) }}
+ className="extra-info"
+ id="composition-generated"
+ style={{ display: isVisible ? 'block' : 'none' }}
+/> Would you like me to help set up DOMPurify in your project?
🧰 Tools🪛 Biome
|
||
</Box> | ||
); | ||
}, | ||
}, | ||
}, | ||
]; | ||
|
||
export const Composition = (props: Omit<TTabProps<TComposition>, 'rows'>) => ( | ||
|
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.
Reconsider the use of 'hotfix' as a static tag.
Using a static 'hotfix' tag for all non-main branches could lead to confusion and potential deployment issues. Consider using a more specific tag format that includes:
This would provide better traceability and prevent tag conflicts.
Here's a suggested modification:
📝 Committable suggestion