Repository navigation
Refactor variable of front end - #13953
Conversation
Signed-off-by: Jin Hai <[email protected]>
| @@ -1,344 +1,332 @@ | |||
| const api_host = `/v1`; | |||
| const ExternalApi = `/api`; | |||
| const webAPI = `/v1`; | |||
There was a problem hiding this comment.
const modifies constants, and it's recommended to capitalize the first letter.
Signed-off-by: Jin Hai <[email protected]>
Signed-off-by: Jin Hai <[email protected]>
📝 WalkthroughWalkthroughThe changes refactor API base URL constants across the codebase. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
web/src/hooks/use-document-request.ts (1)
467-475: Disambiguate the twouseGetDocumentUrlhooks.
web/src/components/document-preview/hooks.tsalready exportsuseGetDocumentUrl, but that version takesisAgent: booleanand returns a string. Reusing the same name here for a callback-producing hook makes imports easy to misread during refactors like this.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@web/src/hooks/use-document-request.ts` around lines 467 - 475, The exported hook name useGetDocumentUrl conflicts with another hook of the same name that returns a string (the other takes isAgent:boolean), so rename this callback-producing hook (e.g., useGetDocumentUrlCallback or useGetDocumentUrlFactory) to avoid ambiguity, update the internal identifier getDocumentUrl remains the same, change the export and all imports/usages to the new name, and run a project-wide search to replace any imports of useGetDocumentUrl that should point to this callback-producing version to ensure callers still receive the useCallback-returning function.web/src/components/next-message-item/reference-image-list.tsx (1)
82-82: Share the document-image URL builder.This duplicates the path logic in
web/src/components/image/index.tsxLine 16. A small shared helper would keepPhotoViewand<Image />aligned the next time this route or its cache-busting rules change.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@web/src/components/next-message-item/reference-image-list.tsx` at line 82, Duplicate URL construction for document images exists between the PhotoView usage in reference-image-list.tsx (PhotoView src={`${webAPI}/document/image/${id}`}) and the Image component in web/src/components/image/index.tsx; extract that logic into a single exported helper (e.g., getDocumentImageUrl or buildDocumentImageUrl) that accepts the image id and base webAPI and returns the full URL, replace the inline string interpolation in reference-image-list.tsx (PhotoView) and the Image component to call this helper, and export/import the helper from a shared module so both components consume the same URL builder.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@web/src/components/image/index.tsx`:
- Around line 14-17: The CSS class on the <img> element uses an invalid unit
"40wh" so the max-height is ignored; update the classNames call in
web/src/components/image/index.tsx (the img element rendering, where className
is built) to use a valid viewport height unit such as "max-h-[40vh]" (replace
"40wh" with "40vh") so the image height cap is applied.
---
Nitpick comments:
In `@web/src/components/next-message-item/reference-image-list.tsx`:
- Line 82: Duplicate URL construction for document images exists between the
PhotoView usage in reference-image-list.tsx (PhotoView
src={`${webAPI}/document/image/${id}`}) and the Image component in
web/src/components/image/index.tsx; extract that logic into a single exported
helper (e.g., getDocumentImageUrl or buildDocumentImageUrl) that accepts the
image id and base webAPI and returns the full URL, replace the inline string
interpolation in reference-image-list.tsx (PhotoView) and the Image component to
call this helper, and export/import the helper from a shared module so both
components consume the same URL builder.
In `@web/src/hooks/use-document-request.ts`:
- Around line 467-475: The exported hook name useGetDocumentUrl conflicts with
another hook of the same name that returns a string (the other takes
isAgent:boolean), so rename this callback-producing hook (e.g.,
useGetDocumentUrlCallback or useGetDocumentUrlFactory) to avoid ambiguity,
update the internal identifier getDocumentUrl remains the same, change the
export and all imports/usages to the new name, and run a project-wide search to
replace any imports of useGetDocumentUrl that should point to this
callback-producing version to ensure callers still receive the
useCallback-returning function.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 3d7d4e9d-cd32-4253-b1de-127d22a5bd45
📒 Files selected for processing (7)
internal/cli/common_command.goweb/src/components/document-preview/hooks.tsweb/src/components/image/index.tsxweb/src/components/next-message-item/reference-image-list.tsxweb/src/hooks/use-document-request.tsweb/src/pages/document-viewer/index.tsxweb/src/utils/api.ts
| <img | ||
| {...props} | ||
| src={`${api_host}/document/image/${id}${t ? `?_t=${t}` : ''}`} | ||
| src={`${webAPI}/document/image/${id}${t ? `?_t=${t}` : ''}`} | ||
| className={classNames('max-w-[45vw] max-h-[40wh] block', className)} |
There was a problem hiding this comment.
Fix the invalid max-height unit.
Line 17 uses max-h-[40wh], which is not a valid CSS unit, so the height cap is ignored.
Proposed fix
- className={classNames('max-w-[45vw] max-h-[40wh] block', className)}
+ className={classNames('max-w-[45vw] max-h-[40vh] block', className)}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| <img | |
| {...props} | |
| src={`${api_host}/document/image/${id}${t ? `?_t=${t}` : ''}`} | |
| src={`${webAPI}/document/image/${id}${t ? `?_t=${t}` : ''}`} | |
| className={classNames('max-w-[45vw] max-h-[40wh] block', className)} | |
| <img | |
| {...props} | |
| src={`${webAPI}/document/image/${id}${t ? `?_t=${t}` : ''}`} | |
| className={classNames('max-w-[45vw] max-h-[40vh] block', className)} |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@web/src/components/image/index.tsx` around lines 14 - 17, The CSS class on
the <img> element uses an invalid unit "40wh" so the max-height is ignored;
update the classNames call in web/src/components/image/index.tsx (the img
element rendering, where className is built) to use a valid viewport height unit
such as "max-h-[40vh]" (replace "40wh" with "40vh") so the image height cap is
applied.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #13953 +/- ##
=======================================
Coverage 96.52% 96.52%
=======================================
Files 10 10
Lines 690 690
Branches 108 108
=======================================
Hits 666 666
Misses 8 8
Partials 16 16 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
### What problem does this PR solve? api_host -> webAPI ExternalApi -> restAPIv1 ### Type of change - [x] Refactoring <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Updated internal API endpoint configuration to use consolidated base URL constants for improved maintainability and consistency across the application. * **Chores** * Updated server-side protocol validation for admin connectivity checks. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Jin Hai <[email protected]>
What problem does this PR solve?
api_host -> webAPI
ExternalApi -> restAPIv1
Type of change
Summary by CodeRabbit
Refactor
Chores