|
@@ -1,4 +1,4 @@
|
|
|
-import React, { useEffect, useState } from "react";
|
|
|
|
|
|
|
+import React, { useContext, useEffect, useState } from "react";
|
|
|
import { useQuery } from "@tanstack/react-query";
|
|
import { useQuery } from "@tanstack/react-query";
|
|
|
import axios from "axios";
|
|
import axios from "axios";
|
|
|
import _ from "lodash";
|
|
import _ from "lodash";
|
|
@@ -11,26 +11,30 @@ import Fieldset from "components/porter/Fieldset";
|
|
|
import Pagination from "components/porter/Pagination";
|
|
import Pagination from "components/porter/Pagination";
|
|
|
import Spacer from "components/porter/Spacer";
|
|
import Spacer from "components/porter/Spacer";
|
|
|
import Text from "components/porter/Text";
|
|
import Text from "components/porter/Text";
|
|
|
|
|
+import { type DeploymentTarget } from "lib/hooks/useDeploymentTarget";
|
|
|
|
|
+import { formattedPath } from "lib/porter-apps/routing";
|
|
|
|
|
|
|
|
import api from "shared/api";
|
|
import api from "shared/api";
|
|
|
|
|
+import { Context } from "shared/Context";
|
|
|
import { feedDate } from "shared/string_utils";
|
|
import { feedDate } from "shared/string_utils";
|
|
|
|
|
+
|
|
|
import EventCard from "./events/cards/EventCard";
|
|
import EventCard from "./events/cards/EventCard";
|
|
|
import { porterAppEventValidator, type PorterAppEvent } from "./events/types";
|
|
import { porterAppEventValidator, type PorterAppEvent } from "./events/types";
|
|
|
|
|
|
|
|
type Props = {
|
|
type Props = {
|
|
|
appName: string;
|
|
appName: string;
|
|
|
- currentProject: number;
|
|
|
|
|
- currentCluster: number;
|
|
|
|
|
- deploymentTargetId: string;
|
|
|
|
|
|
|
+ projectId: number;
|
|
|
|
|
+ clusterId: number;
|
|
|
|
|
+ deploymentTarget: DeploymentTarget;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const EVENTS_POLL_INTERVAL = 5000; // poll every 5 seconds
|
|
const EVENTS_POLL_INTERVAL = 5000; // poll every 5 seconds
|
|
|
|
|
|
|
|
const ActivityFeed: React.FC<Props> = ({
|
|
const ActivityFeed: React.FC<Props> = ({
|
|
|
appName,
|
|
appName,
|
|
|
- deploymentTargetId,
|
|
|
|
|
- currentCluster,
|
|
|
|
|
- currentProject,
|
|
|
|
|
|
|
+ deploymentTarget,
|
|
|
|
|
+ clusterId,
|
|
|
|
|
+ projectId,
|
|
|
}) => {
|
|
}) => {
|
|
|
const [events, setEvents] = useState<PorterAppEvent[] | undefined>(undefined);
|
|
const [events, setEvents] = useState<PorterAppEvent[] | undefined>(undefined);
|
|
|
const [page, setPage] = useState<number>(1);
|
|
const [page, setPage] = useState<number>(1);
|
|
@@ -40,22 +44,24 @@ const ActivityFeed: React.FC<Props> = ({
|
|
|
);
|
|
);
|
|
|
const [isPorterAgentInstalling, setIsPorterAgentInstalling] = useState(false);
|
|
const [isPorterAgentInstalling, setIsPorterAgentInstalling] = useState(false);
|
|
|
|
|
|
|
|
|
|
+ const { currentProject } = useContext(Context);
|
|
|
|
|
+
|
|
|
const {
|
|
const {
|
|
|
data: eventFetchData,
|
|
data: eventFetchData,
|
|
|
isLoading: isEventFetchLoading,
|
|
isLoading: isEventFetchLoading,
|
|
|
isRefetching,
|
|
isRefetching,
|
|
|
} = useQuery(
|
|
} = useQuery(
|
|
|
- ["appEvents", deploymentTargetId, page],
|
|
|
|
|
|
|
+ ["appEvents", deploymentTarget.id, page],
|
|
|
async () => {
|
|
async () => {
|
|
|
const res = await api.appEvents(
|
|
const res = await api.appEvents(
|
|
|
"<token>",
|
|
"<token>",
|
|
|
{
|
|
{
|
|
|
- deployment_target_id: deploymentTargetId,
|
|
|
|
|
|
|
+ deployment_target_id: deploymentTarget.id,
|
|
|
page,
|
|
page,
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
- cluster_id: currentCluster,
|
|
|
|
|
- project_id: currentProject,
|
|
|
|
|
|
|
+ cluster_id: clusterId,
|
|
|
|
|
+ project_id: projectId,
|
|
|
porter_app_name: appName,
|
|
porter_app_name: appName,
|
|
|
}
|
|
}
|
|
|
);
|
|
);
|
|
@@ -95,12 +101,12 @@ const ActivityFeed: React.FC<Props> = ({
|
|
|
|
|
|
|
|
const { data: porterAgentCheck, isLoading: porterAgentCheckLoading } =
|
|
const { data: porterAgentCheck, isLoading: porterAgentCheckLoading } =
|
|
|
useQuery(
|
|
useQuery(
|
|
|
- ["detectPorterAgent", currentProject, currentCluster],
|
|
|
|
|
|
|
+ ["detectPorterAgent", projectId, clusterId],
|
|
|
async () => {
|
|
async () => {
|
|
|
const res = await api.detectPorterAgent(
|
|
const res = await api.detectPorterAgent(
|
|
|
"<token>",
|
|
"<token>",
|
|
|
{},
|
|
{},
|
|
|
- { project_id: currentProject, cluster_id: currentCluster }
|
|
|
|
|
|
|
+ { project_id: projectId, cluster_id: clusterId }
|
|
|
);
|
|
);
|
|
|
// response will either have version key if porter agent found, or error key if not
|
|
// response will either have version key if porter agent found, or error key if not
|
|
|
const parsed = await z
|
|
const parsed = await z
|
|
@@ -131,7 +137,7 @@ const ActivityFeed: React.FC<Props> = ({
|
|
|
await api.installPorterAgent(
|
|
await api.installPorterAgent(
|
|
|
"<token>",
|
|
"<token>",
|
|
|
{},
|
|
{},
|
|
|
- { project_id: currentProject, cluster_id: currentCluster }
|
|
|
|
|
|
|
+ { project_id: projectId, cluster_id: clusterId }
|
|
|
);
|
|
);
|
|
|
window.location.reload();
|
|
window.location.reload();
|
|
|
} catch (err) {
|
|
} catch (err) {
|
|
@@ -211,13 +217,22 @@ const ActivityFeed: React.FC<Props> = ({
|
|
|
<Text>{feedDate(event.created_at).split(", ")[1]}</Text>
|
|
<Text>{feedDate(event.created_at).split(", ")[1]}</Text>
|
|
|
</Time>
|
|
</Time>
|
|
|
<EventCard
|
|
<EventCard
|
|
|
- deploymentTargetId={deploymentTargetId}
|
|
|
|
|
|
|
+ deploymentTargetId={deploymentTarget.id}
|
|
|
event={event}
|
|
event={event}
|
|
|
key={i}
|
|
key={i}
|
|
|
isLatestDeployEvent={i === getLatestDeployEventIndex()}
|
|
isLatestDeployEvent={i === getLatestDeployEventIndex()}
|
|
|
- projectId={currentProject}
|
|
|
|
|
- clusterId={currentCluster}
|
|
|
|
|
|
|
+ projectId={projectId}
|
|
|
|
|
+ clusterId={clusterId}
|
|
|
appName={appName}
|
|
appName={appName}
|
|
|
|
|
+ tabUrlGenerator={({ tab, queryParams }) =>
|
|
|
|
|
+ formattedPath({
|
|
|
|
|
+ currentProject,
|
|
|
|
|
+ deploymentTarget,
|
|
|
|
|
+ tab,
|
|
|
|
|
+ appName,
|
|
|
|
|
+ queryParams,
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
/>
|
|
/>
|
|
|
</EventWrapper>
|
|
</EventWrapper>
|
|
|
);
|
|
);
|