-
Notifications
You must be signed in to change notification settings - Fork 16.7k
fix(dashboard): refresh tabs as they load when dashboard is refreshed #35265
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
Changes from all commits
4527e25
a522571
9bf0df2
1102a09
3d057c2
ed4c199
d8fbc11
752fa9e
f544500
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 |
|---|---|---|
|
|
@@ -16,15 +16,16 @@ | |
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| import { Fragment, useCallback, memo } from 'react'; | ||
| import { Fragment, useCallback, memo, useEffect } from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import classNames from 'classnames'; | ||
| import { useDispatch, useSelector } from 'react-redux'; | ||
| import { t } from '@superset-ui/core'; | ||
| import { styled } from '@apache-superset/core/ui'; | ||
|
|
||
| import { EditableTitle, EmptyState } from '@superset-ui/core/components'; | ||
| import { setEditMode } from 'src/dashboard/actions/dashboardState'; | ||
| import { setEditMode, onRefresh } from 'src/dashboard/actions/dashboardState'; | ||
| import getChartIdsFromComponent from 'src/dashboard/util/getChartIdsFromComponent'; | ||
| import DashboardComponent from 'src/dashboard/containers/DashboardComponent'; | ||
| import AnchorLink from 'src/dashboard/components/AnchorLink'; | ||
| import { | ||
|
|
@@ -37,6 +38,9 @@ import { TAB_TYPE } from 'src/dashboard/util/componentTypes'; | |
| export const RENDER_TAB = 'RENDER_TAB'; | ||
| export const RENDER_TAB_CONTENT = 'RENDER_TAB_CONTENT'; | ||
|
|
||
| // Delay before refreshing charts to ensure they are fully mounted | ||
| const CHART_MOUNT_DELAY = 100; | ||
|
|
||
| const propTypes = { | ||
| dashboardId: PropTypes.number.isRequired, | ||
| id: PropTypes.string.isRequired, | ||
|
|
@@ -64,6 +68,7 @@ const propTypes = { | |
| handleComponentDrop: PropTypes.func.isRequired, | ||
| updateComponents: PropTypes.func.isRequired, | ||
| setDirectPathToChild: PropTypes.func.isRequired, | ||
| isComponentVisible: PropTypes.bool, | ||
| }; | ||
|
|
||
| const defaultProps = { | ||
|
|
@@ -114,6 +119,43 @@ const renderDraggableContent = dropProps => | |
| const Tab = props => { | ||
| const dispatch = useDispatch(); | ||
| const canEdit = useSelector(state => state.dashboardInfo.dash_edit_perm); | ||
| const dashboardLayout = useSelector(state => state.dashboardLayout.present); | ||
| const lastRefreshTime = useSelector( | ||
| state => state.dashboardState.lastRefreshTime, | ||
| ); | ||
| const tabActivationTime = useSelector( | ||
| state => state.dashboardState.tabActivationTimes?.[props.id] || 0, | ||
| ); | ||
| const dashboardInfo = useSelector(state => state.dashboardInfo); | ||
|
|
||
| useEffect(() => { | ||
| if (props.renderType === RENDER_TAB_CONTENT && props.isComponentVisible) { | ||
| if ( | ||
| lastRefreshTime && | ||
| tabActivationTime && | ||
| lastRefreshTime > tabActivationTime | ||
| ) { | ||
| const chartIds = getChartIdsFromComponent(props.id, dashboardLayout); | ||
| if (chartIds.length > 0) { | ||
| requestAnimationFrame(() => { | ||
| setTimeout(() => { | ||
| dispatch(onRefresh(chartIds, true, 0, dashboardInfo.id)); | ||
| }, CHART_MOUNT_DELAY); | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| }, [ | ||
| props.isComponentVisible, | ||
| props.renderType, | ||
| props.id, | ||
| lastRefreshTime, | ||
| tabActivationTime, | ||
| dashboardLayout, | ||
EnxDev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| dashboardInfo.id, | ||
|
Contributor
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. A bit worried about the dependancy array, have seen that dependancy array might sometimes cause an infinite number of calls , especially , dispatch and dashboardlayout which can be a huge object
Member
Author
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 see any issues from manual testing |
||
| dispatch, | ||
| ]); | ||
|
|
||
| const handleChangeTab = useCallback( | ||
| ({ pathToTabIndex }) => { | ||
| props.setDirectPathToChild(pathToTabIndex); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| import { useSelector } from 'react-redux'; | ||
| import { useMemo } from 'react'; | ||
| import { RootState } from 'src/dashboard/types'; | ||
| import getChartIdsFromLayout from '../getChartIdsFromLayout'; | ||
|
|
||
| export const useAllChartIds = () => { | ||
| const layout = useSelector( | ||
| (state: RootState) => state.dashboardLayout.present, | ||
| ); | ||
| return useMemo(() => getChartIdsFromLayout(layout), [layout]); | ||
This comment was marked as resolved.
Sorry, something went wrong. |
||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| import { CHART_TYPE } from './componentTypes'; | ||
| import type { DashboardLayout } from '../types'; | ||
|
|
||
| export default function getChartIdsFromComponent( | ||
| componentId: string, | ||
| layout: DashboardLayout, | ||
| ): number[] { | ||
|
Comment on lines
+22
to
+25
This comment was marked as resolved.
Sorry, something went wrong. |
||
| const chartIds: number[] = []; | ||
| const component = layout[componentId]; | ||
|
|
||
| if (!component) return chartIds; | ||
|
|
||
| // If this component is a chart, add its ID | ||
| if (component.type === CHART_TYPE && component.meta?.chartId) { | ||
| chartIds.push(component.meta.chartId); | ||
| } | ||
|
|
||
| // Recursively check children | ||
| if (component.children) { | ||
| component.children.forEach((childId: string) => { | ||
| chartIds.push(...getChartIdsFromComponent(childId, layout)); | ||
| }); | ||
| } | ||
|
|
||
| return chartIds; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.