From 61142546715f29952b359fda41f2a47a10309f73 Mon Sep 17 00:00:00 2001 From: sylenien Date: Thu, 23 Jun 2022 18:01:18 +0200 Subject: [PATCH] fix(ui): fix dashboard widget scroll position on change --- .../DashboardMetricSelection/DashboardMetricSelection.tsx | 8 ++++++++ .../Dashboard/components/WidgetWrapper/WidgetWrapper.tsx | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/frontend/app/components/Dashboard/components/DashboardMetricSelection/DashboardMetricSelection.tsx b/frontend/app/components/Dashboard/components/DashboardMetricSelection/DashboardMetricSelection.tsx index a31bd4ffe..e1e2ccd06 100644 --- a/frontend/app/components/Dashboard/components/DashboardMetricSelection/DashboardMetricSelection.tsx +++ b/frontend/app/components/Dashboard/components/DashboardMetricSelection/DashboardMetricSelection.tsx @@ -36,6 +36,7 @@ function DashboardMetricSelection(props: IProps) { const [activeCategory, setActiveCategory] = React.useState(); const [selectAllCheck, setSelectAllCheck] = React.useState(false); const selectedWidgetIds = useObserver(() => dashboardStore.selectedWidgets.map((widget: any) => widget.metricId)); + const scrollContainer = React.useRef(null); useEffect(() => { dashboardStore?.fetchTemplates(true).then((categories) => { @@ -43,6 +44,12 @@ function DashboardMetricSelection(props: IProps) { }); }, []); + useEffect(() => { + if (scrollContainer.current) { + scrollContainer.current.scrollTop = 0; + } + }, [activeCategory, scrollContainer.current]); + const handleWidgetCategoryClick = (category: any) => { setActiveCategory(category); setSelectAllCheck(false); @@ -100,6 +107,7 @@ function DashboardMetricSelection(props: IProps) {
{activeCategory && activeCategory.widgets.map((widget: any) => ( void; isWidget?: boolean; } -function WidgetWrapper(props: Props) { +function WidgetWrapper(props: Props & RouteComponentProps) { const { dashboardStore } = useStore(); const { isWidget = false, active = false, index = 0, moveListItem = null, isPreview = false, isTemplate = false, dashboardId, siteId } = props; const widget: any = useObserver(() => props.widget);