Remove some dead code (#6611)

We could remove a lot more than this, this is just a start.

There are various tools to help with this, knip is a good one
This commit is contained in:
Félix Malfait
2024-08-11 20:43:18 +02:00
committed by GitHub
parent 39512a779e
commit d5350e11a3
61 changed files with 23 additions and 1044 deletions

View File

@ -1,50 +0,0 @@
import { mapFavorites } from '../mapFavorites';
describe('mapFavorites', () => {
it('should return the correct value', () => {
const favorites = [
{
id: '1',
person: {
id: '2',
name: {
firstName: 'John',
lastName: 'Doe',
},
avatarUrl: 'https://example.com/avatar.png',
},
},
{
id: '3',
company: {
id: '4',
name: 'My Company',
domainName: 'example.com',
},
position: 1,
},
];
const res = mapFavorites(favorites);
expect(res).toHaveLength(2);
// Person
expect(res[0].id).toBe('1');
expect(res[0].labelIdentifier).toBe('John Doe');
expect(res[0].avatarUrl).toBe('https://example.com/avatar.png');
expect(res[0].avatarType).toBe('rounded');
expect(res[0].link).toBe('/object/person/2');
expect(res[0].recordId).toBe('2');
expect(res[0].position).toBeUndefined();
// Company
expect(res[1].id).toBe('3');
expect(res[1].labelIdentifier).toBe('My Company');
expect(res[1].avatarUrl).toBe('https://favicon.twenty.com/example.com');
expect(res[1].avatarType).toBe('squared');
expect(res[1].link).toBe('/object/company/4');
expect(res[1].recordId).toBe('4');
expect(res[1].position).toBe(1);
});
});

View File

@ -1,40 +0,0 @@
import { getCompanyDomainName } from '@/object-metadata/utils/getCompanyDomainName';
import { getLogoUrlFromDomainName } from '~/utils';
import { isDefined } from '~/utils/isDefined';
export const mapFavorites = (favorites: any) => {
return favorites
.map((favorite: any) => {
const recordInformation = isDefined(favorite?.person)
? {
id: favorite.person.id,
labelIdentifier:
favorite.person.name.firstName +
' ' +
favorite.person.name.lastName,
avatarUrl: favorite.person.avatarUrl,
avatarType: 'rounded',
link: `/object/person/${favorite.person.id}`,
}
: isDefined(favorite?.company)
? {
id: favorite.company.id,
labelIdentifier: favorite.company.name,
avatarUrl: getLogoUrlFromDomainName(
getCompanyDomainName(favorite.company),
),
avatarType: 'squared',
link: `/object/company/${favorite.company.id}`,
}
: undefined;
return {
...recordInformation,
recordId: recordInformation?.id,
id: favorite?.id,
position: favorite?.position,
};
})
.filter(isDefined)
.sort((a: any, b: any) => a.position - b.position);
};