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

Expose status_info in the UI #332

Merged
merged 4 commits into from
Nov 16, 2023
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
1 change: 1 addition & 0 deletions src/common/models/Build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type Build = {
};
packages: BuildPackage[];
status: string;
status_info: string | null;
size: number;
scheduled_on: string;
started_on: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ export const EnvironmentCreate = ({ environmentNotification }: IEnvCreate) => {
description: createLabel(name, "create")
}
});
} catch ({ data }) {
} catch (e) {
setError({
message: data.message,
message: e?.data?.message ?? createLabel(undefined, "error"),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This used to fail because data was undefined.

A repro: try to create an environment with 256 a chars as the env name: 'a' * 256. This causes a SQL error on the server because the field is only 255 chars long. With this change, the UI now shows an error message.

I'm not adding a "before" screenshot because before it was just showing nothing - same page you have when you click Create. You could also see an uncaught exception in the dev browser console (that's usually opened by pressing f12).

Screen Shot 2023-11-08 at 21 06 21

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the possible error messages that will be displayed here?

Copy link
Contributor Author

@nkaretnikov nkaretnikov Nov 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e?.data?.message corresponds to what used to be here before. I think message is not actually used by the said route, but I would keep it just in case, in case it's changed later. The route on the server is:

api_post_specification
...
return {"status": "ok", "data": {"build_id": build_id}}

Unlike some other routes, it doesn't include the message field.

The new message is always a generic error message shown on the screenshot above. This is what we do elsewhere as well, so it's consistent.

visible: true
});
}
Expand Down
8 changes: 7 additions & 1 deletion src/features/metadata/components/EnvBuilds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ export const EnvBuilds = ({
>
Status: {""}
<Typography component="span" sx={{ fontSize: "13px" }}>
{currentBuild.status}
{currentBuild.status_info ? (
<>
{currentBuild.status} ({currentBuild.status_info})
</>
) : (
<>{currentBuild.status}</>
)}
{(currentBuild.status === "Building" ||
currentBuild.status === "Queued") && (
<CircularProgress
Expand Down
74 changes: 40 additions & 34 deletions src/utils/helpers/buildMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,44 +41,50 @@ const dateToTimezone = (date: string) => {
};

export const buildMapper = (data: Build[], currentBuildId: number) => {
return data.map(({ id, status, ended_on, scheduled_on }: Build) => {
let duration = 0;
if (ended_on && scheduled_on) {
const startTime = new Date(scheduled_on);
const endTime = new Date(ended_on);
duration = (endTime.valueOf() - startTime.valueOf()) / 60000;
duration = Math.round(duration);
}
if (id === currentBuildId) {
return {
id,
name: `${dateToTimezone(ended_on ?? scheduled_on)} - Active`,
status: isCompleted(status, duration)
};
}
return data.map(
({ id, status, status_info, ended_on, scheduled_on }: Build) => {
let duration = 0;
if (ended_on && scheduled_on) {
const startTime = new Date(scheduled_on);
const endTime = new Date(ended_on);
duration = (endTime.valueOf() - startTime.valueOf()) / 60000;
duration = Math.round(duration);
}
if (id === currentBuildId) {
return {
id,
name: `${dateToTimezone(ended_on ?? scheduled_on)} - Active`,
status: isCompleted(status, duration),
status_info
};
}

if (isBuilding(status)) {
return {
id,
name: `${dateToTimezone(scheduled_on)} - Building`,
status: "Building"
};
}
if (isBuilding(status)) {
return {
id,
name: `${dateToTimezone(scheduled_on)} - Building`,
status: "Building",
status_info
};
}

if (isQueued(status)) {
return {
id,
name: `${dateToTimezone(scheduled_on)} - Queued`,
status: "Building",
status_info
};
}

if (isQueued(status)) {
return {
id,
name: `${dateToTimezone(scheduled_on)} - Queued`,
status: "Building"
name: `${dateToTimezone(ended_on ?? scheduled_on)} - ${
STATUS_OPTIONS[status]
}`,
status: isCompleted(status, duration),
status_info
};
}

return {
id,
name: `${dateToTimezone(ended_on ?? scheduled_on)} - ${
STATUS_OPTIONS[status]
}`,
status: isCompleted(status, duration)
};
});
);
};