Skip to content

Commit

Permalink
fix: analytics chart kebab menu positioning (#1785)
Browse files Browse the repository at this point in the history
  • Loading branch information
filipgutica authored Nov 19, 2024
1 parent a0a821d commit 54783b3
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@
:allow-csv-export="true"
:chart-data="(exploreResult)"
:chart-options="analyticsChartOptions"
chart-title="Request count by Status Code"
:go-to-explore="(exploreLink)"
:legend-position="legendPosition"
:show-annotations="showAnnotationsToggle"
Expand Down Expand Up @@ -251,7 +250,7 @@
</template>

<script setup lang="ts">
import { computed, ref, watch, inject } from 'vue'
import { computed, ref, watch, inject, provide } from 'vue'
import {
AnalyticsChart,
ChartLegendPosition,
Expand All @@ -266,6 +265,8 @@ import { lookupStatusCodeColor } from '../../src/utils/customColors'
import type { SandboxNavigationItem } from '@kong-ui-public/sandbox-layout'
import { generateMultipleMetricTimeSeriesData, generateSingleMetricTimeSeriesData } from '@kong-ui-public/analytics-utilities'
import CodeText from '../CodeText.vue'
import { INJECT_QUERY_PROVIDER } from '../../src/constants'
import useEvaluateFeatureFlag from '../../src/composables/useEvauluateFeatureFlag'
enum Metrics {
TotalRequests = 'TotalRequests',
Expand Down Expand Up @@ -332,6 +333,7 @@ const exportCsv = () => {
}
const exploreLink: string = 'https://cloud.konghq.tech/us/analytics/explorer'
provide(INJECT_QUERY_PROVIDER, { evaluateFeatureFlagFn: () => true })
const exploreResultText = ref('')
const hasError = computed(() => !isValidJson(exploreResultText.value))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,11 @@ describe('<AnalyticsChart />', () => {

cy.getTestId('chart-action-menu').should('exist')

cy.get('.chart-header').trigger('mouseenter')
cy.getTestId('kebab-action-menu').should('be.visible')

// eslint-disable-next-line cypress/unsafe-to-chain-command
cy.getTestId('chart-action-menu').click().then(() => {
cy.getTestId('kebab-action-menu').click().then(() => {
cy.getTestId('chart-jump-to-explore').should('not.exist')

cy.getTestId('csv-export-button').click()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<template>
<div class="analytics-chart-shell">
<div
class="analytics-chart-shell"
:class="{ 'is-hovering': isHovering }"
@mouseenter="handleMouseEnter"
@mouseleave="handleMouseLeave"
>
<div
v-if="showChartHeader"
class="chart-header"
>
<div
Expand Down Expand Up @@ -43,10 +47,17 @@
class="dropdown"
data-testid="chart-action-menu"
>
<MoreIcon
:color="KUI_COLOR_TEXT_NEUTRAL"
:size="KUI_ICON_SIZE_40"
/>
<button
appearance="none"
:aria-label="i18n.t('more_actions')"
class="kebab-action-menu"
data-testid="kebab-action-menu"
>
<MoreIcon
:color="KUI_COLOR_TEXT_NEUTRAL"
:size="KUI_ICON_SIZE_40"
/>
</button>
<template #items>
<KDropdownItem
v-if="!!goToExplore"
Expand Down Expand Up @@ -158,7 +169,7 @@ import { msToGranularity } from '@kong-ui-public/analytics-utilities'
import type { AbsoluteTimeRangeV4, ExploreAggregations, ExploreResultV4, GranularityValues } from '@kong-ui-public/analytics-utilities'
import { hasMillisecondTimestamps, defaultStatusCodeColors } from '../utils'
import TimeSeriesChart from './chart-types/TimeSeriesChart.vue'
import { KUI_COLOR_TEXT_NEUTRAL, KUI_COLOR_TEXT_WARNING, KUI_ICON_SIZE_40 } from '@kong/design-tokens'
import { KUI_COLOR_TEXT_NEUTRAL, KUI_COLOR_TEXT_WARNING, KUI_ICON_SIZE_40, KUI_SPACE_70 } from '@kong/design-tokens'
import { MoreIcon, WarningIcon } from '@kong/icons'
import CsvExportModal from './CsvExportModal.vue'
import CsvExportButton from './CsvExportButton.vue'
Expand Down Expand Up @@ -249,6 +260,8 @@ const { evaluateFeatureFlag } = composables.useEvaluateFeatureFlag()
const hasKebabMenuAccess = evaluateFeatureFlag('ma-3043-analytics-chart-kebab-menu', false)
const rawChartData = toRef(props, 'chartData')
const isHovering = ref(false)
const computedChartData = computed(() => {
return isTimeSeriesChart.value
Expand Down Expand Up @@ -364,10 +377,6 @@ const hasValidChartData = computed(() => {
return props.chartData && props.chartData.meta && props.chartData.data.length
})
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 || props.showMenu)
const timeSeriesGranularity = computed<GranularityValues>(() => {
Expand Down Expand Up @@ -429,6 +438,22 @@ const chartTooltipSortFn = computed(() => {
}
})
const chartHeaderPosition = computed(() => {
return props.chartTitle || !hasKebabMenuAccess || (resultSetTruncated.value && maxEntitiesShown.value) ? 'relative' : 'absolute'
})
const chartHeaderWidth = computed(() => {
return chartHeaderPosition.value === 'relative' ? '100%' : KUI_SPACE_70
})
const handleMouseEnter = () => {
isHovering.value = true
}
const handleMouseLeave = () => {
isHovering.value = false
}
provide('showLegendValues', showLegendValues)
provide('legendPosition', toRef(props, 'legendPosition'))
Expand All @@ -440,8 +465,16 @@ provide('legendPosition', toRef(props, 'legendPosition'))
.analytics-chart-shell {
height: 100%;
position: relative;
width: 100%;
&.is-hovering {
.chart-header :deep(.popover-trigger-wrapper) {
opacity: 1;
visibility: visible;
}
}
.analytics-chart-parent {
height: inherit;
width: inherit;
Expand All @@ -458,6 +491,15 @@ provide('legendPosition', toRef(props, 'legendPosition'))
display: flex;
justify-content: flex-start;
padding-bottom: var(--kui-space-60, $kui-space-60);
position: v-bind('chartHeaderPosition');
right: 0;
width: v-bind('chartHeaderWidth');
z-index: 999;
&:hover :deep(.popover-trigger-wrapper) {
opacity: 1;
visibility: visible;
}
.chart-header-icons-wrapper {
display: flex;
Expand Down Expand Up @@ -493,6 +535,21 @@ provide('legendPosition', toRef(props, 'legendPosition'))
margin-left: var(--kui-space-auto, $kui-space-auto);
margin-right: var(--kui-space-0, $kui-space-0);
:deep(.popover-trigger-wrapper) {
opacity: 0;
transform: fade(0, -10px);
transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s;
visibility: hidden;
}
.kebab-action-menu {
background: $kui-color-background-transparent;
border: none;
color: inherit;
cursor: pointer;
height: 100%;
}
li.k-dropdown-item {
a {
text-decoration: none;
Expand All @@ -512,5 +569,4 @@ provide('legendPosition', toRef(props, 'legendPosition'))
}
}
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
>
<canvas
ref="canvas"
class="chart-canvas"
/>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
:key="remountLineKey"
ref="chartInstance"
:chart-id="chartID"
class="chart-canvas"
:data="(chartData as any)"
data-testid="time-series-line-chart"
:options="(options as any)"
Expand All @@ -23,6 +24,7 @@
:key="remountBarKey"
ref="chartInstance"
:chart-id="chartID"
class="chart-canvas"
:data="(chartData as any)"
data-testid="time-series-bar-chart"
:options="(options as any)"
Expand Down
1 change: 1 addition & 0 deletions packages/analytics/analytics-chart/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"debug": "debug",
"total": "Total",
"jumpToExplore": "Open in Explorer",
"more_actions": "More actions",
"chartUnits": {
"ms": "ms",
"bytes": "Byte{plural}",
Expand Down

0 comments on commit 54783b3

Please sign in to comment.