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

fix 14991: support custom comparison period start date #22267

Conversation

nikitaevg
Copy link
Contributor

@nikitaevg nikitaevg commented May 12, 2024

Problem

Fix #14991

Changes

This is a draft of the frontend implementation.

Here's how it looks like.

Does this work well for both Cloud and self-hosted?

How did you test this code?

Copy link
Contributor Author

@nikitaevg nikitaevg left a comment

Choose a reason for hiding this comment

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

Hi @mariusandra! Could you please review the UI and the comments I left in the PR?

@@ -2003,6 +2007,7 @@ export interface TrendsFilterType extends FilterType {
// 7 days to remove weekly variation. Smoothing is performed as a moving average.
smoothing_intervals?: number
compare?: boolean
comparison?: Comparison
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Once this change is rolled out I plan to remove the compare field and use comparison instead. If comparison is present, we should compare based on its internal fields.

For now these fields will work together for backward compatibility.

interval = 'hour'
}
let diffBetweenDates = dateTo.diff(dateFrom, interval, /* float= */ true)
// This assumes that dateTo is now, so we need to look twice further to see
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This assumption is not always true. I'll fix it in the next PRs to not overcomplicate this one

/>
<RollingDateRangeFilter
pageKey={key}
dateFrom={comparisonRelativePeriodStart}
Copy link
Contributor Author

@nikitaevg nikitaevg May 19, 2024

Choose a reason for hiding this comment

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

There's a problem here. When I update the insight range, the comparison period is not updated, because RollingDateRangeFilter stores the current values in the state. Here's a video of what I mean, "2 days" comparison period remains the same.

IIUC if I want to update the comparison period when the range updates, I need to

  1. create compareFilterLogic
  2. Connect it to the insightLogic; listen to the updateInsightFilter
  3. On updateInsightFilter call a method that would update RollingDateRangeFilter state from the new comparison period

Is that correct? If so, I suggest I implement it in the follow up PR, WDYT? Maybe there's a simpler way to do this?


const DEFAULT_RELATIVE_START_DATE = '1d'

export const getDefaultComparisonPeriodRelativeStartDate = (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method is based on getComparePeriodDates. It's simpler and seems more consistent between "last 7 days" and "last 6 days"

@posthog-bot
Copy link
Contributor

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week.

@posthog-bot
Copy link
Contributor

This PR was closed due to lack of activity. Feel free to reopen if it's still relevant.

@posthog-bot posthog-bot closed this Jun 3, 2024
@mariusandra mariusandra reopened this Jun 4, 2024
@mariusandra mariusandra requested a review from a team June 4, 2024 14:54
@mariusandra
Copy link
Collaborator

@PostHog/team-product-analytics can someone have a look at this? I understand there's an alternative in the works?

@posthog-bot posthog-bot removed the stale label Jun 5, 2024
@posthog-bot
Copy link
Contributor

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week.

@aspicer
Copy link
Contributor

aspicer commented Jun 17, 2024

Hi @nikitaevg, we shipped this last week: #22397 which covers these changes.

I didn't see this PR until I had already built out the functionality. Closing this.

@aspicer aspicer closed this Jun 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make it easier to compare a specific week day, month of the year with a previous instance
4 participants