Skip to content

[Dashboard Agent] Extract safe dashboard attachment integration refactors#261422

Merged
rbrtj merged 18 commits into
elastic:mainfrom
mbondyra:dashboard_agent-dashboard_integration
Apr 7, 2026
Merged

[Dashboard Agent] Extract safe dashboard attachment integration refactors#261422
rbrtj merged 18 commits into
elastic:mainfrom
mbondyra:dashboard_agent-dashboard_integration

Conversation

@mbondyra
Copy link
Copy Markdown
Contributor

@mbondyra mbondyra commented Apr 6, 2026

Description

This PR pulls out the lower-risk dashboard agent refactors from the larger source work so the remaining session-management changes can be reviewed separately.

Summary

  • Rename the shared dashboard attachment converters to make the data flow explicit:
    • attachmentToDashboardState -> attachmentDataToDashboardState
    • dashboardStateToAttachment -> dashboardStateToAttachmentData
  • Extract dashboard schema definitions from types.ts into dashboard_schema_types.ts, and reuse the shared section grid schema from the common package.
  • Add a shared isDashboardAttachment type guard and adopt it where dashboard attachments are handled.
  • Align shared API docs with the renamed converter APIs.
  • Rename preview_attachment_in_dashboard to preview_attachment and simplify preview/origin handling around deleted linked dashboards.
  • Refine origin syncing so attachments relink only in the intended save flows, while preserving the newer deleted-origin behavior introduced during this branch’s work.
  • Extract dashboard integration responsibilities into dedicated helpers:
    • agent_live_updates_subscription.ts
    • origin_sync_subscription.ts
    • manual_changes_subscription.ts
    • dashboard_app_integration.ts
  • Remove the on_attachment_mount wrapper (not used in the future) and inline dashboard app integration wiring into attachment registration.

Why

These changes isolate naming cleanups, shared-type extraction, and dashboard integration decomposition before the larger attachment session refactor lands. That should make the remaining review focus on the harder behavioral changes instead of mechanical moves.

@mbondyra mbondyra requested a review from a team as a code owner April 6, 2026 20:35
@mbondyra mbondyra added release_note:skip Skip the PR/issue when compiling release notes backport:skip This PR does not require backporting labels Apr 6, 2026
Copy link
Copy Markdown
Contributor

@rbrtj rbrtj left a comment

Choose a reason for hiding this comment

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

great improvements!
left a few questions

mbondyra added 15 commits April 7, 2026 14:50
Make the shared dashboard converter accept attachment data directly so callers don't need to pass the full attachment wrapper. This keeps the extracted review scoped to the dashboard-agent API cleanup before the larger functionality lands.

Made-with: Cursor
Rename the shared dashboard state converter so its API clearly reflects that it returns attachment data. This keeps the extracted dashboard-agent cleanup small and makes later functional review easier.

Made-with: Cursor
Move dashboard schema definitions into a dedicated shared module and keep the attachment types file focused on attachment wrappers and re-exports. This further separates non-functional API cleanup from the harder behavior changes that will follow.

Made-with: Cursor
Introduce a reusable dashboard attachment type guard and use it in the current dashboard sync and management paths. This keeps attachment narrowing centralized before the larger attachment workflow changes land.

Made-with: Cursor
Restore the shared converter comment wording so the extracted dashboard-agent package matches the source branch exactly. This keeps the cleanup stack consistent before we move on to functional changes.

Made-with: Cursor
Use the shared dashboard section grid schema in manage dashboard operations instead of maintaining a duplicate local definition. This keeps dashboard operation validation aligned with the shared attachment schema.

Made-with: Cursor
Rename the dashboard preview helper and align its preview flow with the source branch behavior. This keeps the public integration cleanup separate from the larger dashboard app integration changes.

Made-with: Cursor
Introduce the dashboard app live updates subscription as a standalone extraction from the source branch. This keeps the new subscription logic reviewable before wiring in the wider app integration flow.

Made-with: Cursor
Introduce the dashboard origin sync subscription and compose it inside the existing mount sync helper. This keeps the new origin sync logic isolated while preserving the target branch's current mount integration shape.

Made-with: Cursor
Keep dashboard attachment origins aligned with saves and deleted dashboards without pulling in the manual changes subscription refactor.

Made-with: Cursor
Align the dashboard attachment manual-sync wiring with the extracted subscription helper so mount sync composes the target structure more directly.

Made-with: Cursor
Rename the dashboard app integration entrypoint and align its API with the target structure while preserving the current origin and manual sync behavior.

Made-with: Cursor
Move dashboard attachment mount wiring into the dashboard app integration flow, remove the temporary on-attachment mount wrapper, and keep the latest origin sync adjustments together with that cleanup.

Made-with: Cursor
@mbondyra mbondyra force-pushed the dashboard_agent-dashboard_integration branch from 0c8fa5f to 148c2fa Compare April 7, 2026 12:59
Comment on lines +36 to 44
const linkedDashboardExists = attachment.origin
? await checkSavedDashboardExist(attachment.origin)
: false;

if (dashboardHasBeenDeleted) {
await updateOrigin('');
attachmentLinkedSavedObjectId = undefined;
}

// b) Viewing saved dashboard + attachment not linked -> navigate to new unsaved dashboard
if (!attachmentLinkedSavedObjectId && !currentSavedObjectId) {
if (!currentSavedObjectId && !linkedDashboardExists) {
// b) Viewing unsaved dashboard + attachment linked to deleted dashboard
dashboardApi.setState(dashboardState);
return;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Low dashboard_integration/preview_attachment.ts:36

The updateOrigin parameter is passed to previewAttachmentInDashboard but never called. When attachment.origin references a deleted dashboard, the function no longer clears the stale reference, leaving attachment.origin pointing to a non-existent dashboard indefinitely. Consider restoring the updateOrigin('') call when linkedDashboardExists is false.

-  const linkedDashboardExists = attachment.origin
+  let linkedDashboardExists = false;
+  if (attachment.origin) {
+    linkedDashboardExists = await checkSavedDashboardExist(attachment.origin);
+    if (!linkedDashboardExists) {
+      await updateOrigin('');
+    }
+  }
 
   if (!currentSavedObjectId && !linkedDashboardExists) {
🤖 Copy this AI Prompt to have your agent fix this:
In file x-pack/platform/plugins/shared/dashboard_agent/public/attachment_types/dashboard_integration/preview_attachment.ts around lines 36-44:

The `updateOrigin` parameter is passed to `previewAttachmentInDashboard` but never called. When `attachment.origin` references a deleted dashboard, the function no longer clears the stale reference, leaving `attachment.origin` pointing to a non-existent dashboard indefinitely. Consider restoring the `updateOrigin('')` call when `linkedDashboardExists` is false.

Evidence trail:
x-pack/platform/plugins/shared/dashboard_agent/public/attachment_types/dashboard_integration/preview_attachment.ts lines 16, 23 (parameter defined and destructured but never called in function body lines 24-54). git_diff MERGE_BASE..REVIEWED_COMMIT shows this is a new file. git_grep for 'updateOrigin' shows it IS called in other files like use_register_canvas_action_buttons.ts:99,104 and origin_sync_subscription.ts:45,57, demonstrating intended usage pattern.

@elastic-vault-github-plugin-prod elastic-vault-github-plugin-prod Bot requested a review from a team as a code owner April 7, 2026 13:41
@botelastic botelastic Bot added the Team:One Workflow Team label for One Workflow (Workflow automation) label Apr 7, 2026
@rbrtj rbrtj removed the request for review from a team April 7, 2026 14:19
@rbrtj rbrtj removed the Team:One Workflow Team label for One Workflow (Workflow automation) label Apr 7, 2026
@rbrtj rbrtj enabled auto-merge (squash) April 7, 2026 14:21
@rbrtj rbrtj merged commit 2dc1eb6 into elastic:main Apr 7, 2026
20 checks passed
@elasticmachine
Copy link
Copy Markdown
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
dashboardAgent 595 599 +4

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/dashboard-agent-common 16 17 +1

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
dashboardAgent 135.7KB 136.4KB +768.0B
Unknown metric groups

API count

id before after diff
@kbn/dashboard-agent-common 25 26 +1

History

mbondyra added a commit to Heenawter/kibana that referenced this pull request Apr 7, 2026
* commit 'bfc2446fdbcba2b3183f4518817c9757198c95ef':
  [Cascade] make cascade layout enabled by default (elastic#260698)
  [Dashboard Agent] Extract safe dashboard attachment integration refactors (elastic#261422)
  [One Workflow] Replace workflows:aiAgent:enabled with agentBuilder:experimentalFeatures (elastic#261330)
  [EDR Workflows] Osquery: hide query code from dropdown and show Elastic for automated Run By (elastic#261394)
  [Observability Onboarding] Add data detection & loading indicators to onboarding flows  (elastic#257870)
  [Significant events] Format event count with locale-aware number separators (elastic#261570)
  [Fleet] Fix deprecated filter in browse integrations (elastic#261459)
  [Lens as code] Split `xyStateSchema` config (elastic#261089)
  [Data Views as Code] Use `ref_id` and add metadata in data views schemas (elastic#261181)

Made-with: Cursor

# Conflicts:
#	x-pack/platform/packages/shared/dashboard-agent/dashboard-agent-common/types.ts
mbondyra added a commit to mbondyra/kibana that referenced this pull request Apr 7, 2026
…r-uid-to-id

* commit '2dc1eb699581a0b24f3b433de8db41d312bc5c93':
  [Dashboard Agent] Extract safe dashboard attachment integration refactors (elastic#261422)

# Conflicts:
#	x-pack/platform/packages/shared/dashboard-agent/dashboard-agent-common/types.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting release_note:skip Skip the PR/issue when compiling release notes v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants