Skip to content

Commit

Permalink
misc refactors (#3801)
Browse files Browse the repository at this point in the history
  • Loading branch information
Feroze Mohideen authored Oct 12, 2023
1 parent 4029f42 commit 96d52d9
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 81 deletions.
129 changes: 51 additions & 78 deletions dashboard/src/lib/porter-apps/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,84 +218,57 @@ export function defaultSerialized({
// A SerializedService holds just the values of a ClientService
// These values can be used to create a protobuf Service
export function serializeService(service: ClientService): SerializedService {
return match(service.config)
.with({ type: "web" }, (config) =>
Object.freeze({
name: service.name.value,
run: service.run.value,
instances: service.instances.value,
port: service.port.value,
cpuCores: service.cpuCores.value,
ramMegabytes: service.ramMegabytes.value,
smartOptimization: service.smartOptimization?.value,
config: {
type: "web" as const,
autoscaling: serializeAutoscaling({
autoscaling: config.autoscaling,
}),
healthCheck: serializeHealth({ health: config.healthCheck }),
domains: config.domains.map((domain) => ({
name: domain.name.value,
})),
ingressAnnotations: Object.fromEntries(
config.ingressAnnotations
.filter((a) => a.key.length > 0 && a.value.length > 0)
.map((annotation) => [annotation.key, annotation.value])
),
private: config.private?.value,
},
})
)
.with({ type: "worker" }, (config) =>
Object.freeze({
name: service.name.value,
run: service.run.value,
instances: service.instances.value,
port: service.port.value,
cpuCores: service.cpuCores.value,
ramMegabytes: service.ramMegabytes.value,
smartOptimization: service.smartOptimization?.value,
config: {
type: "worker" as const,
autoscaling: serializeAutoscaling({
autoscaling: config.autoscaling,
}),
},
})
)
.with({ type: "job" }, (config) =>
Object.freeze({
name: service.name.value,
run: service.run.value,
instances: service.instances.value,
port: service.port.value,
cpuCores: service.cpuCores.value,
ramMegabytes: service.ramMegabytes.value,
smartOptimization: service.smartOptimization?.value,
config: {
type: "job" as const,
allowConcurrent: config.allowConcurrent?.value,
cron: config.cron.value,
suspendCron: config.suspendCron?.value,
timeoutSeconds: config.timeoutSeconds.value,
},
})
)
.with({ type: "predeploy" }, () =>
Object.freeze({
name: service.name.value,
run: service.run.value,
instances: service.instances.value,
port: service.port.value,
cpuCores: service.cpuCores.value,
smartOptimization: service.smartOptimization?.value,
ramMegabytes: service.ramMegabytes.value,
config: {
type: "predeploy" as const,
},
})
)
.exhaustive();
return Object.freeze({
name: service.name.value,
run: service.run.value,
instances: service.instances.value,
port: service.port.value,
cpuCores: service.cpuCores.value,
ramMegabytes: Math.round(service.ramMegabytes.value), // RAM must be an integer
smartOptimization: service.smartOptimization?.value,
config: match(service.config)
.with({ type: "web" }, (config) =>
Object.freeze({
type: "web" as const,
autoscaling: serializeAutoscaling({
autoscaling: config.autoscaling,
}),
healthCheck: serializeHealth({ health: config.healthCheck }),
domains: config.domains.map((domain) => ({
name: domain.name.value,
})),
ingressAnnotations: Object.fromEntries(
config.ingressAnnotations
.filter((a) => a.key.length > 0 && a.value.length > 0)
.map((annotation) => [annotation.key, annotation.value])
),
private: config.private?.value,
})
)
.with({ type: "worker" }, (config) =>
Object.freeze({
type: "worker" as const,
autoscaling: serializeAutoscaling({
autoscaling: config.autoscaling,
}),
})
)
.with({ type: "job" }, (config) =>
Object.freeze({
type: "job" as const,
allowConcurrent: config.allowConcurrent?.value,
cron: config.cron.value,
suspendCron: config.suspendCron?.value,
timeoutSeconds: config.timeoutSeconds.value,
})
)
.with({ type: "predeploy" }, () =>
Object.freeze({
type: "predeploy" as const,
})
)
.exhaustive(),
});
}

// deserializeService converts a SerializedService to a ClientService
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {useCallback, useContext, useEffect, useMemo, useState} from "react";
import { FieldErrors, FormProvider, useForm } from "react-hook-form";
import { FormProvider, useForm } from "react-hook-form";
import {
PorterAppFormData,
SourceOptions,
Expand Down Expand Up @@ -39,9 +39,8 @@ import { Error as ErrorComponent } from "components/porter/Error";
import _ from "lodash";
import axios from "axios";
import HelmEditorTab from "./tabs/HelmEditorTab";
import HelmLatestValues from "../validate-apply/helm/HelmLatestValues";
import HelmLatestValuesTab from "./tabs/HelmLatestValuesTab";
import {Context} from "../../../../shared/Context";
import { Context } from "shared/Context";

// commented out tabs are not yet implemented
// will be included as support is available based on data from app revisions rather than helm releases
Expand Down

0 comments on commit 96d52d9

Please sign in to comment.