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

Update Attachment Table on RICH_TEXT Field Edits (#6565) #7617

Closed
wants to merge 2 commits into from

Conversation

yadavshubham01
Copy link
Contributor

i implements a feature that ensures the attachment table is updated whenever new images are added to a RICH_TEXT field. This enhancement improves the data consistency and integrity of our application's file management system, ensuring that all relevant attachments are correctly linked to their respective entries.

Changes Made:
Image Handling Logic :-
Modified the existing functionality for handling image uploads within the RICH_TEXT field.
Implemented a mechanism to detect when new images are added to the RICH_TEXT content.
Attachment Table Update :-
Added a function that updates the attachment table with the details of newly added images.
Each image upload will now trigger an insert operation in the attachment table, including fields such as fileId, fileName, and fileUrl.
Integration with GraphQL :--
Updated the relevant GraphQL mutations to support the addition of attachments in conjunction with RICH_TEXT field edits.
Ensured proper error handling and logging for failed uploads or attachment inserts.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This pull request implements a feature to update the attachment table when new images are added to RICH_TEXT fields, enhancing data consistency in the application's file management system.

  • Added new 'AddAttachment' mutation in packages/twenty-front/src/generated/graphql.tsx for creating attachment records
  • Updated RichTextEditor component in packages/twenty-front/src/modules/activities/components/RichTextEditor.tsx to handle image uploads and update attachment table
  • Modified UPLOAD_FILE mutation in packages/twenty-front/src/modules/attachments/graphql/queries/uploadFile.ts to return file id and url
  • Added ADD_ATTACHMENT mutation in uploadFile.ts to create attachment records with file details

3 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines 141 to 147
if (!uploadedFileData) {
throw new Error("Couldn't upload Image");
}

if (!result?.data?.uploadFile) {
throw new Error("Couldn't upload Image");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: This check is redundant as it's already covered by the previous condition.

Copy link
Member

@charlesBochet charlesBochet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting one, thanks for raising it @yadavshubham01

Here are my thought on this one:

  1. Product behavior: I agree it would be great to store uploaded files as attachments @Bonapara @FelixMalfait what do you think of the product behavior
  2. Eng strategy: we are doing it in two calls: uploadFile, then addAttachment. These two calls belong to the same atomic operations and I would prefer having only one uploadAttachment customResolver doing both. However, taking the look at useUploadAttachment (which is used on Files tab), I can see we are already doing two calls there so I guess we can keep doing it
  3. Could we try to re-use useUploadAttachment logic instead?
  4. In your PR I don't see the code for addAttachment custom resolver, but with 3 in mind I could prefer that we reuse useUploadAttachment which is doing createAttachment

Putting this on hold the time to get an answer from Product on this

@yadavshubham01
Copy link
Contributor Author

Hey @charlesBochet ,
Thanks you for your feedback

@FelixMalfait
Copy link
Member

FelixMalfait commented Oct 14, 2024

@charlesBochet yes this is the right product behavior, here's the related issue: #6565

@charlesBochet
Copy link
Member

Ok @yadavshubham01, could you re-use the useUploadAttachment hook in this case?

@yadavshubham01
Copy link
Contributor Author

hey @charlesBochet Is there anything wrong in this PR and i don't understand re-use of useUploadAttachment hook

@yadavshubham01
Copy link
Contributor Author

hey @charlesBochet i just create new PR #7690 that re-use the useUploadAttachment hook in this case

@charlesBochet
Copy link
Member

Ok, perfect, closing this one

lucasbordeau added a commit that referenced this pull request Nov 5, 2024
Reusing the useUploadAttachment Hook

In the implementation of the feature to ensure the attachment table is
updated whenever new images are added to a RICH_TEXT field #7617 , it is
likely that the useUploadAttachment hook is reused.

The useUploadAttachment hook is responsible for handling the upload of
attachments, including images, and returning the uploaded file URL. By
reusing this hook, you can leverage its existing functionality to handle
image uploads within the RICH_TEXT field.

In this case, the modified image handling logic would utilize the
useUploadAttachment hook to upload new images added to the RICH_TEXT
content. The hook would then return the uploaded file URL, which would
be used to update the attachment table with the details of the newly
added images.

By reusing the useUploadAttachment hook, you can avoid duplicating code
and ensure consistency in the way attachments are handled throughout the
application.

Fixes #6565

---------

Co-authored-by: Charles Bochet <[email protected]>
Co-authored-by: Lucas Bordeau <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants