Skip to content

Commit

Permalink
Set EmitUnpopulated to false; Use string for proto enums
Browse files Browse the repository at this point in the history
- #707
- #708

Signed-off-by: Sunghoon Kang <hoon@akuity.io>
  • Loading branch information
Sunghoon Kang committed Sep 12, 2023
1 parent e522c04 commit 6d008bb
Show file tree
Hide file tree
Showing 7 changed files with 401 additions and 525 deletions.
10 changes: 1 addition & 9 deletions api/v1alpha1/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,8 @@ message GitSubscription {
string branch = 2;
}

enum HealthState {
// buf:lint:ignore ENUM_ZERO_VALUE_SUFFIX
HEALTH_STATE_UNKNOWN = 0;
HEALTH_STATE_HEALTHY = 1;
HEALTH_STATE_UNHEALTHY = 2;
HEALTH_STATE_PROGRESSING = 3;
}

message Health {
HealthState status = 1;
string status = 1;
repeated string issues = 2;
}

Expand Down
2 changes: 1 addition & 1 deletion internal/api/option/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func newJSONCodec(name string) connect.Codec {
name: name,
m: &protojson.MarshalOptions{
UseProtoNames: true,
EmitUnpopulated: true,
EmitUnpopulated: false,
},
um: &protojson.UnmarshalOptions{
DiscardUnknown: true,
Expand Down
24 changes: 2 additions & 22 deletions internal/api/types/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,8 @@ func FromHealthProto(h *v1alpha1.Health) *kargoapi.Health {
return nil
}

status := kargoapi.HealthStateUnknown
switch h.GetStatus() {
case v1alpha1.HealthState_HEALTH_STATE_UNKNOWN:
status = kargoapi.HealthStateUnknown
case v1alpha1.HealthState_HEALTH_STATE_HEALTHY:
status = kargoapi.HealthStateHealthy
case v1alpha1.HealthState_HEALTH_STATE_UNHEALTHY:
status = kargoapi.HealthStateUnhealthy
}
return &kargoapi.Health{
Status: status,
Status: kargoapi.HealthState(h.GetStatus()),
Issues: h.GetIssues(),
}
}
Expand Down Expand Up @@ -783,19 +774,8 @@ func ToChartProto(c kargoapi.Chart) *v1alpha1.Chart {
}

func ToHealthProto(h kargoapi.Health) *v1alpha1.Health {
status := v1alpha1.HealthState_HEALTH_STATE_UNKNOWN
switch h.Status {
case kargoapi.HealthStateHealthy:
status = v1alpha1.HealthState_HEALTH_STATE_HEALTHY
case kargoapi.HealthStateUnhealthy:
status = v1alpha1.HealthState_HEALTH_STATE_UNHEALTHY
case kargoapi.HealthStateProgressing:
status = v1alpha1.HealthState_HEALTH_STATE_PROGRESSING
case kargoapi.HealthStateUnknown:
status = v1alpha1.HealthState_HEALTH_STATE_UNKNOWN
}
return &v1alpha1.Health{
Status: status,
Status: string(h.Status),
Issues: h.Issues,
}
}
Expand Down
786 changes: 359 additions & 427 deletions pkg/api/v1alpha1/types.pb.go

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions ui/src/features/common/health-status/health-status-icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { Tooltip } from 'antd';
import { CSSProperties } from 'react';

import { Health, HealthState } from '@ui/gen/v1alpha1/types_pb';
import { Health } from '@ui/gen/v1alpha1/types_pb';

import { healthStateToString } from './utils';
import { HealthStatus, healthStatusToEnum } from './utils';

export const HealthStatusIcon = (props: {
health?: Health;
Expand All @@ -23,12 +23,12 @@ export const HealthStatusIcon = (props: {
const reason = health?.issues?.join('; ') ?? '';

return (
<Tooltip title={healthStateToString(health?.status) + (reason !== '' ? `: ${reason}` : '')}>
<Tooltip title={health?.status ?? '' + (reason !== '' ? `: ${reason}` : '')}>
<FontAwesomeIcon
icon={iconForHealthStatus(health?.status)}
spin={health?.status === HealthState.PROGRESSING}
icon={iconForHealthStatus(health)}
spin={healthStatusToEnum(health?.status) === HealthStatus.PROGRESSING}
style={{
color: !hideColor ? colorForHealthStatus(health?.status) : undefined,
color: !hideColor ? colorForHealthStatus(health) : undefined,
fontSize: '18px',
...props.style
}}
Expand All @@ -37,30 +37,30 @@ export const HealthStatusIcon = (props: {
);
};

const iconForHealthStatus = (status?: HealthState): IconDefinition => {
switch (status) {
case HealthState.HEALTHY:
const iconForHealthStatus = (health?: Health): IconDefinition => {
switch (healthStatusToEnum(health?.status)) {
case HealthStatus.HEALTHY:
return faHeart;
case HealthState.UNHEALTHY:
case HealthStatus.UNHEALTHY:
return faHeartBroken;
case HealthState.PROGRESSING:
case HealthStatus.PROGRESSING:
return faCircleNotch;
case HealthState.UNKNOWN:
case HealthStatus.UNKNOWN:
return faQuestionCircle;
default:
return faCircle;
}
};

const colorForHealthStatus = (status?: HealthState): string => {
switch (status) {
case HealthState.HEALTHY:
const colorForHealthStatus = (health?: Health): string => {
switch (healthStatusToEnum(health?.status)) {
case HealthStatus.HEALTHY:
return '#52c41a';
case HealthState.UNHEALTHY:
case HealthStatus.UNHEALTHY:
return '#f5222d';
case HealthState.PROGRESSING:
case HealthStatus.PROGRESSING:
return '#0dabea';
case HealthState.UNKNOWN:
case HealthStatus.UNKNOWN:
return '#faad14';
default:
return '#ccc';
Expand Down
28 changes: 17 additions & 11 deletions ui/src/features/common/health-status/utils.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { HealthState } from '@ui/gen/v1alpha1/types_pb';
export enum HealthStatus {
HEALTHY = 'Healthy',
PROGRESSING = 'Progressing',
UNHEALTHY = 'Unhealthy',
UNKNOWN = 'Unknown',
UNDEFINED = ''
}

export const healthStateToString = (status?: HealthState): string => {
export const healthStatusToEnum = (status?: string): HealthStatus => {
switch (status) {
case HealthState.HEALTHY:
return 'Healthy';
case HealthState.PROGRESSING:
return 'Progressing';
case HealthState.UNHEALTHY:
return 'Unhealthy';
case HealthState.UNKNOWN:
return 'Unknown';
case HealthStatus.HEALTHY:
return HealthStatus.HEALTHY;
case HealthStatus.PROGRESSING:
return HealthStatus.PROGRESSING;
case HealthStatus.UNHEALTHY:
return HealthStatus.UNHEALTHY;
case HealthStatus.UNKNOWN:
return HealthStatus.UNKNOWN;
default:
return '';
return HealthStatus.UNDEFINED;
}
};
40 changes: 3 additions & 37 deletions ui/src/gen/v1alpha1/types_pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,6 @@ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialM
import { Message, proto3, Timestamp } from "@bufbuild/protobuf";
import { ListMeta, ObjectMeta } from "../metav1/types_pb.js";

/**
* @generated from enum git.luolix.top.akuity.kargo.pkg.api.v1alpha1.HealthState
*/
export enum HealthState {
/**
* buf:lint:ignore ENUM_ZERO_VALUE_SUFFIX
*
* @generated from enum value: HEALTH_STATE_UNKNOWN = 0;
*/
UNKNOWN = 0,

/**
* @generated from enum value: HEALTH_STATE_HEALTHY = 1;
*/
HEALTHY = 1,

/**
* @generated from enum value: HEALTH_STATE_UNHEALTHY = 2;
*/
UNHEALTHY = 2,

/**
* @generated from enum value: HEALTH_STATE_PROGRESSING = 3;
*/
PROGRESSING = 3,
}
// Retrieve enum metadata with: proto3.getEnumType(HealthState)
proto3.util.setEnumType(HealthState, "git.luolix.top.akuity.kargo.pkg.api.v1alpha1.HealthState", [
{ no: 0, name: "HEALTH_STATE_UNKNOWN" },
{ no: 1, name: "HEALTH_STATE_HEALTHY" },
{ no: 2, name: "HEALTH_STATE_UNHEALTHY" },
{ no: 3, name: "HEALTH_STATE_PROGRESSING" },
]);

/**
* @generated from message git.luolix.top.akuity.kargo.pkg.api.v1alpha1.ArgoCDAppUpdate
*/
Expand Down Expand Up @@ -573,9 +539,9 @@ export class GitSubscription extends Message<GitSubscription> {
*/
export class Health extends Message<Health> {
/**
* @generated from field: git.luolix.top.akuity.kargo.pkg.api.v1alpha1.HealthState status = 1;
* @generated from field: string status = 1;
*/
status = HealthState.UNKNOWN;
status = "";

/**
* @generated from field: repeated string issues = 2;
Expand All @@ -590,7 +556,7 @@ export class Health extends Message<Health> {
static readonly runtime: typeof proto3 = proto3;
static readonly typeName = "git.luolix.top.akuity.kargo.pkg.api.v1alpha1.Health";
static readonly fields: FieldList = proto3.util.newFieldList(() => [
{ no: 1, name: "status", kind: "enum", T: proto3.getEnumType(HealthState) },
{ no: 1, name: "status", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 2, name: "issues", kind: "scalar", T: 9 /* ScalarType.STRING */, repeated: true },
]);

Expand Down

0 comments on commit 6d008bb

Please sign in to comment.