From b103fc272a7113b00b6094701dc9481f484f6777 Mon Sep 17 00:00:00 2001 From: Filip Gutica Date: Thu, 31 Oct 2024 22:44:39 -0700 Subject: [PATCH 1/4] feat(dashboards and charts): editable tiles | slottable menu items - add new edit-tile event to dashboard renderer - forward go to explore to analytics chart through tile definition - add new editable property to tile definition that will add an "edit" item to the analytics chart kebab menu. Clicking on edit, will emit an @edit-tile event with the entire GridTile object containing the tile layout, definition and index --- .../src/components/AnalyticsChart.vue | 8 ++- .../sandbox/pages/RendererDemo.vue | 9 ++- .../src/components/BarChartRenderer.vue | 43 +++---------- .../components/BaseAnalyticsChartRenderer.vue | 62 +++++++++++++++++++ .../src/components/DashboardRenderer.vue | 9 +++ .../src/components/DashboardTile.vue | 10 +++ .../src/components/GoldenSignalsRenderer.vue | 30 +++++---- .../components/TimeseriesChartRenderer.vue | 50 +++------------ .../dashboard-renderer/src/locales/en.json | 3 +- .../src/types/dashboard-renderer-types.ts | 12 ++++ 10 files changed, 148 insertions(+), 88 deletions(-) create mode 100644 packages/analytics/dashboard-renderer/src/components/BaseAnalyticsChartRenderer.vue diff --git a/packages/analytics/analytics-chart/src/components/AnalyticsChart.vue b/packages/analytics/analytics-chart/src/components/AnalyticsChart.vue index 6cf40329ff..01fd31f79e 100644 --- a/packages/analytics/analytics-chart/src/components/AnalyticsChart.vue +++ b/packages/analytics/analytics-chart/src/components/AnalyticsChart.vue @@ -68,6 +68,7 @@ {{ i18n.t('csvExport.exportButton') }} + @@ -230,6 +231,11 @@ const props = defineProps({ required: false, default: false, }, + showMenu: { + type: Boolean, + required: false, + default: false, + }, }) const emit = defineEmits<{ @@ -361,7 +367,7 @@ const showChartHeader = computed(() => { return (hasValidChartData.value && resultSetTruncated.value && maxEntitiesShown.value) || props.chartTitle || (props.allowCsvExport && hasValidChartData.value) }) -const hasMenuOptions = computed(() => (props.allowCsvExport && hasValidChartData.value) || !!props.goToExplore) +const hasMenuOptions = computed(() => (props.allowCsvExport && hasValidChartData.value) || !!props.goToExplore || props.showMenu) const timeSeriesGranularity = computed(() => { diff --git a/packages/analytics/dashboard-renderer/sandbox/pages/RendererDemo.vue b/packages/analytics/dashboard-renderer/sandbox/pages/RendererDemo.vue index 9b3323ebeb..e8c7ee3f14 100644 --- a/packages/analytics/dashboard-renderer/sandbox/pages/RendererDemo.vue +++ b/packages/analytics/dashboard-renderer/sandbox/pages/RendererDemo.vue @@ -13,6 +13,7 @@ :class="{ 'custom-styling': isToggled}" :config="(dashboardConfig as DashboardConfig)" :context="context" + @edit-tile="onEditTile" > diff --git a/packages/analytics/dashboard-renderer/src/components/BaseAnalyticsChartRenderer.vue b/packages/analytics/dashboard-renderer/src/components/BaseAnalyticsChartRenderer.vue new file mode 100644 index 0000000000..059b1d7046 --- /dev/null +++ b/packages/analytics/dashboard-renderer/src/components/BaseAnalyticsChartRenderer.vue @@ -0,0 +1,62 @@ + + + + + diff --git a/packages/analytics/dashboard-renderer/src/components/DashboardRenderer.vue b/packages/analytics/dashboard-renderer/src/components/DashboardRenderer.vue index b037b76ea0..9ba7831b04 100644 --- a/packages/analytics/dashboard-renderer/src/components/DashboardRenderer.vue +++ b/packages/analytics/dashboard-renderer/src/components/DashboardRenderer.vue @@ -26,6 +26,7 @@ :definition="tile.meta" :height="tile.layout.size.rows * (config.tileHeight || DEFAULT_TILE_HEIGHT) + parseInt(KUI_SPACE_70, 10)" :query-ready="queryReady" + @edit-tile="onEditTile(tile)" /> @@ -53,6 +54,10 @@ const props = defineProps<{ config: DashboardConfig, }>() +const emit = defineEmits<{ + (e: 'edit-tile', tile: GridTile): void +}>() + const { i18n } = composables.useI18n() // Note: queryBridge is not directly used by the DashboardRenderer component. It is required by many of the @@ -151,6 +156,10 @@ const mergedContext = computed(() => { // Right now, tiles don't have unique keys. Perhaps in the future they will, // and we can use that instead of `index` as the fragment key. +const onEditTile = (tile: GridTile) => { + emit('edit-tile', tile) +} + diff --git a/packages/analytics/dashboard-renderer/src/locales/en.json b/packages/analytics/dashboard-renderer/src/locales/en.json index b823239c6d..b41b0e493d 100644 --- a/packages/analytics/dashboard-renderer/src/locales/en.json +++ b/packages/analytics/dashboard-renderer/src/locales/en.json @@ -5,7 +5,8 @@ "24h": "Last 24-Hour Summary", "7d": "Last 7-Day Summary", "30d": "Last 30-Day Summary" - } + }, + "edit": "Edit" }, "queryDataProvider": { "timeRangeExceeded": "The time range for this report is outside of your organization's data retention period" diff --git a/packages/analytics/dashboard-renderer/src/types/dashboard-renderer-types.ts b/packages/analytics/dashboard-renderer/src/types/dashboard-renderer-types.ts index a1fac860ce..b7f4c018cd 100644 --- a/packages/analytics/dashboard-renderer/src/types/dashboard-renderer-types.ts +++ b/packages/analytics/dashboard-renderer/src/types/dashboard-renderer-types.ts @@ -55,6 +55,14 @@ const allowCsvExport = { type: 'boolean', } as const +const goToExplore = { + type: 'string', +} as const + +const editable = { + type: 'boolean', +} as const + const chartDatasetColorsSchema = { type: ['object', 'array'], items: { @@ -96,6 +104,7 @@ export const barChartSchema = { syntheticsDataKey, chartTitle, allowCsvExport, + goToExplore, }, required: ['type'], additionalProperties: false, @@ -117,6 +126,7 @@ export const timeseriesChartSchema = { syntheticsDataKey, chartTitle, allowCsvExport, + goToExplore, }, required: ['type'], additionalProperties: false, @@ -398,6 +408,7 @@ export const tileDefinitionSchema = { chart: { anyOf: [barChartSchema, gaugeChartSchema, timeseriesChartSchema, metricCardSchema, topNTableSchema, slottableSchema], }, + editable, }, required: ['query', 'chart'], additionalProperties: false, @@ -497,4 +508,5 @@ export interface RendererProps { queryReady: boolean chartOptions: T height: number + editable?: boolean } From 231a753e3702a5289a7763d6e0fb207550f85cea Mon Sep 17 00:00:00 2001 From: Filip Gutica Date: Fri, 1 Nov 2024 12:54:33 -0700 Subject: [PATCH 2/4] fix: move editable to context --- .../dashboard-renderer/sandbox/pages/RendererDemo.vue | 3 +-- .../dashboard-renderer/src/components/BarChartRenderer.vue | 2 +- .../src/components/BaseAnalyticsChartRenderer.vue | 4 ++-- .../src/components/DashboardRenderer.vue | 7 ++++++- .../dashboard-renderer/src/components/DashboardTile.vue | 2 +- .../src/components/TimeseriesChartRenderer.vue | 2 +- .../src/types/dashboard-renderer-types.ts | 7 +------ 7 files changed, 13 insertions(+), 14 deletions(-) diff --git a/packages/analytics/dashboard-renderer/sandbox/pages/RendererDemo.vue b/packages/analytics/dashboard-renderer/sandbox/pages/RendererDemo.vue index e8c7ee3f14..e603e58700 100644 --- a/packages/analytics/dashboard-renderer/sandbox/pages/RendererDemo.vue +++ b/packages/analytics/dashboard-renderer/sandbox/pages/RendererDemo.vue @@ -46,6 +46,7 @@ const appLinks: SandboxNavigationItem[] = inject('app-links', []) const context: DashboardRendererContext = { filters: [], refreshInterval: 0, + editable: true, } const dashboardConfig: DashboardConfig = { @@ -136,7 +137,6 @@ const dashboardConfig: DashboardConfig = { datasource: 'basic', dimensions: ['route'], }, - editable: true, }, layout: { position: { @@ -159,7 +159,6 @@ const dashboardConfig: DashboardConfig = { datasource: 'basic', dimensions: ['time'], }, - editable: true, }, layout: { position: { diff --git a/packages/analytics/dashboard-renderer/src/components/BarChartRenderer.vue b/packages/analytics/dashboard-renderer/src/components/BarChartRenderer.vue index e8f61df26e..cc87b0473f 100644 --- a/packages/analytics/dashboard-renderer/src/components/BarChartRenderer.vue +++ b/packages/analytics/dashboard-renderer/src/components/BarChartRenderer.vue @@ -3,7 +3,7 @@