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

DEVPROD-14700: Add pin analytics event #620

Merged
merged 3 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ type Action =
| { name: "Clicked variant label" }
| { name: "Clicked task box"; "task.status": string }
| { name: "Clicked jump to most recent commit button" }
| {
name: "Clicked pin build variant";
action: "pinned" | "unpinned";
variant: string;
}
| { name: "Changed project"; project: string }
| { name: "Filtered by build variant"; type: FilterType }
| { name: "Filtered by requester"; requesters: string[] }
Expand Down
1 change: 1 addition & 0 deletions apps/spruce/src/pages/waterfall/BuildRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ const BuildContainer = styled.div`

const StyledIconButton = styled(IconButton)`
top: -${size.xxs};
z-index: 1;
${({ active }) => active && "transform: rotate(-30deg);"}
`;

Expand Down
40 changes: 25 additions & 15 deletions apps/spruce/src/pages/waterfall/WaterfallGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useSuspenseQuery } from "@apollo/client";
import styled from "@emotion/styled";
import { fromZonedTime } from "date-fns-tz";
import { size, transitionDuration } from "@evg-ui/lib/constants/tokens";
import { useWaterfallAnalytics } from "analytics";
import { WalkthroughGuideCueRef } from "components/WalkthroughGuideCue";
import {
DEFAULT_POLL_INTERVAL,
Expand Down Expand Up @@ -51,16 +52,22 @@ export const WaterfallGrid: React.FC<WaterfallGridProps> = ({
}) => {
useWaterfallTrace();
const { adminBetaSettings } = useAdminBetaFeatures();
const { sendEvent } = useWaterfallAnalytics();

const [pins, setPins] = useState<string[]>(
getObject(WATERFALL_PINNED_VARIANTS_KEY)?.[projectIdentifier] ?? [],
);

const handlePinBV = useCallback(
(buildVariant: string) => () => {
(buildVariant: string, wasPinned: boolean) => () => {
sendEvent({
name: "Clicked pin build variant",
action: wasPinned ? "unpinned" : "pinned",
variant: buildVariant,
});
setPins((prev: string[]) => {
const bvIndex = prev.indexOf(buildVariant);
if (bvIndex > -1) {
if (wasPinned) {
const bvIndex = prev.indexOf(buildVariant);
const removed = [...prev];
removed.splice(bvIndex, 1);
return removed;
Expand Down Expand Up @@ -169,18 +176,21 @@ export const WaterfallGrid: React.FC<WaterfallGridProps> = ({
</Versions>
</StickyHeader>
<BuildVariantProvider>
{buildVariants.map((b, i) => (
<BuildRow
key={b.id}
build={b}
handlePinClick={handlePinBV(b.id)}
isFirstBuild={i === 0}
lastActiveVersionId={lastActiveVersionId}
pinned={pins.includes(b.id)}
projectIdentifier={projectIdentifier}
versions={versions}
/>
))}
{buildVariants.map((b, i) => {
const pinned = pins.includes(b.id);
sophstad marked this conversation as resolved.
Show resolved Hide resolved
return (
<BuildRow
key={b.id}
build={b}
handlePinClick={handlePinBV(b.id, pinned)}
sophstad marked this conversation as resolved.
Show resolved Hide resolved
isFirstBuild={i === 0}
lastActiveVersionId={lastActiveVersionId}
pinned={pinned}
projectIdentifier={projectIdentifier}
versions={versions}
/>
);
})}
</BuildVariantProvider>
{adminBetaSettings?.spruceWaterfallEnabled && (
<OnboardingTutorial guideCueRef={guideCueRef} />
Expand Down