-
Notifications
You must be signed in to change notification settings - Fork 14
fix: Resolve issues of new file viewer UI 🐛 #2922
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
Conversation
WalkthroughReplaces the legacy Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/cozy-viewer/src/ViewerInformationsWrapper.jsx (1)
99-107:⚠️ Potential issue | 🟡 MinorMissing PropType for
currentIndex.The
currentIndexprop is used (line 21) and included in effect dependencies (line 48) but is not declared in PropTypes.🔧 Proposed fix
ViewerInformationsWrapper.propTypes = { disableFooter: PropTypes.bool, validForPanel: PropTypes.bool, toolbarRef: PropTypes.object, + currentIndex: PropTypes.number, children: PropTypes.oneOfType([ PropTypes.node, PropTypes.arrayOf(PropTypes.node) ]) }
🧹 Nitpick comments (2)
packages/cozy-viewer/src/Panel/AI/AIAssistantPanel.jsx (1)
174-174: Consider narrowing the dependency to avoid unnecessary re-fetches.Adding the entire
locationobject to the dependency array will triggerfetchSummaryrecreation (and thus a re-fetch via theuseEffecton line 189-191) whenever any property oflocationchanges—not justtype. This could cause unintended API calls if other state properties or pathname change.Consider extracting only the relevant value:
♻️ Suggested approach
+ const summaryType = location.state?.type + const fetchSummary = useCallback( async (force = false) => { // ... existing logic }, - [client, file, t, location] + [client, file, t, summaryType] )Then update
summarizeFileto acceptsummaryTypeas a parameter instead of reading fromlocation.statedirectly.packages/cozy-viewer/src/ViewerInformationsWrapper.jsx (1)
44-48: Clarify the purpose ofcurrentIndexin the dependency array.The effect ensures the file viewer panel opens when the AI assistant closes. Including
currentIndexmeans the effect also runs when switching files—even ifisOpenAiAssistanthasn't changed. While callingsetIsOpenFileViewerPanel(true)when the panel is already open is harmless, consider adding a comment to clarify the intent, or conditionally check before setting:💡 Optional: Add guard or comment
useEffect(() => { if (!isOpenAiAssistant) { + // Ensure panel is visible when AI assistant closes or when switching files setIsOpenFileViewerPanel(true) } }, [isOpenAiAssistant, currentIndex, setIsOpenFileViewerPanel])
54ad923 to
8eb712c
Compare
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: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
packages/cozy-viewer/src/ViewerInformationsWrapper.jsx (1)
99-107:⚠️ Potential issue | 🟡 MinorMissing
currentIndexin PropTypes.The
currentIndexprop is destructured and used in the component but is not defined in PropTypes.📝 Proposed fix
ViewerInformationsWrapper.propTypes = { disableFooter: PropTypes.bool, validForPanel: PropTypes.bool, toolbarRef: PropTypes.object, + currentIndex: PropTypes.number, children: PropTypes.oneOfType([ PropTypes.node, PropTypes.arrayOf(PropTypes.node) ]) }packages/cozy-viewer/src/Panel/AI/AIAssistantPanel.jsx (1)
284-294:⚠️ Potential issue | 🟡 MinorPropTypes and defaultProps are stale and don't match actual usage.
The component only receives
classNameas a prop (line 34), but propTypes declareisLoading,summary,onStop, andonSendwhich are not used. The defaultProps also define values for internal state variables.🔧 Proposed fix
AIAssistantPanel.propTypes = { - isLoading: PropTypes.bool, - summary: PropTypes.string, - onStop: PropTypes.func, - onSend: PropTypes.func + className: PropTypes.string } -AIAssistantPanel.defaultProps = { - isLoading: false, - summary: '' -}
🧹 Nitpick comments (4)
packages/cozy-viewer/src/ViewerInformationsWrapper.jsx (1)
44-48: Consider adding a comment to clarify thecurrentIndexdependency.The
currentIndexappears in the dependency array but is not used in the effect body. This is intentional—it ensures the file viewer panel reopens when navigating between files—but this pattern can confuse future maintainers who may see it as an unnecessary dependency or a linting oversight.📝 Suggested clarification
useEffect(() => { + // When AI assistant closes OR user navigates to a different file, + // ensure the file viewer panel is open if (!isOpenAiAssistant) { setIsOpenFileViewerPanel(true) } }, [isOpenAiAssistant, currentIndex, setIsOpenFileViewerPanel])packages/cozy-viewer/src/Panel/AI/AIAssistantPanel.jsx (1)
57-104: Potential stale closure:summarizeFilereadslocation.statebut isn't memoized.The
summarizeFilefunction (lines 79-84) readslocation.state.typeto select the system prompt, but it's defined as a regular function inside the component. WhenfetchSummarycallssummarizeFile, iflocationchanges between renders, the closure may reference stale state.Consider either:
- Moving the prompt selection logic into
fetchSummary(which haslocationin its deps), or- Passing
location.state.typeas a parameter tosummarizeFile♻️ Suggested refactor: Pass type as parameter
- const summarizeFile = async ({ client, file, stream = false, model }) => { + const summarizeFile = async ({ client, file, stream = false, model, summaryType }) => { try { // ... extractText logic unchanged ... let systemPrompt = SUMMARY_SYSTEM_PROMPT - if (location.state?.type === 'makeSummaryLonger') { + if (summaryType === 'makeSummaryLonger') { systemPrompt = LONG_SUMMARY_SYSTEM_PROMPT - } else if (location.state?.type === 'makeSummaryShorter') { + } else if (summaryType === 'makeSummaryShorter') { systemPrompt = SHORT_SUMMARY_SYSTEM_PROMPT }Then in
fetchSummary:- const response = await summarizeFile({ client, file, stream: false }) + const response = await summarizeFile({ client, file, stream: false, summaryType: location.state?.type })packages/cozy-viewer/src/Panel/getPanelBlocks.jsx (1)
91-98: Update JSDoc to document the newtparameter.The function signature now includes
t(translation function), but the JSDoc at lines 91-97 doesn't document it.📝 Suggested documentation update
/** * Returns the blocks to display in the panel * `@param` {Object} options * `@param` {PanelBlocksSpecs} options.panelBlocksSpecs - Specs of the blocks to display in the panel * `@param` {import('cozy-client/types/types').FileDocument} options.file - File object + * `@param` {Function} options.t - Translation function * `@returns` {Array.<React.Component>} */ const getPanelBlocks = ({ panelBlocksSpecs, file, t }) => {packages/cozy-viewer/src/actions/makeSummaryLonger.js (1)
26-26: Minor inconsistency: Parameter order differs frommakeSummaryShorter.This function uses
({ t, navigate, location })whilemakeSummaryShorteruses({ t, location, navigate }). While this works due to destructuring, consistent ordering improves readability.♻️ Suggested fix for consistency
-export const makeSummaryLonger = ({ t, navigate, location }) => { +export const makeSummaryLonger = ({ t, location, navigate }) => {
zatteo
left a comment
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.
When you fix multiple bugs, please create one commit per bug to ease understanding and future retrieval of bug fix reason
8eb712c to
fae0b35
Compare
|
Much better thank you! |
Related to:
linagora/twake-drive#3691
Changes:
This PR resolves these issues of new UI of file viewer:
Make it shorterandAdd more detailare the actions to change the summarization by AIantivirusblock if there is no result