eugenegujing opened a new pull request, #9425:
URL: https://github.com/apache/texera/pull/9425

   ### What changes were proposed in this PR?
   
   A link in an agent chat message opened in the workflow tab, so one click 
replaced the editor with the linked page. The chat renders each message with 
`<markdown>`, and the rendered `<a>` had no `target`.
   
   Links in a chat message now open in a new tab.
   
   - `agent-chat.component.html` binds the `ready` output of the message's 
`<markdown>` to a new `openLinksInNewTab` handler. `ready` fires after every 
render, so a message that is rendered again with new text is handled again.
   - The handler sets `target="_blank"` and `rel="noopener noreferrer"` on 
every link that resolves to an http or https address. That covers links to 
other sites, bare URLs that markdown turns into links, and also anchors, links 
without a protocol, absolute paths and full links to the app. A rendered link 
is not a router link and the app has `<base href="/">`, so each of those would 
load another page of the app in the editor's tab (`#summary` resolves to the 
app root).
   - Links with another scheme, such as `mailto:`, and links whose address 
cannot be parsed are left as they were.
   - A `target` or `rel` the link already carried is replaced, so a message 
cannot keep `rel="opener"`.
   
   The change is local to chat messages. The other markdown views (the Form 
View instructions, the dataset file preview, the dataset, model and hub 
workflow descriptions, and the system prompt tab of the agent's info dialog) 
render links the same way and are not changed here. They are a possible 
follow-up.
   
   Before (`main`). The agent's answer holds a link to a documentation page. 
Clicking it loads the documentation in the same tab, so the editor and the 
conversation are gone.
   
   | Before the click | After the click, the same tab |
   |---|---|
   | <img width="1510" height="951" alt="links-1-main-before-click" 
src="https://github.com/user-attachments/assets/3ff9ec8d-6b27-465c-a2bf-470685135eb6";
 /> | <img width="1512" height="950" 
alt="links-2-main-after-click-same-tab-is-docs" 
src="https://github.com/user-attachments/assets/6625ca15-16e1-46f5-9abf-63b456a0b4a6";
 />|
   
   After (this PR). The same click on the same conversation opens the 
documentation in a second tab. The editor's tab stays as it was.
   
   <img width="1507" height="852" 
alt="links-3-this-pr-after-click-docs-in-new-tab" 
src="https://github.com/user-attachments/assets/c188be2b-563b-478d-a720-b4bd9acbe93a";
 />
   
   
   ### Any related issues, documentation, discussions?
   
   Closes #9422.
   
   ### How was this PR tested?
   
   `cd frontend && NODE_OPTIONS="--no-experimental-webstorage" npx ng test 
--watch=false --include 
src/app/workspace/component/agent/agent-panel/agent-chat/agent-chat.component.spec.ts`:
 67 passed (52 before this PR). The 15 new tests render real messages through 
`<markdown>` and read the resulting links.
   
   - A link to another site over https and over http, a protocol-relative link 
and a bare URL open in a new tab with `rel="noopener noreferrer"`.
   - An anchor, a link with an empty address, a link without a protocol, an 
absolute path, a full link to the app and a link to the same host on another 
port open in a new tab as well.
   - A `mailto:` link, a `javascript:` link (which Angular has already 
rewritten to `unsafe:javascript:`) and a link whose address cannot be parsed 
are untouched.
   - A `target` and `rel` already on a link are replaced.
   - A message without links renders as before. Several links in one message 
are each judged on their own, and so are links in every message of a 
conversation and in a message the user typed.
   - A message rendered again gets its new link handled, and a link that 
becomes a `mailto:` link loses the new-tab marks.
   
   Also `agent-panel.component.spec.ts` (49 passed), which renders the chat 
inside the panel, `npx prettier --check` and `npx eslint` on the three touched 
files, and `npx tsc --noEmit -p src/tsconfig.app.json`. Four mutants were each 
caught by a test: an unparsable address treated as a link, every scheme treated 
as a web link, a link with an empty address skipped, and `rel` extended instead 
of replaced.
   
   Live check on a local stack with the frontend served from this branch. One 
typed message held an anchor link, an absolute path, a `mailto:` link and a 
bare `http://localhost:8080` URL, and the agent's answer held a link to a 
documentation page. In the rendered chat every link except the `mailto:` one 
had `target="_blank"` and `rel="noopener noreferrer"`. Clicking the anchor link 
left the workflow editor and the conversation in place, where before the same 
click loaded the app root in the editor's tab.
   
   ### Was this PR authored or co-authored using generative AI tooling?
   
   Yes. Generated-by: Claude Code (claude-fable-5-2). Co-authored with Claude; 
the author reviewed the change before submission.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to