-
Notifications
You must be signed in to change notification settings - Fork 10
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
feat(dashboards and charts): editable tiles | slottable menu items #1758
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,19 @@ | ||
<!-- BarChartRenderer.vue --> | ||
<template> | ||
<QueryDataProvider | ||
v-slot="{ data }" | ||
<BaseAnalyticsChartRenderer | ||
:chart-options="chartOptions" | ||
:context="context" | ||
:editable="context.editable" | ||
:extra-props="{ showAnnotations: false }" | ||
:height="height" | ||
:query="query" | ||
:query-ready="queryReady" | ||
> | ||
<div class="analytics-chart"> | ||
<AnalyticsChart | ||
:allow-csv-export="chartOptions.allowCsvExport" | ||
:chart-data="data" | ||
:chart-options="options" | ||
:chart-title="chartOptions.chartTitle" | ||
legend-position="bottom" | ||
:show-annotations="false" | ||
:synthetics-data-key="chartOptions.syntheticsDataKey" | ||
tooltip-title="" | ||
/> | ||
</div> | ||
</QueryDataProvider> | ||
/> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import BaseAnalyticsChartRenderer from './BaseAnalyticsChartRenderer.vue' | ||
import type { BarChartOptions, RendererProps } from '../types' | ||
import QueryDataProvider from './QueryDataProvider.vue' | ||
import { computed } from 'vue' | ||
import type { AnalyticsChartOptions } from '@kong-ui-public/analytics-chart' | ||
import { AnalyticsChart } from '@kong-ui-public/analytics-chart' | ||
|
||
const props = defineProps<RendererProps<BarChartOptions>>() | ||
|
||
const options = computed((): AnalyticsChartOptions => ({ | ||
type: props.chartOptions.type, | ||
stacked: props.chartOptions.stacked, | ||
chartDatasetColors: props.chartOptions.chartDatasetColors, | ||
})) | ||
defineProps<RendererProps<BarChartOptions>>() | ||
</script> | ||
|
||
<style scoped lang="scss"> | ||
.analytics-chart { | ||
height: v-bind('`${height}px`'); | ||
} | ||
</style> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<template> | ||
<QueryDataProvider | ||
v-slot="{ data }" | ||
:context="context" | ||
:query="query" | ||
:query-ready="queryReady" | ||
> | ||
<div class="analytics-chart"> | ||
<AnalyticsChart | ||
:allow-csv-export="chartOptions.allowCsvExport" | ||
:chart-data="data" | ||
:chart-options="options" | ||
:chart-title="chartOptions.chartTitle" | ||
legend-position="bottom" | ||
:show-menu="context.editable" | ||
:synthetics-data-key="chartOptions.syntheticsDataKey" | ||
tooltip-title="" | ||
v-bind="extraProps" | ||
> | ||
<template | ||
v-if="context.editable" | ||
#menu-items | ||
> | ||
<KDropdownItem @click="editTile"> | ||
{{ i18n.t('renderer.edit') }} | ||
</KDropdownItem> | ||
</template> | ||
</AnalyticsChart> | ||
</div> | ||
</QueryDataProvider> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import type { RendererProps } from '../types' | ||
import QueryDataProvider from './QueryDataProvider.vue' | ||
import { computed, defineProps } from 'vue' | ||
import type { AnalyticsChartOptions } from '@kong-ui-public/analytics-chart' | ||
import { AnalyticsChart } from '@kong-ui-public/analytics-chart' | ||
import composables from '../composables' | ||
|
||
const props = defineProps<RendererProps<any> & { extraProps?: Record<string, any> }>() | ||
const emit = defineEmits<{ | ||
(e: 'edit-tile'): void | ||
}>() | ||
const { i18n } = composables.useI18n() | ||
|
||
const options = computed((): AnalyticsChartOptions => ({ | ||
type: props.chartOptions.type, | ||
stacked: props.chartOptions.stacked ?? false, | ||
chartDatasetColors: props.chartOptions.chartDatasetColors, | ||
})) | ||
|
||
const editTile = () => { | ||
emit('edit-tile') | ||
} | ||
</script> | ||
|
||
<style scoped lang="scss"> | ||
.analytics-chart { | ||
height: v-bind('`${height}px`'); | ||
} | ||
</style> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
:is="componentData.component" | ||
v-if="componentData" | ||
v-bind="componentData.rendererProps" | ||
@edit-tile="onEditTile" | ||
/> | ||
</div> | ||
</template> | ||
|
@@ -34,6 +35,10 @@ const props = withDefaults(defineProps<{ | |
height: DEFAULT_TILE_HEIGHT, | ||
}) | ||
|
||
const emit = defineEmits<{ | ||
(e: 'edit-tile', tile: TileDefinition): void | ||
}>() | ||
|
||
const rendererLookup: Record<DashboardTileType, Component | undefined> = { | ||
'timeseries_line': TimeseriesChartRenderer, | ||
'horizontal_bar': BarChartRenderer, | ||
|
@@ -56,9 +61,14 @@ const componentData = computed(() => { | |
queryReady: props.queryReady, | ||
chartOptions: props.definition.chart, | ||
height: props.height - PADDING_SIZE * 2, | ||
editable: props.context.editable, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think you need to pass in this prop. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like it's still there... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh, my bad. I got rid of using the prop, forgot to revert this line 😅 |
||
}, | ||
} | ||
}) | ||
|
||
const onEditTile = () => { | ||
emit('edit-tile', props.definition) | ||
} | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,18 +46,24 @@ const overrideTimeframe: Ref<Timeframe> = computed(() => { | |
return relativePeriod | ||
}) | ||
|
||
const options = computed<ProviderProps>(() => ({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a type error here that's somehow getting past CI... 🤔
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's from updates to analytics-utilities which introduced the Not sure if my change is the right one, or we should add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm. I'll make a note to look at this later. I think this is the fault of the schema; it shouldn't allow setting |
||
datasource: props.query?.datasource, | ||
overrideTimeframe: overrideTimeframe.value, | ||
tz: props.context.tz, | ||
additionalFilter: props.context.filters as ExploreFilter[], // TODO: Decide how to handle metric card filters. | ||
longCardTitles: props.chartOptions.longCardTitles, | ||
containerTitle: props.chartOptions.chartTitle, | ||
description: props.chartOptions.description, | ||
percentileLatency: props.chartOptions.percentileLatency, | ||
refreshInterval: props.context.refreshInterval, | ||
queryReady: props.queryReady, | ||
})) | ||
const options = computed<ProviderProps>(() => { | ||
const datasource = props.query?.datasource | ||
if (datasource && datasource !== 'advanced' && datasource !== 'basic') { | ||
throw new Error(`Invalid datasource value: ${datasource}`) | ||
} | ||
return { | ||
datasource: props.query?.datasource, | ||
overrideTimeframe: overrideTimeframe.value, | ||
tz: props.context.tz, | ||
additionalFilter: props.context.filters as ExploreFilter[], // TODO: Decide how to handle metric card filters. | ||
longCardTitles: props.chartOptions.longCardTitles, | ||
containerTitle: props.chartOptions.chartTitle, | ||
description: props.chartOptions.description, | ||
percentileLatency: props.chartOptions.percentileLatency, | ||
refreshInterval: props.context.refreshInterval, | ||
queryReady: props.queryReady, | ||
} | ||
}) | ||
</script> | ||
|
||
<style scoped lang="scss"> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,18 @@ | ||
<!-- TimeseriesChartRenderer.vue --> | ||
<template> | ||
<QueryDataProvider | ||
v-slot="{ data }" | ||
<BaseAnalyticsChartRenderer | ||
:chart-options="chartOptions" | ||
:context="context" | ||
:editable="context.editable" | ||
:height="height" | ||
:query="query" | ||
:query-ready="queryReady" | ||
> | ||
<div class="analytics-chart"> | ||
<AnalyticsChart | ||
:allow-csv-export="chartOptions.allowCsvExport" | ||
:chart-data="data" | ||
:chart-options="options" | ||
:chart-title="chartOptions.chartTitle" | ||
legend-position="bottom" | ||
:synthetics-data-key="chartOptions.syntheticsDataKey" | ||
tooltip-title="" | ||
/> | ||
</div> | ||
</QueryDataProvider> | ||
/> | ||
</template> | ||
<script setup lang="ts"> | ||
import type { RendererProps, TimeseriesChartOptions } from '../types' | ||
import QueryDataProvider from './QueryDataProvider.vue' | ||
import { computed } from 'vue' | ||
import type { AnalyticsChartOptions } from '@kong-ui-public/analytics-chart' | ||
import { AnalyticsChart } from '@kong-ui-public/analytics-chart' | ||
|
||
const props = defineProps<RendererProps<TimeseriesChartOptions>>() | ||
|
||
const options = computed((): AnalyticsChartOptions => { | ||
// Default `stacked` to false. | ||
const stacked = props.chartOptions.stacked ?? false | ||
<script setup lang="ts"> | ||
import BaseAnalyticsChartRenderer from './BaseAnalyticsChartRenderer.vue' | ||
import type { TimeseriesChartOptions, RendererProps } from '../types' | ||
|
||
// Note that `fill` and `stacked` are linked; it's not possible to have a non-filled stacked chart. | ||
// This matches our intuitions about how these charts work. | ||
return { | ||
type: props.chartOptions.type, | ||
stacked, | ||
chartDatasetColors: props.chartOptions.chartDatasetColors, | ||
} | ||
}) | ||
defineProps<RendererProps<TimeseriesChartOptions>>() | ||
</script> | ||
|
||
<style scoped lang="scss"> | ||
.analytics-chart { | ||
height: v-bind('`${height}px`'); | ||
} | ||
</style> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're already passing in
context
-- no need for the extra prop. :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done