diff --git a/pipeline-ui/src/pages/PipelinesPage/PipelineDetailsPage.tsx b/pipeline-ui/src/pages/PipelinesPage/PipelineDetailsPage.tsx
index 2a98093b..247b3a09 100644
--- a/pipeline-ui/src/pages/PipelinesPage/PipelineDetailsPage.tsx
+++ b/pipeline-ui/src/pages/PipelinesPage/PipelineDetailsPage.tsx
@@ -10,13 +10,14 @@ import { pipelineApiInstance, pipelineBuildApiInstance } from "../../services/pi
import { Play, Pencil } from "lucide-react";
import NavBar from "../../components/common/navBar";
import Breadcrumb from "../../components/common/breadcrumb";
+import { ERROR_MAP } from "../../lib/error";
/**
* This page includes the Pipeline Details page.
* It displays the details of a pipeline and allows the user to edit the pipeline.
* It has two modes: view mode and edit mode. In view mode, the user can see the details of the pipeline and start a build. In edit mode,
* the user can edit the name and stages of the pipeline.
- * */
+ * */
@@ -29,32 +30,33 @@ export default function PipelineDetailPage() {
const [isCreateMode, setIsCreateMode] = useState(false);
const [editablePipeline, setEditablePipeline] = useState(null);
const [isDeleteVisible, setIsDeleteVisible] = useState(false);
- const [error, setError] = useState(null);
const saveOrCreate = isCreateMode ? "Create" : "Save";
+ // this logic will be changed once we implement the executor microservice.
+ // only time the button will be hidden is when the pipeline is runnning.
async function checkDelete(pipelineId: string) {
- const { status, data } = await pipelineBuildApiInstance.getAllBuilds();
- if (status !== 200) {
- console.error("Error getting builds");
+ try {
+ const { data } = await pipelineBuildApiInstance.getAllBuilds();
+ return !data.some((build) => build.pipelineId === pipelineId);
+ } catch {
return false;
}
- return !data.some((build) => build.pipelineId === pipelineId);
}
// Fetch pipeline data on component mount or when the id changes
useEffect(() => {
async function fetchData() {
- setError(null);
// If the id is "0", it means we are creating a new pipeline, so we set up a new pipeline object and enter edit mode.
if (id === "0") {
- const newPipeline: Pipeline = {
- id: crypto.randomUUID(),
- name: "New Pipeline",
+ const newPipeline: Pipeline = {
+ id: crypto.randomUUID(),
+ name: "New Pipeline",
stages: [
{ id: crypto.randomUUID(), name: "New Stage", scriptType: "bash", command: "", stageOrder: 0 }
- ] };
+ ]
+ };
setEditablePipeline(newPipeline);
setPipeline(newPipeline);
setIsEditing(true);
@@ -63,17 +65,17 @@ export default function PipelineDetailPage() {
}
// Otherwise, we fetch the pipeline data from the API.
- const response = await pipelineApiInstance.getPipelineById(id as string);
- if (!response || response.status !== 200) {
- setError(["Pipeline not found"]);
+ try {
+ const { data } = await pipelineApiInstance.getPipelineById(id as string);
+ setPipeline(data);
+ // This will be changed once we implement Go-Microservice.
+ setIsDeleteVisible((await checkDelete(id as string)) as boolean);
+ } catch (err) {
+ // error handled by axios interceptor but we can log it here for debugging purposes
+ console.error("[ERROR]:", ERROR_MAP.ERROR_FETCHING_PIPELINE.title, { id }, err);
navigate("/pipelines");
- return;
}
-
- setPipeline(response.data);
- setIsDeleteVisible((await checkDelete(id as string)) as boolean);
}
-
fetchData();
}, [id, navigate]);
@@ -96,38 +98,40 @@ export default function PipelineDetailPage() {
// Handler for the "Delete" button click
async function handleDelete() {
- const { status } = await pipelineApiInstance.deletePipeline(id as string);
- // TODO : handle error properly
- if (status === 204) navigate("/pipelines");
+ try {
+ await pipelineApiInstance.deletePipeline(id as string);
+ navigate("/pipelines");
+ } catch (err) {
+ // error handled by axios interceptor
+ console.error("[ERROR]:", ERROR_MAP.ERROR_DELETING_PIPELINE.title, { id }, err);
+ }
}
// Save changes and exit edit mode
async function handleSave() {
+ // no updating logic yet, that will change once we implement the segragation of the execuutor microservice.
+ // For now, we will just create a new pipeline if we are in create mode.
if (isCreateMode) {
setIsCreateMode(false);
const pipelineToSave = {
name: editablePipeline!.name,
stages: editablePipeline!.stages.map((stage, i) => ({
- name: stage.name,
- scriptType: stage.scriptType,
- command: stage.command,
- stageOrder: i,
- })),
+ name: stage.name,
+ scriptType: stage.scriptType,
+ command: stage.command,
+ stageOrder: i,
+ })),
} as unknown as Pipeline;
-
- const {status, data} = await pipelineApiInstance.createPipeline(pipelineToSave);
- // TODO: handle error properly
- if (status !== 201 || typeof data.id === "undefined") {
- setError(data as unknown as string[]);
+
+ try {
+ const { data } = await pipelineApiInstance.createPipeline(pipelineToSave);
+ setIsEditing(false);
+ navigate(`/pipelines/${data.id}`);
+ } catch (err) {
+ // error handled by axios interceptor, but we can log it here for debugging purposes
+ console.error("[ERROR]:", ERROR_MAP.ERROR_CREATING_PIPELINE.title, err);
setIsCreateMode(true);
- setTimeout(() => {
- setError(null);
- }, 5000);
- return;
}
- setIsEditing(false);
- navigate(`/pipelines/${data.id}`);
- return;
}
}
@@ -144,12 +148,13 @@ export default function PipelineDetailPage() {
// Handler for the "Run Now" button click
async function handleStartBuild() {
- const { status, data } = await pipelineApiInstance.executePipeline({ pipelineId: id as string });
- if (status !== 202) {
- console.error("Error starting build");
- return;
+ try {
+ const { data } = await pipelineApiInstance.executePipeline({ pipelineId: id as string });
+ navigate(`/builds/${data.id}`);
+ } catch (err) {
+ // error handled by axios interceptor
+ console.error("[ERROR]:", ERROR_MAP.ERROR_RUNNING_PIPELINE.title, { id }, err);
}
- navigate(`/builds/${data.id}`);
}
const activePipeline = isEditing ? editablePipeline! : pipeline;
@@ -159,13 +164,6 @@ export default function PipelineDetailPage() {
- {/* Error banner */}
- {error && (
-
- {`Error: ${error}`}
-
- )}
-
{/* Back link / editing badge */}
{isEditing ? (
diff --git a/pipeline-ui/src/pages/PipelinesPage/PipelinesListPage.tsx b/pipeline-ui/src/pages/PipelinesPage/PipelinesListPage.tsx
index 2ccf8b92..0a99d5b9 100644
--- a/pipeline-ui/src/pages/PipelinesPage/PipelinesListPage.tsx
+++ b/pipeline-ui/src/pages/PipelinesPage/PipelinesListPage.tsx
@@ -2,11 +2,12 @@ import { useEffect, useState } from "react";
import { SearchBar } from "../../components/common/searchBar";
import { Button } from "../../components/ui/button";
import { pipelineApiInstance } from "../../services/pipelines.api";
-import type {Pipeline} from '../../gen/api';
+import type { Pipeline } from '../../gen/api';
import NavBar from "../../components/common/navBar";
import { useNavigate } from "react-router-dom";
import { Table, TableHeader, TableRow, TableHead, TableBody, TableCell } from "../../components/ui/table";
import Breadcrumb from "../../components/common/breadcrumb";
+import { ERROR_MAP } from "../../lib/error";
/**
* This page includes the Pipelines List page.
@@ -14,28 +15,25 @@ import Breadcrumb from "../../components/common/breadcrumb";
*/
export default function PipelinePage() {
- const [search, setSearch] = useState("");
+ const [search, setSearch] = useState("");
const [data, setData] = useState([]);
const filtered = data.filter((p) =>
p.name.toLowerCase().includes(search.toLowerCase()),
);
-
+
const navigate = useNavigate();
- // TODO: check call is happening twice
useEffect(() => {
async function fetchData() {
- const {status, data} = await pipelineApiInstance.getAllPipelines();
-
- if (status != 200) {
- console.log("obtained status: ", 200); //TODO: error popup
- return;
+ try {
+ const { data } = await pipelineApiInstance.getAllPipelines();
+ setData(data);
+ } catch (err) {
+ // error handled by axios interceptor but log the error for debugging purposes
+ console.error("[ERROR]:", ERROR_MAP.ERROR_FETCH_PIPELINES.title, err);
}
-
- const pipelines = data;
- setData(pipelines);
}
fetchData();
}, []);
@@ -54,7 +52,7 @@ export default function PipelinePage() {