Solves #16015
- Added a check in `useTimelineActivities.ts` to see if the system
object page we're viewing has timelineActivity being tracked before
querying to get the activity history.
- Removed @WorkspaceIsObjectUIReadOnly decorator from system objects and
added @WorkspaceIsFieldUIReadOnly to standard and system fields to allow
custom field edits as requested in the issue.
- Did not add calendarEvents or other system objects to timelineActivity
just yet since keeping track of timeline activity for every one of them
felt counter-intuitive and bloated. In order to determine which objects
need timelineActivity, I think we need to fix the broken views of system
objects first, such as the one in the attached screenshots - a good
number of them are broken. The check I added to
`useTimelineActivities.ts` hook displays timeline activity as empty for
the time - error would not be shown as suggested by Thomas.
<img width="1062" height="858" alt="image"
src="https://github.com/user-attachments/assets/e877e0fe-b665-46e3-b785-e84f2af7f833"
/>
<br />
<img width="1061" height="858" alt="image"
src="https://github.com/user-attachments/assets/0eba8c1c-444a-4b13-beda-64b95cf39077"
/>
- Editing custom fields on calendar events (and other objects without
position fields) crashed with TypeError: Cannot convert undefined or
null to object in sortCachedObjectEdges. This happened because some
cached queries had empty orderBy arrays ([]), and the optimistic effect
tried to sort with them. Objects without position fields returned
empty orderBy arrays when there were no sorts, while objects with
position fields automatically got [{ position: 'AscNullsFirst' }].
The backend always adds { id: 'AscNullsFirst' } as a fallback, but
the frontend didn't match this. So, I added { id: 'AscNullsFirst' } to
the Frontend as default orderBy when there are no sorts and no position
field.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Apply per-field UI read-only to system/standard fields and skip
timeline activity fetching when the target object isn’t related; refine
record-table cell open/navigation behavior.
>
> - Server: Replace object-level UI read-only with per-field
`isUIReadOnly` across many standard objects (e.g., `calendarEvent`,
`workspaceMember`, messaging, calendar, favorites, attachments,
workflows, etc.), and mirror this via `@WorkspaceIsFieldUIReadOnly` on
workspace entities.
> - Frontend: In `useTimelineActivities.ts`, check object metadata for a
relation to `timelineActivity` and `skip` the query when absent,
preventing errors on system object pages.
> - Frontend: Simplify/adjust record-table cell logic—remove unused
args, allow navigation from first column when non-empty, block editing
for read-only records (while still allowing navigation), and update
button handlers/hover styles accordingly.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
dac1262d70. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Félix Malfait <felix@twenty.com>
120 lines
5.0 KiB
TypeScript
120 lines
5.0 KiB
TypeScript
import { msg } from '@lingui/core/macro';
|
|
import { STANDARD_OBJECT_IDS } from 'twenty-shared/metadata';
|
|
import { RelationOnDeleteAction } from 'twenty-shared/types';
|
|
|
|
import { RelationType } from 'src/engine/metadata-modules/field-metadata/interfaces/relation-type.interface';
|
|
import { Relation } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/relation.interface';
|
|
|
|
import { BaseWorkspaceEntity } from 'src/engine/twenty-orm/base.workspace-entity';
|
|
import { CustomWorkspaceEntity } from 'src/engine/twenty-orm/custom.workspace-entity';
|
|
import { WorkspaceDynamicRelation } from 'src/engine/twenty-orm/decorators/workspace-dynamic-relation.decorator';
|
|
import { WorkspaceEntity } from 'src/engine/twenty-orm/decorators/workspace-entity.decorator';
|
|
import { WorkspaceIsFieldUIReadOnly } from 'src/engine/twenty-orm/decorators/workspace-is-field-ui-readonly.decorator';
|
|
import { WorkspaceIsNullable } from 'src/engine/twenty-orm/decorators/workspace-is-nullable.decorator';
|
|
import { WorkspaceIsSystem } from 'src/engine/twenty-orm/decorators/workspace-is-system.decorator';
|
|
import { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator';
|
|
import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-relation.decorator';
|
|
import { NOTE_TARGET_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
|
|
import { STANDARD_OBJECT_ICONS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-icons';
|
|
import { CompanyWorkspaceEntity } from 'src/modules/company/standard-objects/company.workspace-entity';
|
|
import { NoteWorkspaceEntity } from 'src/modules/note/standard-objects/note.workspace-entity';
|
|
import { OpportunityWorkspaceEntity } from 'src/modules/opportunity/standard-objects/opportunity.workspace-entity';
|
|
import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/person.workspace-entity';
|
|
|
|
@WorkspaceEntity({
|
|
standardId: STANDARD_OBJECT_IDS.noteTarget,
|
|
|
|
namePlural: 'noteTargets',
|
|
labelSingular: msg`Note Target`,
|
|
labelPlural: msg`Note Targets`,
|
|
description: msg`A note target`,
|
|
icon: STANDARD_OBJECT_ICONS.noteTarget,
|
|
})
|
|
@WorkspaceIsSystem()
|
|
export class NoteTargetWorkspaceEntity extends BaseWorkspaceEntity {
|
|
@WorkspaceRelation({
|
|
standardId: NOTE_TARGET_STANDARD_FIELD_IDS.note,
|
|
type: RelationType.MANY_TO_ONE,
|
|
label: msg`Note`,
|
|
description: msg`NoteTarget note`,
|
|
icon: 'IconNotes',
|
|
inverseSideTarget: () => NoteWorkspaceEntity,
|
|
inverseSideFieldKey: 'noteTargets',
|
|
onDelete: RelationOnDeleteAction.SET_NULL,
|
|
})
|
|
@WorkspaceIsFieldUIReadOnly()
|
|
@WorkspaceIsNullable()
|
|
note: Relation<NoteWorkspaceEntity> | null;
|
|
|
|
@WorkspaceJoinColumn('note')
|
|
noteId: string | null;
|
|
|
|
@WorkspaceRelation({
|
|
standardId: NOTE_TARGET_STANDARD_FIELD_IDS.person,
|
|
type: RelationType.MANY_TO_ONE,
|
|
label: msg`Person`,
|
|
description: msg`NoteTarget person`,
|
|
icon: 'IconUser',
|
|
inverseSideTarget: () => PersonWorkspaceEntity,
|
|
inverseSideFieldKey: 'noteTargets',
|
|
onDelete: RelationOnDeleteAction.CASCADE,
|
|
})
|
|
@WorkspaceIsFieldUIReadOnly()
|
|
@WorkspaceIsNullable()
|
|
person: Relation<PersonWorkspaceEntity> | null;
|
|
|
|
@WorkspaceJoinColumn('person')
|
|
personId: string | null;
|
|
|
|
@WorkspaceRelation({
|
|
standardId: NOTE_TARGET_STANDARD_FIELD_IDS.company,
|
|
type: RelationType.MANY_TO_ONE,
|
|
label: msg`Company`,
|
|
description: msg`NoteTarget company`,
|
|
icon: 'IconBuildingSkyscraper',
|
|
inverseSideTarget: () => CompanyWorkspaceEntity,
|
|
inverseSideFieldKey: 'noteTargets',
|
|
onDelete: RelationOnDeleteAction.CASCADE,
|
|
})
|
|
@WorkspaceIsFieldUIReadOnly()
|
|
@WorkspaceIsNullable()
|
|
company: Relation<CompanyWorkspaceEntity> | null;
|
|
|
|
@WorkspaceJoinColumn('company')
|
|
companyId: string | null;
|
|
|
|
@WorkspaceRelation({
|
|
standardId: NOTE_TARGET_STANDARD_FIELD_IDS.opportunity,
|
|
type: RelationType.MANY_TO_ONE,
|
|
label: msg`Opportunity`,
|
|
description: msg`NoteTarget opportunity`,
|
|
icon: 'IconTargetArrow',
|
|
inverseSideTarget: () => OpportunityWorkspaceEntity,
|
|
inverseSideFieldKey: 'noteTargets',
|
|
onDelete: RelationOnDeleteAction.CASCADE,
|
|
})
|
|
@WorkspaceIsFieldUIReadOnly()
|
|
@WorkspaceIsNullable()
|
|
opportunity: Relation<OpportunityWorkspaceEntity> | null;
|
|
|
|
@WorkspaceJoinColumn('opportunity')
|
|
opportunityId: string | null;
|
|
|
|
// todo: remove this decorator and the custom field
|
|
@WorkspaceDynamicRelation({
|
|
type: RelationType.MANY_TO_ONE,
|
|
argsFactory: (oppositeObjectMetadata) => ({
|
|
standardId: NOTE_TARGET_STANDARD_FIELD_IDS.custom,
|
|
name: oppositeObjectMetadata.nameSingular,
|
|
label: oppositeObjectMetadata.labelSingular,
|
|
description: `NoteTarget ${oppositeObjectMetadata.labelSingular}`,
|
|
joinColumn: `${oppositeObjectMetadata.nameSingular}Id`,
|
|
icon: 'IconBuildingSkyscraper',
|
|
}),
|
|
inverseSideTarget: () => CustomWorkspaceEntity,
|
|
inverseSideFieldKey: 'noteTargets',
|
|
onDelete: RelationOnDeleteAction.CASCADE,
|
|
})
|
|
custom: Relation<CustomWorkspaceEntity>;
|
|
}
|