Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import dagre from "dagre";
import { FC, useState } from "react";
import { KubernetesResourceState } from "~/modules/applications-live-state";
import { theme } from "~/theme";
import { uniqueArray } from "~/utils/unique-array";
import { sortedSet } from "~/utils/sorted-set";
import { KubernetesResource } from "./kubernetes-resource";
import { KubernetesResourceDetail } from "./kubernetes-resource-detail";
import { ResourceFilterPopover } from "./resource-filter-popover";
Expand Down Expand Up @@ -95,7 +95,7 @@ export const KubernetesStateView: FC<KubernetesStateViewProps> = ({
setSelectedResource,
] = useState<KubernetesResourceState.AsObject | null>(null);

const kinds: string[] = uniqueArray(resources.map((r) => r.kind));
const kinds: string[] = sortedSet(resources.map((r) => r.kind));
const [filterState, setFilterState] = useState<Record<string, boolean>>(
kinds.reduce<Record<string, boolean>>((prev, current) => {
prev[current] = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Autocomplete from "@material-ui/lab/Autocomplete";
import { FC } from "react";
import { useAppSelector } from "~/hooks/redux";
import { selectAll as selectAllApplications } from "~/modules/applications";
import { uniqueArray } from "~/utils/unique-array";
import { sortedSet } from "~/utils/sorted-set";

interface Props {
value: string | null;
Expand All @@ -13,7 +13,7 @@ interface Props {
export const ApplicationAutocomplete: FC<Props> = ({ value, onChange }) => {
const applications = useAppSelector<string[]>(
(state) =>
uniqueArray(
sortedSet(
selectAllApplications(state.applications).map((app) => app.name)
),
(left, right) => JSON.stringify(left) === JSON.stringify(right)
Expand Down
7 changes: 7 additions & 0 deletions web/src/utils/sorted-set.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { sortedSet } from "./sorted-set";

test("uniqueArray", () => {
expect(sortedSet([])).toEqual([]);
expect(sortedSet([1, 2, 3])).toEqual([1, 2, 3]);
expect(sortedSet([1, 2, 2, 3])).toEqual([1, 2, 3]);
});
2 changes: 2 additions & 0 deletions web/src/utils/sorted-set.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const sortedSet = <T>(arr: Array<T>): Array<T> =>
[...new Set(arr)].sort();
7 changes: 0 additions & 7 deletions web/src/utils/unique-array.test.ts

This file was deleted.

1 change: 0 additions & 1 deletion web/src/utils/unique-array.ts

This file was deleted.