mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
* fix lint Signed-off-by: Roman <ixrock@gmail.com> * fixes & refactoring Signed-off-by: Roman <ixrock@gmail.com> * fix lint, micro-refactoring Signed-off-by: Roman <ixrock@gmail.com> * more refactoring, clean up, responding to comments Signed-off-by: Roman <ixrock@gmail.com> * fix: remove extra check for cluster.allowedApi from processing buffered watch-api events Signed-off-by: Roman <ixrock@gmail.com> * refactoring, detaching NamespaceStore from KubeObjectStore Signed-off-by: Roman <ixrock@gmail.com> * fix: wait for contextReady in NamespaceStore Signed-off-by: Roman <ixrock@gmail.com> * refactoring & fixes Signed-off-by: Roman <ixrock@gmail.com> * fix lint Signed-off-by: Roman <ixrock@gmail.com> * fixes: reloading context stores on NamespaceSelect-change Signed-off-by: Roman <ixrock@gmail.com> * optimize loading all resources when "all namespaces" selected -> single request per resource (when have rights) Signed-off-by: Roman <ixrock@gmail.com> * use native k8s api watches Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * retry watch when it makes sense Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * workaround for browser connection limits Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * cleanup Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * cleanup Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * use always random subdomain for getResponse Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * resubscribe stores on contextNamespace change Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * fix Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * modify watch event before calling callback Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> * Replace placeholder component in NamespaceSelectFilter Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com> Co-authored-by: Roman <ixrock@gmail.com> Co-authored-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
79 lines
2.2 KiB
TypeScript
79 lines
2.2 KiB
TypeScript
import "./namespace-select.scss";
|
|
|
|
import React from "react";
|
|
import { computed } from "mobx";
|
|
import { disposeOnUnmount, observer } from "mobx-react";
|
|
import { Select, SelectOption, SelectProps } from "../select";
|
|
import { cssNames } from "../../utils";
|
|
import { Icon } from "../icon";
|
|
import { namespaceStore } from "./namespace.store";
|
|
import { kubeWatchApi } from "../../api/kube-watch-api";
|
|
|
|
interface Props extends SelectProps {
|
|
showIcons?: boolean;
|
|
showClusterOption?: boolean; // show "Cluster" option on the top (default: false)
|
|
showAllNamespacesOption?: boolean; // show "All namespaces" option on the top (default: false)
|
|
customizeOptions?(options: SelectOption[]): SelectOption[];
|
|
}
|
|
|
|
const defaultProps: Partial<Props> = {
|
|
showIcons: true,
|
|
showClusterOption: false,
|
|
};
|
|
|
|
@observer
|
|
export class NamespaceSelect extends React.Component<Props> {
|
|
static defaultProps = defaultProps as object;
|
|
|
|
componentDidMount() {
|
|
disposeOnUnmount(this, [
|
|
kubeWatchApi.subscribeStores([namespaceStore], {
|
|
preload: true,
|
|
})
|
|
]);
|
|
}
|
|
|
|
@computed.struct get options(): SelectOption[] {
|
|
const { customizeOptions, showClusterOption, showAllNamespacesOption } = this.props;
|
|
let options: SelectOption[] = namespaceStore.items.map(ns => ({ value: ns.getName() }));
|
|
|
|
if (showAllNamespacesOption) {
|
|
options.unshift({ label: "All Namespaces", value: "" });
|
|
} else if (showClusterOption) {
|
|
options.unshift({ label: "Cluster", value: "" });
|
|
}
|
|
|
|
if (customizeOptions) {
|
|
options = customizeOptions(options);
|
|
}
|
|
|
|
return options;
|
|
}
|
|
|
|
formatOptionLabel = (option: SelectOption) => {
|
|
const { showIcons } = this.props;
|
|
const { value, label } = option;
|
|
|
|
return label || (
|
|
<>
|
|
{showIcons && <Icon small material="layers"/>}
|
|
{value}
|
|
</>
|
|
);
|
|
};
|
|
|
|
render() {
|
|
const { className, showIcons, customizeOptions, ...selectProps } = this.props;
|
|
|
|
return (
|
|
<Select
|
|
className={cssNames("NamespaceSelect", className)}
|
|
menuClass="NamespaceSelectMenu"
|
|
formatOptionLabel={this.formatOptionLabel}
|
|
options={this.options}
|
|
{...selectProps}
|
|
/>
|
|
);
|
|
}
|
|
}
|