-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added and optimized missing RatingFieldDisplay component (#5904)
The display for Rating field type was missing, I just added it based on RatingInput in readonly mode and optimized a bit for performance also. Fixes #5900
- Loading branch information
1 parent
dba0b28
commit e1bd3a4
Showing
8 changed files
with
149 additions
and
17 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
8 changes: 8 additions & 0 deletions
8
...c/modules/object-record/record-field/meta-types/display/components/RatingFieldDisplay.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,8 @@ | ||
import { useRatingFieldDisplay } from '@/object-record/record-field/meta-types/hooks/useRatingFieldDisplay'; | ||
import { RatingInput } from '@/ui/field/input/components/RatingInput'; | ||
|
||
export const RatingFieldDisplay = () => { | ||
const { rating } = useRatingFieldDisplay(); | ||
|
||
return <RatingInput value={rating} readonly />; | ||
}; |
34 changes: 34 additions & 0 deletions
34
...-field/meta-types/display/components/__stories__/perf/RatingFieldDisplay.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,34 @@ | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
import { ComponentDecorator } from 'twenty-ui'; | ||
|
||
import { RatingFieldDisplay } from '@/object-record/record-field/meta-types/display/components/RatingFieldDisplay'; | ||
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/RatingFieldDisplay', | ||
decorators: [ | ||
MemoryRouterDecorator, | ||
getFieldDecorator('person', 'testRating'), | ||
ComponentDecorator, | ||
], | ||
component: RatingFieldDisplay, | ||
args: {}, | ||
parameters: { | ||
chromatic: { disableSnapshot: true }, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof RatingFieldDisplay>; | ||
|
||
export const Default: Story = {}; | ||
|
||
export const Performance = getProfilingStory({ | ||
componentName: 'RatingFieldDisplay', | ||
averageThresholdInMs: 0.5, | ||
numberOfRuns: 50, | ||
numberOfTestsPerRun: 100, | ||
}); |
23 changes: 23 additions & 0 deletions
23
...ty-front/src/modules/object-record/record-field/meta-types/hooks/useRatingFieldDisplay.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,23 @@ | ||
import { useContext } from 'react'; | ||
|
||
import { FieldRatingValue } from '@/object-record/record-field/types/FieldMetadata'; | ||
import { useRecordFieldValue } from '@/object-record/record-store/contexts/RecordFieldValueSelectorContext'; | ||
|
||
import { FieldContext } from '../../contexts/FieldContext'; | ||
|
||
export const useRatingFieldDisplay = () => { | ||
const { entityId, fieldDefinition } = useContext(FieldContext); | ||
|
||
const fieldName = fieldDefinition.metadata.fieldName; | ||
|
||
const fieldValue = useRecordFieldValue(entityId, fieldName) as | ||
| FieldRatingValue | ||
| undefined; | ||
|
||
const rating = fieldValue ?? 'RATING_1'; | ||
|
||
return { | ||
fieldDefinition, | ||
rating, | ||
}; | ||
}; |
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
8 changes: 4 additions & 4 deletions
8
packages/twenty-ui/src/display/icon/components/IconTwentyStarFilled.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