feat: Display viz in Artifact panel#16499
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
Your preview environment pr-16499 has been deployed with errors. Preview environment endpoints are available at: |
7e918de to
62b8f0f
Compare
62b8f0f to
903dba1
Compare
903dba1 to
199bb6a
Compare
5bf7fb3 to
ddd669e
Compare
199bb6a to
5b795da
Compare
5b795da to
9cdca7a
Compare
...ages/frontend/src/ee/features/aiCopilot/components/ChatElements/AgentChatAssistantBubble.tsx
Outdated
Show resolved
Hide resolved
...ages/frontend/src/ee/features/aiCopilot/components/ChatElements/AgentChatAssistantBubble.tsx
Outdated
Show resolved
Hide resolved
| </Paper> | ||
| <AiArtifactButton | ||
| onClick={() => | ||
| setArtifact(renderArtifact(), message.uuid) |
There was a problem hiding this comment.
we will use artifact uuid once we have the backend in place, and we could move this logic to a new place, where we can make the queries from that component instead of passing everything here?
ddd669e to
5ecd1a0
Compare
9cdca7a to
627591e
Compare
5ecd1a0 to
37d1fd2
Compare
627591e to
afab005
Compare
| useEffect(() => { | ||
| if (contextArtifact) { | ||
| clearArtifact(); | ||
| } | ||
| }, [agentUuid, threadUuid, projectUuid]); // eslint-disable-line react-hooks/exhaustive-deps |
There was a problem hiding this comment.
This useEffect hook disables the react-hooks/exhaustive-deps ESLint rule, which violates Frontend rules anti-patterns. According to the Frontend rules, when this disable comment is needed, there is likely a better approach to structuring the data. Instead of using an effect to clear contextArtifact when route parameters change, consider deriving the artifact state based on the current route parameters rather than relying on an effect with disabled dependency warnings.
Spotted by Diamond (based on custom rule: packages/frontend rules)
Is this helpful? React 👍 or 👎 to let us know.
| useEffect(() => { | ||
| // We want to auto-open artifact for messages that just completed streaming and have viz | ||
| // in the future, we want to track the viz calls to start showing artifact while streaming | ||
| if ( | ||
| justCompleted && | ||
| isVisualizationAvailable && | ||
| !isQueryError && | ||
| !isQueryLoading && | ||
| queryResults | ||
| ) { | ||
| setArtifact(renderArtifact(), message.uuid); | ||
| clearMessageJustCompleted(message.threadUuid); | ||
| } | ||
| }, [ | ||
| justCompleted, | ||
| isVisualizationAvailable, | ||
| isQueryError, | ||
| isQueryLoading, | ||
| queryResults, | ||
| renderArtifact, | ||
| setArtifact, | ||
| clearMessageJustCompleted, | ||
| message.threadUuid, | ||
| message.uuid, | ||
| ]); |
There was a problem hiding this comment.
I think Graphite also mentioned it in the comment but, I'd like to see if there's a better way to do this instead of useEffect+setState pattern. Or maybe this is temporary before we hook-up with artifacts api?
|
|
||
| const setArtifact = (artifact: ReactNode) => { | ||
| setContextArtifact(artifact); | ||
| const setArtifact = (artifact: ReactNode, id: string) => { |
There was a problem hiding this comment.
does setArtifact need to accept artifact: ReactNode as a param? just the id should be enough to decide wether or not artifact is set and then the component would derive rest
There was a problem hiding this comment.
oh, great point! I didn't think of that, let me see what can I improve
Update: Yeah so the issue here is the current component tree:
┌─AiAgentPageLayout ────────────────────────────────────────────┐
│ (provides context of layout) │
│ │
│ ┌─PanelGroup ────────────────────────────────────────────────┐ │
│ │ │ │
│ │ ┌─Sidebar────┐ ┌─Chat──────────────────┐ ┌ Artifact──────┐ │ │
│ │ │ │ │ ┌─AgentChatDisplay ─┐ │ │ │ │ │
│ │ │ │ │ │ │ │ │ │ │ │
│ │ │ │ │ │ ┌UserBubble─────┐ │ │ │ render() │ │ │
│ │ │ │ │ │ │ │ │ │ │ ▲ │ │ │
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │ │ │ │ │ │ │ │
│ │ │ │ │ │ └───────────────┘ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │ │ │ │ │ │
│ │ │ │ │ │ ┌AssistantBubble┐ │ │ │ │ │ │ │
│ │ │ │ │ │ │ viz───────┼─┼─┼─┼──┘ │ │ │
│ │ │ │ │ │ │ │ │ │ │ │ │ │
│ │ │ │ │ │ └───────────────┘ │ │ │ │ │ │
│ │ │ │ │ └───────────────────┘ │ │ │ │ │
│ │ └────────────┘ └───────────────────────┘ └───────────────┘ │ │
│ └────────────────────────────────────────────────────────────┘ │
│ │
└────────────────────────────────────────────────────────────────┘
the AssistantBubble has access to all the rendering context (vizConfig, queryResults, message data) but the AiAgentPageLayout needs to render the content in the Artifact panel.
A solution could be introducing React portals, let the assistant bubble render directly into the great-grandparent AiAgentPageLayout.
But we will eventually move to passing only the artifact id, and introduce a new artifact component that can fetch that artifact (and versions, etc) and be isolated form the assistant bubble. I think we could leave this as it is for now and tackle the refactor once we come back to this work? What do you think?
tatianainama
left a comment
There was a problem hiding this comment.
slack conversations are not working correctly because of provider missing. Will fix!
0bd01af to
f5eec3b
Compare
f5eec3b to
e71a88b
Compare
| } | ||
|
|
||
| export const AiAgentPageLayoutContext = | ||
| createContext<AiAgentPageLayoutContextType | null>(null); | ||
|
|
||
| export const useAiAgentPageLayout = () => { | ||
| const context = useContext(AiAgentPageLayoutContext); |
There was a problem hiding this comment.
The useAiAgentPageLayout hook should check if the context exists before returning it to prevent null reference errors. Restore the null check to ensure type safety when accessing context properties like 'isSidebarCollapsed'.
Spotted by Diamond (based on CI logs)
Is this helpful? React 👍 or 👎 to let us know.
e71a88b to
16d211b
Compare
16d211b to
d7a1f48
Compare
Merge activity
|
# [0.1944.0](0.1943.1...0.1944.0) (2025-08-22) ### Features * Display viz in Artifact panel ([#16499](#16499)) ([b79c53d](b79c53d))
|
🎉 This PR is included in version 0.1944.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
### Description: Using previous work to display visualizations into the Artifact panel [Screen Recording 2025-08-20 at 17.08.54.mov <span class="graphite__hidden">(uploaded via Graphite)</span> <img class="graphite__hidden" src="https://app.graphite.dev/user-attachments/thumbnails/f6ee543d-6e56-4b34-9609-78fe4fc36614.mov" />](https://app.graphite.dev/user-attachments/video/f6ee543d-6e56-4b34-9609-78fe4fc36614.mov) ### Next - Improve animations and interactions
# [0.1944.0](lightdash/lightdash@0.1943.1...0.1944.0) (2025-08-22) ### Features * Display viz in Artifact panel ([lightdash#16499](lightdash#16499)) ([b79c53d](lightdash@b79c53d))

Description:
Using previous work to display visualizations into the Artifact panel
Screen Recording 2025-08-20 at 17.08.54.mov (uploaded via Graphite)
Next