Skip to content

Commit

Permalink
DEVPROD-14700: Add pin analytics event (#620)
Browse files Browse the repository at this point in the history
Co-authored-by: Mohamed Khelif <[email protected]>
  • Loading branch information
sophstad and khelif96 authored Feb 7, 2025
1 parent fb7a5ee commit d39f571
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
5 changes: 5 additions & 0 deletions apps/spruce/src/analytics/waterfall/useWaterfallAnalytics.ts
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 isPinned = pins.includes(b.id);
return (
<BuildRow
key={b.id}
build={b}
handlePinClick={handlePinBV(b.id, isPinned)}
isFirstBuild={i === 0}
lastActiveVersionId={lastActiveVersionId}
pinned={isPinned}
projectIdentifier={projectIdentifier}
versions={versions}
/>
);
})}
</BuildVariantProvider>
{adminBetaSettings?.spruceWaterfallEnabled && (
<OnboardingTutorial guideCueRef={guideCueRef} />
Expand Down

0 comments on commit d39f571

Please sign in to comment.