fixed issue Display field name on Kanbans & Shows (#3427)
* fixed issue Display field name on Kanbans & Shows * Fixes according to review --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -7,15 +7,21 @@ import { FieldMetadataItem } from '../types/FieldMetadataItem';
|
|||||||
|
|
||||||
import { parseFieldType } from './parseFieldType';
|
import { parseFieldType } from './parseFieldType';
|
||||||
|
|
||||||
|
type FieldMetadataItemAsColumnDefinitionProps = {
|
||||||
|
position: number;
|
||||||
|
field: FieldMetadataItem;
|
||||||
|
objectMetadataItem: ObjectMetadataItem;
|
||||||
|
showLabel?: boolean;
|
||||||
|
labelWidth?: number;
|
||||||
|
};
|
||||||
|
|
||||||
export const formatFieldMetadataItemAsColumnDefinition = ({
|
export const formatFieldMetadataItemAsColumnDefinition = ({
|
||||||
position,
|
position,
|
||||||
field,
|
field,
|
||||||
objectMetadataItem,
|
objectMetadataItem,
|
||||||
}: {
|
showLabel,
|
||||||
position: number;
|
labelWidth,
|
||||||
field: FieldMetadataItem;
|
}: FieldMetadataItemAsColumnDefinitionProps): ColumnDefinition<FieldMetadata> => {
|
||||||
objectMetadataItem: ObjectMetadataItem;
|
|
||||||
}): ColumnDefinition<FieldMetadata> => {
|
|
||||||
const relationObjectMetadataItem =
|
const relationObjectMetadataItem =
|
||||||
field.toRelationMetadata?.fromObjectMetadata ||
|
field.toRelationMetadata?.fromObjectMetadata ||
|
||||||
field.fromRelationMetadata?.toObjectMetadata;
|
field.fromRelationMetadata?.toObjectMetadata;
|
||||||
@ -28,6 +34,8 @@ export const formatFieldMetadataItemAsColumnDefinition = ({
|
|||||||
position,
|
position,
|
||||||
fieldMetadataId: field.id,
|
fieldMetadataId: field.id,
|
||||||
label: field.label,
|
label: field.label,
|
||||||
|
showLabel,
|
||||||
|
labelWidth,
|
||||||
size: 100,
|
size: 100,
|
||||||
type: parseFieldType(field.type),
|
type: parseFieldType(field.type),
|
||||||
metadata: {
|
metadata: {
|
||||||
|
|||||||
@ -268,6 +268,8 @@ export const RecordShowPage = () => {
|
|||||||
field: fieldMetadataItem,
|
field: fieldMetadataItem,
|
||||||
position: index,
|
position: index,
|
||||||
objectMetadataItem,
|
objectMetadataItem,
|
||||||
|
showLabel: true,
|
||||||
|
labelWidth: 90,
|
||||||
}),
|
}),
|
||||||
useUpdateRecord: useUpdateOneObjectRecordMutation,
|
useUpdateRecord: useUpdateOneObjectRecordMutation,
|
||||||
hotkeyScope: InlineCellHotkeyScope.InlineCell,
|
hotkeyScope: InlineCellHotkeyScope.InlineCell,
|
||||||
|
|||||||
@ -10,6 +10,8 @@ export type FieldDefinitionRelationType =
|
|||||||
export type FieldDefinition<T extends FieldMetadata> = {
|
export type FieldDefinition<T extends FieldMetadata> = {
|
||||||
fieldMetadataId: string;
|
fieldMetadataId: string;
|
||||||
label: string;
|
label: string;
|
||||||
|
showLabel?: boolean;
|
||||||
|
labelWidth?: number;
|
||||||
iconName: string;
|
iconName: string;
|
||||||
type: FieldType;
|
type: FieldType;
|
||||||
metadata: T;
|
metadata: T;
|
||||||
|
|||||||
@ -74,6 +74,9 @@ export const RecordInlineCell = () => {
|
|||||||
IconLabel={
|
IconLabel={
|
||||||
fieldDefinition.iconName ? getIcon(fieldDefinition.iconName) : undefined
|
fieldDefinition.iconName ? getIcon(fieldDefinition.iconName) : undefined
|
||||||
}
|
}
|
||||||
|
label={fieldDefinition.label}
|
||||||
|
labelWidth={fieldDefinition.labelWidth}
|
||||||
|
showLabel={fieldDefinition.showLabel}
|
||||||
editModeContent={
|
editModeContent={
|
||||||
<FieldInput
|
<FieldInput
|
||||||
onEnter={handleEnter}
|
onEnter={handleEnter}
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import styled from '@emotion/styled';
|
|||||||
import { motion } from 'framer-motion';
|
import { motion } from 'framer-motion';
|
||||||
|
|
||||||
import { IconComponent } from '@/ui/display/icon/types/IconComponent';
|
import { IconComponent } from '@/ui/display/icon/types/IconComponent';
|
||||||
|
import { EllipsisDisplay } from '@/ui/field/display/components/EllipsisDisplay';
|
||||||
import { HotkeyScope } from '@/ui/utilities/hotkey/types/HotkeyScope';
|
import { HotkeyScope } from '@/ui/utilities/hotkey/types/HotkeyScope';
|
||||||
|
|
||||||
import { useInlineCell } from '../hooks/useInlineCell';
|
import { useInlineCell } from '../hooks/useInlineCell';
|
||||||
@ -38,13 +39,10 @@ const StyledValueContainer = styled.div`
|
|||||||
display: flex;
|
display: flex;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const StyledLabel = styled.div<
|
const StyledLabelContainer = styled.div<{ width?: number }>`
|
||||||
Pick<RecordInlineCellContainerProps, 'labelFixedWidth'>
|
color: ${({ theme }) => theme.font.color.tertiary};
|
||||||
>`
|
font-size: ${({ theme }) => theme.font.size.sm};
|
||||||
align-items: center;
|
width: ${({ width }) => width}px;
|
||||||
|
|
||||||
width: ${({ labelFixedWidth }) =>
|
|
||||||
labelFixedWidth ? `${labelFixedWidth}px` : 'fit-content'};
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const StyledEditButtonContainer = styled(motion.div)`
|
const StyledEditButtonContainer = styled(motion.div)`
|
||||||
@ -74,7 +72,8 @@ const StyledInlineCellBaseContainer = styled.div`
|
|||||||
type RecordInlineCellContainerProps = {
|
type RecordInlineCellContainerProps = {
|
||||||
IconLabel?: IconComponent;
|
IconLabel?: IconComponent;
|
||||||
label?: string;
|
label?: string;
|
||||||
labelFixedWidth?: number;
|
labelWidth?: number;
|
||||||
|
showLabel?: boolean;
|
||||||
buttonIcon?: IconComponent;
|
buttonIcon?: IconComponent;
|
||||||
editModeContent?: React.ReactNode;
|
editModeContent?: React.ReactNode;
|
||||||
editModeContentOnly?: boolean;
|
editModeContentOnly?: boolean;
|
||||||
@ -88,7 +87,8 @@ type RecordInlineCellContainerProps = {
|
|||||||
export const RecordInlineCellContainer = ({
|
export const RecordInlineCellContainer = ({
|
||||||
IconLabel,
|
IconLabel,
|
||||||
label,
|
label,
|
||||||
labelFixedWidth,
|
labelWidth,
|
||||||
|
showLabel,
|
||||||
buttonIcon,
|
buttonIcon,
|
||||||
editModeContent,
|
editModeContent,
|
||||||
displayModeContent,
|
displayModeContent,
|
||||||
@ -133,8 +133,10 @@ export const RecordInlineCellContainer = ({
|
|||||||
<IconLabel stroke={theme.icon.stroke.sm} />
|
<IconLabel stroke={theme.icon.stroke.sm} />
|
||||||
</StyledIconContainer>
|
</StyledIconContainer>
|
||||||
)}
|
)}
|
||||||
{label && (
|
{showLabel && label && (
|
||||||
<StyledLabel labelFixedWidth={labelFixedWidth}>{label}</StyledLabel>
|
<StyledLabelContainer width={labelWidth}>
|
||||||
|
<EllipsisDisplay maxWidth={labelWidth}>{label}</EllipsisDisplay>
|
||||||
|
</StyledLabelContainer>
|
||||||
)}
|
)}
|
||||||
</StyledLabelAndIconContainer>
|
</StyledLabelAndIconContainer>
|
||||||
)}
|
)}
|
||||||
@ -148,6 +150,7 @@ export const RecordInlineCellContainer = ({
|
|||||||
isDisplayModeContentEmpty={isDisplayModeContentEmpty}
|
isDisplayModeContentEmpty={isDisplayModeContentEmpty}
|
||||||
isDisplayModeFixHeight={isDisplayModeFixHeight}
|
isDisplayModeFixHeight={isDisplayModeFixHeight}
|
||||||
isHovered={isHovered}
|
isHovered={isHovered}
|
||||||
|
emptyPlaceholder={showLabel ? 'Empty' : label}
|
||||||
>
|
>
|
||||||
{editModeContent}
|
{editModeContent}
|
||||||
</RecordInlineCellDisplayMode>
|
</RecordInlineCellDisplayMode>
|
||||||
@ -159,6 +162,7 @@ export const RecordInlineCellContainer = ({
|
|||||||
isDisplayModeContentEmpty={isDisplayModeContentEmpty}
|
isDisplayModeContentEmpty={isDisplayModeContentEmpty}
|
||||||
isDisplayModeFixHeight={isDisplayModeFixHeight}
|
isDisplayModeFixHeight={isDisplayModeFixHeight}
|
||||||
isHovered={isHovered}
|
isHovered={isHovered}
|
||||||
|
emptyPlaceholder={showLabel ? 'Empty' : label}
|
||||||
>
|
>
|
||||||
{displayModeContent}
|
{displayModeContent}
|
||||||
</RecordInlineCellDisplayMode>
|
</RecordInlineCellDisplayMode>
|
||||||
|
|||||||
@ -55,6 +55,7 @@ type RecordInlineCellDisplayModeProps = {
|
|||||||
disableHoverEffect?: boolean;
|
disableHoverEffect?: boolean;
|
||||||
isDisplayModeFixHeight?: boolean;
|
isDisplayModeFixHeight?: boolean;
|
||||||
isHovered?: boolean;
|
isHovered?: boolean;
|
||||||
|
emptyPlaceholder?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const RecordInlineCellDisplayMode = ({
|
export const RecordInlineCellDisplayMode = ({
|
||||||
@ -62,6 +63,7 @@ export const RecordInlineCellDisplayMode = ({
|
|||||||
isDisplayModeContentEmpty,
|
isDisplayModeContentEmpty,
|
||||||
disableHoverEffect,
|
disableHoverEffect,
|
||||||
isDisplayModeFixHeight,
|
isDisplayModeFixHeight,
|
||||||
|
emptyPlaceholder = 'Empty',
|
||||||
isHovered,
|
isHovered,
|
||||||
}: React.PropsWithChildren<RecordInlineCellDisplayModeProps>) => (
|
}: React.PropsWithChildren<RecordInlineCellDisplayModeProps>) => (
|
||||||
<StyledRecordInlineCellNormalModeOuterContainer
|
<StyledRecordInlineCellNormalModeOuterContainer
|
||||||
@ -72,7 +74,7 @@ export const RecordInlineCellDisplayMode = ({
|
|||||||
>
|
>
|
||||||
<StyledRecordInlineCellNormalModeInnerContainer>
|
<StyledRecordInlineCellNormalModeInnerContainer>
|
||||||
{isDisplayModeContentEmpty || !children ? (
|
{isDisplayModeContentEmpty || !children ? (
|
||||||
<StyledEmptyField>{'Empty'}</StyledEmptyField>
|
<StyledEmptyField>{emptyPlaceholder}</StyledEmptyField>
|
||||||
) : (
|
) : (
|
||||||
children
|
children
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user