Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores committed Jul 30, 2024
1 parent 112f4b7 commit fa5ca48
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/app/Shared/Services/api.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export const isKeyValue = (o: any): o is KeyValue => {
return typeof o === 'object' && _.isEqual(new Set(['key', 'value']), new Set(Object.getOwnPropertyNames(o)));
};

export const keyValueToString = (kv: KeyValue): string => {
return `${kv.key}=${kv.value}`;
};

export interface Metadata {
labels: KeyValue[];
}
Expand Down
14 changes: 6 additions & 8 deletions src/app/Topology/Shared/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import { JmxAuthDescription } from '@app/Shared/Components/JmxAuthDescription';
import { JmxSslDescription } from '@app/Shared/Components/JmxSslDescription';
import { TopologyFilters } from '@app/Shared/Redux/Filters/TopologyFilterSlice';
import { NodeType, EnvironmentNode, TargetNode } from '@app/Shared/Services/api.types';
import { NodeType, EnvironmentNode, TargetNode, keyValueToString } from '@app/Shared/Services/api.types';
import { DEFAULT_EMPTY_UNIVERSE, isTargetNode } from '@app/Shared/Services/api.utils';
import {
Button,
Expand Down Expand Up @@ -110,8 +110,7 @@ export const isGroupNodeFiltered = (
matched = matched && filter.Name.includes(groupNode.name);
}
if (filter.Label && filter.Label.length) {
matched =
matched && groupNode.labels.map((kv) => `${kv.key}=${kv.value}`).filter((v) => filter.Label.includes(v)).length > 0;
matched = matched && groupNode.labels.map(keyValueToString).some((v) => filter.Label.includes(v));
}
return matched;
};
Expand All @@ -131,16 +130,15 @@ export const isTargetNodeFiltered = ({ target }: TargetNode, filters?: TopologyF
matched = matched && target.jvmId !== undefined && filters.JvmId.includes(target.jvmId);
}
if (filters.Label && filters.Label.length) {
matched =
matched && target.labels.map((kv) => `${kv.key}=${kv.value}`).some((v) => filters.Label.includes(v));
matched = matched && target.labels.map(keyValueToString).some((v) => filters.Label.includes(v));
}
if (filters.Annotation && filters.Annotation.length) {
const annotations = target.annotations;
matched =
matched &&
[...annotations?.cryostat, ...annotations?.platform].filter(
(kv) => filters.Annotation.includes(`${kv.key}=${kv.value}`),
).length > 0;
[...annotations?.cryostat, ...annotations?.platform].some((kv) =>
filters.Annotation.includes(keyValueToString(kv)),
);
}
return matched;
};
4 changes: 2 additions & 2 deletions src/app/Topology/Toolbar/TopologyFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
topologyUpdateCategoryIntent,
topologyUpdateCategoryTypeIntent,
} from '@app/Shared/Redux/ReduxStore';
import { EnvironmentNode, TargetNode, isKeyValue } from '@app/Shared/Services/api.types';
import { EnvironmentNode, TargetNode, isKeyValue, keyValueToString } from '@app/Shared/Services/api.types';
import { flattenTree, getUniqueNodeTypes, isTargetNode } from '@app/Shared/Services/api.utils';
import { getDisplayFieldName } from '@app/utils/utils';
import {
Expand Down Expand Up @@ -355,7 +355,7 @@ export const fieldValueToStrings = (value: unknown): string[] => {
if (Array.isArray(value)) {
if (value.length > 0 && typeof value[0] === 'object') {
if (isKeyValue(value[0])) {
return value.map((o) => `${o.key}=${o.value}`);
return value.map(keyValueToString);
} else {
return value.map((o) => {
let str = '';
Expand Down

0 comments on commit fa5ca48

Please sign in to comment.