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

Dashboards: allow changing date filters & refresh #3363

Merged
merged 34 commits into from
Feb 23, 2021
Merged

Conversation

macobo
Copy link
Contributor

@macobo macobo commented Feb 17, 2021

Changes

After this change we show a date filter + refresh button in the dashboard headers.

2021-02-18_09-33

On a high level dashboards now have a separate filters property which needs to be merged into dashboard items.

This was a deceptively hard change. Some things which got refactored as part of this:

  1. Calculating filters_hash: it's now updated every time the dashboard is updated (e.g. when date filter changes).
  2. Serializing dashboard_item filters
  3. Caching + communication mechanisms for each of the insight logics rendered
  4. Porting most of dashboards + date filters code to typescript
  5. We don't pass logics as props anymore, instead using BindProps at the top level.
  6. We also don't show double loading bars in dashboards anymore when things are loading.

Next steps

Since this PR is huge, I've split off some work:

  • Adding component tests for dashboards. I'd like to finish cypress-vcr first.

Checklist

  • All querysets/queries filter by Organization, by Team, and by User
  • Django backend tests

@macobo macobo requested a review from EDsCODE February 17, 2021 13:41
@timgl timgl temporarily deployed to posthog-actual-date-ran-3r08r9 February 17, 2021 13:44 Inactive
@macobo macobo temporarily deployed to posthog-actual-date-ran-3r08r9 February 17, 2021 15:07 Inactive
@macobo macobo temporarily deployed to posthog-actual-date-ran-3r08r9 February 17, 2021 15:35 Inactive
@macobo macobo marked this pull request as ready for review February 18, 2021 07:39
@macobo macobo temporarily deployed to posthog-actual-date-ran-3r08r9 February 19, 2021 11:37 Inactive
Copy link
Member

@EDsCODE EDsCODE left a comment

Choose a reason for hiding this comment

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

Looks good overall. a small note

const [rangeDateFrom, setRangeDateFrom] = useState(
dateFrom && isDate.test(dateFrom as string) ? moment(dateFrom) : undefined
)
const [rangeDateTo, setRangeDateTo] = useState(dateTo && isDate.test(dateTo as string) ? moment(dateTo) : undefined)
Copy link
Member

Choose a reason for hiding this comment

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

Can also accept these as moments directly since the dateFrom/dateTo are typed as undefined | string | moment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I remember there being a good reason why these useState calls needed to exist, but it's not obvious from code. They were also there in the previous version btw. :/

const { dashboard, itemsLoading, items } = useValues(logic)
function _Dashboard({ id, shareToken }: Props): JSX.Element {
return (
<BindLogic logic={dashboardLogic} props={{ id: parseInt(id), shareToken }}>
Copy link
Member

Choose a reason for hiding this comment

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

💪

}
actions.updateDashboard(filters)
dashboardItemsModel.actions.refreshAllDashboardItems(filters)
},
}),
})
Copy link
Member

Choose a reason for hiding this comment

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

One inconsistency I found was that if you had set a dashboard date filter, refreshing the page doesn't apply the filter even though it's in the url params

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting, it should not be part of the URL anymore but be saved on the model. Were you on the latest branch?

if (props.dashboardItemId) {
actions.setFilters(filters)
}
},
}),
})
Copy link
Member

Choose a reason for hiding this comment

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

Not quite relevant here, but important to note is that when using a non custom date range (where dateto defaults to now()), retention dashboard items won't have any change which could be confusing UX-wise.

@EDsCODE EDsCODE mentioned this pull request Feb 22, 2021
6 tasks
@macobo macobo temporarily deployed to posthog-actual-date-ran-3r08r9 February 23, 2021 07:58 Inactive
@macobo macobo temporarily deployed to posthog-actual-date-ran-3r08r9 February 23, 2021 09:11 Inactive
@macobo macobo temporarily deployed to posthog-actual-date-ran-3r08r9 February 23, 2021 10:01 Inactive
@macobo macobo merged commit f403900 into master Feb 23, 2021
@macobo macobo deleted the actual-date-ranges branch February 23, 2021 10:19
@paolodamico paolodamico mentioned this pull request Mar 9, 2021
2 tasks
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.

None yet

3 participants