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 Short URLs #7259

Merged
merged 46 commits into from
Nov 25, 2021
Merged

Insight Short URLs #7259

merged 46 commits into from
Nov 25, 2021

Conversation

mariusandra
Copy link
Collaborator

@mariusandra mariusandra commented Nov 22, 2021

Changes

  • Converts insights to use the short_id in the URLs and elsewhere else it made sense
  • Kept the insight.id field for making API requests
  • Adopts a new type, InsightShortId, which is now the "primary key" for insights, as far as any frontend logic is concerned.
  • Does not attempt to unify dashboardItemId, insightId, insightShortId, shortId, id and any of the various forms that you might see around. That's for another PR.
  • Rewrite all insightEdit and insightNew urls to use the short_id
  • Improve the insightLogic to work that way as well.

How did you test this code?

  • Made all existing tests pass
  • Clicked around in the interface on various insights pages, reloaded dashboards, renamed a dashboard item, and so on.

@mariusandra mariusandra changed the title convert a bunch of things to user short_id instead of id Insight Short URLs Nov 22, 2021
@mariusandra mariusandra marked this pull request as ready for review November 24, 2021 07:44
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.

some inline comments

'api/projects/@current/event_definitions/',
].includes(pathname)
) {
return { results: [] }
return { results: [], next: null }
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 reduces some noise in tests, didn't seem to break or fix anything else.

pageKey: dashboardItemId ? dashboardItemId : null,
})
)
const { diffType, groupedAnnotations } = useValues(annotationsLogic({ insightShortId: dashboardItemId }))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

annotationsLogic's pageKey was only being used by dashboardItemIds, so let's call a spade a spade.

@@ -213,32 +215,32 @@ export const dashboardLogic = kea<dashboardLogicType<DashboardLogicProps>>({
],
refreshStatus: [
{} as Record<
number,
string,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

TypeScript Records always are <string, something_else>, putting InsightShortId as the type of the Record's key here caused Object.values to not return the right type for the values. 🤷‍♂️

I also considered leaving it as number and using insight.id as the object's key, but that didn't seem suitable considering all the other refactors to shortId where possible...

frontend/src/models/annotationsModel.ts Outdated Show resolved Hide resolved
Comment on lines +622 to +623
// Creating a nominal type: https://github.com/microsoft/TypeScript/issues/202#issuecomment-961853101
export type InsightShortId = string & { readonly '': unique symbol }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Neat!

frontend/src/scenes/dashboard/DashboardItem.tsx Outdated Show resolved Hide resolved
Comment on lines +554 to +556
const savedInsight: DashboardItemType = await api.update(
`api/projects/${teamLogic.values.currentTeamId}/insights/${insightId}`,
{ ...values.insight, saved: true }
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice if we don't have to make (at worst) two blocking api calls while trying to save an insight. I think it makes more sense that resolving the short id into an insight id happens all in the backend under a single POST call.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

99.99% of the time here, we have the insight.id and all is good. The async call is never made. The only time we have insightLogic with loaded data and there's no insight.id, is if we show the insight on a dashboard, and pre-populate its data with props.dashboardItemId, props.cachedResults and props.filters. I'd like to refactor those three to just one field insight that also includes the id field, but I fear this will make the PR even bigger as it's a sizeable refactor on its own. Let's defer it for after the PR please.

@mariusandra
Copy link
Collaborator Author

@Twixes this should be reviewable as well. Trying to get the final tests to go green, which should have happened now...

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.

🚀

@mariusandra mariusandra merged commit 638592c into insight-urls-one-more-time Nov 25, 2021
@mariusandra mariusandra deleted the insight-short-urls branch November 25, 2021 14:34
mariusandra added a commit that referenced this pull request Nov 25, 2021
* insight route refactor, part 1

* add fromItem to get redirects

* fix some tests

* adjust many more paths

* fix test

* move new insight creation into insight logic

* fix a noisy test

* simplify one test

* open the url with the right filters

* null fix

* fix some more noisy tests

* move saved insights to `/insights`, fix logic tests

* fix cypress urls

* fix some tests

* fix even more insight urls

* wait a bit longer

* add old saved_insights redirect

* this might not be there yet

* rename newInsight -> insightNew

* rename Scene.Insights -> Scene.Insight

* also redirect old searches without fromItem

* fix link

* fix TS merge bugs

* fix import

* fix imports

* fix tests

* fix test

* Run prettier

* fix changes after merge

* switch to a simpler scene

* fix another test

* fix "save as" reset

* rerun tests

* Insight Short URLs (#7259)

* 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>

Co-authored-by: Michael Matloka <dev@twixes.com>
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