Skip to content
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

fix(dashboard-renderer): ResizeObserver on dashboard tiles #1291

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
class="tile-container"
:context="mergedContext"
:definition="tile.meta"
:fit-to-content="tile.layout.size.fitToContent"
:height="tile.layout.size.rows * (config.tileHeight || DEFAULT_TILE_HEIGHT) + parseInt(KUI_SPACE_70, 10)"
/>
</template>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<template>
<div class="tile-boundary">
<div
ref="tileBoundary"
class="tile-boundary"
>
<component
:is="componentData.component"
v-if="componentData"
Expand All @@ -12,25 +15,34 @@ import { ChartTypes, type DashboardRendererContext, type TileDefinition } from '
import type {
Component,
} from 'vue'
import { computed } from 'vue'
import { computed, onMounted, onUnmounted, ref } from 'vue'
import '@kong-ui-public/analytics-chart/dist/style.css'
import '@kong-ui-public/analytics-metric-provider/dist/style.css'
import SimpleChartRenderer from './SimpleChartRenderer.vue'
import BarChartRenderer from './BarChartRenderer.vue'
import { DEFAULT_TILE_HEIGHT } from '../constants'
import TimeseriesChartRenderer from './TimeseriesChartRenderer.vue'
import GoldenSignalsRenderer from './GoldenSignalsRenderer.vue'
import { KUI_SPACE_70 } from '@kong/design-tokens'
import TopNTableRenderer from './TopNTableRenderer.vue'
import { KUI_SPACE_70 } from '@kong/design-tokens'

const PADDING_SIZE = parseInt(KUI_SPACE_70, 10)

const props = withDefaults(defineProps<{
definition: TileDefinition,
context: DashboardRendererContext,
height?: number
height?: number,
fitToContent?: boolean,
}>(), {
height: DEFAULT_TILE_HEIGHT,
fitToContent: false,
})

const heightRef = ref(props.height)
const tileBoundary = ref<HTMLDivElement | null>(null)

const resizeObserver = new ResizeObserver(entries => {
heightRef.value = entries[0].contentRect.height
})

const rendererLookup: Record<ChartTypes, Component | undefined> = {
Expand All @@ -54,14 +66,27 @@ const componentData = computed(() => {
context: props.context,
queryReady: true, // TODO: Pipelining
chartOptions: props.definition.chart,
height: props.height - PADDING_SIZE * 2,
height: heightRef.value - PADDING_SIZE * 2,
},
}
})

onMounted(() => {
if (tileBoundary.value && props.fitToContent) {
resizeObserver.observe(tileBoundary.value as HTMLDivElement)
}
})

onUnmounted(() => {
if (tileBoundary.value) {
resizeObserver.unobserve(tileBoundary.value as HTMLDivElement)
}
})

</script>

<style lang="scss" scoped>
.tile-boundary {
height: v-bind('`${height}px`');
height: v-bind('`${heightRef}px`');
}
</style>
Loading