Skip to content

feat: show popup notification on successful template build #18369

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

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import type {
PatchTemplateVersionRequest,
TemplateVersion,
} from "api/typesGenerated";
import { displayError } from "components/GlobalSnackbar/utils";
import { displayError, displaySuccess } from "components/GlobalSnackbar/utils";
import { Loader } from "components/Loader/Loader";
import { linkToTemplate, useLinks } from "modules/navigation";
import { useWatchVersionLogs } from "modules/templates/useWatchVersionLogs";
import { type FC, useEffect, useState } from "react";
import { type FC, useEffect, useRef, useState } from "react";
import { Helmet } from "react-helmet-async";
import {
keepPreviousData,
Expand Down Expand Up @@ -122,11 +122,31 @@ const TemplateVersionEditorPage: FC = () => {
const [provisionerTags, setProvisionerTags] = useState<
Record<string, string>
>({});
// Track previous job status to detect when a build completes successfully
const previousJobStatus = useRef<string | undefined>(undefined);
useEffect(() => {
if (activeTemplateVersion?.job.tags) {
setProvisionerTags(activeTemplateVersion.job.tags);
}
}, [activeTemplateVersion?.job.tags]);

// Show notification when build succeeds
useEffect(() => {
if (!activeTemplateVersion || !templateQuery.data) {
return;
}

// Only show notification when status changes from running/pending to succeeded
if (previousJobStatus.current &&
["running", "pending"].includes(previousJobStatus.current) &&
activeTemplateVersion.job.status === "succeeded") {
const templateName = templateQuery.data.display_name || templateQuery.data.name;
displaySuccess(`Template ${templateName} (${activeTemplateVersion.name}) built successfully`);
}

// Update the previous status for next comparison
previousJobStatus.current = activeTemplateVersion.job.status;
}, [activeTemplateVersion?.job.status, templateQuery.data]);

return (
<>
Expand Down
Loading