Skip to content

Add article that renders IDP analytics events from JSON (LG-5590)#218

Merged
zachmargolis merged 10 commits intomainfrom
margolis-analytics-event-documentation
Mar 4, 2022
Merged

Add article that renders IDP analytics events from JSON (LG-5590)#218
zachmargolis merged 10 commits intomainfrom
margolis-analytics-event-documentation

Conversation

@zachmargolis
Copy link
Contributor

See 18F/identity-idp#6014

This is basically the same idea as GSA-TTS/identity-site#707, pulling JSON and making a page from it. This time I figured we don't care as much about browser compatibility, since it's our handbook, that I didn't bother with that and just went with inline ES6. The future is now!

Screenshot of what it looks like with the IDP serving this data

Screen Shot 2022-03-02 at 6 27 54 PM

@zachmargolis
Copy link
Contributor Author

One thing that was really nice about the old docs was the fairly compact example format, so I tried to replicate that with 2d67c51:

examples screenshots
simple event Screen Shot 2022-03-03 at 10 20 04 AM
complex event Screen Shot 2022-03-03 at 10 20 22 AM

@zachmargolis zachmargolis merged commit c437adf into main Mar 4, 2022
@zachmargolis zachmargolis deleted the margolis-analytics-event-documentation branch March 4, 2022 22:26
Copy link
Contributor

@aduth aduth left a comment

Choose a reason for hiding this comment

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

Cool use of native ESM!

import { h, Component, render } from '../../preact.module.js';
import htm from '../../htm.module.js';

// Copied from https://github.com/bryanbraun/anchorjs
Copy link
Contributor

Choose a reason for hiding this comment

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

While unfortunate 'til more packages ship ESM-native code, this seems okay enough.

A few alternatives that pop to mind, none of which I'm particularly compelled toward:

  • Import from an ESM-upgrading CDN like Skypack or unpkg ?module
  • Use something like Snowpack
    • I was more fond of the v1 behavior, which was mostly minimalistic as a way to create local, ESM-upgraded versions of CJS packages. It's now pretty feature-rich, more than we might need or want.
  • Just use a bundler 🤷 ESBuild could work well, since we don't need much transpilation beyond module bundling, and could let us use JSX/TypeScript.

Comment on lines +54 to +56
const setRef = (dom) => {
if (dom && document.location.hash.slice(1) === slug) {
setTimeout(() => dom.scrollIntoView(), 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: The name dom suggests to me that this is a full DOM object (e.g. a JSOM DOM wrapper object), when in-fact it's just an element node. I might have used element or node instead.


function Example({ event_name, attributes }) {
function typeExample(type) {
switch(type) {
Copy link
Contributor

Choose a reason for hiding this comment

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

For future: Would be nice to set up ESLint/Prettier in this project.


const eventProperties = attributeExamples.
join("\n ").
replace(/( $)/, ''); // fix last line indentation
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit/Question: Group shouldn't be necessary?

Suggested change
replace(/( $)/, ''); // fix last line indentation
replace(/ $/, ''); // fix last line indentation

Copy link
Contributor

Choose a reason for hiding this comment

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

Would String#trimEnd have worked here?

Suggested change
replace(/( $)/, ''); // fix last line indentation
trimEnd(); // fix last line indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Parens were optional, but turns out trimEnd() removes a trailing newline that I wanted to keep for bracket alignment.

There's probably a better way to manage building these fixed-width examples than futzing with indentation and newlines like this

Comment on lines +159 to +161
return html`${events.map((event) =>
html`<${Event} ...${event} />`
)}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Outer html might not be necessary?

Suggested change
return html`${events.map((event) =>
html`<${Event} ...${event} />`
)}`;
return events.map((event) => html`<${Event} ...${event} />`);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup! this worked

}

function Sidenav({ events }) {
return html`${events.map(({ event_name: name }) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

Same note about outer html, unless I'm mistaken (haven't tested).

const { idpBaseUrl } = container.dataset;
const eventsUrl = `${idpBaseUrl}/api/analytics-events`;

const sidenav = document.querySelector('#sidenav');
Copy link
Contributor

Choose a reason for hiding this comment

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

Not impactful here, but micro-optimization note that getElementById is ~2x faster than querySelector.

https://www.measurethat.net/Benchmarks/Show/2488/0/getelementbyid-vs-queryselector

Suggested change
const sidenav = document.querySelector('#sidenav');
const sidenav = document.getElementById('sidenav');

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.

3 participants