Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 55 additions & 1 deletion assets/js/analytics-events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Alert } from "./components/alert";
import { urlify } from "./components/anchor-link";
import { Sidenav } from "./components/sidenav";
import { Heading } from "./components/heading";
import { permalink, searchURL } from "./github-urls";

interface AnalyticsEventAttribute {
name: string;
Expand All @@ -15,10 +16,29 @@ interface AnalyticsEventAttribute {
}

interface AnalyticsEvent {
/**
* String name for the event (the one that gets logged to events.log)
*/
event_name: string;
previous_event_names?: string[];
description: string;
attributes: AnalyticsEventAttribute[];
/**
* Ruby analytics method name
*/
method_name?: string;
/**
* Source file that this documentation comes from
*/
source_file?: string;
/**
* Line in source file where documentation comes from
*/
source_line?: number;
/**
* SHA that documentation was generated from
*/
source_sha?: string;
}

function Example({
Expand Down Expand Up @@ -101,11 +121,45 @@ function Event({ event }: { event: AnalyticsEvent }) {
previous_event_names: previousEventNames,
description,
attributes = [],
method_name: methodName,
source_file: sourceFile,
source_line: sourceLine,
source_sha: sourceSHA,
} = event;

return (
<div>
<Heading level="h3">{eventName}</Heading>
<Heading level="h3" className="margin-bottom-0">
{eventName}
</Heading>
{methodName && sourceFile && sourceLine && (
<small>
<a
className="usa-link"
href={permalink({
repo: "18f/identity-idp",
ref: sourceSHA,
file: sourceFile,
line: sourceLine,
})}
>
Source definition
</a>
,{" "}
<a
className="usa-link"
href={searchURL({
needle: methodName,
repo: "18f/identity-idp",
extension: "rb",
type: "code",
Comment thread
zachmargolis marked this conversation as resolved.
path: "app",
})}
>
source usages
</a>
</small>
)}
<p>{description}</p>
{previousEventNames?.length ? (
<>
Expand Down
4 changes: 3 additions & 1 deletion assets/js/components/heading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface HeadingProps {
level: HeadingLevel;

id?: string;
className?: string;

children: string;
}
Expand All @@ -15,11 +16,12 @@ export function Heading({
level,
children,
id = urlify(children),
className,
}: HeadingProps) {
Comment on lines +19 to 20
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could also consider forwarding along any valid HTML props.

Suggested change
className,
}: HeadingProps) {
...props,
}: HeadingProps & JSX.HTMLAttributes<HTMLHeadingElement>) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok! And we'd want to remove those from the definition of HeadingProps then, right?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah there's a few more revisions that would need to be done in addition to that suggestion (also importing the JSX type and applying the props to TagName). The only thing we'd need to remove from the prop type is className.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

y'know, in retrospect, I think this is fine as-is, if you want to just leave it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

LOL ok will leave it

const TagName = level;

return (
<TagName id={id}>
<TagName id={id} className={className}>
{children}
<AnchorLink slug={id} />
</TagName>
Expand Down
File renamed without changes.
61 changes: 61 additions & 0 deletions assets/js/github-urls.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
export function permalink({
repo,
ref = "main",
file,
line,
}: {
repo: string;
file: string;
ref?: string;
line?: number | string;
}) {
return `https://github.com/${repo}/blob/${ref}/${file}${
line ? `#L${line}` : ""
}`;
}

export function searchURL({
needle,
repo,
extension,
path,
Comment thread
zachmargolis marked this conversation as resolved.
type,
}: {
needle?: string;
path?: string;
repo?: string;
/**
* @example "rb"
*/
extension?: string;
type?:
| "repositories"
| "code"
| "commits"
| "issues"
| "discussions"
| "registrypackages"
| "wikis"
| "users";
}) {
const url = new URL("https://github.com/search");

const q = [
needle,
repo && `repo:${repo}`,
extension && `extension:${extension}`,
path && `path:${path}`,
]
.filter(Boolean)
.join(" ");

if (q) {
url.searchParams.set("q", q);
}

if (type) {
url.searchParams.set("type", type);
}

return url.toString();
}
2 changes: 1 addition & 1 deletion assets/js/private-articles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { createPortal } from "preact/compat";
import { useQuery } from "preact-fetching";
import { useCurrentUser, PrivateLoginLink } from "./private";
import { Alert } from "./components/alert";
import { fetchGitHubFile, isGithubDirectory, isGithubFile } from "./github";
import { fetchGitHubFile, isGithubDirectory, isGithubFile } from "./github-api";
import { Navigation, SidenavWithWrapper } from "./components/sidenav";
import { Heading } from "./components/heading";
import type { HeadingLevel } from "./components/heading";
Expand Down