Skip to content

Commit

Permalink
DEVPROD-14495: Clean up waterfall types (#597)
Browse files Browse the repository at this point in the history
  • Loading branch information
sophstad authored Jan 28, 2025
1 parent ff2db15 commit cd5d110
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 40 deletions.
2 changes: 0 additions & 2 deletions apps/spruce/src/gql/generated/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9683,8 +9683,6 @@ export type WaterfallQuery = {
version: string;
builds: Array<{
__typename?: "WaterfallBuild";
activated?: boolean | null;
displayName: string;
id: string;
version: string;
tasks: Array<{
Expand Down
2 changes: 0 additions & 2 deletions apps/spruce/src/gql/queries/waterfall.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ query Waterfall($options: WaterfallOptions!) {
waterfall(options: $options) {
buildVariants {
builds {
activated
displayName
id
tasks {
displayName
Expand Down
3 changes: 1 addition & 2 deletions apps/spruce/src/pages/waterfall/BuildRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { useWaterfallAnalytics } from "analytics";
import Icon from "components/Icon";
import VisibilityContainer from "components/VisibilityContainer";
import { getTaskRoute, getVariantHistoryRoute } from "constants/routes";
import { WaterfallBuild } from "gql/generated/types";
import { useDimensions } from "hooks/useDimensions";
import { useBuildVariantContext } from "./BuildVariantContext";
import {
Expand Down Expand Up @@ -185,7 +184,7 @@ const calculateBVContainerHeight = ({
builds,
columnWidth,
}: {
builds: WaterfallBuild[];
builds: Build[];
columnWidth: number;
}) => {
const numTasks = Math.max(...builds.map((b) => b.tasks.length));
Expand Down
25 changes: 17 additions & 8 deletions apps/spruce/src/pages/waterfall/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Unpacked } from "@evg-ui/lib/types/utils";
import { WaterfallVersionFragment, WaterfallQuery } from "gql/generated/types";
import { WaterfallVersionFragment } from "gql/generated/types";

// Although this is pretty much a duplicate of the GraphQL type, it is
// necessary to resolve type errors.
Expand All @@ -10,13 +9,23 @@ export type WaterfallVersion = {
version: WaterfallVersionFragment | null;
};

export type Build = Unpacked<
Unpacked<WaterfallQuery["waterfall"]["buildVariants"]>["builds"]
>;
export type Build = {
id: string;
tasks: Array<{
displayName: string;
displayStatusCache: string;
execution: number;
id: string;
status: string;
}>;
version: string;
};

export type BuildVariant = Unpacked<
WaterfallQuery["waterfall"]["buildVariants"]
>;
export type BuildVariant = {
builds: Build[];
displayName: string;
id: string;
};

export enum WaterfallFilterOptions {
BuildVariant = "buildVariants",
Expand Down
86 changes: 60 additions & 26 deletions apps/spruce/src/pages/waterfall/useFilters.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { MemoryRouter } from "react-router-dom";
import { renderHook } from "@evg-ui/lib/test_utils";
import { WaterfallVersionFragment } from "gql/generated/types";
import { BuildVariant } from "./types";
import { useFilters } from "./useFilters";

type WrapperProps = {
Expand Down Expand Up @@ -32,6 +33,20 @@ describe("useFilters", () => {
);
expect(result.current).toStrictEqual({
...waterfall,
versions: [
{
inactiveVersions: [flattenedVersions[0]],
version: null,
},
{
inactiveVersions: null,
version: flattenedVersions[1],
},
{
inactiveVersions: null,
version: flattenedVersions[2],
},
],
activeVersionIds: ["b", "c"],
});
});
Expand Down Expand Up @@ -85,6 +100,20 @@ describe("useFilters", () => {

const pinnedWaterfall = {
...waterfall,
versions: [
{
inactiveVersions: [flattenedVersions[0]],
version: null,
},
{
inactiveVersions: null,
version: flattenedVersions[1],
},
{
inactiveVersions: null,
version: flattenedVersions[2],
},
],
activeVersionIds: ["b", "c"],
buildVariants: [
waterfall.buildVariants[1],
Expand Down Expand Up @@ -144,6 +173,20 @@ describe("useFilters", () => {

const filteredWaterfall = {
...waterfall,
versions: [
{
inactiveVersions: [flattenedVersions[0]],
version: null,
},
{
inactiveVersions: null,
version: flattenedVersions[1],
},
{
inactiveVersions: null,
version: flattenedVersions[2],
},
],
activeVersionIds: ["b", "c"],
};

Expand Down Expand Up @@ -216,6 +259,20 @@ describe("useFilters", () => {

const filteredWaterfall = {
...waterfall,
versions: [
{
inactiveVersions: [flattenedVersions[0]],
version: null,
},
{
inactiveVersions: null,
version: flattenedVersions[1],
},
{
inactiveVersions: null,
version: flattenedVersions[2],
},
],
activeVersionIds: ["b", "c"],
buildVariants: [
{
Expand Down Expand Up @@ -421,23 +478,20 @@ const flattenedVersions: WaterfallVersionFragment[] = [
},
];

const waterfall = {
const waterfall: {
buildVariants: BuildVariant[];
} = {
buildVariants: [
{
id: "1",
version: "a",
displayName: "BV 1",
builds: [
{
activated: false,
displayName: "Build A",
id: "i",
tasks: [],
version: "a",
},
{
activated: true,
displayName: "Build 12345",
id: "ii",
tasks: [
{
Expand All @@ -462,11 +516,8 @@ const waterfall = {
{
id: "2",
displayName: "BV 2",
version: "b",
builds: [
{
activated: true,
displayName: "Build B",
id: "ii",
tasks: [
{
Expand All @@ -484,11 +535,8 @@ const waterfall = {
{
id: "3",
displayName: "BV 3",
version: "c",
builds: [
{
activated: true,
displayName: "Build C",
id: "iii",
tasks: [
{
Expand All @@ -511,18 +559,4 @@ const waterfall = {
],
},
],
versions: [
{
inactiveVersions: [flattenedVersions[0]],
version: null,
},
{
inactiveVersions: null,
version: flattenedVersions[1],
},
{
inactiveVersions: null,
version: flattenedVersions[2],
},
],
};

0 comments on commit cd5d110

Please sign in to comment.