ui: move focus to session list on line click

This commit is contained in:
nick-delirium 2025-01-14 14:15:27 +01:00
parent 5fcc974382
commit 8f6731b7d2
No known key found for this signature in database
GPG key ID: 93ABD695DF5FDBA0
3 changed files with 22 additions and 4 deletions

View file

@ -89,6 +89,7 @@ function WidgetChart(props: Props) {
}, [data.chart]);
const onChartClick = (event: any) => {
metricStore.setDrillDown(true);
if (event) {
if (isTableWidget || isPieChart) {
// get the filter of clicked row
@ -216,6 +217,7 @@ function WidgetChart(props: Props) {
const onFocus = (seriesName: string)=> {
metricStore.setFocusedSeriesName(seriesName);
metricStore.setDrillDown(true)
}
const renderChart = React.useCallback(() => {

View file

@ -1,8 +1,7 @@
import React, { useEffect, useState } from 'react';
import { NoContent, Loader, Pagination } from 'UI';
import {Button, Tag, Tooltip, Select, Dropdown} from 'antd';
import {Button, Tag, Tooltip, Dropdown, notification} from 'antd';
import {UndoOutlined, DownOutlined} from '@ant-design/icons'
//import Select from 'Shared/Select';
import cn from 'classnames';
import { useStore } from 'App/mstore';
import SessionItem from 'Shared/SessionItem';
@ -19,6 +18,7 @@ interface Props {
}
function WidgetSessions(props: Props) {
const listRef = React.useRef<HTMLDivElement>(null);
const { className = '' } = props;
const [activeSeries, setActiveSeries] = useState('all');
const [data, setData] = useState<any>([]);
@ -63,6 +63,17 @@ function WidgetSessions(props: Props) {
.fetchSessions(metricId, filter)
.then((res: any) => {
setData(res);
if (metricStore.drillDown) {
setTimeout(() => {
notification.open({
placement: 'top',
role: 'status',
message: 'Sessions Refreshed!'
})
listRef.current?.scrollIntoView({ behavior: 'smooth' });
metricStore.setDrillDown(false);
}, 0)
}
})
.finally(() => {
setLoading(false);
@ -181,7 +192,7 @@ function WidgetSessions(props: Props) {
</div>
</div>
<div className="mt-3">
<div className="mt-3" >
<Loader loading={loading}>
<NoContent
title={
@ -202,7 +213,7 @@ function WidgetSessions(props: Props) {
</React.Fragment>
))}
<div className="flex items-center justify-between p-5">
<div className="flex items-center justify-between p-5" ref={listRef}>
<div>
Showing{' '}
<span className="font-medium">

View file

@ -102,6 +102,7 @@ export default class MetricStore {
cardCategory: string | null = CATEGORIES.product_analytics;
focusedSeriesName: string | null = null;
drillDown = false;
constructor() {
makeAutoObservable(this);
@ -138,6 +139,10 @@ export default class MetricStore {
this.instance.update(metric || new Widget());
}
setDrillDown(val: boolean) {
this.drillDown = val;
}
setFocusedSeriesName(name: string | null, resetOnSame = true) {
if (this.focusedSeriesName === name && resetOnSame) {
this.focusedSeriesName = null;