Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relation selection is broken on Activity in create state #6035

Open
ijreilly opened this issue Jun 26, 2024 · 1 comment
Open

Relation selection is broken on Activity in create state #6035

ijreilly opened this issue Jun 26, 2024 · 1 comment

Comments

@ijreilly
Copy link
Contributor

Scope & Context

https://github.com/twentyhq/twenty/assets/51697796/7d095d3a-0b8a-4f1e-a439-d11f10852db0
(To reproduce, we must be in create mode, meaning not have given a title nor description to the task)

Technical inputs

The relations are well persisted in the DB but disappearing from the cache. We may need to update the cache ourselves.

Copy link

greptile-apps bot commented Jun 26, 2024

To fix the relation selection issue in create state for Activity, follow these steps:

  1. Locate Cache Update Logic: Open src/components/ActivityEditorEffect.tsx and src/components/ActivityBodyEditor.tsx.

  2. Update Cache on Create: In src/hooks/useCreateActivityInCache.ts, ensure the cache is updated when a new activity is created. Add logic to update relations in the cache.

// src/hooks/useCreateActivityInCache.ts
import { useQueryClient } from 'react-query';

const useCreateActivityInCache = () => {
  const queryClient = useQueryClient();

  const updateCache = (newActivity) => {
    queryClient.setQueryData(['activities'], (oldData) => {
      return {
        ...oldData,
        activities: [...oldData.activities, newActivity],
      };
    });
    // Add logic to update relations in the cache
    queryClient.setQueryData(['relations'], (oldData) => {
      return {
        ...oldData,
        relations: [...oldData.relations, ...newActivity.relations],
      };
    });
  };

  return { updateCache };
};

export default useCreateActivityInCache;
  1. Ensure Cache Consistency: In src/components/ActivityEditorFields.tsx, ensure that the relations are correctly passed and updated in the cache when the activity is created.
// src/components/ActivityEditorFields.tsx
import useCreateActivityInCache from 'src/hooks/useCreateActivityInCache';

const ActivityEditorFields = () => {
  const { updateCache } = useCreateActivityInCache();

  const handleCreateActivity = (newActivity) => {
    // Your existing logic to create activity
    updateCache(newActivity);
  };

  return (
    // Your component JSX
  );
};

export default ActivityEditorFields;

References

Edit Issue Bot Settings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🆕 New
Development

No branches or pull requests

1 participant