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(insights): query based duplicateInsight #23435

Merged
merged 15 commits into from
Jul 12, 2024

Conversation

thmsobrmlr
Copy link
Contributor

@thmsobrmlr thmsobrmlr commented Jul 3, 2024

Problem

We want to have only query based insights frontend side, but we still need to send them to the backend with filters. The bigger goal of the coming PRs is to adapt all instances where we send insights to the backend for persistance with a wrapper function, so that the frontend can happily live with query based insights only.

Changes

This PR lets all instances of duplicateInsight take a query based insight and conditionally:

  • sends it with filters or query to the backend, based on a feature flag
  • returns it with filters or query, based on a boolean value -> work is in progress to set this to true everywhere

How did you test this code?

With flag disabled:

  • Duplicated an insight on a dashboard
  • ... on the insights page (list view)
  • ... on the insights page (card view)
  • ... on the insight page

With flag enabled:

  • Duplicated an insight on a dashboard
  • ... on the insights page (list view)
  • ... on the insights page (card view)
  • ... on the insight page

@thmsobrmlr thmsobrmlr changed the base branch from master to remove-legacy-filters-save-as July 3, 2024 10:26
@thmsobrmlr thmsobrmlr force-pushed the duplicate-query-based-insight branch from b94faf7 to acae7df Compare July 3, 2024 14:32
Base automatically changed from remove-legacy-filters-save-as to master July 3, 2024 14:39
@thmsobrmlr thmsobrmlr force-pushed the duplicate-query-based-insight branch from acae7df to a52762c Compare July 3, 2024 14:39
@thmsobrmlr thmsobrmlr force-pushed the duplicate-query-based-insight branch from 84f1b6c to 2027c9d Compare July 3, 2024 20:49
@PostHog PostHog deleted a comment from github-actions bot Jul 3, 2024
@PostHog PostHog deleted a comment from posthog-bot Jul 3, 2024
@PostHog PostHog deleted a comment from github-actions bot Jul 4, 2024

type ReturnedInsightModelByFlag<Flag extends boolean> = Flag extends true ? QueryBasedInsightModel : InsightModel

export const insightsApi = {
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 initially did the handling in lib/api.ts, but that doesn't work as (1) it's included in the toolbar and importing anything there explodes size (2) doing so breaks kea, likely due to some logics needing to be mounted in the right order. Therefore this wrapper.

Copy link
Contributor

github-actions bot commented Jul 4, 2024

Size Change: +134 B (+0.01%)

Total Size: 1.07 MB

ℹ️ View Unchanged
Filename Size Change
frontend/dist/toolbar.js 1.07 MB +134 B (+0.01%)

compressed-size-action

sourceInsight.name = ''
sourceInsight.derived_name = 'should be copied'
await logic.asyncActions.duplicateInsight(sourceInsight)
expect(api.create).toHaveBeenCalledWith(
`api/projects/${MOCK_TEAM_ID}/insights`,
expect.objectContaining({ name: '' })
expect.objectContaining({ name: '' }),
expect.objectContaining({})
Copy link
Contributor Author

@thmsobrmlr thmsobrmlr Jul 4, 2024

Choose a reason for hiding this comment

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

ApiRequest.create is implemented like this:

return await api.create(this.assembleFullUrl(), options?.data, options)

Meaning the data gets repeated in options. I didn't want to change the implementation in this PR, therefore adjusting tests.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@thmsobrmlr thmsobrmlr changed the title refactor(insights): make save as use query based insight refactor(insights): query based duplicateInsight Jul 4, 2024
@thmsobrmlr thmsobrmlr marked this pull request as ready for review July 4, 2024 11:07
@thmsobrmlr thmsobrmlr requested a review from a team July 4, 2024 11:11
thmsobrmlr and others added 2 commits July 12, 2024 09:27
# Conflicts:
#	frontend/__snapshots__/scenes-app-insights--funnel-top-to-bottom-breakdown--dark.png
#	frontend/src/scenes/saved-insights/SavedInsights.tsx
@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@thmsobrmlr thmsobrmlr merged commit 307a783 into master Jul 12, 2024
91 checks passed
@thmsobrmlr thmsobrmlr deleted the duplicate-query-based-insight branch July 12, 2024 10:07
thmsobrmlr added a commit that referenced this pull request Jul 15, 2024
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