forked from twentyhq/twenty
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Linaria for performance optimization (twentyhq#5693)
- Added Linaria to have compiled CSS on our optimized field displays - Refactored mocks for performance stories on fields - Refactored generateRecordChipData into a global context, computed only when we fetch object metadata items. - Refactored ChipFieldDisplay - Refactored PhoneFieldDisplay
- Loading branch information
1 parent
30d3ebc
commit 732e891
Showing
43 changed files
with
2,167 additions
and
520 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
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
18 changes: 18 additions & 0 deletions
18
...ages/twenty-front/src/modules/object-metadata/context/PreComputedChipGeneratorsContext.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,18 @@ | ||
import { createContext } from 'react'; | ||
|
||
import { RecordChipData } from '@/object-record/record-field/types/RecordChipData'; | ||
import { ObjectRecord } from '@/object-record/types/ObjectRecord'; | ||
|
||
export type ChipGeneratorPerObjectPerField = Record< | ||
string, | ||
Record<string, (record: ObjectRecord) => RecordChipData> | ||
>; | ||
|
||
export type PreComputedChipGeneratorsContextProps = { | ||
chipGeneratorPerObjectPerField: ChipGeneratorPerObjectPerField; | ||
}; | ||
|
||
export const PreComputedChipGeneratorsContext = | ||
createContext<PreComputedChipGeneratorsContextProps>( | ||
{} as PreComputedChipGeneratorsContextProps, | ||
); |
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
22 changes: 17 additions & 5 deletions
22
...src/modules/object-record/record-field/meta-types/display/components/ChipFieldDisplay.tsx
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 |
---|---|---|
@@ -1,12 +1,24 @@ | ||
import { RecordChip } from '@/object-record/components/RecordChip'; | ||
import { useChipField } from '@/object-record/record-field/meta-types/hooks/useChipField'; | ||
import { EntityChip } from 'twenty-ui'; | ||
|
||
import { useChipFieldDisplay } from '@/object-record/record-field/meta-types/hooks/useChipFieldDisplay'; | ||
import { getImageAbsoluteURIOrBase64 } from '~/utils/image/getImageAbsoluteURIOrBase64'; | ||
|
||
export const ChipFieldDisplay = () => { | ||
const { objectNameSingular, record } = useChipField(); | ||
const { recordValue, generateRecordChipData } = useChipFieldDisplay(); | ||
|
||
if (!recordValue) { | ||
return null; | ||
} | ||
|
||
if (!record) return null; | ||
const recordChipData = generateRecordChipData(recordValue); | ||
|
||
return ( | ||
<RecordChip objectNameSingular={objectNameSingular || ''} record={record} /> | ||
<EntityChip | ||
entityId={recordValue.id} | ||
name={recordChipData.name as any} | ||
avatarType={recordChipData.avatarType} | ||
avatarUrl={getImageAbsoluteURIOrBase64(recordChipData.avatarUrl) ?? ''} | ||
linkToEntity={recordChipData.linkToShowPage} | ||
/> | ||
); | ||
}; |
5 changes: 2 additions & 3 deletions
5
...rc/modules/object-record/record-field/meta-types/display/components/PhoneFieldDisplay.tsx
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 |
---|---|---|
@@ -1,9 +1,8 @@ | ||
import { usePhoneFieldDisplay } from '@/object-record/record-field/meta-types/hooks/usePhoneFieldDisplay'; | ||
import { PhoneDisplay } from '@/ui/field/display/components/PhoneDisplay'; | ||
|
||
import { usePhoneField } from '../../hooks/usePhoneField'; | ||
|
||
export const PhoneFieldDisplay = () => { | ||
const { fieldValue } = usePhoneField(); | ||
const { fieldValue } = usePhoneFieldDisplay(); | ||
|
||
return <PhoneDisplay value={fieldValue} />; | ||
}; |
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
67 changes: 0 additions & 67 deletions
67
...ecord/record-field/meta-types/display/components/__stories__/ChipFieldDisplay.stories.tsx
This file was deleted.
Oops, something went wrong.
68 changes: 0 additions & 68 deletions
68
...cord/record-field/meta-types/display/components/__stories__/PhoneFieldDisplay.stories.tsx
This file was deleted.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
...rd-field/meta-types/display/components/__stories__/perf/ChipFieldDisplay.perf.stories.tsx
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 { Meta, StoryObj } from '@storybook/react'; | ||
import { ComponentDecorator } from 'twenty-ui'; | ||
|
||
import { ChipFieldDisplay } from '@/object-record/record-field/meta-types/display/components/ChipFieldDisplay'; | ||
import { ChipGeneratorsDecorator } from '~/testing/decorators/ChipGeneratorsDecorator'; | ||
import { getFieldDecorator } from '~/testing/decorators/getFieldDecorator'; | ||
import { MemoryRouterDecorator } from '~/testing/decorators/MemoryRouterDecorator'; | ||
import { getProfilingStory } from '~/testing/profiling/utils/getProfilingStory'; | ||
|
||
const meta: Meta = { | ||
title: 'UI/Data/Field/Display/ChipFieldDisplay', | ||
decorators: [ | ||
MemoryRouterDecorator, | ||
ChipGeneratorsDecorator, | ||
getFieldDecorator('person', 'name'), | ||
ComponentDecorator, | ||
], | ||
component: ChipFieldDisplay, | ||
args: {}, | ||
parameters: { | ||
chromatic: { disableSnapshot: true }, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof ChipFieldDisplay>; | ||
|
||
export const Default: Story = {}; | ||
|
||
export const Performance = getProfilingStory({ | ||
componentName: 'ChipFieldDisplay', | ||
averageThresholdInMs: 0.2, | ||
numberOfRuns: 20, | ||
numberOfTestsPerRun: 100, | ||
}); |
Oops, something went wrong.