Move annotation refreshing to AutoRefresh
parent
b901165c63
commit
29733441ad
|
@ -120,32 +120,24 @@ interface State {
|
||||||
|
|
||||||
@ErrorHandling
|
@ErrorHandling
|
||||||
class DashboardPage extends Component<Props, State> {
|
class DashboardPage extends Component<Props, State> {
|
||||||
private intervalID: number
|
|
||||||
|
|
||||||
public constructor(props: Props) {
|
public constructor(props: Props) {
|
||||||
super(props)
|
super(props)
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
|
scrollTop: 0,
|
||||||
isEditMode: false,
|
isEditMode: false,
|
||||||
selectedCell: null,
|
selectedCell: null,
|
||||||
scrollTop: 0,
|
|
||||||
windowHeight: window.innerHeight,
|
windowHeight: window.innerHeight,
|
||||||
dashboardLinks: EMPTY_LINKS,
|
dashboardLinks: EMPTY_LINKS,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async componentDidMount() {
|
public async componentDidMount() {
|
||||||
const {source, getAnnotationsAsync, timeRange, autoRefresh} = this.props
|
const {autoRefresh} = this.props
|
||||||
|
|
||||||
const annotationRange = millisecondTimeRange(timeRange)
|
|
||||||
getAnnotationsAsync(source.links.annotations, annotationRange)
|
|
||||||
|
|
||||||
AutoRefresh.poll(autoRefresh)
|
|
||||||
|
|
||||||
if (autoRefresh) {
|
if (autoRefresh) {
|
||||||
this.intervalID = window.setInterval(() => {
|
AutoRefresh.poll(autoRefresh)
|
||||||
getAnnotationsAsync(source.links.annotations, annotationRange)
|
AutoRefresh.subscribe(this.fetchAnnotations)
|
||||||
}, autoRefresh)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener('resize', this.handleWindowResize, true)
|
window.addEventListener('resize', this.handleWindowResize, true)
|
||||||
|
@ -155,45 +147,37 @@ class DashboardPage extends Component<Props, State> {
|
||||||
this.getDashboardLinks()
|
this.getDashboardLinks()
|
||||||
}
|
}
|
||||||
|
|
||||||
public componentWillReceiveProps(nextProps: Props) {
|
public fetchAnnotations = () => {
|
||||||
const {source, getAnnotationsAsync, timeRange} = this.props
|
const {source, timeRange, getAnnotationsAsync} = this.props
|
||||||
if (this.props.autoRefresh !== nextProps.autoRefresh) {
|
const rangeMs = millisecondTimeRange(timeRange)
|
||||||
clearInterval(this.intervalID)
|
getAnnotationsAsync(source.links.annotations, rangeMs)
|
||||||
this.intervalID = null
|
|
||||||
const annotationRange = millisecondTimeRange(timeRange)
|
|
||||||
if (nextProps.autoRefresh) {
|
|
||||||
this.intervalID = window.setInterval(() => {
|
|
||||||
getAnnotationsAsync(source.links.annotations, annotationRange)
|
|
||||||
}, nextProps.autoRefresh)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public componentDidUpdate(prevProps: Props) {
|
public componentDidUpdate(prevProps: Props) {
|
||||||
|
const {dashboard, autoRefresh} = this.props
|
||||||
|
|
||||||
const prevPath = getDeep(prevProps.location, 'pathname', null)
|
const prevPath = getDeep(prevProps.location, 'pathname', null)
|
||||||
const thisPath = getDeep(this.props.location, 'pathname', null)
|
const thisPath = getDeep(this.props.location, 'pathname', null)
|
||||||
|
|
||||||
const templates = getDeep<TempVarsModels.Template[]>(
|
const templates = this.parseTempVar(dashboard)
|
||||||
this.props.dashboard,
|
const prevTemplates = this.parseTempVar(prevProps.dashboard)
|
||||||
'templates',
|
|
||||||
[]
|
const intersection = _.intersection(templates, prevTemplates)
|
||||||
).map(t => t.tempVar)
|
const isTemplateDeleted = intersection.length !== prevTemplates.length
|
||||||
const prevTemplates = getDeep<TempVarsModels.Template[]>(
|
|
||||||
prevProps.dashboard,
|
|
||||||
'templates',
|
|
||||||
[]
|
|
||||||
).map(t => t.tempVar)
|
|
||||||
const isTemplateDeleted: boolean =
|
|
||||||
_.intersection(templates, prevTemplates).length !== prevTemplates.length
|
|
||||||
|
|
||||||
if ((prevPath && thisPath && prevPath !== thisPath) || isTemplateDeleted) {
|
if ((prevPath && thisPath && prevPath !== thisPath) || isTemplateDeleted) {
|
||||||
this.getDashboard()
|
this.getDashboard()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (autoRefresh !== prevProps.autoRefresh) {
|
||||||
|
AutoRefresh.poll(autoRefresh)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public componentWillUnmount() {
|
public componentWillUnmount() {
|
||||||
clearInterval(this.intervalID)
|
AutoRefresh.stopPolling()
|
||||||
this.intervalID = null
|
AutoRefresh.unsubscribe(this.fetchAnnotations)
|
||||||
|
|
||||||
window.removeEventListener('resize', this.handleWindowResize, true)
|
window.removeEventListener('resize', this.handleWindowResize, true)
|
||||||
this.props.handleDismissEditingAnnotation()
|
this.props.handleDismissEditingAnnotation()
|
||||||
}
|
}
|
||||||
|
@ -220,7 +204,6 @@ class DashboardPage extends Component<Props, State> {
|
||||||
cellQueryStatus,
|
cellQueryStatus,
|
||||||
thresholdsListType,
|
thresholdsListType,
|
||||||
thresholdsListColors,
|
thresholdsListColors,
|
||||||
|
|
||||||
inPresentationMode,
|
inPresentationMode,
|
||||||
handleChooseAutoRefresh,
|
handleChooseAutoRefresh,
|
||||||
handleShowCellEditorOverlay,
|
handleShowCellEditorOverlay,
|
||||||
|
@ -349,6 +332,12 @@ class DashboardPage extends Component<Props, State> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public parseTempVar(
|
||||||
|
dashboard: DashboardsModels.Dashboard
|
||||||
|
): TempVarsModels.Template[] {
|
||||||
|
return getDeep(dashboard, 'templates', []).map(t => t.tempVar)
|
||||||
|
}
|
||||||
|
|
||||||
private handleWindowResize = (): void => {
|
private handleWindowResize = (): void => {
|
||||||
this.setState({windowHeight: window.innerHeight})
|
this.setState({windowHeight: window.innerHeight})
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,7 +111,7 @@ class LineGraph extends PureComponent<LineGraphProps> {
|
||||||
labelsKMB: true,
|
labelsKMB: true,
|
||||||
fillGraph: true,
|
fillGraph: true,
|
||||||
axisLabelWidth: 60,
|
axisLabelWidth: 60,
|
||||||
animatedZooms: false,
|
animatedZooms: true,
|
||||||
drawAxesAtZero: true,
|
drawAxesAtZero: true,
|
||||||
axisLineColor: '#383846',
|
axisLineColor: '#383846',
|
||||||
gridLineColor: '#383846',
|
gridLineColor: '#383846',
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
type func = () => any
|
type func = (...args: any[]) => any
|
||||||
|
|
||||||
class AutoRefresh {
|
class AutoRefresh {
|
||||||
public subscribers: func[] = []
|
public subscribers: func[] = []
|
||||||
|
@ -21,6 +21,10 @@ class AutoRefresh {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public stopPolling() {
|
||||||
|
this.clearInterval()
|
||||||
|
}
|
||||||
|
|
||||||
private clearInterval() {
|
private clearInterval() {
|
||||||
if (!this.intervalID) {
|
if (!this.intervalID) {
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue