mirror of
https://github.com/twentyhq/twenty.git
synced 2025-01-06 03:45:15 +03:00
Refactor RelationFieldDisplay to eliminate dependency on non-ui components (#1949)
* job done * removed example type * removed unused temporary type
This commit is contained in:
parent
29c013f826
commit
b9f23d9be6
@ -170,6 +170,7 @@ export const CompanyBoardCard = () => {
|
||||
type: viewField.type,
|
||||
metadata: viewField.metadata,
|
||||
buttonIcon: viewField.buttonIcon,
|
||||
entityChipDisplayMapper: viewField.entityChipDisplayMapper,
|
||||
},
|
||||
useUpdateEntityMutation: useUpdateOnePipelineProgressMutation,
|
||||
hotkeyScope: InlineCellHotkeyScope.InlineCell,
|
||||
|
@ -25,6 +25,7 @@ import {
|
||||
IconUsers,
|
||||
} from '@/ui/icon/index';
|
||||
import { Entity } from '@/ui/input/relation-picker/types/EntityTypeForSelect';
|
||||
import { User } from '~/generated/graphql';
|
||||
|
||||
export const companiesAvailableColumnDefinitions: ColumnDefinition<FieldMetadata>[] =
|
||||
[
|
||||
@ -76,6 +77,13 @@ export const companiesAvailableColumnDefinitions: ColumnDefinition<FieldMetadata
|
||||
isVisible: true,
|
||||
infoTooltipContent:
|
||||
'Your team member responsible for managing the company account.',
|
||||
entityChipDisplayMapper: (dataObject: User) => {
|
||||
return {
|
||||
name: dataObject?.displayName,
|
||||
pictureUrl: dataObject?.avatarUrl ?? undefined,
|
||||
avatarType: 'rounded',
|
||||
};
|
||||
},
|
||||
} satisfies ColumnDefinition<FieldRelationMetadata>,
|
||||
{
|
||||
key: 'createdAt',
|
||||
|
@ -23,6 +23,8 @@ import {
|
||||
IconUser,
|
||||
} from '@/ui/icon/index';
|
||||
import { Entity } from '@/ui/input/relation-picker/types/EntityTypeForSelect';
|
||||
import { Company } from '~/generated/graphql';
|
||||
import { getLogoUrlFromDomainName } from '~/utils';
|
||||
|
||||
export const peopleAvailableColumnDefinitions: ColumnDefinition<FieldMetadata>[] =
|
||||
[
|
||||
@ -71,6 +73,13 @@ export const peopleAvailableColumnDefinitions: ColumnDefinition<FieldMetadata>[]
|
||||
relationType: Entity.Company,
|
||||
},
|
||||
infoTooltipContent: 'Contact’s company.',
|
||||
entityChipDisplayMapper: (dataObject: Company) => {
|
||||
return {
|
||||
name: dataObject?.name,
|
||||
pictureUrl: getLogoUrlFromDomainName(dataObject?.domainName),
|
||||
avatarType: 'squared',
|
||||
};
|
||||
},
|
||||
} satisfies ColumnDefinition<FieldRelationMetadata>,
|
||||
{
|
||||
key: 'phone',
|
||||
|
@ -14,6 +14,7 @@ import {
|
||||
IconUser,
|
||||
} from '@/ui/icon';
|
||||
import { Entity } from '@/ui/input/relation-picker/types/EntityTypeForSelect';
|
||||
import { Person } from '~/generated/graphql';
|
||||
|
||||
export const pipelineAvailableFieldDefinitions: BoardFieldDefinition<FieldMetadata>[] =
|
||||
[
|
||||
@ -70,5 +71,12 @@ export const pipelineAvailableFieldDefinitions: BoardFieldDefinition<FieldMetada
|
||||
isVisible: true,
|
||||
buttonIcon: IconPencil,
|
||||
infoTooltipContent: 'Primary contact within the company.',
|
||||
entityChipDisplayMapper: (dataObject: Person) => {
|
||||
return {
|
||||
name: dataObject?.displayName,
|
||||
pictureUrl: dataObject?.avatarUrl ?? undefined,
|
||||
avatarType: 'rounded',
|
||||
};
|
||||
},
|
||||
} satisfies BoardFieldDefinition<FieldRelationMetadata>,
|
||||
];
|
||||
|
@ -1,52 +1,24 @@
|
||||
import { CompanyChip } from '@/companies/components/CompanyChip';
|
||||
import { PersonChip } from '@/people/components/PersonChip';
|
||||
import { Entity } from '@/ui/input/relation-picker/types/EntityTypeForSelect';
|
||||
import { UserChip } from '@/users/components/UserChip';
|
||||
import { getLogoUrlFromDomainName } from '~/utils';
|
||||
import { logError } from '~/utils/logError';
|
||||
import { EntityChip } from '@/ui/chip/components/EntityChip';
|
||||
|
||||
import { useRelationField } from '../../hooks/useRelationField';
|
||||
|
||||
export const RelationFieldDisplay = () => {
|
||||
const { fieldDefinition, fieldValue } = useRelationField();
|
||||
|
||||
switch (fieldDefinition.metadata.relationType) {
|
||||
case Entity.Person: {
|
||||
return (
|
||||
<PersonChip
|
||||
id={fieldValue?.id ?? ''}
|
||||
name={fieldValue?.displayName ?? ''}
|
||||
pictureUrl={fieldValue?.avatarUrl ?? ''}
|
||||
/>
|
||||
);
|
||||
}
|
||||
case Entity.User: {
|
||||
return (
|
||||
<UserChip
|
||||
id={fieldValue?.id ?? ''}
|
||||
name={fieldValue?.displayName ?? ''}
|
||||
pictureUrl={fieldValue?.avatarUrl ?? ''}
|
||||
/>
|
||||
);
|
||||
}
|
||||
case Entity.Company: {
|
||||
return (
|
||||
<CompanyChip
|
||||
id={fieldValue?.id ?? ''}
|
||||
name={fieldValue?.name ?? ''}
|
||||
pictureUrl={
|
||||
fieldValue?.domainName
|
||||
? getLogoUrlFromDomainName(fieldValue.domainName)
|
||||
: ''
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
default:
|
||||
logError(
|
||||
`Unknown relation type: "${fieldDefinition.metadata.relationType}"
|
||||
in RelationFieldDisplay`,
|
||||
);
|
||||
return <> </>;
|
||||
const { fieldValue, fieldDefinition } = useRelationField();
|
||||
const { entityChipDisplayMapper } = fieldDefinition;
|
||||
if (!entityChipDisplayMapper) {
|
||||
throw new Error(
|
||||
"Missing entityChipDisplayMapper in FieldContext. Please provide it in the FieldContextProvider's value prop.",
|
||||
);
|
||||
}
|
||||
const { name, pictureUrl, avatarType } =
|
||||
entityChipDisplayMapper?.(fieldValue);
|
||||
|
||||
return (
|
||||
<EntityChip
|
||||
entityId={fieldValue?.id}
|
||||
name={name}
|
||||
pictureUrl={pictureUrl}
|
||||
avatarType={avatarType}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { IconComponent } from '@/ui/icon/types/IconComponent';
|
||||
import { AvatarType } from '@/users/components/Avatar';
|
||||
|
||||
import { FieldMetadata } from './FieldMetadata';
|
||||
import { FieldType } from './FieldType';
|
||||
@ -12,4 +13,9 @@ export type FieldDefinition<T extends FieldMetadata> = {
|
||||
buttonIcon?: IconComponent;
|
||||
basePathToShowPage?: string;
|
||||
infoTooltipContent?: string;
|
||||
entityChipDisplayMapper?: (dataObject: any) => {
|
||||
name: string;
|
||||
pictureUrl?: string;
|
||||
avatarType: AvatarType;
|
||||
};
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user