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

misc(treemap): add placeholder, gist and file upload features #12511

Merged
merged 20 commits into from
May 20, 2021

Conversation

connorjclark
Copy link
Collaborator

@connorjclark connorjclark commented May 19, 2021

ref #11254

https://gist.github.com/connorjclark/060f0322480cc9dbad793b8cea405e46

https://lighthouse-git-treemap-appify-googlechrome.vercel.app/gh-pages/treemap/?gist=060f0322480cc9dbad793b8cea405e46

TODO/follow up PR:

  • Loading indicator, like viewer
  • Options menu, "Save as gist" if not already, like viewer
  • "Back to placeholder" button from the treemap view

@connorjclark connorjclark requested a review from a team as a code owner May 19, 2021 00:08
@connorjclark connorjclark requested review from patrickhulce and removed request for a team May 19, 2021 00:08
@google-cla google-cla bot added the cla: yes label May 19, 2021
Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

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

WDYT about "misc(treemap): add placeholder, load from gist, and file drop features" for PR name? I was hunting around for the upload functionality until I saw the "gist creation" was a todo which was the only upload I could think of.

I wasn't able to build treemap locally either (complaining about umd.js of eventtargetshim) so I couldn't test anything out, but looks like a solid copy of viewer :)

@@ -36,6 +36,7 @@ class GithubApi {
return Promise.reject(new Error('Save already in progress'));
}

// @ts-ignore
Copy link
Collaborator

Choose a reason for hiding this comment

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

what's with all the explanationless ignores? :)

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 have no idea...all the sudden tsc -p . fails because of these. but not in my editor...having weird issues lately :/

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok it's b/c the Strings import in build-treemap causes TSC to more than it should for tsc -p .

Copy link
Collaborator

Choose a reason for hiding this comment

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

Have you tried replacing with window.logger? That's what's declared on the typedefs.

* @param {File} file
* @return {Promise<string>}
*/
readFile(file) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

seems like it should be static?

Copy link
Collaborator

Choose a reason for hiding this comment

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

ah I see below that would be annoying for tests, alright

lighthouse-viewer/app/src/drag-and-drop.js Outdated Show resolved Hide resolved
<h1 class="treemap-placeholder__heading">Lighthouse Treemap</h1>
<div class="treemap-placeholder__help">To view a treemap: Paste the Lighthouse result json or a Gist URL.<br>
You can also drag 'n drop the file or click here to select it.<br><br>
To get a fresh report, use the Lighthouse browser extension (<a href="https://chrome.google.com/webstore/detail/lighthouse/blipmdconlkpinefehnmjammfjpmpbjk">Chrome</a> / <a href="https://addons.mozilla.org/en-US/firefox/addon/google-lighthouse/">Firefox</a>)<br>
Copy link
Collaborator

Choose a reason for hiding this comment

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

The extension bit might be more confusing advice for treemap since they'll end up back over at viewer instead of the treemap and they may or may not have the "view treemap" button.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

They should always have it after PSI upgrades. does that resolve your concern?

Copy link
Collaborator

Choose a reason for hiding this comment

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

They should always have it after PSI upgrades. does that resolve your concern?

Not particularly. My concern is that if we didn't copy/paste from viewer it feels like we wouldn't have written this that paragraph this way and especially not encourage the extension (the reason we did so for viewer is because the extension is the entrypoint for most people using viewer).

The "may or may not have the view treemap button" was also a comment on the general applicability of this page compared to viewer and how appropriate it is to explain that. For example, should we use this space instead to link to a treemap / sourcemaps article on web.dev?

lighthouse-treemap/app/src/main.js Outdated Show resolved Hide resolved
*/
convertToOptions(json) {
if (json instanceof Object) {
if ('lhr' in json) return json;
Copy link
Collaborator

Choose a reason for hiding this comment

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

it's so messed up that TS thinks this is OK 😆

json is inferred to be never at this point, so we've basically silently devolved from unknown to any

@connorjclark connorjclark changed the title misc(treemap): add placeholder div, gist and upload features misc(treemap): add placeholder div, gist and file upload features May 19, 2021
@connorjclark
Copy link
Collaborator Author

I wasn't able to build treemap locally either (complaining about umd.js of eventtargetshim) so I couldn't test anything out, but looks like a solid copy of viewer :)

what's the error? I get no error.

@patrickhulce
Copy link
Collaborator

what's the error? I get no error.

Same error as CI. The issue is require.resolve('event-target-shim/umd.js').

In Node 10 this works as expected by requiring that file. In Node 12+ this looks for an export called umd.js which does not exist and throws instead of finding the file. require.resolve('event-target-shim/umd') works fine as there is an export called umd. Honestly I'm more confused why this works just fine on your end :)

@connorjclark
Copy link
Collaborator Author

connorjclark commented May 19, 2021

Same error as CI. The issue is require.resolve('event-target-shim/umd.js').

woah... why does CI keep going after this..

idk i'm on v12.13.0

@connorjclark
Copy link
Collaborator Author

connorjclark commented May 19, 2021

In Node 12+ this looks for an export called umd.js which does not exist and throws instead of finding the file.

what's that now? Then why do the following lines, which also import a file with the .js extension work? or is it different because it's not multiple path levels deep?

what is this node 12 feature/change to module resolution called?

EDIT: oh, I just noticed the exports field in package.json, guess that's it.

types/i18n.d.ts Outdated

export type LhlMessages = Record<string, {message: string}>;

export type Strings = Record<LH.Locale, LhlMessages>;
Copy link
Member

Choose a reason for hiding this comment

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

I'd really like to avoid making global types when they aren't needed, or at least scope these to treemap.d.ts. Defining LhlMessages in locales.js where the actual object is also defined was very intentional, and LH.Strings is a simple and can just be defined in place.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removed Strings. but LhlMessages is used in 6 different files, so despite intention it is being used globally just in the more cumbersome jsdoc import style.

Copy link
Member

Choose a reason for hiding this comment

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

so despite intention it is being used globally just in the more cumbersome jsdoc import style.

Strong disagree. At no point has anyone suggested setting global.i18n = require('./lighthouse-core/lib/i18n/i18n.js') so we can avoid require('../../../lib/i18n/i18n.js') in all the files that use it, for instance.

I think that it's not worth hashing out the usefulness of globals (whether in value- or type-space) in this PR, though, but more importantly I think there's enough going on in here without making changes to types in core. Can we revert and follow up later? Happy to discuss at another time.

@paulirish
Copy link
Member

A few months ago we discussed an idea of merging these into a single webapp. The report viewer, the treemap, the calculator. At the time I think it was decided things were too early.

Seems like it's time to reopen that conversation? :)

@connorjclark
Copy link
Collaborator Author

At the time I think it was decided things were too early.
Seems like it's time to reopen that conversation? :)

Happy to discuss this, but it shouldn't block moving forward with this PR :)


wdyt of adding to placeholder: "What is this? Show me an example" text that links to a gist?

Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

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

It seemed like this wasn't actually waiting on committer, so I took another look.

WDYT about "misc(treemap): add placeholder UI, load from gist, and file drop features" for PR name? I was hunting around for the upload functionality until I saw the "gist creation" was a todo which was the only upload I could think of.

Bump :)

The treemap tests appear to be broken in CI, but I wasn't able to manually reproduce. Something else might have changed with the programmatic triggering?

build/build-treemap.js Outdated Show resolved Hide resolved
@@ -0,0 +1,116 @@
<svg width="128" height="128" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
Copy link
Collaborator

Choose a reason for hiding this comment

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

I can't comment directly on them, but those favicon file renames seem like a mistake. I don't see a manifest.json for the treemap app that references them and I don't see the viewer references removed either.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oops... I copied the images folder, and accidently deleted excess images from the wrong folder. hence "rename"

lighthouse-treemap/app/styles/treemap.css Show resolved Hide resolved
@connorjclark
Copy link
Collaborator Author

It seemed like this wasn't actually waiting on committer, so I took another look.

WDYT about "misc(treemap): add placeholder UI, load from gist, and file drop features" for PR name? I was hunting around for the upload functionality until I saw the "gist creation" was a todo which was the only upload I could think of.
Bump :)

I renamed the title: misc(treemap): add placeholder div, gist and file upload features. Does this not clear up ambiguity? maybe we need an oxford comma too :)

The treemap tests appear to be broken in CI, but I wasn't able to manually reproduce. Something else might have changed with the programmatic triggering?

Been poking at this. No idea why this is failing now.

@patrickhulce
Copy link
Collaborator

Does this not clear up ambiguity? maybe we need an oxford comma too :)

haha, oxford comma aside, the both upload + lack of "fetch only" from gist distinction in combination is still confusing to me, but the chance that someone reads this again to learn what it contained is pretty low so 🤷

@@ -77,9 +77,12 @@ describe('Lighthouse Treemap', () => {
await new Promise(resolve => browser.on('targetcreated', resolve));
const target = (await browser.targets()).find(target => target.url() === treemapUrl);
page = await target.page();
await openerPage.close();
Copy link
Collaborator Author

@connorjclark connorjclark May 20, 2021

Choose a reason for hiding this comment

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

deleting await openerPage.close(); fixed the issue. shrug.

Co-authored-by: Patrick Hulce <[email protected]>
@connorjclark connorjclark changed the title misc(treemap): add placeholder div, gist and file upload features misc(treemap): add placeholder, gist and file upload features May 20, 2021
@connorjclark connorjclark merged commit 30b3e06 into master May 20, 2021
@connorjclark connorjclark deleted the treemap-appify branch May 20, 2021 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants