/** * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ import React from "react"; import { disposeOnUnmount, observer } from "mobx-react"; import { onMultiSelectFor, Select } from "../select/select"; import { Icon } from "../icon/icon"; import { Button } from "../button/button"; import { SubTitle } from "../layout/sub-title"; import type { Cluster } from "../../../common/cluster/cluster"; import { observable, reaction, makeObservable } from "mobx"; import { ClusterMetricsResourceType } from "../../../common/cluster-types"; export interface ClusterMetricsSettingProps { cluster: Cluster; } @observer export class ClusterMetricsSetting extends React.Component { @observable hiddenMetrics = observable.set(); constructor(props: ClusterMetricsSettingProps) { super(props); makeObservable(this); } componentDidMount() { this.hiddenMetrics = observable.set(this.props.cluster.preferences.hiddenMetrics ?? []); disposeOnUnmount(this, [ reaction(() => this.props.cluster.preferences.hiddenMetrics, () => { this.hiddenMetrics = observable.set(this.props.cluster.preferences.hiddenMetrics ?? []); }), ]); } save = () => { this.props.cluster.preferences.hiddenMetrics = Array.from(this.hiddenMetrics); }; onChangeButton = () => { this.hiddenMetrics.replace(Object.keys(ClusterMetricsResourceType)); this.save(); }; reset = () => { this.hiddenMetrics.clear(); this.save(); }; renderMetricsSelect() { const metricResourceTypeOptions = Object.values(ClusterMetricsResourceType) .map(type => ({ value: type, label: type, isSelected: this.hiddenMetrics.has(type), })); return ( <>