Skip to content

Commit

Permalink
handle object or KeyValue[] labels/annnotations
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores committed Feb 29, 2024
1 parent 49e15e5 commit 4b904ea
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/app/Topology/Entity/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,15 @@ import {
import { ActiveRecDetail, Nothing } from './ResourceDetails';
import { DescriptionConfig, TargetOwnedResourceType, TargetRelatedResourceType, ResourceTypes, PatchFn } from './types';

export const keyValueEntryTransformer = (kv: { key: string; value: string }[]): string[] =>
kv.map((k) => `${k.key}=${k.value}`);
export const keyValueEntryTransformer = (kv: { key: string; value: string }[]): string[] => {
if (Array.isArray(kv)) {
return kv.map((k) => `${k.key}=${k.value}`);
} else if (!!kv && typeof kv === 'object') {
return Object.entries(kv).map(([k, v]) => `${k}=${v}`);
} else {
throw new Error(`Unknown kv of type "${typeof kv}": ${JSON.stringify(kv)}`);
}
};

export const valuesEntryTransformer: (kv: string[] | object) => string[] = Object.values;

Expand Down

0 comments on commit 4b904ea

Please sign in to comment.