@kong-ui-public/dashboard-renderer 0.35.8 → 0.35.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +313 -14
  2. package/package.json +5 -5
package/README.md CHANGED
@@ -6,6 +6,19 @@ Render Analytics charts on a page from a JSON definition.
6
6
  - [Usage](#usage)
7
7
  - [Props](#props)
8
8
  - [Example](#example)
9
+ - [Slotted content](#slotted-content)
10
+ - [Auto-fit row content](#auto-fit-row-content)
11
+ - [Editable Dashboard Features](#editable-dashboard-features)
12
+ - [Editable Dashboard Events](#editable-dashboard-events)
13
+ - [Dashboard Config Schema](#dashboard-config-schema)
14
+ - [Tile Definition](#tile-definition)
15
+ - [Chart Options](#chart-options)
16
+ - [Chart Types](#chart-types)
17
+ - [Common Chart Properties](#common-chart-properties)
18
+ - [Query Configuration](#query-configuration)
19
+ - [Time Range Configuration](#time-range-configuration)
20
+ - [Layout Configuration](#layout-configuration)
21
+ - [Usage Example](#usage-example)
9
22
 
10
23
  ## Requirements
11
24
 
@@ -27,14 +40,21 @@ Render Analytics charts on a page from a JSON definition.
27
40
 
28
41
  ### Props
29
42
 
30
- This component only takes two properties:
43
+ This component takes two properties:
31
44
 
32
- - [context](https://github.com/Kong/public-ui-components/blob/main/packages/analytics/dashboard-renderer/src/types/dashboard-renderer-types.ts) : The time range that the dashboard should query and any additional filters that should be applied.
33
- - [config](https://github.com/Kong/public-ui-components/blob/main/packages/analytics/dashboard-renderer/src/types/dashboard-renderer-types.ts) : The dashboard config and layout.
45
+ - [context](https://github.com/Kong/public-ui-components/blob/main/packages/analytics/dashboard-renderer/src/types/renderer-types.ts): The time range that the dashboard should query, any additional filters that should be applied, and editing configuration.
46
+ - [config](https://github.com/Kong/public-ui-components/blob/main/packages/analytics/analytics-utilities/src/dashboardSchema.ts): The dashboard config and layout.
34
47
 
35
- For context `filters` and `timeSpec` see [here](https://github.com/Kong/public-ui-components/blob/main/packages/analytics/analytics-utilities/src/types/explore-v4.ts).
48
+ #### Context Properties
49
+
50
+ | Property | Type | Required | Default | Description |
51
+ |----------|------|----------|---------|-------------|
52
+ | filters | [AllFilters[]](https://github.com/Kong/public-ui-components/blob/main/packages/analytics/analytics-utilities/src/types/explore/all.ts) | Yes | - | Filters to be applied to the dashboard. Context filters are merged into tile specic filters. Filters that are not relevent to the tile's query datasource are ignored. |
53
+ | timeSpec | [TimeRangeV4](https://github.com/Kong/public-ui-components/blob/main/packages/analytics/analytics-utilities/src/types/explore/common.ts) | No | 7 days | The time range for queries. Tiles can provide their own time range, which will override the global time range, for that tile. |
54
+ | tz | string | No | Local timezone | Timezone to include with queries, if different than the browser timezone |
55
+ | refreshInterval | number | No | DEFAULT_TILE_REFRESH_INTERVAL_MS | Interval for refreshing tiles |
56
+ | editable | boolean | No | false | Enables dashboard editing capabilities |
36
57
 
37
- If a `timeSpec` is not provided in the `context` object, the renderer will determine a default, which is currently 7 days.
38
58
 
39
59
  ### Example
40
60
 
@@ -42,6 +62,8 @@ If a `timeSpec` is not provided in the `context` object, the renderer will deter
42
62
  <DashboardRenderer
43
63
  :context="context"
44
64
  :config="config"
65
+ @edit-tile="handleEditTile"
66
+ @update-tiles="handleUpdateTiles"
45
67
  />
46
68
  ```
47
69
 
@@ -58,6 +80,7 @@ const context: DashboardRendererContext = {
58
80
  type: 'relative',
59
81
  time_range: '15M',
60
82
  },
83
+ editable: true, // Enable editing capabilities
61
84
  }
62
85
 
63
86
  const config: DashboardConfig = {
@@ -68,6 +91,7 @@ const config: DashboardConfig = {
68
91
  },
69
92
  tiles: [
70
93
  {
94
+ id: 'unique-tile-id', // Required for editable dashboards
71
95
  definition: {
72
96
  chart: {
73
97
  type: 'horizontal_bar',
@@ -86,8 +110,8 @@ const config: DashboardConfig = {
86
110
  },
87
111
  // Spans 2 columns and 1 rows
88
112
  size: {
89
- col: 2,
90
- row: 1,
113
+ cols: 2,
114
+ rows: 1,
91
115
  }
92
116
  }
93
117
  },
@@ -113,8 +137,8 @@ const config: DashboardConfig = {
113
137
  },
114
138
  // Spans 2 columns and 1 rows
115
139
  size: {
116
- col: 2,
117
- row: 1,
140
+ cols: 2,
141
+ rows: 1,
118
142
  }
119
143
  }
120
144
  },
@@ -178,8 +202,8 @@ const config: DashboardConfig = {
178
202
  },
179
203
  // Spans 2 columns and 1 rows
180
204
  size: {
181
- col: 2,
182
- row: 1,
205
+ cols: 2,
206
+ rows: 1,
183
207
  }
184
208
  }
185
209
  },
@@ -200,8 +224,8 @@ const config: DashboardConfig = {
200
224
  },
201
225
  // Spans 2 columns and 1 rows
202
226
  size: {
203
- col: 2,
204
- row: 1,
227
+ cols: 2,
228
+ rows: 1,
205
229
  }
206
230
  }
207
231
  },
@@ -211,10 +235,13 @@ const config: DashboardConfig = {
211
235
 
212
236
  #### Auto-fit row content
213
237
 
238
+ __Note__: _this will only work in non-editable mode_
239
+
214
240
  This example will create a dynamically-sized row that fits to its content rather than being fixed at the configured row height. Note that this works because each chart is only rendered in 1 row; if a chart has `fitToContent` and `layout.size.rows > 1`, the `fitToContent` setting will be ignored.
215
241
 
216
242
  Rendering `AnalyticsChart` components (e.g., horizontal bar, vertical bar, timeseries charts) with dynamic row heights may lead to undefined behavior. This option is best used with non-canvas charts (e.g., TopN charts).
217
243
 
244
+
218
245
  ```typescript
219
246
  import type { DashboardRendererContext, DashboardConfig } from '@kong-ui-public/dashboard-renderer'
220
247
  import { DashboardRenderer, ChartTypes } from '@kong-ui-public/dashboard-renderer'
@@ -278,4 +305,276 @@ const config: DashboardConfig = {
278
305
  },
279
306
  ],
280
307
  }
281
- ```
308
+ ```
309
+
310
+ ### Editable Dashboard Example
311
+
312
+ ```typescript
313
+ const context: DashboardRendererContext = {
314
+ filters: [],
315
+ timeSpec: {
316
+ type: 'relative',
317
+ time_range: '15M',
318
+ },
319
+ editable: true, // Enable editing capabilities
320
+ }
321
+
322
+ const config: DashboardConfig = {
323
+ gridSize: {
324
+ cols: 4,
325
+ rows: 1,
326
+ },
327
+ tiles: [
328
+ {
329
+ id: 'unique-tile-id', // Required for editable dashboards
330
+ definition: {
331
+ chart: {
332
+ type: 'horizontal_bar',
333
+ },
334
+ query: {
335
+ metrics: ['request_count'],
336
+ dimensions: ['route']
337
+ },
338
+ },
339
+ layout: {
340
+ position: {
341
+ col: 0,
342
+ row: 0,
343
+ },
344
+ size: {
345
+ cols: 2,
346
+ rows: 1,
347
+ }
348
+ }
349
+ }
350
+ ]
351
+ }
352
+ ```
353
+
354
+ ```html
355
+ <DashboardRenderer
356
+ :context="context"
357
+ :config="config"
358
+ @edit-tile="handleEditTile"
359
+ @update-tiles="handleUpdateTiles"
360
+ />
361
+ ```
362
+
363
+ ## Editable Dashboard Features
364
+
365
+ When `editable` is enabled:
366
+
367
+ ### User Interface Features
368
+ - Tiles can be dragged and repositioned using the tile header
369
+ - Tiles can be resized using handles in the bottom corners
370
+ - Each tile displays an edit button and a kebab menu with additional options
371
+ - Tiles can be removed via the kebab menu
372
+
373
+ ## Editable Dashboard Events
374
+
375
+ The DashboardRenderer component emits the following events when in editable mode:
376
+
377
+ | Event | Payload | Description |
378
+ |-------|---------|-------------|
379
+ | `edit-tile` | `GridTile<TileDefinition>` | Emitted when the edit button is clicked on a tile. The payload includes the complete tile configuration including its layout and metadata. |
380
+ | `update-tiles` | `TileConfig[]` | Emitted when tiles are moved, resized, or removed. The payload is an array of all tiles with their updated positions and sizes. |
381
+ | `remove-tile` | `GridTile<TileDefinition>` | Emitted when a tile is removed via the kebab menu. The payload includes the configuration of the removed tile. |
382
+
383
+
384
+ ```Html
385
+ <DashboardRenderer
386
+ :context="context"
387
+ :config="config"
388
+ @edit-tile="handleTileEdit"
389
+ @update-tiles="handleLayoutUpdate"
390
+ @remove-tile="handleTileRemoval"
391
+ />
392
+ ```
393
+
394
+ ```typescript
395
+ const handleEditTile = (tile: GridTile<TileDefinition>) => {
396
+ // Handle tile editing, e.g., open an edit modal
397
+ console.log('Editing tile:', tile.id)
398
+ }
399
+
400
+ const handleUpdateTiles = (tiles: TileConfig[]) => {
401
+ // Handle layout updates, e.g., save to backend
402
+ console.log('Updated tiles:', tiles)
403
+ }
404
+
405
+ const handleRemoveTile = (tile: GridTile<TileDefinition>) => {
406
+ // Handle tile removal, e.g., update backend
407
+ console.log('Removed tile:', tile.id)
408
+ }
409
+ ```
410
+
411
+ Note: These events are only emitted when the dashboard is in editable mode (`context.editable = true`).
412
+
413
+ Note: When using editable dashboards, each tile should have a unique `id` property to properly track changes and handle events correctly. If no `id` is provided, one will be generated automatically, but this may lead to unexpected behavior when tracking changes to the tile.
414
+
415
+ ## Dashboard Config Schema
416
+
417
+ The dashboard configuration schema is defined in `@kong-ui-public/analytics-utilities`.
418
+
419
+ ### DashboardConfig
420
+ The root configuration type for a dashboard.
421
+
422
+ ```typescript
423
+ interface DashboardConfig {
424
+ tiles: TileConfig[] // Array of tile configurations
425
+ tileHeight?: number // Optional height of each tile in pixels
426
+ gridSize: { // Required grid layout configuration
427
+ cols: number // Number of columns in the grid
428
+ rows: number // Number of rows in the grid
429
+ }
430
+ }
431
+ ```
432
+
433
+ ### Tile Config
434
+ Configuration for individual dashboard tiles.
435
+
436
+ ```typescript
437
+ interface TileConfig {
438
+ definition: TileDefinition // The tile's chart and query configuration
439
+ layout: TileLayout // The tile's position and size in the grid
440
+ id?: string // Optional unique identifier (required for editable dashboards)
441
+ }
442
+ ```
443
+
444
+ ### Tile Definition
445
+ Configuration for the chart and query within a tile.
446
+
447
+ ```typescript
448
+ interface TileDefinition {
449
+ chart: ChartOptions // Configuration for the chart type and options
450
+ query: ValidDashboardQuery // Configuration for the data query
451
+ }
452
+ ```
453
+
454
+ ### Chart Options
455
+ Chart type and options configuration.
456
+
457
+ ```typescript
458
+ interface ChartOptions {
459
+ type: DashboardTileType // The type of chart
460
+ chartTitle?: string // Optional title for the chart
461
+ syntheticsDataKey?: string // Optional key for synthetic tests
462
+ allowCsvExport?: boolean // Optional flag to allow CSV export
463
+ chartDatasetColors?: AnalyticsChartColors | string[] // Optional custom colors for datasets
464
+ }
465
+ ```
466
+
467
+ ### Chart Types
468
+
469
+ The following chart types are supported:
470
+
471
+ - `horizontal_bar`: Horizontal bar chart
472
+ - `vertical_bar`: Vertical bar chart
473
+ - `gauge`: Gauge chart
474
+ - `timeseries_line`: Line chart for time series data
475
+ - `timeseries_bar`: Bar chart for time series data
476
+ - `golden_signals`: Metric cards showing key performance indicators
477
+ - `top_n`: Table showing top N results
478
+ - `slottable`: Custom content slot
479
+
480
+ Each chart type has its own configuration schema with specific options.
481
+
482
+ ### Common Chart Properties
483
+
484
+ Most chart types support these common properties:
485
+ - `chartTitle`: String title for the chart
486
+ - `syntheticsDataKey`: Key for synthetic tests (if applicable)
487
+ - `allowCsvExport`: Boolean to enable/disable CSV export
488
+ - `chartDatasetColors`: Custom colors for datasets (object or array) `{ [key: string]: string } | string[]`
489
+
490
+ ### Query Configuration
491
+
492
+ [See here](https://github.com/Kong/public-ui-components/blob/main/packages/analytics/analytics-utilities/src/types/explore) for explore query types.
493
+
494
+ Queries can be configured for three different data sources:
495
+
496
+ 1. `advanced`: Uses the advanced explore API
497
+ 2. `basic`: Uses the basic explore API
498
+ 3. `ai`: Uses the AI explore API
499
+
500
+ Each query type supports:
501
+ - `metrics`: Array of aggregations to collect
502
+ - `dimensions`: Array of attributes to group by (max 2)
503
+ - `filters`: Array of query filters
504
+ - `time_range`: Time range configuration (relative or absolute)
505
+ - `granularity`: Time bucket size for temporal queries
506
+ - `limit`: Number of results to return
507
+
508
+ ### Time Range Configuration
509
+
510
+ [See here](https://github.com/Kong/public-ui-components/blob/main/packages/analytics/analytics-utilities/src/types/explore/common.ts) for time range types.
511
+
512
+ __Note:__ _Providing a time range in with the tile query will override the global time range provided in the dashboard context._
513
+
514
+ Two types of time ranges are supported:
515
+
516
+ 1. Relative:
517
+ ```typescript
518
+ {
519
+ type: 'relative'
520
+ time_range: string // e.g., '1h', '7d'
521
+ tz?: string // Renderer defaults to browser timezone if not provided'
522
+ }
523
+ ```
524
+
525
+ 2. Absolute:
526
+ ```typescript
527
+ {
528
+ type: 'absolute'
529
+ start: string // Start timestamp
530
+ end: string // End timestamp
531
+ tz?: string // Timezone
532
+ }
533
+ ```
534
+
535
+ ### Layout Configuration
536
+
537
+ The `TileLayout` type controls tile positioning and sizing:
538
+
539
+ ```typescript
540
+ interface TileLayout {
541
+ position: {
542
+ col: number // Starting column (0-based)
543
+ row: number // Starting row (0-based)
544
+ }
545
+ size: {
546
+ cols: number // Number of columns to span
547
+ rows: number // Number of rows to span
548
+ fitToContent?: boolean // Enable auto-height for the row
549
+ }
550
+ }
551
+ ```
552
+
553
+ ### Usage Example
554
+
555
+ ```typescript
556
+ const dashboardConfig: DashboardConfig = {
557
+ gridSize: {
558
+ cols: 4,
559
+ rows: 2
560
+ },
561
+ tiles: [{
562
+ id: 'requests-by-route',
563
+ definition: {
564
+ chart: {
565
+ type: 'horizontal_bar',
566
+ chartTitle: 'Requests by Route'
567
+ },
568
+ query: {
569
+ datasource: 'advanced',
570
+ metrics: ['request_count'],
571
+ dimensions: ['route']
572
+ }
573
+ },
574
+ layout: {
575
+ position: { col: 0, row: 0 },
576
+ size: { cols: 2, rows: 1 }
577
+ }
578
+ }]
579
+ }
580
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kong-ui-public/dashboard-renderer",
3
- "version": "0.35.8",
3
+ "version": "0.35.9",
4
4
  "type": "module",
5
5
  "main": "./dist/dashboard-renderer.umd.js",
6
6
  "module": "./dist/dashboard-renderer.es.js",
@@ -28,9 +28,9 @@
28
28
  "vue": "^3.5.12",
29
29
  "@kong-ui-public/analytics-chart": "^6.1.7",
30
30
  "@kong-ui-public/analytics-config-store": "^0.8.37",
31
+ "@kong-ui-public/i18n": "^2.2.10",
31
32
  "@kong-ui-public/analytics-metric-provider": "^8.6.22",
32
33
  "@kong-ui-public/analytics-utilities": "^6.3.1",
33
- "@kong-ui-public/i18n": "^2.2.10",
34
34
  "@kong-ui-public/sandbox-layout": "^2.1.61"
35
35
  },
36
36
  "repository": {
@@ -54,11 +54,11 @@
54
54
  "@kong/kongponents": "^9.21.5",
55
55
  "swrv": "^1.0.4",
56
56
  "vue": ">= 3.3.13 < 4",
57
- "@kong-ui-public/analytics-chart": "^6.1.7",
58
- "@kong-ui-public/analytics-config-store": "^0.8.37",
59
57
  "@kong-ui-public/analytics-metric-provider": "^8.6.22",
60
58
  "@kong-ui-public/analytics-utilities": "^6.3.1",
61
- "@kong-ui-public/i18n": "^2.2.10"
59
+ "@kong-ui-public/analytics-chart": "^6.1.7",
60
+ "@kong-ui-public/i18n": "^2.2.10",
61
+ "@kong-ui-public/analytics-config-store": "^0.8.37"
62
62
  },
63
63
  "dependencies": {
64
64
  "ajv": "^8.17.1",