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

[front] - chore(InputBar): prettified url pasting #11416

Merged
merged 7 commits into from
Mar 18, 2025

Conversation

JulesBelveze
Copy link
Contributor

@JulesBelveze JulesBelveze commented Mar 17, 2025

Description

This PR implements a custom node extension for rendering data source links in the input bar editor. When a user pastes a URL that corresponds to a data source node, the URL is transformed into a Chip component.

The solution leverages Tiptap's ReactNodeViewRenderer to bridge ProseMirror's document model with React components. This allows us to maintain proper document structure.

  1. Created a custom node extension (DataSourceLinkExtension) that defines how data source links are represented in the editor document model

    • Stores essential metadata like nodeId, title, provider, and spaceId
    • Uses Tiptap's atom node pattern for atomic UI elements
  2. Implemented a React component (DataSourceLinkComponent) that renders the data source link

    • Uses Sparkle's Chip component for consistent UI
    • Dynamically displays the connector icon based on provider type
  3. Updated URL handler logic to transform detected URLs into data source link nodes

    • Simplified code by removing manual text formatting
    • Improved maintainability by using structured nodes instead of plain text

This implementation follows the same pattern used for mentions in the editor, ensuring consistency across the codebase. The custom node approach provides better semantics, styling control, and future extensibility compared to plain text replacement.

Risk

Low, behind FF

Deploy Plan

Deploy front

@JulesBelveze JulesBelveze changed the title [front] - chore(InputBar [front] - chore(InputBar): prettified url pasting Mar 17, 2025
…ource link components for the editor

 - Added 'DataSourceLinkComponent' to render data source links with icons in the input bar editor
 - Implemented 'DataSourceLinkExtension' for tiptap editor, enabling inline data source linking within text editor
…urceLinkExtension into custom editor

 - Added DataSourceLinkExtension to the list of extensions in useCustomEditor to handle data source links
 - Simplified useUrlHandler hook to directly insert dataSourceLink nodes upon selection of a node
 - Simplified the markup of DataSourceLinkComponent for clarity
 - Adjusted Chip component usage with icon and smaller size "xs"
 - Ensure compatibility with the latest features and bug fixes in the @dust-tt/sparkle library
 - Maintain integrity and stable functionality within the project dependencies
…itor hook

 - Remove duplicate DataSourceLinkExtension import in useCustomEditor.tsx
 - Add a missing dependency to useEffect in OAuth finalize page

[front/components] - style: add whitespace for better readability in extensions

 - Insert a blank line for visual separation in DataSourceLinkExtension.ts and useUrlHandler.tsx
…ip text is readable

 - Added `color="white"` to `Chip` component to improve text visibility against varying backgrounds
@JulesBelveze JulesBelveze force-pushed the front/url-pasting-custom-node branch from 6d76009 to 6a7a8b6 Compare March 17, 2025 16:20
@JulesBelveze
Copy link
Contributor Author

Note: the last step will be to add wrapping whitespaces where needed.

Copy link
Contributor

@philipperolet philipperolet left a comment

Choose a reason for hiding this comment

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

Looks good :) a few questions:

  • is there a way for the user to go back to the URL?
  • is the URL still rendered when the message is submitted? (notably mentioned to the model)
    Second point is quite important, here we want to make sure the model has a message in which what it sees is consistent with what is attached. So I would say don't render the URL, render the doc's title + maybe content fragment id in some way)

Also, in general for UX-related PRs, screenshots in the description go a long way

@JulesBelveze
Copy link
Contributor Author

is there a way for the user to go back to the URL?

Currently no, is that something we want?

Also, in general for UX-related PRs, screenshots in the description go a long way

My bad, though I added it. Here you go:

Screenshot 2025-03-18 at 11 38 49

is the URL still rendered when the message is submitted?

For now when the message is submitted, the "Chip" goes away. But the intent is to have to persist as it is rendered in the InputBar.

@JulesBelveze
Copy link
Contributor Author

@philipperolet Lemme know what you think would be nice here and I'll update it.
Will add the chip persisting in a separate PR 👌🏼

@philipperolet philipperolet self-requested a review March 18, 2025 11:25
Copy link
Contributor

@philipperolet philipperolet left a comment

Choose a reason for hiding this comment

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

LGTM; ccing @Duncid @pinotalexandre for chip / mention design => how do we want the "pasted url" to look once recognized as one of our knowledge?

As for the ability to remove the mention and get back to a url, I think we can skip --- very edge casy IMO, wdyt design?

Or, we could turn the mention back to an url if the user deletes the related attachment?

@philipperolet philipperolet self-requested a review March 18, 2025 11:28
@philipperolet
Copy link
Contributor

is there a way for the user to go back to the URL?

Currently no, is that something we want?

Also, in general for UX-related PRs, screenshots in the description go a long way

My bad, though I added it. Here you go:

Screenshot 2025-03-18 at 11 38 49 > is the URL still rendered when the message is submitted?

For now when the message is submitted, the "Chip" goes away. But the intent is to have to persist as it is rendered in the InputBar.

here is the current design @Duncid @pinotalexandre

@Duncid
Copy link
Contributor

Duncid commented Mar 18, 2025

@JulesBelveze I think we can remove the Google Drive Icon given that it is in the top bar attachement. Will make it look better.

@pinotalexandre
Copy link
Collaborator

is there a way for the user to go back to the URL?
In which case it could be usefull?

Globally looking good!
We can also set a width limit (the same as the attachement) to avoid too long mention like this :
image

@pinotalexandre
Copy link
Collaborator

"Bug" spotted :
Also, if pasting twice the same link, It will add 2 times the file as attachement

@pinotalexandre
Copy link
Collaborator

If deleting the attachements and then repasting the link, the attachement is not displayed anymore

…: simplify DataSourceLinkComponent

 - Remove provider-specific icon from DataSourceLink chip display
 - Rely on default Chip component styling without custom icons
@JulesBelveze JulesBelveze merged commit 236d548 into main Mar 18, 2025
6 checks passed
@JulesBelveze JulesBelveze deleted the front/url-pasting-custom-node branch March 18, 2025 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants