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

Update to match new Core API for getting build statuses. #139

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions src/__generated__/gql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 3 additions & 9 deletions src/__generated__/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions src/components/CreateEnvironment/MatchingEnvs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { useQuery } from "@apollo/client";
import { Box, Typography } from "@mui/material";

import { ALL_ENVIRONMENTS, Package } from "../../../queries";
import EnvironmentTable from "../../ViewEnvironments/EnvironmentTable";
import EnvironmentTable, { BuildStatusContext } from "../../ViewEnvironments/EnvironmentTable";
import { anyPackageVersion } from "../packageValidation";
import type { Environment as EnvironmentType } from "../../../queries";
import { useContext } from "react";

type MatchingEnvsParams = {
selectedPackages: Package[];
Expand All @@ -18,6 +19,7 @@ type MatchingEnvsParams = {
// environment they are trying to create already exists.
export default function matchingEnvs(props: MatchingEnvsParams) {
const { loading, data, error } = useQuery(ALL_ENVIRONMENTS);
const buildStatuses = useContext(BuildStatusContext);

if (loading) {
return <div>...</div>;
Expand Down Expand Up @@ -46,9 +48,10 @@ export default function matchingEnvs(props: MatchingEnvsParams) {
</Typography>
</Box>
<EnvironmentTable
buildStatuses={buildStatuses?.statuses ?? null}
environments={matchingEnvironments}
highlightPackages={props.selectedPackages}
setSelectedEnv={props.setSelectedEnv}
setSelectedEnv={props.setSelectedEnv}
/>
<Typography variant="subtitle1" gutterBottom align="right">
Or, create a new environment:
Expand Down
20 changes: 9 additions & 11 deletions src/components/ViewEnvironments/EnvironmentList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { EnvironmentsQueryContext } from "../../EnvironmentsQueryContext";
import EnvironmentDrawer, { recipeDescriptionContext } from "../Drawer";
import { HelpIcon } from "../../HelpIcon";
import { UserContext } from "../../UserContext";
import EnvironmentTable from "../EnvironmentTable";
import EnvironmentTable, { BuildStatusContext } from "../EnvironmentTable";
import { useSearchParams } from "react-router-dom";
import CreateEnvPrompt from "../CreateEnvPrompt";

Expand All @@ -37,6 +37,7 @@ function arrayEqual<T>(a: T[], b: T[]): boolean {
// EnvironmentList displays the 'view environments' page of the program.
const EnvironmentList = () => {
const { loading, data, error } = useContext(EnvironmentsQueryContext);
const buildStatuses = useContext(BuildStatusContext);
const [filter, setFilter] = useState("");
const [filterText, setFilterText] = useState("");
const client = useApolloClient();
Expand Down Expand Up @@ -103,6 +104,7 @@ const EnvironmentList = () => {
return () => clearInterval(interval);
}, [loading, error, refetchInterval]);


if (loading) {
return <Box width="100%" height="300px" lineHeight="300px" textAlign="center"><CircularProgress /></Box>;
}
Expand All @@ -113,19 +115,14 @@ const EnvironmentList = () => {
);
}

const environmentsInProgress = data.environments.filter(
(e) => e.state == "queued",
);

const avgWaitSecs = data.environments.find((e) => e.avgWaitSecs != null)
?.avgWaitSecs;
const environmentsInProgress = data.environments.reduce((c, e) => c + +(e.state == "queued"), 0);

let filteredEnvironments = data.environments.slice().map(env => Object.assign(
Object.assign({}, env),
{
"packages": env.packages.toSpliced(0, 0, ...[
(env.interpreters.python ? { "name": "python", "version": env.interpreters.python } : null) as any,
(env.interpreters.r ? { "name": "r", "version": env.interpreters.r } : null) as any
(env.interpreters.python ? { "name": "python", "version": env.interpreters.python } : null) as typeof env.packages[0],
(env.interpreters.r ? { "name": "r", "version": env.interpreters.r } : null) as typeof env.packages[0]
].filter(e => e))
}));

Expand Down Expand Up @@ -378,15 +375,16 @@ const EnvironmentList = () => {
{filteredEnvironments.some((e) => e.state === "queued") ||
ignoreReady ? (
<Alert severity="info">
There are currently {environmentsInProgress.length} environments in
There are currently {environmentsInProgress} environments in
the build queue. Average wait time:{" "}
{avgWaitSecs != null ? humanize(avgWaitSecs * 1000) : "unknown"}.
{buildStatuses != null ? humanize(buildStatuses.avg * 1000) : "unknown"}.
</Alert>
) : null}
</Box>
<Container id="environment_table">
{filteredEnvironments.length > 0 ? (
<EnvironmentTable
buildStatuses={buildStatuses?.statuses ?? null}
environments={filteredEnvironments}
highlightPackages={highlightPackages}
setSelectedEnv={(env: EnvironmentType) => {
Expand Down
Loading