import "./crd-list.scss"; import React from "react"; import { Trans } from "@lingui/macro"; import { computed } from "mobx"; import { observer } from "mobx-react"; import { Link } from "react-router-dom"; import { stopPropagation } from "../../utils"; import { KubeObjectListLayout } from "../kube-object"; import { crdStore } from "./crd.store"; import { apiManager } from "../../api/api-manager"; import { crdApi, CustomResourceDefinition } from "../../api/endpoints/crd.api"; import { KubeObjectMenu, KubeObjectMenuProps } from "../kube-object/kube-object-menu"; import { Select, SelectOption } from "../select"; import { navigation, setQueryParams } from "../../navigation"; import { Icon } from "../icon"; enum sortBy { kind = "kind", group = "group", version = "version", scope = "scope", age = "age", } @observer export class CrdList extends React.Component { @computed get groups(): string[] { return navigation.searchParams.getAsArray("groups"); } onGroupChange(group: string): void { const groups = [...this.groups]; const index = groups.findIndex(item => item == group); if (index !== -1) { groups.splice(index, 1); } else { groups.push(group); } setQueryParams({ groups }); } render(): JSX.Element { const selectedGroups = this.groups; const sortingCallbacks = { [sortBy.kind]: (crd: CustomResourceDefinition): string => crd.getResourceKind(), [sortBy.group]: (crd: CustomResourceDefinition): string => crd.getGroup(), [sortBy.version]: (crd: CustomResourceDefinition): string => crd.getVersion(), [sortBy.scope]: (crd: CustomResourceDefinition): string => crd.getScope(), }; return ( { return selectedGroups.length ? items.filter(item => selectedGroups.includes(item.getGroup())) : items; } ]} renderHeaderTitle={Custom Resources} customizeHeader={(): (JSX.Element | {filters: JSX.Element}) => { let placeholder = All groups; if (selectedGroups.length == 1) { placeholder = <>Group: {selectedGroups[0]}; } if (selectedGroups.length >= 2) { placeholder = <>Groups: {selectedGroups.join(", ")}; } return { // fixme: move to global filters filters: (