Feroze Mohideen 2 år sedan
förälder
incheckning
3f6097a278
2 ändrade filer med 17 tillägg och 16 borttagningar
  1. 8 7
      dashboard/src/lib/porter-apps/services.ts
  2. 9 9
      dashboard/src/lib/porter-apps/values.ts

+ 8 - 7
dashboard/src/lib/porter-apps/services.ts

@@ -66,6 +66,7 @@ export const serviceValidator = z.object({
   canDelete: z.boolean().default(true).optional(),
   name: serviceStringValidator,
   run: serviceStringValidator,
+  runOptional: serviceStringValidator.optional(),
   instances: serviceNumberValidator,
   port: serviceNumberValidator,
   cpuCores: serviceNumberValidator,
@@ -91,7 +92,7 @@ export type ClientService = z.infer<typeof serviceValidator>;
 // This is used as an intermediate step to convert a ClientService to a protobuf Service
 export type SerializedService = {
   name: string;
-  run: string;
+  runOptional?: string;
   instances: number;
   port: number;
   cpuCores: number;
@@ -143,7 +144,7 @@ export function defaultSerialized({
 }): SerializedService {
   const baseService = {
     name,
-    run: "",
+    runOptional: "",
     instances: 1,
     port: 3000,
     cpuCores: 0.1,
@@ -209,7 +210,7 @@ export function serializeService(service: ClientService): SerializedService {
     .with({ type: "web" }, (config) =>
       Object.freeze({
         name: service.name.value,
-        run: service.run.value,
+        runOptional: service.runOptional?.value,
         instances: service.instances.value,
         port: service.port.value,
         cpuCores: service.cpuCores.value,
@@ -231,7 +232,7 @@ export function serializeService(service: ClientService): SerializedService {
     .with({ type: "worker" }, (config) =>
       Object.freeze({
         name: service.name.value,
-        run: service.run.value,
+        runOptional: service.runOptional?.value,
         instances: service.instances.value,
         port: service.port.value,
         cpuCores: service.cpuCores.value,
@@ -248,7 +249,7 @@ export function serializeService(service: ClientService): SerializedService {
     .with({ type: "job" }, (config) =>
       Object.freeze({
         name: service.name.value,
-        run: service.run.value,
+        runOptional: service.runOptional?.value,
         instances: service.instances.value,
         port: service.port.value,
         cpuCores: service.cpuCores.value,
@@ -266,7 +267,7 @@ export function serializeService(service: ClientService): SerializedService {
     .with({ type: "predeploy" }, () =>
       Object.freeze({
         name: service.name.value,
-        run: service.run.value,
+        runOptional: service.runOptional?.value,
         instances: service.instances.value,
         port: service.port.value,
         cpuCores: service.cpuCores.value,
@@ -295,7 +296,7 @@ export function deserializeService({
     expanded,
     canDelete: !override,
     name: ServiceField.string(service.name, override?.name),
-    run: ServiceField.string(service.run, override?.run),
+    run: ServiceField.string(service.runOptional, override?.runOptional),
     instances: ServiceField.number(service.instances, override?.instances),
     port: ServiceField.number(service.port, override?.port),
     cpuCores: ServiceField.number(service.cpuCores, override?.cpuCores),

+ 9 - 9
dashboard/src/lib/porter-apps/values.ts

@@ -48,10 +48,10 @@ const getNumericValue = (
 
 // ServiceField is a helper to create a ServiceString, ServiceNumber, or ServiceBoolean
 export const ServiceField = {
-  string: (defaultValue: string, overrideValue?: string): ServiceString => {
+  string: (defaultValue?: string, overrideValue?: string): ServiceString => {
     return {
       readOnly: !!overrideValue,
-      value: overrideValue ?? defaultValue,
+      value: overrideValue ?? defaultValue ?? "",
     };
   },
   number: (
@@ -126,15 +126,15 @@ export function deserializeAutoscaling({
         : ServiceField.number(10, undefined),
       cpuThresholdPercent: autoscaling.cpuThresholdPercent
         ? ServiceField.number(
-            autoscaling.cpuThresholdPercent,
-            override?.cpuThresholdPercent
-          )
+          autoscaling.cpuThresholdPercent,
+          override?.cpuThresholdPercent
+        )
         : ServiceField.number(50, undefined),
       memoryThresholdPercent: autoscaling.memoryThresholdPercent
         ? ServiceField.number(
-            autoscaling.memoryThresholdPercent,
-            override?.memoryThresholdPercent
-          )
+          autoscaling.memoryThresholdPercent,
+          override?.memoryThresholdPercent
+        )
         : ServiceField.number(50, undefined),
     }
   );
@@ -175,7 +175,7 @@ export function deserializeHealthCheck({
       enabled: ServiceField.boolean(health.enabled, override?.enabled),
       httpPath: health.httpPath
         ? ServiceField.string(health.httpPath, override?.httpPath)
-        :  ServiceField.string("", undefined),
+        : ServiceField.string("", undefined),
     }
   );
 }