Skip to content
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

Merged
merged 2 commits into from
Aug 29, 2019

Conversation

121watts
Copy link
Contributor

@121watts 121watts commented Aug 28, 2019

What

  • Move the IntersectionObserver logic out of the Cell component and into the TimeSeries component
  • Removed state from DashboardPage and moved the "inView" logic into TimeSeries

Why

  • Consolidates all logic of wether a Cell should fetch data in one place
  • Allows @alexpaxton to replace all local page components with @influxdata/clockface
  • Enables @alexpaxton to remove FancyScrollbars
  • Enables extracting ReactGridLayout and styles into presentational components that can be shared across multiple projects (like Quartz)

@121watts 121watts requested a review from chnn August 28, 2019 22:55
@121watts 121watts assigned ebb-tide and unassigned ebb-tide Aug 28, 2019
@121watts 121watts requested a review from ebb-tide August 28, 2019 22:56
Copy link
Contributor

@chnn chnn left a 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',
Copy link
Contributor

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) {
Copy link
Contributor

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() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public componentWillMount() {
public componentWillUnmount() {

Copy link
Contributor Author

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) {
Copy link
Contributor

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

Suggested change
if (!this.isIntersecting && isIntersecting) {
if (!this.isIntersecting && isIntersecting && this.pendingReload) {

Copy link
Contributor

@chnn chnn Aug 28, 2019

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.

Copy link
Contributor Author

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 => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙌

@ebb-tide
Copy link
Contributor

Why did we do this?

Copy link
Contributor Author

@121watts 121watts left a 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 🤣

@alexpaxton
Copy link
Contributor

@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

@121watts 121watts merged commit 25c74b2 into master Aug 29, 2019
@121watts 121watts deleted the fix/dashboard-page branch August 29, 2019 00:02
e-dard pushed a commit that referenced this pull request Aug 30, 2019
#14858)

* refactor(dashboards): move time series fetcing descision to TimeSeries

* fix: styles and wont refetch already rendered data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants