Improve performance of demo workspace - Rename getImageAbsoluteURIOrBase64 function (#6282)

### Description

1. This PR is a continuation of a previous PR:
https://github.com/twentyhq/twenty/pull/6201#pullrequestreview-2175601222

2. One test case was removed here:
`packages/twenty-front/src/utils/image/__tests__/getImageAbsoluteURI.test.ts`
because since we are not handling base64 images anymore, the result is
the same of the last test case. Would you rather we update the test
instead?


### Refs

- #3514
- https://github.com/twentyhq/twenty/pull/6201

### Demo


https://www.loom.com/share/4f32b535c77a4d418e319b095d09452c?sid=df34adf8-b013-44ef-b794-d54846f52d2d

Fixes #3514

---------

Co-authored-by: gitstart-twenty <gitstart-twenty@users.noreply.github.com>
This commit is contained in:
gitstart-app[bot]
2024-07-29 14:07:21 +02:00
committed by GitHub
parent 00fea17920
commit fed12ddfcd
31 changed files with 124 additions and 97 deletions

View File

@ -0,0 +1,21 @@
import { getImageAbsoluteURI } from '../getImageAbsoluteURI';
describe('getImageAbsoluteURI', () => {
it('should return null if imageUrl is null', () => {
const imageUrl = null;
const result = getImageAbsoluteURI(imageUrl);
expect(result).toBeNull();
});
it('should return absolute url if the imageUrl is an absolute url', () => {
const imageUrl = 'https://XXX';
const result = getImageAbsoluteURI(imageUrl);
expect(result).toBe(imageUrl);
});
it('should return fully formed url if imageUrl is a relative url', () => {
const imageUrl = 'XXX';
const result = getImageAbsoluteURI(imageUrl);
expect(result).toBe('http://localhost:3000/files/XXX');
});
});

View File

@ -1,27 +0,0 @@
import { getImageAbsoluteURIOrBase64 } from '../getImageAbsoluteURIOrBase64';
describe('getImageAbsoluteURIOrBase64', () => {
it('should return null if imageUrl is null', () => {
const imageUrl = null;
const result = getImageAbsoluteURIOrBase64(imageUrl);
expect(result).toBeNull();
});
it('should return base64 encoded string if prefixed with data', () => {
const imageUrl = 'data:XXX';
const result = getImageAbsoluteURIOrBase64(imageUrl);
expect(result).toBe(imageUrl);
});
it('should return absolute url if the imageUrl is an absolute url', () => {
const imageUrl = 'https://XXX';
const result = getImageAbsoluteURIOrBase64(imageUrl);
expect(result).toBe(imageUrl);
});
it('should return fully formed url if imageUrl is a relative url', () => {
const imageUrl = 'XXX';
const result = getImageAbsoluteURIOrBase64(imageUrl);
expect(result).toBe('http://localhost:3000/files/XXX');
});
});

View File

@ -1,11 +1,11 @@
import { REACT_APP_SERVER_BASE_URL } from '~/config';
export const getImageAbsoluteURIOrBase64 = (imageUrl?: string | null) => {
export const getImageAbsoluteURI = (imageUrl?: string | null) => {
if (!imageUrl) {
return null;
}
if (imageUrl?.startsWith('data:') || imageUrl?.startsWith('https:')) {
if (imageUrl?.startsWith('https:')) {
return imageUrl;
}