twentyhq / twenty

Building a modern alternative to Salesforce, powered by the community.
https://twenty.com
GNU Affero General Public License v3.0
15.54k stars 1.63k forks source link

[Timebox] Custom Code Execution #6283

Open martmull opened 1 month ago

martmull commented 1 month ago
greptile-apps[bot] commented 1 month ago

To implement custom code execution, follow these steps:

  1. Identify the Hook or Component for Custom Code Execution:

    • For record handling, consider RecordTableWithWrappers.tsx located at /packages/twenty-front/src/modules/object-record/record-table/components/RecordTableWithWrappers.tsx.
    • For timeline activities, consider useTimelineActivities.ts located at /packages/twenty-front/src/modules/activities/timeline/hooks/useTimelineActivities.ts.
  2. Add Custom Code Execution Logic:

    • In RecordTableWithWrappers.tsx, you can add custom logic within the handleUpdate or handleDelete functions.
      const handleUpdate = useRecoilCallback(
      ({ set }) => async (recordId: string, fieldMetadata: FieldMetadata, value: any) => {
      // Custom code execution logic here
      console.log('Custom code execution before update');
      await updateRecordMutation({ recordId, fieldMetadata, value });
      set(RecordUpdateContext, { recordId, fieldMetadata, value });
      },
      [updateRecordMutation]
      );
    • In useTimelineActivities.ts, you can add custom logic within the useEffect or useFindManyRecords hooks.
      useEffect(() => {
      // Custom code execution logic here
      console.log('Custom code execution on targetable object change');
      set(objectShowPageTargetableObjectState, targetableObject);
      }, [targetableObject]);
  3. Ensure Proper State Management:

    • Use Recoil state management to ensure that the custom code execution does not interfere with existing state logic.
    • Example in useNavigationSection.ts located at /packages/twenty-front/src/modules/ui/navigation/navigation-drawer/hooks/useNavigationSection.ts.
      const { closeNavigationSection, openNavigationSection } = useNavigationSection(scopeId);
      // Custom code execution logic here
      console.log('Custom code execution in navigation section');

References

/packages/twenty-front/src/modules/object-record/record-table/components/RecordTableWithWrappers.tsx /packages/twenty-front/src/modules/activities/timeline/hooks/useTimelineActivities.ts /packages/twenty-server/src/engine/twenty-orm/decorators/workspace-is-not-audit-logged.decorator.ts /packages/twenty-server/src/modules/messaging/blocklist-manager/listeners/messaging-blocklist.listener.ts /packages/twenty-front/src/modules/object-record/record-filter/utils/isRecordMatchingFilter.ts /packages/twenty-server/src/engine/api/graphql/workspace-query-builder/factories/args-string.factory.ts /packages/twenty-server/src/engine/api/graphql/workspace-schema-storage/workspace-schema-storage.service.ts /packages/twenty-front/src/modules/ui/navigation/navigation-drawer/hooks/useNavigationSection.ts /packages/twenty-front/src/modules/object-record/record-field/hooks/useRecordFieldInput.ts /packages/twenty-server/src/engine/twenty-orm/twenty-orm.module.ts

#### About Greptile This response provides a starting point for your research, not a precise solution. Help us improve! Please leave a ๐Ÿ‘ if this is helpful and ๐Ÿ‘Ž if it is irrelevant. [Ask Greptile](https://app.greptile.com/chat/github/twentyhq/twenty/main) ยท [Edit Issue Bot Settings](https://app.greptile.com/apps/github)