diff --git a/apps/spruce/src/gql/fragments/basePatch.graphql b/apps/spruce/src/gql/fragments/basePatch.graphql index 3600e2ea2..8125bdc74 100644 --- a/apps/spruce/src/gql/fragments/basePatch.graphql +++ b/apps/spruce/src/gql/fragments/basePatch.graphql @@ -10,6 +10,10 @@ fragment BasePatch on Patch { } status variantsTasks { + displayTasks { + execTasks + name + } name tasks } diff --git a/apps/spruce/src/gql/generated/types.ts b/apps/spruce/src/gql/generated/types.ts index bb09e52d1..2a070415d 100644 --- a/apps/spruce/src/gql/generated/types.ts +++ b/apps/spruce/src/gql/generated/types.ts @@ -394,6 +394,12 @@ export enum DispatcherVersion { } export type DisplayTask = { + __typename?: "DisplayTask"; + execTasks: Array; + name: Scalars["String"]["output"]; +}; + +export type DisplayTaskInput = { ExecTasks: Array; Name: Scalars["String"]["input"]; }; @@ -3335,12 +3341,13 @@ export type UserSettingsInput = { export type VariantTask = { __typename?: "VariantTask"; + displayTasks: Array; name: Scalars["String"]["output"]; tasks: Array; }; export type VariantTasks = { - displayTasks: Array; + displayTasks: Array; tasks: Array; variant: Scalars["String"]["input"]; }; @@ -3691,6 +3698,11 @@ export type BasePatchFragment = { __typename?: "VariantTask"; name: string; tasks: Array; + displayTasks: Array<{ + __typename?: "DisplayTask"; + execTasks: Array; + name: string; + }>; }>; }; @@ -5472,6 +5484,11 @@ export type SchedulePatchMutation = { __typename?: "VariantTask"; name: string; tasks: Array; + displayTasks: Array<{ + __typename?: "DisplayTask"; + execTasks: Array; + name: string; + }>; }>; }; }; @@ -5629,6 +5646,11 @@ export type UpdatePatchDescriptionMutation = { __typename?: "VariantTask"; name: string; tasks: Array; + displayTasks: Array<{ + __typename?: "DisplayTask"; + execTasks: Array; + name: string; + }>; }>; }; }; @@ -6953,6 +6975,11 @@ export type ConfigurePatchQuery = { __typename?: "VariantTask"; name: string; tasks: Array; + displayTasks: Array<{ + __typename?: "DisplayTask"; + execTasks: Array; + name: string; + }>; }>; }; }; @@ -6995,6 +7022,11 @@ export type PatchQuery = { __typename?: "VariantTask"; name: string; tasks: Array; + displayTasks: Array<{ + __typename?: "DisplayTask"; + execTasks: Array; + name: string; + }>; }>; }; }; diff --git a/apps/spruce/src/pages/configurePatch/configurePatchCore/ConfigureTasks/index.tsx b/apps/spruce/src/pages/configurePatch/configurePatchCore/ConfigureTasks/index.tsx index 788e2385c..9246d5185 100644 --- a/apps/spruce/src/pages/configurePatch/configurePatchCore/ConfigureTasks/index.tsx +++ b/apps/spruce/src/pages/configurePatch/configurePatchCore/ConfigureTasks/index.tsx @@ -4,14 +4,14 @@ import styled from "@emotion/styled"; import Checkbox from "@leafygreen-ui/checkbox"; import Tooltip from "@leafygreen-ui/tooltip"; import { Body, Disclaimer } from "@leafygreen-ui/typography"; -import pluralize from "pluralize"; import Icon from "components/Icon"; import TextInput from "components/TextInputWithValidation"; -import { CharKey } from "constants/keys"; -import { size } from "constants/tokens"; import { VariantTask } from "gql/generated/types"; import useKeyboardShortcut from "hooks/useKeyboardShortcut"; +import pluralize from "pluralize"; import { validateRegexp } from "utils/validators"; +import { CharKey } from "constants/keys"; +import { size } from "constants/tokens"; import { AliasState, ChildPatchAliased, @@ -66,33 +66,33 @@ const ConfigureTasks: React.FC = ({ }, () => { searchRef.current?.focus(); - }, + } ); const childPatchCount = childPatches?.length || 0; const totalDownstreamTaskCount = aliasCount + childPatchCount; const totalSelectedBuildVariantCount = Object.values( - selectedBuildVariantTasks, + selectedBuildVariantTasks ).reduce( (count, tasks) => count + (Object.values(tasks).some((isSelected) => isSelected) ? 1 : 0), - 0, + 0 ); // Deduplicate tasks across selected build variants const visibleTasks = useMemo(() => { const tasks = selectedBuildVariants.map( - (bv) => selectedBuildVariantTasks[bv] || {}, + (bv) => selectedBuildVariantTasks[bv] || {} ); const previouslySelectedVariants = selectedBuildVariants.map( - (bv) => activatedVariants.find((vt) => vt.name === bv) || undefined, + (bv) => activatedVariants.find((vt) => vt.name === bv) || undefined ); return deduplicateTasks( tasks, // @ts-expect-error: FIXME. This comment was added by an automated script. previouslySelectedVariants, - new RegExp(search), + new RegExp(search) ); }, [ selectedBuildVariantTasks, @@ -104,15 +104,15 @@ const ConfigureTasks: React.FC = ({ // Sort tasks alphabetically const sortedVisibleTasks = useMemo( () => Object.entries(visibleTasks).sort((a, b) => a[0].localeCompare(b[0])), - [visibleTasks], + [visibleTasks] ); const currentAliases = getVisibleAliases( selectedAliases, - selectedBuildVariants, + selectedBuildVariants ); const currentAliasTasks = selectableAliases.filter(({ alias }) => - selectedBuildVariants.includes(alias), + selectedBuildVariants.includes(alias) ); // Show an alias's variants/tasks if it is the only menu item selected const shouldShowAliasTasks = @@ -120,7 +120,7 @@ const ConfigureTasks: React.FC = ({ const currentChildPatches = getVisibleChildPatches( childPatches, - selectedBuildVariants, + selectedBuildVariants ); // Show a child patch's variants/tasks if it is the only menu item selected const shouldShowChildPatchTasks = @@ -168,25 +168,25 @@ const ConfigureTasks: React.FC = ({ const selectAllCheckboxState = getSelectAllCheckboxState( visibleTasks, currentAliases, - shouldShowChildPatchTasks, + shouldShowChildPatchTasks ); const variantHasActivatedTasks = sortedVisibleTasks.some((t) => - isTaskCheckboxActivated(t[1]), + isTaskCheckboxActivated(t[1]) ); const taskDisclaimerCopy = `${totalSelectedTaskCount} ${pluralize( "task", - totalSelectedTaskCount, + totalSelectedTaskCount )} across ${totalSelectedBuildVariantCount} build ${pluralize( "variant", - totalSelectedBuildVariantCount, + totalSelectedBuildVariantCount )}, ${totalDownstreamTaskCount} trigger ${pluralize("alias", aliasCount)}`; const selectAllCheckboxCopy = getSelectAllCheckboxCopy( selectedBuildVariants.length, sortedVisibleTasks.length, - search.length > 0, + search.length > 0 ); return ( @@ -313,7 +313,7 @@ const ConfigureTasks: React.FC = ({ const getSelectAllCheckboxCopy = ( selectedBuildVariantsCount: number, sortedVisibleTaskCount: number, - hasFilter: boolean, + hasFilter: boolean ) => { if (hasFilter) { return "Select all tasks in view"; @@ -323,7 +323,7 @@ const getSelectAllCheckboxCopy = ( ? `Add ${pluralize("alias", selectedBuildVariantsCount)} to patch` : `Select all tasks in ${pluralize( "this", - selectedBuildVariantsCount, + selectedBuildVariantsCount )} ${pluralize("variant", selectedBuildVariantsCount)}`; }; const Actions = styled.div` diff --git a/apps/spruce/src/pages/configurePatch/configurePatchCore/useConfigurePatch/useConfigurePatch.test.tsx b/apps/spruce/src/pages/configurePatch/configurePatchCore/useConfigurePatch/useConfigurePatch.test.tsx index aa913c83d..777c07584 100644 --- a/apps/spruce/src/pages/configurePatch/configurePatchCore/useConfigurePatch/useConfigurePatch.test.tsx +++ b/apps/spruce/src/pages/configurePatch/configurePatchCore/useConfigurePatch/useConfigurePatch.test.tsx @@ -48,6 +48,7 @@ describe("useConfigurePatch", () => { { name: "ubuntu2004", tasks: ["e2e_test"], + displayTasks: [], }, ], }; diff --git a/apps/spruce/src/pages/configurePatch/configurePatchCore/useConfigurePatch/utils.test.ts b/apps/spruce/src/pages/configurePatch/configurePatchCore/useConfigurePatch/utils.test.ts index ede15b058..153383513 100644 --- a/apps/spruce/src/pages/configurePatch/configurePatchCore/useConfigurePatch/utils.test.ts +++ b/apps/spruce/src/pages/configurePatch/configurePatchCore/useConfigurePatch/utils.test.ts @@ -51,8 +51,9 @@ describe("initializeTaskState", () => { { name: "variant1", tasks: ["task1"], + displayTasks: [], }, - ]), + ]) ).toStrictEqual({ variant1: { task1: true, @@ -78,8 +79,9 @@ describe("initializeTaskState", () => { { name: "variant2", tasks: ["task2"], + displayTasks: [], }, - ]), + ]) ).toStrictEqual({ variant1: { task1: false, @@ -111,6 +113,7 @@ describe("initializeAliasState", () => { { name: "variant1", tasks: ["task1"], + displayTasks: [], }, ], }, diff --git a/apps/spruce/src/utils/tasks/estimatedActivatedTasks.test.ts b/apps/spruce/src/utils/tasks/estimatedActivatedTasks.test.ts index 69b98b911..8e8967e15 100644 --- a/apps/spruce/src/utils/tasks/estimatedActivatedTasks.test.ts +++ b/apps/spruce/src/utils/tasks/estimatedActivatedTasks.test.ts @@ -27,14 +27,14 @@ describe("getNumEstimatedActivatedTasks", () => { }, }; const variantsTasks: Array = [ - { name: "variant1", tasks: ["task1"] }, + { name: "variant1", tasks: ["task1"], displayTasks: [] }, ]; expect( sumActivatedTasksInVariantsTasks( selectedBuildVariantTasks, generatedTaskCounts, - variantsTasks, - ), + variantsTasks + ) ).toBe(12); }); it("should compute zero when configuring a patch where all selected tasks have already been created", () => { @@ -46,16 +46,16 @@ describe("getNumEstimatedActivatedTasks", () => { }, }; const variantsTasks: Array = [ - { name: "variant1", tasks: ["task1"] }, - { name: "variant1", tasks: ["task2"] }, - { name: "variant1", tasks: ["task3"] }, + { name: "variant1", tasks: ["task1"], displayTasks: [] }, + { name: "variant1", tasks: ["task2"], displayTasks: [] }, + { name: "variant1", tasks: ["task3"], displayTasks: [] }, ]; expect( sumActivatedTasksInVariantsTasks( selectedBuildVariantTasks, generatedTaskCounts, - variantsTasks, - ), + variantsTasks + ) ).toBe(0); }); it("should compute the correct number of activated tasks to be created when configuring a patch where no tasks have already been created", () => { @@ -70,8 +70,8 @@ describe("getNumEstimatedActivatedTasks", () => { sumActivatedTasksInVariantsTasks( selectedBuildVariantTasks, generatedTaskCounts, - [], - ), + [] + ) ).toBe(18); }); it("should compute the correct number of activated tasks to be created when scheduling multiple unscheduled tasks", () => { @@ -87,7 +87,7 @@ describe("getNumEstimatedActivatedTasks", () => { }, }; expect(sumActivatedTasksInSelectedTasks(vsts, generatedTaskCounts)).toBe( - 153, + 153 ); }); it("should compute the correct number of activated tasks to be created when restarting some tasks in a version", () => { @@ -99,7 +99,7 @@ describe("getNumEstimatedActivatedTasks", () => { }, }; expect(sumActivatedTasksInSelectedTasks(vsts, generatedTaskCounts)).toBe( - 102, + 102 ); }); it("should compute zero for empty input", () => {