Skip to content

Commit 92d9ee8

Browse files
authored
Merge branch 'master' into enableSOC2Check
2 parents f2029bb + d359996 commit 92d9ee8

File tree

7 files changed

+124
-58
lines changed

7 files changed

+124
-58
lines changed

dashboard/src/lib/hooks/useAppStatus.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import _ from "lodash";
33
import pluralize from "pluralize";
44
import z from "zod";
55

6+
import { type ClientService } from "lib/porter-apps/services";
7+
68
import api from "shared/api";
79
import {
810
useWebsockets,
@@ -43,14 +45,14 @@ type SerializedServiceStatus = z.infer<typeof serviceStatusValidator>;
4345
export const useAppStatus = ({
4446
projectId,
4547
clusterId,
46-
serviceNames,
48+
services,
4749
deploymentTargetId,
4850
appName,
4951
kind = "pod",
5052
}: {
5153
projectId: number;
5254
clusterId: number;
53-
serviceNames: string[];
55+
services: ClientService[];
5456
deploymentTargetId: string;
5557
appName: string;
5658
kind?: string;
@@ -116,6 +118,7 @@ export const useAppStatus = ({
116118
};
117119

118120
useEffect(() => {
121+
const serviceNames = services.map((s) => s.name.value);
119122
void Promise.all(serviceNames.map(updatePods));
120123
for (const serviceName of serviceNames) {
121124
setupWebsocket(serviceName);

dashboard/src/lib/porter-apps/services.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,25 @@ export type DetectedServices = {
3939
};
4040
type ClientServiceType = "web" | "worker" | "job" | "predeploy";
4141

42+
type ClientWebService = ClientService & { config: ClientWebConfig };
43+
export const isClientWebService = (
44+
service: ClientService
45+
): service is ClientWebService => {
46+
return service.config.type === "web";
47+
};
48+
type ClientWorkerService = ClientService & { config: ClientWorkerConfig };
49+
export const isClientWorkerService = (
50+
service: ClientService
51+
): service is ClientWorkerService => {
52+
return service.config.type === "worker";
53+
};
54+
type ClientJobService = ClientService & { config: ClientJobConfig };
55+
export const isClientJobService = (
56+
service: ClientService
57+
): service is ClientJobService => {
58+
return service.config.type === "job";
59+
};
60+
4261
const webConfigValidator = z.object({
4362
type: z.literal("web"),
4463
autoscaling: autoscalingValidator.optional(),

dashboard/src/main/home/app-dashboard/app-view/tabs/Overview.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { type PorterAppFormData } from "lib/porter-apps";
99
import {
1010
defaultSerialized,
1111
deserializeService,
12+
isClientWebService,
13+
isClientWorkerService,
1214
} from "lib/porter-apps/services";
1315

1416
import { useClusterResources } from "shared/ClusterResourcesContext";
@@ -33,12 +35,15 @@ const Overview: React.FC<Props> = ({ buttonStatus }) => {
3335
projectId,
3436
clusterId,
3537
deploymentTarget,
38+
latestClientServices,
3639
} = useLatestRevision();
3740

3841
const { serviceVersionStatus } = useAppStatus({
3942
projectId,
4043
clusterId,
41-
serviceNames: latestProto.serviceList.map((s) => s.name),
44+
services: latestClientServices.filter(
45+
(s) => isClientWebService(s) || isClientWorkerService(s) // we only care about the pod status of web and workers
46+
),
4247
deploymentTargetId: deploymentTarget.id,
4348
appName: latestProto.name,
4449
});

dashboard/src/main/home/app-dashboard/validate-apply/services-settings/ServiceContainer.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@ import { match } from "ts-pattern";
88
import Spacer from "components/porter/Spacer";
99
import { type ClientServiceStatus } from "lib/hooks/useAppStatus";
1010
import { type PorterAppFormData } from "lib/porter-apps";
11-
import { type ClientService } from "lib/porter-apps/services";
11+
import {
12+
isClientJobService,
13+
type ClientService,
14+
} from "lib/porter-apps/services";
1215

1316
import chip from "assets/computer-chip.svg";
1417
import job from "assets/job.png";
1518
import web from "assets/web.png";
1619
import worker from "assets/worker.png";
1720

18-
import ServiceStatusFooter from "./ServiceStatusFooter";
21+
import JobFooter from "./footers/JobFooter";
22+
import ServiceStatusFooter from "./footers/ServiceStatusFooter";
1923
import JobTabs from "./tabs/JobTabs";
2024
import WebTabs from "./tabs/WebTabs";
2125
import WorkerTabs from "./tabs/WorkerTabs";
@@ -38,6 +42,7 @@ type ServiceProps = {
3842
};
3943
clusterIngressIp: string;
4044
showDisableTls: boolean;
45+
existingServiceNames: string[];
4146
};
4247

4348
const ServiceContainer: React.FC<ServiceProps> = ({
@@ -52,6 +57,7 @@ const ServiceContainer: React.FC<ServiceProps> = ({
5257
internalNetworkingDetails,
5358
clusterIngressIp,
5459
showDisableTls,
60+
existingServiceNames,
5561
}) => {
5662
const renderTabs = (service: ClientService): JSX.Element => {
5763
return match(service)
@@ -186,13 +192,14 @@ const ServiceContainer: React.FC<ServiceProps> = ({
186192
</StyledSourceBox>
187193
)}
188194
</AnimatePresence>
189-
{status && (
190-
<ServiceStatusFooter
191-
serviceName={service.name.value}
192-
isJob={service.config.type === "job"}
193-
status={status}
194-
/>
195+
{!isClientJobService(service) && status && (
196+
<ServiceStatusFooter status={status} />
195197
)}
198+
{isClientJobService(service) &&
199+
// make sure that this service is in a created revision before showing the job footer - cannot view history / run jobs that are not deployed
200+
existingServiceNames.includes(service.name.value) && (
201+
<JobFooter jobName={service.name.value} />
202+
)}
196203
<Spacer y={0.5} />
197204
</>
198205
);

dashboard/src/main/home/app-dashboard/validate-apply/services-settings/ServiceList.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ const ServiceList: React.FC<ServiceListProps> = ({
238238
internalNetworkingDetails={internalNetworkingDetails}
239239
clusterIngressIp={clusterIngressIp}
240240
showDisableTls={loadBalancerType === "ALB"}
241+
existingServiceNames={existingServiceNames}
241242
/>
242243
) : null;
243244
})}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import React from "react";
2+
import _ from "lodash";
3+
import styled from "styled-components";
4+
5+
import Button from "components/porter/Button";
6+
import Container from "components/porter/Container";
7+
import Link from "components/porter/Link";
8+
import Spacer from "components/porter/Spacer";
9+
10+
import { useLatestRevision } from "../../../app-view/LatestRevisionContext";
11+
import TriggerJobButton from "../../jobs/TriggerJobButton";
12+
13+
type JobFooterProps = {
14+
jobName: string;
15+
};
16+
const ServiceStatusFooter: React.FC<JobFooterProps> = ({ jobName }) => {
17+
const { latestProto, projectId, clusterId, deploymentTarget, appName } =
18+
useLatestRevision();
19+
20+
return (
21+
<StyledStatusFooter>
22+
<Container row>
23+
<Link to={`/apps/${latestProto.name}/job-history?service=${jobName}`}>
24+
<Button
25+
onClick={() => {}}
26+
height="30px"
27+
width="87px"
28+
color="#ffffff11"
29+
withBorder
30+
>
31+
<I className="material-icons">open_in_new</I>
32+
History
33+
</Button>
34+
</Link>
35+
<Spacer inline x={1} />
36+
<TriggerJobButton
37+
projectId={projectId}
38+
clusterId={clusterId}
39+
appName={appName}
40+
jobName={jobName}
41+
deploymentTargetId={deploymentTarget.id}
42+
/>
43+
</Container>
44+
</StyledStatusFooter>
45+
);
46+
};
47+
48+
export default ServiceStatusFooter;
49+
50+
const I = styled.i`
51+
font-size: 14px;
52+
margin-right: 5px;
53+
`;
54+
55+
const StyledStatusFooter = styled.div`
56+
width: 100%;
57+
padding: 10px 15px;
58+
background: ${(props) => props.theme.fg2};
59+
border-bottom-left-radius: 5px;
60+
border-bottom-right-radius: 5px;
61+
border: 1px solid #494b4f;
62+
border-top: 0;
63+
overflow: hidden;
64+
display: flex;
65+
align-items: stretch;
66+
flex-direction: row;
67+
animation: fadeIn 0.5s;
68+
@keyframes fadeIn {
69+
from {
70+
opacity: 0;
71+
}
72+
to {
73+
opacity: 1;
74+
}
75+
}
76+
`;

dashboard/src/main/home/app-dashboard/validate-apply/services-settings/ServiceStatusFooter.tsx renamed to dashboard/src/main/home/app-dashboard/validate-apply/services-settings/footers/ServiceStatusFooter.tsx

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,70 +7,25 @@ import { match } from "ts-pattern";
77
import Button from "components/porter/Button";
88
import Container from "components/porter/Container";
99
import Link from "components/porter/Link";
10-
import Spacer from "components/porter/Spacer";
1110
import Tag from "components/porter/Tag";
1211
import Text from "components/porter/Text";
1312
import { type ClientServiceStatus } from "lib/hooks/useAppStatus";
1413
import { isClientServiceNotification } from "lib/porter-apps/notification";
1514

1615
import alert from "assets/alert-warning.svg";
1716

18-
import { useLatestRevision } from "../../app-view/LatestRevisionContext";
19-
import TriggerJobButton from "../jobs/TriggerJobButton";
17+
import { useLatestRevision } from "../../../app-view/LatestRevisionContext";
2018

2119
type ServiceStatusFooterProps = {
22-
serviceName: string;
2320
status: ClientServiceStatus[];
24-
isJob: boolean;
2521
};
2622
const ServiceStatusFooter: React.FC<ServiceStatusFooterProps> = ({
27-
serviceName,
2823
status,
29-
isJob,
3024
}) => {
3125
const [expanded, setExpanded] = useState<boolean>(false);
32-
const {
33-
latestProto,
34-
projectId,
35-
clusterId,
36-
deploymentTarget,
37-
appName,
38-
latestClientNotifications,
39-
tabUrlGenerator,
40-
} = useLatestRevision();
26+
const { latestClientNotifications, tabUrlGenerator } = useLatestRevision();
4127
const [height, setHeight] = useState<Height>(0);
4228

43-
if (isJob) {
44-
return (
45-
<StyledStatusFooter>
46-
<Container row>
47-
<Link
48-
to={`/apps/${latestProto.name}/job-history?service=${serviceName}`}
49-
>
50-
<Button
51-
onClick={() => {}}
52-
height="30px"
53-
width="87px"
54-
color="#ffffff11"
55-
withBorder
56-
>
57-
<I className="material-icons">open_in_new</I>
58-
History
59-
</Button>
60-
</Link>
61-
<Spacer inline x={1} />
62-
<TriggerJobButton
63-
projectId={projectId}
64-
clusterId={clusterId}
65-
appName={appName}
66-
jobName={serviceName}
67-
deploymentTargetId={deploymentTarget.id}
68-
/>
69-
</Container>
70-
</StyledStatusFooter>
71-
);
72-
}
73-
7429
return (
7530
<>
7631
{status.map((versionStatus, i) => {

0 commit comments

Comments
 (0)