Skip to content

Commit

Permalink
feat: add display tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
ZackarySantana committed Oct 10, 2024
1 parent f6542be commit de610a3
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 35 deletions.
4 changes: 4 additions & 0 deletions apps/spruce/src/gql/fragments/basePatch.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ fragment BasePatch on Patch {
}
status
variantsTasks {
displayTasks {
execTasks
name
}
name
tasks
}
Expand Down
34 changes: 33 additions & 1 deletion apps/spruce/src/gql/generated/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,12 @@ export enum DispatcherVersion {
}

export type DisplayTask = {
__typename?: "DisplayTask";
execTasks: Array<Scalars["String"]["output"]>;
name: Scalars["String"]["output"];
};

export type DisplayTaskInput = {
ExecTasks: Array<Scalars["String"]["input"]>;
Name: Scalars["String"]["input"];
};
Expand Down Expand Up @@ -3335,12 +3341,13 @@ export type UserSettingsInput = {

export type VariantTask = {
__typename?: "VariantTask";
displayTasks: Array<DisplayTask>;
name: Scalars["String"]["output"];
tasks: Array<Scalars["String"]["output"]>;
};

export type VariantTasks = {
displayTasks: Array<DisplayTask>;
displayTasks: Array<DisplayTaskInput>;
tasks: Array<Scalars["String"]["input"]>;
variant: Scalars["String"]["input"];
};
Expand Down Expand Up @@ -3691,6 +3698,11 @@ export type BasePatchFragment = {
__typename?: "VariantTask";
name: string;
tasks: Array<string>;
displayTasks: Array<{
__typename?: "DisplayTask";
execTasks: Array<string>;
name: string;
}>;
}>;
};

Expand Down Expand Up @@ -5472,6 +5484,11 @@ export type SchedulePatchMutation = {
__typename?: "VariantTask";
name: string;
tasks: Array<string>;
displayTasks: Array<{
__typename?: "DisplayTask";
execTasks: Array<string>;
name: string;
}>;
}>;
};
};
Expand Down Expand Up @@ -5629,6 +5646,11 @@ export type UpdatePatchDescriptionMutation = {
__typename?: "VariantTask";
name: string;
tasks: Array<string>;
displayTasks: Array<{
__typename?: "DisplayTask";
execTasks: Array<string>;
name: string;
}>;
}>;
};
};
Expand Down Expand Up @@ -6953,6 +6975,11 @@ export type ConfigurePatchQuery = {
__typename?: "VariantTask";
name: string;
tasks: Array<string>;
displayTasks: Array<{
__typename?: "DisplayTask";
execTasks: Array<string>;
name: string;
}>;
}>;
};
};
Expand Down Expand Up @@ -6995,6 +7022,11 @@ export type PatchQuery = {
__typename?: "VariantTask";
name: string;
tasks: Array<string>;
displayTasks: Array<{
__typename?: "DisplayTask";
execTasks: Array<string>;
name: string;
}>;
}>;
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -66,33 +66,33 @@ const ConfigureTasks: React.FC<Props> = ({
},
() => {
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,
Expand All @@ -104,23 +104,23 @@ const ConfigureTasks: React.FC<Props> = ({
// 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 =
currentAliasTasks.length === 1 && selectedBuildVariants.length === 1;

const currentChildPatches = getVisibleChildPatches(
childPatches,
selectedBuildVariants,
selectedBuildVariants
);
// Show a child patch's variants/tasks if it is the only menu item selected
const shouldShowChildPatchTasks =
Expand Down Expand Up @@ -168,25 +168,25 @@ const ConfigureTasks: React.FC<Props> = ({
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 (
<TabContentWrapper>
Expand Down Expand Up @@ -313,7 +313,7 @@ const ConfigureTasks: React.FC<Props> = ({
const getSelectAllCheckboxCopy = (
selectedBuildVariantsCount: number,
sortedVisibleTaskCount: number,
hasFilter: boolean,
hasFilter: boolean
) => {
if (hasFilter) {
return "Select all tasks in view";
Expand All @@ -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`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe("useConfigurePatch", () => {
{
name: "ubuntu2004",
tasks: ["e2e_test"],
displayTasks: [],
},
],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ describe("initializeTaskState", () => {
{
name: "variant1",
tasks: ["task1"],
displayTasks: [],
},
]),
])
).toStrictEqual({
variant1: {
task1: true,
Expand All @@ -78,8 +79,9 @@ describe("initializeTaskState", () => {
{
name: "variant2",
tasks: ["task2"],
displayTasks: [],
},
]),
])
).toStrictEqual({
variant1: {
task1: false,
Expand Down Expand Up @@ -111,6 +113,7 @@ describe("initializeAliasState", () => {
{
name: "variant1",
tasks: ["task1"],
displayTasks: [],
},
],
},
Expand Down
24 changes: 12 additions & 12 deletions apps/spruce/src/utils/tasks/estimatedActivatedTasks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ describe("getNumEstimatedActivatedTasks", () => {
},
};
const variantsTasks: Array<VariantTask> = [
{ 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", () => {
Expand All @@ -46,16 +46,16 @@ describe("getNumEstimatedActivatedTasks", () => {
},
};
const variantsTasks: Array<VariantTask> = [
{ 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", () => {
Expand All @@ -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", () => {
Expand All @@ -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", () => {
Expand All @@ -99,7 +99,7 @@ describe("getNumEstimatedActivatedTasks", () => {
},
};
expect(sumActivatedTasksInSelectedTasks(vsts, generatedTaskCounts)).toBe(
102,
102
);
});
it("should compute zero for empty input", () => {
Expand Down

0 comments on commit de610a3

Please sign in to comment.