mirror of
https://github.com/PostHog/posthog.git
synced 2024-11-24 09:14:46 +01:00
Fix date range component in insights (#4248)
This commit is contained in:
parent
209431c6f6
commit
da040fc024
@ -1,19 +1,19 @@
|
||||
import React from 'react'
|
||||
import { useValues, useActions } from 'kea'
|
||||
import { dateFilterLogic } from './dateFilterLogic'
|
||||
import { DateFilterProps, DateFilter as DateFilterComponent } from 'lib/components/DateFilter/DateFilter'
|
||||
import { insightDateFilterLogic } from './insightDateFilterLogic'
|
||||
import { DateFilterProps, DateFilter } from 'lib/components/DateFilter/DateFilter'
|
||||
import './index.scss'
|
||||
|
||||
export function DateFilter(props: DateFilterProps): JSX.Element {
|
||||
export function InsightDateFilter(props: DateFilterProps): JSX.Element {
|
||||
const {
|
||||
dates: { dateFrom, dateTo },
|
||||
highlightDateChange,
|
||||
} = useValues(dateFilterLogic)
|
||||
const { setDates } = useActions(dateFilterLogic)
|
||||
} = useValues(insightDateFilterLogic)
|
||||
const { setDates } = useActions(insightDateFilterLogic)
|
||||
|
||||
return (
|
||||
<span className={highlightDateChange ? 'insights-date-filter highlighted' : ''}>
|
||||
<DateFilterComponent
|
||||
<DateFilter
|
||||
{...props}
|
||||
dateFrom={dateFrom}
|
||||
dateTo={dateTo}
|
@ -1,8 +1,8 @@
|
||||
import { kea } from 'kea'
|
||||
import { router } from 'kea-router'
|
||||
import dayjs from 'dayjs'
|
||||
import { dateFilterLogicType } from 'scenes/insights/DateFilter/dateFilterLogicType'
|
||||
import { objectsEqual } from 'lib/utils'
|
||||
import { insightDateFilterLogicType } from './insightDateFilterLogicType'
|
||||
|
||||
type Dayjs = dayjs.Dayjs
|
||||
|
||||
@ -11,7 +11,7 @@ interface UrlParams {
|
||||
date_to?: string
|
||||
}
|
||||
|
||||
export const dateFilterLogic = kea<dateFilterLogicType<UrlParams, Dayjs>>({
|
||||
export const insightDateFilterLogic = kea<insightDateFilterLogicType<UrlParams, Dayjs>>({
|
||||
actions: () => ({
|
||||
setDates: (dateFrom: string | Dayjs | undefined, dateTo: string | Dayjs | undefined) => ({
|
||||
dateFrom,
|
@ -1,7 +1,6 @@
|
||||
import { useValues } from 'kea'
|
||||
import { ChartFilter } from 'lib/components/ChartFilter'
|
||||
import { CompareFilter } from 'lib/components/CompareFilter/CompareFilter'
|
||||
import { DateFilter } from 'lib/components/DateFilter/DateFilter'
|
||||
import { IntervalFilter } from 'lib/components/IntervalFilter'
|
||||
import { SaveToDashboard } from 'lib/components/SaveToDashboard/SaveToDashboard'
|
||||
import { TZIndicator } from 'lib/components/TimezoneAware'
|
||||
@ -11,6 +10,7 @@ import React from 'react'
|
||||
import { DisplayType, FilterType } from '~/types'
|
||||
import { ViewType } from '../insightLogic'
|
||||
import { CalendarOutlined } from '@ant-design/icons'
|
||||
import { InsightDateFilter } from '../InsightDateFilter'
|
||||
|
||||
interface InsightDisplayConfigProps {
|
||||
clearAnnotationsToCreate: () => void
|
||||
@ -114,7 +114,7 @@ function DefaultInsightDisplayConfig({
|
||||
)}
|
||||
|
||||
{showDateFilter[activeView] && (
|
||||
<DateFilter defaultValue="Last 7 days" disabled={dateFilterDisabled} bordered={false} />
|
||||
<InsightDateFilter defaultValue="Last 7 days" disabled={dateFilterDisabled} bordered={false} />
|
||||
)}
|
||||
|
||||
{showComparePrevious[activeView] && <CompareFilter />}
|
||||
@ -161,7 +161,7 @@ function HorizontalDefaultInsightDisplayConfig({
|
||||
{showIntervalFilter(activeView, allFilters) && <IntervalFilter view={activeView} />}
|
||||
{showDateFilter[activeView] && (
|
||||
<>
|
||||
<DateFilter
|
||||
<InsightDateFilter
|
||||
defaultValue="Last 7 days"
|
||||
disabled={dateFilterDisabled}
|
||||
bordered={false}
|
||||
|
@ -3,13 +3,13 @@ import { kea } from 'kea'
|
||||
import { insightCommandLogicType } from './insightCommandLogicType'
|
||||
import { compareFilterLogic } from 'lib/components/CompareFilter/compareFilterLogic'
|
||||
import { RiseOutlined } from '@ant-design/icons'
|
||||
import { dateFilterLogic } from 'scenes/insights/DateFilter/dateFilterLogic'
|
||||
import { insightDateFilterLogic } from 'scenes/insights/InsightDateFilter/insightDateFilterLogic'
|
||||
import { dateMapping } from 'lib/utils'
|
||||
|
||||
const INSIGHT_COMMAND_SCOPE = 'insights'
|
||||
|
||||
export const insightCommandLogic = kea<insightCommandLogicType>({
|
||||
connect: [commandPaletteLogic, compareFilterLogic, dateFilterLogic],
|
||||
connect: [commandPaletteLogic, compareFilterLogic, insightDateFilterLogic],
|
||||
events: () => ({
|
||||
afterMount: () => {
|
||||
const funnelCommands: Command[] = [
|
||||
@ -27,7 +27,7 @@ export const insightCommandLogic = kea<insightCommandLogicType>({
|
||||
icon: RiseOutlined,
|
||||
display: `Set Time Range to ${key}`,
|
||||
executor: () => {
|
||||
dateFilterLogic.actions.setDates(value[0], value[1])
|
||||
insightDateFilterLogic.actions.setDates(value[0], value[1])
|
||||
},
|
||||
})),
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user