-
Notifications
You must be signed in to change notification settings - Fork 20
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
file type restricted to jpg jpeg and png fix #1448
Conversation
📝 Walkthrough📝 WalkthroughWalkthroughThe changes involve updates to two components, Changes
Possibly related PRs
Suggested reviewers
Poem
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: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
📒 Files selected for processing (2)
- micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/pages/employee/tenantMgmt/ConfigUploaderComponent.js (1 hunks)
- micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/pages/employee/tenantMgmt/LogoUploaderComponent.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/pages/employee/tenantMgmt/ConfigUploaderComponent.js (1)
Pattern
**/*.js
: checkmicro-ui/web/micro-ui-internals/packages/modules/sandbox/src/pages/employee/tenantMgmt/LogoUploaderComponent.js (1)
Pattern
**/*.js
: check
🔇 Additional comments (3)
micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/pages/employee/tenantMgmt/LogoUploaderComponent.js (1)
55-55
: 🧹 Nitpick (assertive)🛠️ Refactor suggestion
Refine file type restriction to match PR objective
The addition of the
accept
attribute is a good step towards restricting file uploads to specific image formats. However, there are a few points to consider:
- The current value "image/*, .jpg, .png, .jpeg" allows all image types, which is broader than the PR objective of restricting to JPG, JPEG, and PNG only.
- The order of mime types and file extensions can be optimized for clarity.
Consider refining the
accept
attribute as follows:-accept="image/*, .jpg, .png, .jpeg" +accept="image/jpeg, image/png, .jpg, .jpeg, .png"This change will:
- Strictly limit uploads to JPG, JPEG, and PNG formats.
- Improve clarity by listing mime types first, followed by file extensions.
While client-side restrictions are helpful, it's crucial to implement server-side validation as well. This ensures that only the desired file types are processed, even if the client-side restrictions are bypassed.
To ensure this change doesn't conflict with any existing file upload logic, please run the following script:
This script will help identify any other places in the codebase where file types or extensions are being checked, ensuring consistency with this new restriction.
micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/pages/employee/tenantMgmt/ConfigUploaderComponent.js (2)
Line range hint
1-82
: Consider refactoring file upload logic into a custom hookThe component currently handles file upload logic, state management for the upload process, and UI rendering. To improve separation of concerns and make the component more maintainable, consider moving the file upload logic into a custom hook.
Here's a high-level suggestion for refactoring:
- Create a new file, e.g.,
useFileUpload.js
:import { useState, useEffect } from 'react'; import { useTranslation } from 'react-i18next'; export const useFileUpload = (onSelect) => { const [file, setFile] = useState(null); const [fileStoreId, setFileStoreId] = useState(null); const [showToast, setShowToast] = useState(null); const [toastMessage, setToastMessage] = useState(''); const [isError, setIsError] = useState(false); const { t } = useTranslation(); const tenantId = Digit.ULBService.getCurrentTenantId(); const handleUploadFile = async () => { // ... existing upload logic ... }; useEffect(() => { if (file) { handleUploadFile(); } }, [file]); useEffect(() => { if (fileStoreId) { onSelect('ConfigUploaderComponent', { fileStoreId, type: 'your_type_here' }); } }, [fileStoreId, onSelect]); const selectFile = (files) => setFile(files?.[0]); return { selectFile, showToast, toastMessage, isError, setShowToast, }; };
- Update the
ConfigUploaderComponent
to use the new hook:import { useFileUpload } from './useFileUpload'; const ConfigUploaderComponent = ({ onSelect, ...props }) => { const { selectFile, showToast, toastMessage, isError, setShowToast } = useFileUpload(onSelect); return ( <> <LabelFieldPair className={'uploader-label-field'}> <CardLabel>{`${t('BANNER_UPLOAD')}`}</CardLabel> <Uploader uploadedFiles={[]} variant="uploadFile" onUpload={(files) => selectFile(files)} accept=".jpg, .jpeg, .png" /> </LabelFieldPair> {showToast && ( <Toast error={isError} label={toastMessage} onClose={() => setShowToast(false)} /> )} </> ); };This refactoring would:
- Separate concerns, making the component focused on rendering.
- Make the file upload logic reusable across components.
- Improve testability of both the UI component and the upload logic.
To ensure this refactoring doesn't introduce issues, we should verify the usage of
ConfigUploaderComponent
:#!/bin/bash # Description: Check for usage of ConfigUploaderComponent # Test: Search for imports and usage of ConfigUploaderComponent rg --type js 'import.*ConfigUploaderComponent|<ConfigUploaderComponent'
59-59
: 🛠️ Refactor suggestionRefine file type restrictions for better specificity
The addition of the
accept
attribute is a good step towards meeting the PR objective of restricting file uploads to JPG, JPEG, and PNG formats. However, the current implementation might be too permissive.Consider modifying the
accept
attribute to be more specific:-accept="image/*, .jpg, .png, .jpeg" +accept=".jpg, .jpeg, .png"This change will:
- Strictly limit uploads to the specified file extensions.
- Prevent potential uploads of other image formats (e.g., GIF, WebP) that the current
image/*
might allow.- Align more closely with the stated PR objective.
To ensure this change doesn't conflict with other parts of the codebase, let's verify the usage:
✅ Verification successful
File Type Restrictions Verified
The proposed modification to the
accept
attribute has been verified. There are no otherUploader
components withaccept
attributes that might be affected by this change.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for other Uploader components that might be affected by this change # Test: Search for other Uploader components with accept attributes rg --type js 'Uploader.*accept'Length of output: 235
file type restricted to jpg jpeg and png fix
Summary by CodeRabbit