Просмотр исходного кода

require agent for activity feed (#3134)

Co-authored-by: Justin Rhee <jusrhee@Justins-MacBook-Air.local>
jusrhee 2 лет назад
Родитель
Сommit
9beaebd6c3

+ 73 - 0
dashboard/src/main/home/app-dashboard/expanded-app/activity-feed/ActivityFeed.tsx

@@ -15,6 +15,7 @@ import Fieldset from "components/porter/Fieldset";
 import { feedDate } from "shared/string_utils";
 import { feedDate } from "shared/string_utils";
 import Pagination from "components/porter/Pagination";
 import Pagination from "components/porter/Pagination";
 import { PorterAppEvent, PorterAppEventType } from "shared/types";
 import { PorterAppEvent, PorterAppEventType } from "shared/types";
+import Button from "components/porter/Button";
 
 
 type Props = {
 type Props = {
   chart: any;
   chart: any;
@@ -30,6 +31,32 @@ const ActivityFeed: React.FC<Props> = ({ chart, stackName, appData }) => {
   const [error, setError] = useState<any>(null);
   const [error, setError] = useState<any>(null);
   const [page, setPage] = useState<number>(1);
   const [page, setPage] = useState<number>(1);
   const [numPages, setNumPages] = useState<number>(0);
   const [numPages, setNumPages] = useState<number>(0);
+  const [hasPorterAgent, setHasPorterAgent] = useState(true);
+  const [isPorterAgentInstalling, setIsPorterAgentInstalling] = useState(false);
+
+  useEffect(() => {
+    checkForAgent();
+  }, []);
+
+  const checkForAgent = () => {
+    const project_id = currentProject?.id;
+    const cluster_id = currentCluster?.id;
+
+    api
+      .detectPorterAgent("<token>", {}, { project_id, cluster_id })
+      .then((res: any) => {
+        if (res.data?.version != "v3") {
+          setHasPorterAgent(false);
+        } else {
+          setHasPorterAgent(true);
+        }
+      })
+      .catch((err) => {
+        if (err.response?.status === 404) {
+          setHasPorterAgent(false);
+        }
+      });
+  };
 
 
   const getEvents = async () => {
   const getEvents = async () => {
     setLoading(true);
     setLoading(true);
@@ -57,6 +84,29 @@ const ActivityFeed: React.FC<Props> = ({ chart, stackName, appData }) => {
     getEvents();
     getEvents();
   }, [page]);
   }, [page]);
 
 
+  const installAgent = async () => {
+    const project_id = currentProject?.id;
+    const cluster_id = currentCluster?.id;
+
+    setIsPorterAgentInstalling(true);
+
+    api
+      .installPorterAgent("<token>", {}, { project_id, cluster_id })
+      .then()
+      .catch((err) => {
+        setIsPorterAgentInstalling(false);
+        console.log(err);
+      });
+  };
+
+  if (isPorterAgentInstalling) {
+    return (
+      <Fieldset>
+        <Text size={16}>Installing agent...</Text>
+      </Fieldset>
+    );
+  }
+
   if (error) {
   if (error) {
     return (
     return (
       <Fieldset>
       <Fieldset>
@@ -76,6 +126,24 @@ const ActivityFeed: React.FC<Props> = ({ chart, stackName, appData }) => {
     );
     );
   }
   }
 
 
+  if (!hasPorterAgent) {
+    return (
+      <Fieldset>
+        <Text size={16}>
+          We couldn't detect the Porter agent on your cluster
+        </Text>
+        <Spacer y={0.5} />
+        <Text color="helper">
+          In order to use the events tab, you need to install the Porter agent.
+        </Text>
+        <Spacer y={1} />
+        <Button onClick={() => installAgent()}>
+          <I className="material-icons">add</I> Install Porter agent
+        </Button>
+      </Fieldset>
+    );
+  }
+
   if (events?.length === 0) {
   if (events?.length === 0) {
     return (
     return (
       <Fieldset>
       <Fieldset>
@@ -114,6 +182,11 @@ const ActivityFeed: React.FC<Props> = ({ chart, stackName, appData }) => {
 
 
 export default ActivityFeed;
 export default ActivityFeed;
 
 
+const I = styled.i`
+  font-size: 14px;
+  margin-right: 5px;
+`;
+
 const Time = styled.div`
 const Time = styled.div`
   opacity: 0;
   opacity: 0;
   animation: fadeIn 0.3s 0.1s;
   animation: fadeIn 0.3s 0.1s;