forked from twentyhq/twenty
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/performance-refactor-styled-component (twentyhq#5516)
In this PR I'm optimizing a whole RecordTableCell in real conditions with a complex RelationFieldDisplay component : - Broke down getObjectRecordIdentifier into multiple utils - Precompute memoized function for getting chip data per field with useRecordChipDataGenerator() - Refactored RelationFieldDisplay - Use CSS modules where performance is needed instead of styled components - Create a CSS theme with global CSS variables to be used by CSS modules
- Loading branch information
1 parent
3680647
commit a017847
Showing
39 changed files
with
1,044 additions
and
461 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
packages/twenty-front/src/modules/object-metadata/utils/getAvatarType.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular'; | ||
|
||
export const getAvatarType = (objectNameSingular: string) => { | ||
if (objectNameSingular === CoreObjectNameSingular.WorkspaceMember) { | ||
return 'rounded'; | ||
} | ||
|
||
if (objectNameSingular === CoreObjectNameSingular.Company) { | ||
return 'squared'; | ||
} | ||
|
||
return 'rounded'; | ||
}; |
36 changes: 36 additions & 0 deletions
36
packages/twenty-front/src/modules/object-metadata/utils/getAvatarUrl.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular'; | ||
import { FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem'; | ||
import { ObjectRecord } from '@/object-record/types/ObjectRecord'; | ||
import { getLogoUrlFromDomainName } from '~/utils'; | ||
import { isDefined } from '~/utils/isDefined'; | ||
|
||
import { getImageIdentifierFieldValue } from './getImageIdentifierFieldValue'; | ||
|
||
export const getAvatarUrl = ( | ||
objectNameSingular: string, | ||
record: ObjectRecord, | ||
imageIdentifierFieldMetadataItem: FieldMetadataItem | undefined, | ||
) => { | ||
if (objectNameSingular === CoreObjectNameSingular.WorkspaceMember) { | ||
return record.avatarUrl ?? undefined; | ||
} | ||
|
||
if (objectNameSingular === CoreObjectNameSingular.Company) { | ||
return getLogoUrlFromDomainName(record.domainName ?? ''); | ||
} | ||
|
||
if (objectNameSingular === CoreObjectNameSingular.Person) { | ||
return record.avatarUrl ?? ''; | ||
} | ||
|
||
const imageIdentifierFieldValue = getImageIdentifierFieldValue( | ||
record, | ||
imageIdentifierFieldMetadataItem, | ||
); | ||
|
||
if (isDefined(imageIdentifierFieldValue)) { | ||
return imageIdentifierFieldValue; | ||
} | ||
|
||
return ''; | ||
}; |
14 changes: 14 additions & 0 deletions
14
packages/twenty-front/src/modules/object-metadata/utils/getImageIdentifierFieldValue.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem'; | ||
import { ObjectRecord } from '@/object-record/types/ObjectRecord'; | ||
import { isDefined } from '~/utils/isDefined'; | ||
|
||
export const getImageIdentifierFieldValue = ( | ||
record: ObjectRecord, | ||
imageIdentifierFieldMetadataItem: FieldMetadataItem | undefined, | ||
) => { | ||
if (isDefined(imageIdentifierFieldMetadataItem?.name)) { | ||
return record[imageIdentifierFieldMetadataItem.name] as string; | ||
} | ||
|
||
return null; | ||
}; |
24 changes: 24 additions & 0 deletions
24
packages/twenty-front/src/modules/object-metadata/utils/getLabelIdentifierFieldValue.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular'; | ||
import { FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem'; | ||
import { ObjectRecord } from '@/object-record/types/ObjectRecord'; | ||
import { FieldMetadataType } from '~/generated-metadata/graphql'; | ||
import { isDefined } from '~/utils/isDefined'; | ||
|
||
export const getLabelIdentifierFieldValue = ( | ||
record: ObjectRecord, | ||
labelIdentifierFieldMetadataItem: FieldMetadataItem | undefined, | ||
objectNameSingular: string, | ||
) => { | ||
if ( | ||
objectNameSingular === CoreObjectNameSingular.WorkspaceMember || | ||
labelIdentifierFieldMetadataItem?.type === FieldMetadataType.FullName | ||
) { | ||
return `${record.name?.firstName ?? ''} ${record.name?.lastName ?? ''}`; | ||
} | ||
|
||
if (isDefined(labelIdentifierFieldMetadataItem?.name)) { | ||
return record[labelIdentifierFieldMetadataItem.name] as string | number; | ||
} | ||
|
||
return ''; | ||
}; |
22 changes: 22 additions & 0 deletions
22
packages/twenty-front/src/modules/object-metadata/utils/getLinkToShowPage.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular'; | ||
import { getBasePathToShowPage } from '@/object-metadata/utils/getBasePathToShowPage'; | ||
import { ObjectRecord } from '@/object-record/types/ObjectRecord'; | ||
|
||
export const getLinkToShowPage = ( | ||
objectNameSingular: string, | ||
record: ObjectRecord, | ||
) => { | ||
const basePathToShowPage = getBasePathToShowPage({ | ||
objectNameSingular, | ||
}); | ||
|
||
const isWorkspaceMemberObjectMetadata = | ||
objectNameSingular === CoreObjectNameSingular.WorkspaceMember; | ||
|
||
const linkToShowPage = | ||
isWorkspaceMemberObjectMetadata || !record.id | ||
? '' | ||
: `${basePathToShowPage}${record.id}`; | ||
|
||
return linkToShowPage; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.