-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Dashboard Agent] Extract safe dashboard attachment integration refactors #261422
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
Merged
rbrtj
merged 18 commits into
elastic:main
from
mbondyra:dashboard_agent-dashboard_integration
Apr 7, 2026
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
78a8cf9
[Dashboard Agent] narrow attachment-to-state converter input
mbondyra d89ed54
[Dashboard Agent] narrow state-to-attachment converter output
mbondyra 9a50585
[Dashboard Agent] extract dashboard schema types
mbondyra f94fae8
[Dashboard Agent] add shared dashboard attachment guard
mbondyra 8ca70a0
[Dashboard Agent] align attachment converter docs
mbondyra 153ba7d
[Dashboard Agent] reuse shared section grid schema
mbondyra f31d740
[Dashboard Agent] rename preview attachment helper
mbondyra 771769b
[Dashboard Agent] add live updates subscription
mbondyra a225ad3
[Dashboard Agent] add origin sync subscription
mbondyra 04edd1b
[Dashboard Agent] refine attachment origin syncing
mbondyra db50293
[Dashboard Agent] rename manual changes subscription
mbondyra f89386b
[Dashboard Agent] rename dashboard app integration helper
mbondyra 69ca6e5
[Dashboard Agent] inline dashboard app mount integration
mbondyra 13e2838
code review
mbondyra 148c2fa
tests
mbondyra 1d011cf
conflict
mbondyra 545c201
Changes from node scripts/eslint_all_files --no-cache --fix
kibanamachine b5fdbf4
Merge branch 'main' into dashboard_agent-dashboard_integration
rbrtj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
157 changes: 157 additions & 0 deletions
157
...platform/packages/shared/dashboard-agent/dashboard-agent-common/dashboard_schema_types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import { z } from '@kbn/zod/v4'; | ||
|
|
||
| // ============================================================================ | ||
| // Panel Grid Schema - ideally we should import the schema from dashboard schemas, but they use config-schema library | ||
| // which is not compatible with Zod, so we duplicate the relevant parts here for validation of attachment data. | ||
| // ============================================================================ | ||
|
|
||
| /** | ||
| * Grid dimensions (in dashboard grid units) for layout. | ||
| * Dashboard grid is 48 columns wide; height is in same units. | ||
| */ | ||
| export const panelGridSchema = z.object({ | ||
| x: z.number(), | ||
| y: z.number(), | ||
| w: z.number().int().min(1).max(48), | ||
| h: z.number().int().min(1), | ||
| }); | ||
|
|
||
| // ============================================================================ | ||
| // Panel Schema | ||
| // ============================================================================ | ||
|
|
||
| /** | ||
| * Zod schema for dashboard panel entries. | ||
| * The `type` field contains the actual embeddable type. | ||
| */ | ||
| const attachmentPanelSchema = z.object({ | ||
| type: z.string(), | ||
| uid: z.string(), | ||
| config: z.record(z.string(), z.unknown()), | ||
| grid: panelGridSchema, | ||
| }); | ||
|
|
||
| export type AttachmentPanel = z.infer<typeof attachmentPanelSchema>; | ||
|
|
||
| // ============================================================================ | ||
| // Section Schema | ||
| // ============================================================================ | ||
|
|
||
| export const sectionGridSchema = z.object({ | ||
| y: z.number().int().min(0).describe('Section position in outer dashboard grid coordinates.'), | ||
| }); | ||
|
|
||
| const dashboardSectionSchema = z.object({ | ||
| uid: z.string(), | ||
| title: z.string(), | ||
| collapsed: z.boolean(), | ||
| grid: sectionGridSchema, | ||
| panels: z.array(attachmentPanelSchema), | ||
| }); | ||
|
|
||
| export type DashboardSection = z.infer<typeof dashboardSectionSchema>; | ||
|
|
||
| export const isSection = ( | ||
| widget: AttachmentPanel | DashboardSection | ||
| ): widget is DashboardSection => { | ||
| return 'panels' in widget; | ||
| }; | ||
|
|
||
| // ============================================================================ | ||
| // Query Schema | ||
| // ============================================================================ | ||
|
|
||
| const querySchema = z.object({ | ||
| expression: z.union([z.string(), z.record(z.string(), z.unknown())]), | ||
| language: z.string(), | ||
| }); | ||
|
|
||
| // ============================================================================ | ||
| // Time Range Schema | ||
| // ============================================================================ | ||
|
|
||
| const timeRangeSchema = z.object({ | ||
| from: z.string(), | ||
| to: z.string(), | ||
| mode: z.union([z.literal('absolute'), z.literal('relative')]).optional(), | ||
| }); | ||
|
|
||
| // ============================================================================ | ||
| // Refresh Interval Schema | ||
| // ============================================================================ | ||
|
|
||
| const refreshIntervalSchema = z.object({ | ||
| pause: z.boolean(), | ||
| value: z.number(), | ||
| }); | ||
|
|
||
| // ============================================================================ | ||
| // Dashboard Options Schema | ||
| // ============================================================================ | ||
|
|
||
| const optionsSchema = z.object({ | ||
| auto_apply_filters: z.boolean().optional(), | ||
| hide_panel_titles: z.boolean().optional(), | ||
| hide_panel_borders: z.boolean().optional(), | ||
| use_margins: z.boolean().optional(), | ||
| sync_colors: z.boolean().optional(), | ||
| sync_tooltips: z.boolean().optional(), | ||
| sync_cursor: z.boolean().optional(), | ||
| }); | ||
|
|
||
| // ============================================================================ | ||
| // Access Control Schema | ||
| // ============================================================================ | ||
|
|
||
| const accessControlSchema = z | ||
| .object({ | ||
| access_mode: z.union([z.literal('write_restricted'), z.literal('default')]).optional(), | ||
| }) | ||
| .optional(); | ||
|
|
||
| // ============================================================================ | ||
| // Filter Schema | ||
| // ============================================================================ | ||
|
|
||
| // Filters have complex union types that are difficult to express precisely in Zod. | ||
| const filterSchema = z.record(z.string(), z.unknown()); | ||
|
|
||
| // ============================================================================ | ||
| // Pinned Panels (Controls) Schema | ||
| // ============================================================================ | ||
|
|
||
| // Controls have complex union types. We use a permissive schema here. | ||
| const pinnedControlSchema = z.record(z.string(), z.unknown()); | ||
| const pinnedPanelsSchema = z.array(pinnedControlSchema); | ||
|
|
||
| // ============================================================================ | ||
| // Dashboard Attachment Data Schema (matches DashboardState) | ||
| // ============================================================================ | ||
|
|
||
| /** | ||
| * Zod schema for dashboard attachment data. | ||
| * This schema matches the structure of DashboardState from @kbn/dashboard-plugin. | ||
| */ | ||
| export const dashboardAttachmentDataSchema = z.object({ | ||
| title: z.string(), | ||
| description: z.string().optional(), | ||
| panels: z.array(z.union([attachmentPanelSchema, dashboardSectionSchema])), | ||
| query: querySchema.optional(), | ||
| time_range: timeRangeSchema.optional(), | ||
| refresh_interval: refreshIntervalSchema.optional(), | ||
| filters: z.array(filterSchema).optional(), | ||
| options: optionsSchema.optional(), | ||
| tags: z.array(z.string()).optional(), | ||
| pinned_panels: pinnedPanelsSchema.optional(), | ||
| access_control: accessControlSchema.optional(), | ||
| project_routing: z.string().optional(), | ||
| }); | ||
|
|
||
| export type DashboardAttachmentData = z.infer<typeof dashboardAttachmentDataSchema>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...latform/packages/shared/dashboard-agent/dashboard-agent-common/is_dashboard_attachment.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import type { VersionedAttachment } from '@kbn/agent-builder-common/attachments'; | ||
| import { DASHBOARD_ATTACHMENT_TYPE } from './constants'; | ||
| import type { DashboardAttachmentData } from './types'; | ||
|
|
||
| export const isDashboardAttachment = ( | ||
| attachment: VersionedAttachment | ||
| ): attachment is VersionedAttachment<typeof DASHBOARD_ATTACHMENT_TYPE, DashboardAttachmentData> => | ||
| attachment.type === DASHBOARD_ATTACHMENT_TYPE; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.