-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dashboards: allow changing date filters & refresh (#3363)
* DashboardHeader to ts * Convert files to typescript * Use BindLogic instead of passing logics as arguments * Improve typing for dashboards * Fix DashboardHeader types * Improve typing: DashboardItem * Fix InsightHistoryPanel, SharedDashboard types * Add WIP code for date ranges on dashboards * DateFilter/dateFilterLogic to typescript * Show 'Custom' daterange by default on a dashboard * Border for dates in Dashboard * Add dashboard.filters field * Populate dashboard.filters, use it in code * Fix some type errors in dashboardItemsModel * Fetch dashboard items again on date change * Make dashboard items refresh as dashboard gets updated * Add refresh button to DashboardHeader * Make saving dashboard items work again * Update dashboard type * Don't update URL in DateFilter * Update selected time range on load * Avoid flickering in DateFilter * Only show 'Custom' in dashboards * Show calendar icon next to date filter in dashboard * Avoid double-loading results due to date change * Kill some duplicated code * Avoid cache when filters change (datefilters on dashboard) * Test individual update_cache method * Add test for import_from and attributes being updated * Fix typing errors * Update api/dashboard tests * Avoid redirects when changing date range for funnels or retention Previously funnelLogic might be mounted in the background, causing a reload * Add a missing breakpoint * Reformat with black
- Loading branch information
Showing
33 changed files
with
491 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { kea } from 'kea' | ||
import { router } from 'kea-router' | ||
import { Moment } from 'moment' | ||
import { dateFilterLogicType } from 'lib/components/DateFilter/dateFilterLogicType' | ||
import { objectsEqual } from 'lib/utils' | ||
|
||
interface UrlParams { | ||
date_from?: string | ||
date_to?: string | ||
} | ||
|
||
export const dateFilterLogic = kea<dateFilterLogicType<UrlParams, Moment>>({ | ||
actions: () => ({ | ||
setDates: (dateFrom: string | Moment | undefined, dateTo: string | Moment | undefined) => ({ | ||
dateFrom, | ||
dateTo, | ||
}), | ||
}), | ||
reducers: () => ({ | ||
dates: [ | ||
{ | ||
dateFrom: undefined as string | Moment | undefined, | ||
dateTo: undefined as string | Moment | undefined, | ||
}, | ||
{ | ||
setDates: (_, dates) => dates, | ||
}, | ||
], | ||
}), | ||
listeners: ({ values }) => ({ | ||
setDates: () => { | ||
const { date_from, date_to, ...searchParams } = router.values.searchParams // eslint-disable-line | ||
const { pathname } = router.values.location | ||
|
||
searchParams.date_from = values.dates.dateFrom | ||
searchParams.date_to = values.dates.dateTo | ||
|
||
if ( | ||
(pathname === '/insights' && !objectsEqual(date_from, values.dates.dateFrom)) || | ||
!objectsEqual(date_to, values.dates.dateTo) | ||
) { | ||
router.actions.push(pathname, searchParams) | ||
} | ||
}, | ||
}), | ||
urlToAction: ({ actions }) => ({ | ||
'/insights': (_: any, { date_from, date_to }: UrlParams) => { | ||
actions.setDates(date_from, date_to) | ||
}, | ||
}), | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.