diff --git a/ui/src/dashboards/containers/DashboardPage.tsx b/ui/src/dashboards/containers/DashboardPage.tsx index 124023775..a329cb3d1 100644 --- a/ui/src/dashboards/containers/DashboardPage.tsx +++ b/ui/src/dashboards/containers/DashboardPage.tsx @@ -37,7 +37,7 @@ import idNormalizer, {TYPE_ID} from 'src/normalizers/id' import {millisecondTimeRange} from 'src/dashboards/utils/time' import {getDeep} from 'src/utils/wrappers' import {updateDashboardLinks} from 'src/dashboards/utils/dashboardSwitcherLinks' -import {GlobalAutoRefresh} from 'src/utils/AutoRefresh' +import {GlobalAutoRefresher} from 'src/utils/AutoRefresher' // APIs import {loadDashboardLinks} from 'src/dashboards/apis' @@ -179,8 +179,8 @@ class DashboardPage extends Component { public async componentDidMount() { const {autoRefresh} = this.props - GlobalAutoRefresh.poll(autoRefresh) - GlobalAutoRefresh.subscribe(this.fetchAnnotations) + GlobalAutoRefresher.poll(autoRefresh) + GlobalAutoRefresher.subscribe(this.fetchAnnotations) window.addEventListener('resize', this.handleWindowResize, true) @@ -214,7 +214,7 @@ class DashboardPage extends Component { } if (autoRefresh !== prevProps.autoRefresh) { - GlobalAutoRefresh.poll(autoRefresh) + GlobalAutoRefresher.poll(autoRefresh) } if ( @@ -226,8 +226,8 @@ class DashboardPage extends Component { } public componentWillUnmount() { - GlobalAutoRefresh.stopPolling() - GlobalAutoRefresh.unsubscribe(this.fetchAnnotations) + GlobalAutoRefresher.stopPolling() + GlobalAutoRefresher.unsubscribe(this.fetchAnnotations) window.removeEventListener('resize', this.handleWindowResize, true) this.props.handleDismissEditingAnnotation() diff --git a/ui/src/data_explorer/containers/DataExplorer.tsx b/ui/src/data_explorer/containers/DataExplorer.tsx index c7754bb16..8fca356e6 100644 --- a/ui/src/data_explorer/containers/DataExplorer.tsx +++ b/ui/src/data_explorer/containers/DataExplorer.tsx @@ -9,7 +9,7 @@ import _ from 'lodash' // Utils import {stripPrefix} from 'src/utils/basepath' -import {GlobalAutoRefresh} from 'src/utils/AutoRefresh' +import {GlobalAutoRefresher} from 'src/utils/AutoRefresher' // Components import QueryMaker from 'src/data_explorer/components/QueryMaker' @@ -82,7 +82,7 @@ export class DataExplorer extends PureComponent { await handleGetDashboards() } - GlobalAutoRefresh.poll(autoRefresh) + GlobalAutoRefresher.poll(autoRefresh) if (query && query.length) { const qc = this.props.queryConfigs[0] @@ -97,7 +97,7 @@ export class DataExplorer extends PureComponent { public componentDidUpdate(prevProps: Props) { const {autoRefresh} = this.props if (autoRefresh !== prevProps.autoRefresh) { - GlobalAutoRefresh.poll(autoRefresh) + GlobalAutoRefresher.poll(autoRefresh) } } @@ -116,7 +116,7 @@ export class DataExplorer extends PureComponent { } public componentWillUnmount() { - GlobalAutoRefresh.stopPolling() + GlobalAutoRefresher.stopPolling() } public render() { diff --git a/ui/src/hosts/containers/HostPage.js b/ui/src/hosts/containers/HostPage.js index a1fda4b7f..e8e40a80a 100644 --- a/ui/src/hosts/containers/HostPage.js +++ b/ui/src/hosts/containers/HostPage.js @@ -20,7 +20,7 @@ import {EMPTY_LINKS} from 'src/dashboards/constants/dashboardHeader' import {setAutoRefresh, delayEnablePresentationMode} from 'shared/actions/app' import {ErrorHandling} from 'src/shared/decorators/errors' -import {GlobalAutoRefresh} from 'src/utils/AutoRefresh' +import {GlobalAutoRefresher} from 'src/utils/AutoRefresher' @ErrorHandling class HostPage extends Component { @@ -55,7 +55,7 @@ class HostPage extends Component { } = await getLayouts() const {location, autoRefresh} = this.props - GlobalAutoRefresh.poll(autoRefresh) + GlobalAutoRefresher.poll(autoRefresh) // fetching layouts and mappings can be done at the same time const {host, measurements} = await this.fetchHostsAndMeasurements(layouts) @@ -82,12 +82,12 @@ class HostPage extends Component { componentDidUpdate(prevProps) { const {autoRefresh} = this.props if (prevProps.autoRefresh !== autoRefresh) { - GlobalAutoRefresh.poll(autoRefresh) + GlobalAutoRefresher.poll(autoRefresh) } } componentWillUnmount() { - GlobalAutoRefresh.stopPolling() + GlobalAutoRefresher.stopPolling() } handleChooseTimeRange = ({lower, upper}) => { diff --git a/ui/src/shared/components/time_series/TimeSeries.tsx b/ui/src/shared/components/time_series/TimeSeries.tsx index 2588225de..2c41f4acd 100644 --- a/ui/src/shared/components/time_series/TimeSeries.tsx +++ b/ui/src/shared/components/time_series/TimeSeries.tsx @@ -19,7 +19,7 @@ import {TimeSeriesServerResponse, TimeSeriesResponse} from 'src/types/series' import {GrabDataForDownloadHandler} from 'src/types/layout' // Utils -import {GlobalAutoRefresh, AutoRefresh} from 'src/utils/AutoRefresh' +import {GlobalAutoRefresher, AutoRefresher} from 'src/utils/AutoRefresher' import {CellNoteVisibility} from 'src/types/dashboards' // Components @@ -39,7 +39,7 @@ interface Props { queries: Query[] timeRange: TimeRange children: (r: RenderProps) => JSX.Element - autoRefresh?: AutoRefresh + autoRefresher?: AutoRefresher inView?: boolean templates?: Template[] editQueryStatus?: () => void @@ -67,7 +67,7 @@ class TimeSeries extends Component { public static defaultProps = { inView: true, templates: [], - autoRefresh: GlobalAutoRefresh, + autoRefresher: GlobalAutoRefresher, } public static getDerivedStateFromProps(props: Props, state: State) { @@ -119,24 +119,24 @@ class TimeSeries extends Component { } public async componentDidMount() { - const {autoRefresh} = this.props + const {autoRefresher} = this.props this.isComponentMounted = true this.executeQueries() - autoRefresh.subscribe(this.executeQueries) + autoRefresher.subscribe(this.executeQueries) } public componentWillUnmount() { - const {autoRefresh} = this.props + const {autoRefresher} = this.props this.isComponentMounted = false - autoRefresh.unsubscribe(this.executeQueries) + autoRefresher.unsubscribe(this.executeQueries) } public async componentDidUpdate(prevProps: Props) { - if (this.props.autoRefresh !== prevProps.autoRefresh) { - prevProps.autoRefresh.unsubscribe(this.executeQueries) - this.props.autoRefresh.subscribe(this.executeQueries) + if (this.props.autoRefresher !== prevProps.autoRefresher) { + prevProps.autoRefresher.unsubscribe(this.executeQueries) + this.props.autoRefresher.subscribe(this.executeQueries) } if (!this.isPropsDifferent(prevProps)) { diff --git a/ui/src/utils/AutoRefresh.ts b/ui/src/utils/AutoRefresher.ts similarity index 82% rename from ui/src/utils/AutoRefresh.ts rename to ui/src/utils/AutoRefresher.ts index 391088151..4e70bc2c6 100644 --- a/ui/src/utils/AutoRefresh.ts +++ b/ui/src/utils/AutoRefresher.ts @@ -1,6 +1,6 @@ type func = (...args: any[]) => any -export class AutoRefresh { +export class AutoRefresher { public subscribers: func[] = [] private intervalID: NodeJS.Timer @@ -39,7 +39,7 @@ export class AutoRefresh { } } -// A global singleton, intended to be configured (via `AutoRefresh#poll`) at a -// page level and consumed arbitrarily deep within the page's render tree +// A global singleton, intended to be configured (via `AutoRefresher#poll`) at +// a page level and consumed arbitrarily deep within the page's render tree // (usually in a `TimeSeries` component) -export const GlobalAutoRefresh = new AutoRefresh() +export const GlobalAutoRefresher = new AutoRefresher()