Преглед изворни кода

Implemented api endpoints for incident page

jnfrati пре 4 година
родитељ
комит
07ce5145e8

+ 19 - 6
dashboard/src/main/home/cluster-dashboard/dashboard/incidents/IncidentPage.tsx

@@ -1,5 +1,5 @@
 import Loading from "components/Loading";
-import React, { useEffect, useMemo, useState } from "react";
+import React, { useContext, useEffect, useMemo, useState } from "react";
 import { useHistory, useParams } from "react-router";
 import styled from "styled-components";
 import TitleSection from "components/TitleSection";
@@ -9,6 +9,8 @@ import nodePng from "assets/node.png";
 import { Drawer, withStyles } from "@material-ui/core";
 import EventDrawer from "./EventDrawer";
 import { useRouting } from "shared/routing";
+import api from "shared/api";
+import { Context } from "shared/Context";
 
 type IncidentPageParams = {
   incident_id: string;
@@ -17,6 +19,8 @@ type IncidentPageParams = {
 const IncidentPage = () => {
   const { incident_id } = useParams<IncidentPageParams>();
 
+  const { currentProject, currentCluster } = useContext(Context);
+
   const [incident, setIncident] = useState<Incident>(null);
 
   const [selectedEvent, setSelectedEvent] = useState<IncidentEvent>(null);
@@ -30,11 +34,20 @@ const IncidentPage = () => {
 
     setIncident(null);
 
-    mockApi().then((res) => {
-      if (isSubscribed) {
-        setIncident(res.data);
-      }
-    });
+    api
+      .getIncidentById<Incident>(
+        "<token>",
+        { incident_id },
+        {
+          cluster_id: currentCluster.id,
+          project_id: currentProject.id,
+        }
+      )
+      .then((res) => {
+        if (isSubscribed) {
+          setIncident(res.data);
+        }
+      });
 
     return () => {
       isSubscribed = false;

+ 2 - 4
dashboard/src/shared/api.tsx

@@ -1621,13 +1621,11 @@ const getIncidentById = baseApi<
   {
     project_id: number;
     cluster_id: number;
-    namespace: string;
-    release_name: string;
   }
 >(
   "GET",
-  ({ project_id, cluster_id, namespace, release_name: name }) =>
-    `/api/projects/${project_id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${name}/incidents`
+  ({ project_id, cluster_id }) =>
+    `/api/projects/${project_id}/clusters/${cluster_id}/incidents`
 );
 
 const getIncidentLogsByLogId = baseApi<