mirror of
https://github.com/twentyhq/twenty.git
synced 2025-01-07 17:28:47 +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,
|
type: viewField.type,
|
||||||
metadata: viewField.metadata,
|
metadata: viewField.metadata,
|
||||||
buttonIcon: viewField.buttonIcon,
|
buttonIcon: viewField.buttonIcon,
|
||||||
|
entityChipDisplayMapper: viewField.entityChipDisplayMapper,
|
||||||
},
|
},
|
||||||
useUpdateEntityMutation: useUpdateOnePipelineProgressMutation,
|
useUpdateEntityMutation: useUpdateOnePipelineProgressMutation,
|
||||||
hotkeyScope: InlineCellHotkeyScope.InlineCell,
|
hotkeyScope: InlineCellHotkeyScope.InlineCell,
|
||||||
|
@ -25,6 +25,7 @@ import {
|
|||||||
IconUsers,
|
IconUsers,
|
||||||
} from '@/ui/icon/index';
|
} from '@/ui/icon/index';
|
||||||
import { Entity } from '@/ui/input/relation-picker/types/EntityTypeForSelect';
|
import { Entity } from '@/ui/input/relation-picker/types/EntityTypeForSelect';
|
||||||
|
import { User } from '~/generated/graphql';
|
||||||
|
|
||||||
export const companiesAvailableColumnDefinitions: ColumnDefinition<FieldMetadata>[] =
|
export const companiesAvailableColumnDefinitions: ColumnDefinition<FieldMetadata>[] =
|
||||||
[
|
[
|
||||||
@ -76,6 +77,13 @@ export const companiesAvailableColumnDefinitions: ColumnDefinition<FieldMetadata
|
|||||||
isVisible: true,
|
isVisible: true,
|
||||||
infoTooltipContent:
|
infoTooltipContent:
|
||||||
'Your team member responsible for managing the company account.',
|
'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>,
|
} satisfies ColumnDefinition<FieldRelationMetadata>,
|
||||||
{
|
{
|
||||||
key: 'createdAt',
|
key: 'createdAt',
|
||||||
|
@ -23,6 +23,8 @@ import {
|
|||||||
IconUser,
|
IconUser,
|
||||||
} from '@/ui/icon/index';
|
} from '@/ui/icon/index';
|
||||||
import { Entity } from '@/ui/input/relation-picker/types/EntityTypeForSelect';
|
import { Entity } from '@/ui/input/relation-picker/types/EntityTypeForSelect';
|
||||||
|
import { Company } from '~/generated/graphql';
|
||||||
|
import { getLogoUrlFromDomainName } from '~/utils';
|
||||||
|
|
||||||
export const peopleAvailableColumnDefinitions: ColumnDefinition<FieldMetadata>[] =
|
export const peopleAvailableColumnDefinitions: ColumnDefinition<FieldMetadata>[] =
|
||||||
[
|
[
|
||||||
@ -71,6 +73,13 @@ export const peopleAvailableColumnDefinitions: ColumnDefinition<FieldMetadata>[]
|
|||||||
relationType: Entity.Company,
|
relationType: Entity.Company,
|
||||||
},
|
},
|
||||||
infoTooltipContent: 'Contact’s company.',
|
infoTooltipContent: 'Contact’s company.',
|
||||||
|
entityChipDisplayMapper: (dataObject: Company) => {
|
||||||
|
return {
|
||||||
|
name: dataObject?.name,
|
||||||
|
pictureUrl: getLogoUrlFromDomainName(dataObject?.domainName),
|
||||||
|
avatarType: 'squared',
|
||||||
|
};
|
||||||
|
},
|
||||||
} satisfies ColumnDefinition<FieldRelationMetadata>,
|
} satisfies ColumnDefinition<FieldRelationMetadata>,
|
||||||
{
|
{
|
||||||
key: 'phone',
|
key: 'phone',
|
||||||
|
@ -14,6 +14,7 @@ import {
|
|||||||
IconUser,
|
IconUser,
|
||||||
} from '@/ui/icon';
|
} from '@/ui/icon';
|
||||||
import { Entity } from '@/ui/input/relation-picker/types/EntityTypeForSelect';
|
import { Entity } from '@/ui/input/relation-picker/types/EntityTypeForSelect';
|
||||||
|
import { Person } from '~/generated/graphql';
|
||||||
|
|
||||||
export const pipelineAvailableFieldDefinitions: BoardFieldDefinition<FieldMetadata>[] =
|
export const pipelineAvailableFieldDefinitions: BoardFieldDefinition<FieldMetadata>[] =
|
||||||
[
|
[
|
||||||
@ -70,5 +71,12 @@ export const pipelineAvailableFieldDefinitions: BoardFieldDefinition<FieldMetada
|
|||||||
isVisible: true,
|
isVisible: true,
|
||||||
buttonIcon: IconPencil,
|
buttonIcon: IconPencil,
|
||||||
infoTooltipContent: 'Primary contact within the company.',
|
infoTooltipContent: 'Primary contact within the company.',
|
||||||
|
entityChipDisplayMapper: (dataObject: Person) => {
|
||||||
|
return {
|
||||||
|
name: dataObject?.displayName,
|
||||||
|
pictureUrl: dataObject?.avatarUrl ?? undefined,
|
||||||
|
avatarType: 'rounded',
|
||||||
|
};
|
||||||
|
},
|
||||||
} satisfies BoardFieldDefinition<FieldRelationMetadata>,
|
} satisfies BoardFieldDefinition<FieldRelationMetadata>,
|
||||||
];
|
];
|
||||||
|
@ -1,52 +1,24 @@
|
|||||||
import { CompanyChip } from '@/companies/components/CompanyChip';
|
import { EntityChip } from '@/ui/chip/components/EntityChip';
|
||||||
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 { useRelationField } from '../../hooks/useRelationField';
|
import { useRelationField } from '../../hooks/useRelationField';
|
||||||
|
|
||||||
export const RelationFieldDisplay = () => {
|
export const RelationFieldDisplay = () => {
|
||||||
const { fieldDefinition, fieldValue } = useRelationField();
|
const { fieldValue, fieldDefinition } = useRelationField();
|
||||||
|
const { entityChipDisplayMapper } = fieldDefinition;
|
||||||
switch (fieldDefinition.metadata.relationType) {
|
if (!entityChipDisplayMapper) {
|
||||||
case Entity.Person: {
|
throw new Error(
|
||||||
return (
|
"Missing entityChipDisplayMapper in FieldContext. Please provide it in the FieldContextProvider's value prop.",
|
||||||
<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 { 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 { IconComponent } from '@/ui/icon/types/IconComponent';
|
||||||
|
import { AvatarType } from '@/users/components/Avatar';
|
||||||
|
|
||||||
import { FieldMetadata } from './FieldMetadata';
|
import { FieldMetadata } from './FieldMetadata';
|
||||||
import { FieldType } from './FieldType';
|
import { FieldType } from './FieldType';
|
||||||
@ -12,4 +13,9 @@ export type FieldDefinition<T extends FieldMetadata> = {
|
|||||||
buttonIcon?: IconComponent;
|
buttonIcon?: IconComponent;
|
||||||
basePathToShowPage?: string;
|
basePathToShowPage?: string;
|
||||||
infoTooltipContent?: string;
|
infoTooltipContent?: string;
|
||||||
|
entityChipDisplayMapper?: (dataObject: any) => {
|
||||||
|
name: string;
|
||||||
|
pictureUrl?: string;
|
||||||
|
avatarType: AvatarType;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user