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

Insight URL cleanup #7201

Merged
merged 46 commits into from Nov 25, 2021
Merged

Insight URL cleanup #7201

merged 46 commits into from Nov 25, 2021

Conversation

mariusandra
Copy link
Collaborator

@mariusandra mariusandra commented Nov 18, 2021

Changes

  • Changes the URLs to look like this
    • /insights == urls.savedInsights()
    • /insights/new == urls.newInsight() -- redirects after creation to the edit page
    • /insights/123 == urls.insightsView(123)
    • /insights/123?insight=TRENDS == urls.insightsView(123, { insight: 'TRENDS' })
    • /insights/123/edit == urls.insightsEdit(123)
    • /insights/123/edit?insight=TRENDS == urls.insightsEdit(123, { insight: 'TRENDS' })
  • newInsight vs insightNew vs insightsNew? What to use?

For another PR

  • Update the filters into something like /insights/123#q={insight:'TRENDS'}

How did you test this code?

  • In the browser, tried to go through all touched code paths.
  • Also updated the tests to work

@mariusandra mariusandra marked this pull request as ready for review November 18, 2021 23:03
Copy link
Collaborator Author

@mariusandra mariusandra left a comment

Choose a reason for hiding this comment

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

This is ready for a look.

Comment on lines +13 to +14
let logic: ReturnType<typeof renameModalLogic.build>
let relevantEntityFilterLogic: ReturnType<typeof entityFilterLogic.build>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This file is a kind of flyby cleanup 🤷

@@ -65,7 +65,7 @@ export const insightDateFilterLogic = kea<insightDateFilterLogicType>({
},
}),
urlToAction: ({ actions, values }) => ({
'/insights': (_: any, { date_from, date_to }: UrlParams) => {
'/insights/': (_: any, { date_from, date_to }: UrlParams) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

With / in the end to catch /insights/1 and not catch /insights. This will be refactored very soon (the filters shouldn't talk through the url, but with the insight directly), so keeping as a quick fix.

(!loadedFromAnotherLogic && !objectsEqual(cleanSearchParams, values.filters)) ||
insightModeFromUrl !== values.insightMode
) {
actions.setFilters(cleanSearchParams, insightModeFromUrl)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I had to merge setFilters and setInsightMode, since otherwise they would change the URL in multiple steps (go back/forward between e.g. /insights/12 and /insights/23/edit would cause a lot of url noise with first the edit and then the filters being added)

Comment on lines +15 to +21
if (
[
`api/projects/${MOCK_TEAM_ID}/insights/path`,
`api/projects/${MOCK_TEAM_ID}/insights/paths/`,
`api/projects/${MOCK_TEAM_ID}/insights/123`,
`api/projects/${MOCK_TEAM_ID}/insights`,
].includes(pathname)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Flyby change with the goal of reducing noise in jest tests.

@Twixes Twixes mentioned this pull request Nov 19, 2021
Copy link
Collaborator

@Twixes Twixes left a comment

Choose a reason for hiding this comment

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

Overall looks great! Just a couple of details I think it'd be good to hash out

frontend/src/scenes/urls.ts Outdated Show resolved Hide resolved
frontend/src/scenes/scenes.ts Outdated Show resolved Hide resolved
Comment on lines 240 to 241
if (hashParams.fromItem) {
// `fromItem` for legacy /insights url redirect support
Copy link
Collaborator

@Twixes Twixes Nov 19, 2021

Choose a reason for hiding this comment

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

This gives us backwards compatibility for fromItem URLs, but those without fromItem don't work anymore. I think it may be worth retaining support for this to avoid frustrating users who have old links. Though that would probably require creating a new insight record every time such a link is accessed (createAndRedirectToNewInsight-style), which is not ideal. Your call, let's just make the decision explicit.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed!

@timgl
Copy link
Collaborator

timgl commented Nov 19, 2021

Any thoughts on using short_id instead of normal id? Will result in slightly more appealing urls + we don't leak our usage data as obviously

@Twixes
Copy link
Collaborator

Twixes commented Nov 22, 2021

As for the last commit, that's fixed in master now (just removed the extra table implementation-specific class, th is enough)

Copy link
Collaborator

@Twixes Twixes left a comment

Choose a reason for hiding this comment

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

There's just one thing: "Save as new insight" results in a new insight that's a blank slate (this is also the case on #7259). I looked into it for a bit but not sure why.

@mariusandra
Copy link
Collaborator Author

Hmm... seems to work for me, possibly merging with master fixed it?
2021-11-24 19 50 57

@mariusandra
Copy link
Collaborator Author

I didn't understand the issue initially. This is probably the fix you wanted to see:

2021-11-25 14 45 28

@Twixes anything else blocking here?

Copy link
Collaborator

@Twixes Twixes left a comment

Choose a reason for hiding this comment

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

Yup! All is well now

* convert a bunch of things to user short_id instead of id

* fix more TS errors

* fix test

* fix jest tests

* various fixes

* add wise words

* type InsightShortId-s to make life easier

* reduce a bit of test noise

* use the InsightShortId in the URL

* fix type

* fix test

* fix insight url preloading

* pass dive dashboards as having insight short ids

* fix short url redirect

* mock scenelogic api

* better types and tests

* type fixes

* fix bug of linking to ourselves

* add back "id"

* get rid of some "getInsightId" calls

* two more

* few more

* refactor last usage of getInsightId

* move files around and improve errors

* make it simpler

* small fixes

* redirect to new url from old hashParam=42

* fix regression

* alert the user if we could not find an insight with the old ID format

* switch to a simpler scene

* fix another test

* Fix annotation creation

* Make short ID friendlier

* remove comments

* simplify insight links from dashboards and saved insights

* remove insight router

* fix TS

* Revert "remove insight router"

This reverts commit e52f474.

Co-authored-by: Michael Matloka <dev@twixes.com>
@mariusandra mariusandra merged commit fbba787 into master Nov 25, 2021
@mariusandra mariusandra deleted the insight-urls-one-more-time branch November 25, 2021 14:39
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