Add workspace favorites behind feature flag (#6904)
- make member nullable on favorites - add potential relation with view entity - add a new type of favorite list in front : workspace favorite - build a new component for retrieving workspace favorite to display + refacto the existing one Bonus: - removing activities seed since this is deprecated
This commit is contained in:
@ -0,0 +1,48 @@
|
||||
import { Favorite } from '@/favorites/types/Favorite';
|
||||
import { FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem';
|
||||
import { ObjectRecordIdentifier } from '@/object-record/types/ObjectRecordIdentifier';
|
||||
import { isDefined } from 'twenty-ui';
|
||||
|
||||
export const sortFavorites = (
|
||||
favorites: Favorite[],
|
||||
favoriteRelationFieldMetadataItems: FieldMetadataItem[],
|
||||
getObjectRecordIdentifierByNameSingular: (
|
||||
record: any,
|
||||
objectNameSingular: string,
|
||||
) => ObjectRecordIdentifier,
|
||||
hasLinkToShowPage: boolean,
|
||||
) => {
|
||||
return favorites
|
||||
.map((favorite) => {
|
||||
for (const relationField of favoriteRelationFieldMetadataItems) {
|
||||
if (isDefined(favorite[relationField.name])) {
|
||||
const relationObject = favorite[relationField.name];
|
||||
|
||||
const relationObjectNameSingular =
|
||||
relationField.toRelationMetadata?.fromObjectMetadata.nameSingular ??
|
||||
'';
|
||||
|
||||
const objectRecordIdentifier =
|
||||
getObjectRecordIdentifierByNameSingular(
|
||||
relationObject,
|
||||
relationObjectNameSingular,
|
||||
);
|
||||
|
||||
return {
|
||||
id: favorite.id,
|
||||
recordId: objectRecordIdentifier.id,
|
||||
position: favorite.position,
|
||||
avatarType: objectRecordIdentifier.avatarType,
|
||||
avatarUrl: objectRecordIdentifier.avatarUrl,
|
||||
labelIdentifier: objectRecordIdentifier.name,
|
||||
link: hasLinkToShowPage
|
||||
? objectRecordIdentifier.linkToShowPage
|
||||
: '',
|
||||
} as Favorite;
|
||||
}
|
||||
}
|
||||
|
||||
return favorite;
|
||||
})
|
||||
.sort((a, b) => a.position - b.position);
|
||||
};
|
||||
Reference in New Issue
Block a user