-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
refactor(dashboards): move time series fetcing descision to TimeSeries #14858
Conversation
2021fc0
to
3ed53fa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few things I think we should fix first but +1 on the overall approach.
@@ -78,22 +80,43 @@ const defaultState = (): State => ({ | |||
class TimeSeries extends Component<Props & WithRouterProps, State> { | |||
public static defaultProps = { | |||
implicitSubmit: true, | |||
className: 'vis-plot-container', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be renamed?
} | ||
|
||
public async componentDidUpdate(prevProps: Props) { | ||
if (this.shouldReload(prevProps)) { | ||
if (this.shouldReload(prevProps) && this.isIntersecting) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be put in the shouldReload
method?
this.reload() | ||
} | ||
} | ||
|
||
public componentWillMount() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public componentWillMount() { | |
public componentWillUnmount() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch!
this.observer = new IntersectionObserver(entries => { | ||
entries.forEach(entry => { | ||
const {isIntersecting} = entry | ||
if (!this.isIntersecting && isIntersecting) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this reload a cell every time in scrolls from out of to into view? If true, seems pretty undesirable.
How about queuing reloads into state, then flushing that queue every time the component scrolls into view?
I imagine that working like: any time the component should reload (whether or not it is in view), we set a flag like pendingReload: true
or something. When we reload, we set pendingReload: false
. Then this line could become
if (!this.isIntersecting && isIntersecting) { | |
if (!this.isIntersecting && isIntersecting && this.pendingReload) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm realizing that the existing behavior is reloading the cell when it scrolls from out of view to in view as well, but I still think we should fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. fixed
@@ -238,19 +215,6 @@ class DashboardPage extends Component<Props, State> { | |||
await getDashboard(params.dashboardID) | |||
} | |||
|
|||
private inView = (cell: Cell): boolean => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙌
Why did we do this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did we do this?
lol deniz, the "why" is literally in the PR description 🤣
@ebb-tide Daniel & myself have laid out some changes to dashboards we want to do, such as moving the presentational elements into Clockface. Some of these changes unblock all that. The PR started out as an investigation and ended up as usable code |
#14858) * refactor(dashboards): move time series fetcing descision to TimeSeries * fix: styles and wont refetch already rendered data
What
IntersectionObserver
logic out of theCell
component and into theTimeSeries
componentDashboardPage
and moved the "inView" logic intoTimeSeries
Why
Cell
should fetch data in one place@influxdata/clockface
FancyScrollbars
ReactGridLayout
and styles into presentational components that can be shared across multiple projects (like Quartz)