-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Add Twenty Shared & Fix profile image rendering #8841
base: main
Are you sure you want to change the base?
Conversation
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.
PR Summary
This PR modifies the image URL construction logic to fix profile picture rendering issues, specifically addressing the "File not found" error when displaying profile images.
- Modified
packages/twenty-front/src/utils/image/getImageAbsoluteURI.ts
to use direct string concatenation instead of URL object manipulation - Removed URL encoding/normalization to prevent issues with special characters in image URLs
- Simplified handling of URL path construction by removing leading slash checks
💡 (2/5) Greptile learns from your feedback when you react with 👍/👎!
1 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile
|
||
return serverFilesUrl.toString() as ImageAbsoluteURI<T>; | ||
}; | ||
return `${serverFilesUrl}/files/${imageUrl}` as ImageAbsoluteURI<T>; |
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.
logic: No handling for leading slashes - if imageUrl starts with '/', the result will have double slashes ('//files//'). Add back the previous slash handling logic.
Welcome!
Hello there, congrats on your first PR! We're excited to have you contributing to this project. |
cc @AMoreaux fyi Thank you @mdrazak2001! Do you think you could take a shot at it today? Or should we take over on your PR? |
Hello 👋 Thanks for the contribution. Before adding the fix can you add a test including the URL pattern that broke the function? In this file: Moreover, since you're on this file. Could you add this test? It validate the fact we manage the risk of double slash. it('should return fully formed url if imageUrl is a relative url and start with a /', () => {
const imageUrl = '/XXX';
const result = getImageAbsoluteURI(imageUrl);
expect(result).toBe('http://localhost:3000/files/XXX');
}); The URL API allows you to validate these kinds of use cases. You don't need to manage the double // or the validation of the URI yourself. If you need help or have a lack of time feel free to tell me ;) |
Great suggestion! I'll work on creating a |
@mdrazak2001 yes that'd be great. It might be a bit difficult to do a good configuration so let us know if you're stuck! |
@AMoreaux:
Planned Solution:
I’ll make these updates shortly. Please let me know if there’s anything else you'd like me to address! |
87a2031
to
5be9a09
Compare
Hi @FelixMalfait @AMoreaux |
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.
Lots of works, thanks 🙏
Few comments. TLDR:
- Use the barrel file
- Remove all reference to
react
ortsx
intwenty-shared
- If you want you can remove the type in
getImageAbsoluteURI.ts
I will test it in the browser asap.
"include": [ | ||
"**/__mocks__/**/*", | ||
"jest.config.ts", | ||
"setupTests.ts", | ||
"src/**/*.d.ts", | ||
"src/**/*.spec.ts", | ||
"src/**/*.spec.tsx", | ||
"src/**/*.test.ts", | ||
"src/**/*.test.tsx", | ||
"tsup.config.ts", | ||
"tsup.ui.index.tsx", | ||
"vite.config.ts" | ||
] |
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.
"include": [ | |
"**/__mocks__/**/*", | |
"jest.config.ts", | |
"setupTests.ts", | |
"src/**/*.d.ts", | |
"src/**/*.spec.ts", | |
"src/**/*.spec.tsx", | |
"src/**/*.test.ts", | |
"src/**/*.test.tsx", | |
"tsup.config.ts", | |
"tsup.ui.index.tsx", | |
"vite.config.ts" | |
] | |
"include": [ | |
"jest.config.ts", | |
"setupTests.ts", | |
"src/**/*.spec.ts", | |
"src/**/*.test.ts", | |
"vite.config.ts" | |
] |
It seems some includes are not unused
"**/*.spec.jsx", | ||
"**/*.test.jsx" | ||
], | ||
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"] |
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.
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"] | |
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts"] |
This package shouldn't include tsx
components since we have twenty-ui for that.
packages/twenty-shared/.eslintrc.cjs
Outdated
ignorePatterns: ['!**/*'], | ||
overrides: [ | ||
{ | ||
files: ['*.ts', '*.tsx'], |
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.
files: ['*.ts', '*.tsx'], | |
files: ['*.ts'], |
We will not have tsx
in this package;
packages/twenty-shared/.eslintrc.cjs
Outdated
@@ -0,0 +1,15 @@ | |||
module.exports = { | |||
extends: ['../../.eslintrc.cjs', '../../.eslintrc.react.cjs'], |
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.
extends: ['../../.eslintrc.cjs', '../../.eslintrc.react.cjs'], | |
extends: ['../../.eslintrc.cjs'], |
We will not use react in this package;
global: { | ||
statements: 60, | ||
lines: 60, | ||
functions: 50, | ||
}, |
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.
global: { | |
statements: 60, | |
lines: 60, | |
functions: 50, | |
}, | |
global: { | |
statements: 95, | |
lines: 95, | |
functions: 95, | |
}, |
Since this package will be shared and should contain only easy-to-test functions we can have a high level of coverage.
type ImageAbsoluteURI<T extends string | null | undefined> = T extends string | ||
? string | ||
: null; |
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.
We talked internally, and we would like to remove this type. It will impact the function's return type.
I planned to do it myself but if you want to do it feel free :)
tsconfig.base.json
Outdated
@@ -17,7 +17,8 @@ | |||
"baseUrl": ".", | |||
"paths": { | |||
"twenty-emails": ["packages/twenty-emails/src/index.ts"], | |||
"twenty-ui": ["packages/twenty-ui/src/index.ts"] | |||
"twenty-ui": ["packages/twenty-ui/src/index.ts"], | |||
"twenty-shared": ["packages/twenty-shared/dist"] |
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.
"twenty-shared": ["packages/twenty-shared/dist"] | |
"twenty-shared": ["packages/twenty-shared/src/index.ts"] |
Please target the barrel file here packages/twenty-shared/src/index.ts
instead of targeting dist
packages/twenty-ui/tsconfig.json
Outdated
@@ -10,7 +10,8 @@ | |||
"types": ["node"], | |||
"outDir": "../../.cache/tsc", | |||
"paths": { | |||
"@ui/*": ["packages/twenty-ui/src/*"] | |||
"@ui/*": ["packages/twenty-ui/src/*"], | |||
"twenty-shared": ["packages/twenty-shared/dist"] |
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.
"twenty-shared": ["packages/twenty-shared/dist"] | |
"twenty-shared": ["packages/twenty-shared/src/*"] |
Please target the barrel file here packages/twenty-shared/src/index.ts
instead of targeting dist
packages/twenty-emails/tsconfig.json
Outdated
"baseUrl": "." | ||
"baseUrl": ".", | ||
"paths": { | ||
"twenty-shared": ["packages/twenty-shared/dist"] |
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.
"twenty-shared": ["packages/twenty-shared/dist"] | |
"twenty-shared": ["packages/twenty-shared/src/*"] |
packages/twenty-front/tsconfig.json
Outdated
@@ -24,7 +24,8 @@ | |||
"@/*": ["packages/twenty-front/src/modules/*"], | |||
"~/*": ["packages/twenty-front/src/*"], | |||
"twenty-ui": ["packages/twenty-ui/src/index.ts"], | |||
"@ui/*": ["packages/twenty-ui/src/*"] | |||
"@ui/*": ["packages/twenty-ui/src/*"], | |||
"twenty-shared": ["packages/twenty-shared/src"] |
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.
"twenty-shared": ["packages/twenty-shared/src"] | |
"twenty-shared": ["packages/twenty-shared/src/index.ts"] |
…profile-image-display # Conflicts: # packages/twenty-emails/src/emails/send-invite-link.email.tsx # packages/twenty-emails/src/utils/getImageAbsoluteURI.ts # packages/twenty-front/src/modules/auth/components/Logo.tsx # packages/twenty-front/src/modules/navigation/components/AppNavigationDrawer.tsx # packages/twenty-front/src/modules/object-metadata/utils/getAvatarUrl.ts # packages/twenty-front/src/modules/ui/input/components/ImageInput.tsx # packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/MultiWorkspaceDropdownButton.tsx # packages/twenty-front/src/modules/ui/utilities/page-favicon/components/PageFavicon.tsx # packages/twenty-front/src/pages/settings/admin-panel/SettingsAdminFeatureFlags.tsx # packages/twenty-front/src/pages/settings/serverless-functions/__stories__/SettingsServerlessFunctionDetail.stories.tsx # packages/twenty-ui/src/display/avatar/components/Avatar.tsx # packages/twenty-ui/src/utilities/image/__tests__/getImageAbsoluteURI.test.ts # packages/twenty-ui/src/utilities/image/getImageAbsoluteURI.ts
Refactor the code to streamline the usage of `getImageAbsoluteURI` by storing its result in a variable before rendering. Cleanup unnecessary imports and minor code improvements were applied across several files. This should enhance code readability and maintainability.
Refactor URI handling in `getImageAbsoluteURI` by separating imageUrl and serverUrl checks for better clarity. Update favicon link in HTML and ensure consistency by encompassing logo checking logic inside the JSX return statement. Additional import of `useGetPublicWorkspaceDataBySubdomain` in `WorkspaceProviderEffect` to manage loading state.
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.
Perfect 💯
Thanks a lot for your contribution. I am waiting for the approval of @FelixMalfait for the next steps.
@mdrazak2001 thank you! I'll merge this one today. I have unfortunately merged another fix in the meantime but your PR is bringing more, so I'll rebase it on main and merge it :) |
PR Summary:
Twenty Shared
Package to centralize utilitiies as mentioned in Fix broken image urls in Settings > Profile and Invite To Workspace Email #8942getImageAbsoluteURI.ts
to handle edge cases