Feat/activities custom objects (#3213)
* WIP * WIP - MultiObjectSearch * WIP * WIP * Finished working version * Fix * Fixed and cleaned * Fix * Disabled files and emails for custom objects * Cleaned console.log * Fixed attachment * Fixed * fix lint --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -1,40 +1,41 @@
|
||||
import { ActivityTargetableEntity } from '@/activities/types/ActivityTargetableEntity';
|
||||
import { getTargetableEntitiesWithParents } from '@/activities/utils/getTargetableEntitiesWithParents';
|
||||
import { ActivityTargetableObject } from '@/activities/types/ActivityTargetableEntity';
|
||||
import { flattenTargetableObjectsAndTheirRelatedTargetableObjects } from '@/activities/utils/flattenTargetableObjectsAndTheirRelatedTargetableObjects';
|
||||
|
||||
describe('getTargetableEntitiesWithParents', () => {
|
||||
it('should return the correct value', () => {
|
||||
const entities: ActivityTargetableEntity[] = [
|
||||
const entities: ActivityTargetableObject[] = [
|
||||
{
|
||||
id: '1',
|
||||
type: 'Person',
|
||||
relatedEntities: [
|
||||
targetObjectNameSingular: 'person',
|
||||
relatedTargetableObjects: [
|
||||
{
|
||||
id: '2',
|
||||
type: 'Company',
|
||||
targetObjectNameSingular: 'company',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: '4',
|
||||
type: 'Company',
|
||||
targetObjectNameSingular: 'person',
|
||||
},
|
||||
{
|
||||
id: '3',
|
||||
type: 'Custom',
|
||||
relatedEntities: [
|
||||
targetObjectNameSingular: 'car',
|
||||
relatedTargetableObjects: [
|
||||
{
|
||||
id: '6',
|
||||
type: 'Person',
|
||||
targetObjectNameSingular: 'person',
|
||||
},
|
||||
{
|
||||
id: '5',
|
||||
type: 'Company',
|
||||
targetObjectNameSingular: 'company',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const res = getTargetableEntitiesWithParents(entities);
|
||||
const res =
|
||||
flattenTargetableObjectsAndTheirRelatedTargetableObjects(entities);
|
||||
|
||||
expect(res).toHaveLength(6);
|
||||
expect(res[0].id).toBe('1');
|
||||
|
||||
@ -0,0 +1,21 @@
|
||||
import { ActivityTargetableObject } from '../types/ActivityTargetableEntity';
|
||||
|
||||
export const flattenTargetableObjectsAndTheirRelatedTargetableObjects = (
|
||||
targetableObjectsWithRelatedTargetableObjects: ActivityTargetableObject[],
|
||||
): ActivityTargetableObject[] => {
|
||||
const flattenedTargetableObjects: ActivityTargetableObject[] = [];
|
||||
|
||||
for (const targetableObject of targetableObjectsWithRelatedTargetableObjects ??
|
||||
[]) {
|
||||
flattenedTargetableObjects.push(targetableObject);
|
||||
|
||||
if (targetableObject.relatedTargetableObjects) {
|
||||
for (const relatedEntity of targetableObject.relatedTargetableObjects ??
|
||||
[]) {
|
||||
flattenedTargetableObjects.push(relatedEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return flattenedTargetableObjects;
|
||||
};
|
||||
@ -0,0 +1,15 @@
|
||||
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
|
||||
|
||||
export const getActivityTargetObjectFieldIdName = ({
|
||||
nameSingular,
|
||||
}: {
|
||||
nameSingular: string;
|
||||
}) => {
|
||||
const isCoreObject =
|
||||
nameSingular === CoreObjectNameSingular.Company ||
|
||||
nameSingular === CoreObjectNameSingular.Person;
|
||||
|
||||
const objectFieldIdName = `${!isCoreObject ? '_' : ''}${nameSingular}Id`;
|
||||
|
||||
return objectFieldIdName;
|
||||
};
|
||||
@ -1,16 +0,0 @@
|
||||
import { ActivityTargetableEntity } from '../types/ActivityTargetableEntity';
|
||||
|
||||
export const getTargetableEntitiesWithParents = (
|
||||
entities: ActivityTargetableEntity[],
|
||||
): ActivityTargetableEntity[] => {
|
||||
const entitiesWithRelations: ActivityTargetableEntity[] = [];
|
||||
for (const entity of entities ?? []) {
|
||||
entitiesWithRelations.push(entity);
|
||||
if (entity.relatedEntities) {
|
||||
for (const relatedEntity of entity.relatedEntities ?? []) {
|
||||
entitiesWithRelations.push(relatedEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
return entitiesWithRelations;
|
||||
};
|
||||
Reference in New Issue
Block a user