mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add helper for <Select>.isMulti for storing in a Set<Value>
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
cb0540f83c
commit
a27c092c40
@ -18,7 +18,7 @@ import { Icon } from "../../icon";
|
|||||||
import { showDetails } from "../../kube-detail-params";
|
import { showDetails } from "../../kube-detail-params";
|
||||||
import { SubTitle } from "../../layout/sub-title";
|
import { SubTitle } from "../../layout/sub-title";
|
||||||
import { Notifications } from "../../notifications";
|
import { Notifications } from "../../notifications";
|
||||||
import { Select } from "../../select";
|
import { onMultiSelectFor, Select } from "../../select";
|
||||||
import { Wizard, WizardStep } from "../../wizard";
|
import { Wizard, WizardStep } from "../../wizard";
|
||||||
import { clusterRoleBindingStore } from "./legacy-store";
|
import { clusterRoleBindingStore } from "./legacy-store";
|
||||||
import { clusterRoleStore } from "../+cluster-roles/legacy-store";
|
import { clusterRoleStore } from "../+cluster-roles/legacy-store";
|
||||||
@ -244,25 +244,7 @@ export class ClusterRoleBindingDialog extends React.Component<ClusterRoleBinding
|
|||||||
{` ${option.label}`}
|
{` ${option.label}`}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
onChange={(selected, meta) => {
|
onChange={onMultiSelectFor(this.selectedAccounts)}
|
||||||
switch (meta.action) {
|
|
||||||
case "clear":
|
|
||||||
this.selectedAccounts.clear();
|
|
||||||
break;
|
|
||||||
case "deselect-option":
|
|
||||||
case "remove-value":
|
|
||||||
case "pop-value":
|
|
||||||
if (meta.option) {
|
|
||||||
this.selectedAccounts.delete(meta.option.value);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "select-option":
|
|
||||||
if (meta.option) {
|
|
||||||
this.selectedAccounts.add(meta.option.value);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
maxMenuHeight={200}
|
maxMenuHeight={200}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@ -22,7 +22,7 @@ import { showDetails } from "../../kube-detail-params";
|
|||||||
import { SubTitle } from "../../layout/sub-title";
|
import { SubTitle } from "../../layout/sub-title";
|
||||||
import { Notifications } from "../../notifications";
|
import { Notifications } from "../../notifications";
|
||||||
import type { SelectOption } from "../../select";
|
import type { SelectOption } from "../../select";
|
||||||
import { Select } from "../../select";
|
import { onMultiSelectFor, Select } from "../../select";
|
||||||
import { Wizard, WizardStep } from "../../wizard";
|
import { Wizard, WizardStep } from "../../wizard";
|
||||||
import { roleBindingStore } from "./legacy-store";
|
import { roleBindingStore } from "./legacy-store";
|
||||||
import { clusterRoleStore } from "../+cluster-roles/legacy-store";
|
import { clusterRoleStore } from "../+cluster-roles/legacy-store";
|
||||||
@ -252,25 +252,7 @@ export class RoleBindingDialog extends React.Component<RoleBindingDialogProps> {
|
|||||||
{` ${option.label}`}
|
{` ${option.label}`}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
onChange={(selected, meta) => {
|
onChange={onMultiSelectFor(this.selectedAccounts)}
|
||||||
switch (meta.action) {
|
|
||||||
case "clear":
|
|
||||||
this.selectedAccounts.clear();
|
|
||||||
break;
|
|
||||||
case "deselect-option":
|
|
||||||
case "remove-value":
|
|
||||||
case "pop-value":
|
|
||||||
if (meta.option) {
|
|
||||||
this.selectedAccounts.delete(meta.option.value);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "select-option":
|
|
||||||
if (meta.option) {
|
|
||||||
this.selectedAccounts.add(meta.option.value);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
maxMenuHeight={200}
|
maxMenuHeight={200}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { disposeOnUnmount, observer } from "mobx-react";
|
import { disposeOnUnmount, observer } from "mobx-react";
|
||||||
import { Select } from "../../select/select";
|
import { onMultiSelectFor, Select } from "../../select/select";
|
||||||
import { Icon } from "../../icon/icon";
|
import { Icon } from "../../icon/icon";
|
||||||
import { Button } from "../../button/button";
|
import { Button } from "../../button/button";
|
||||||
import { SubTitle } from "../../layout/sub-title";
|
import { SubTitle } from "../../layout/sub-title";
|
||||||
@ -70,10 +70,7 @@ export class ClusterMetricsSetting extends React.Component<ClusterMetricsSetting
|
|||||||
closeMenuOnSelect={false}
|
closeMenuOnSelect={false}
|
||||||
controlShouldRenderValue={false}
|
controlShouldRenderValue={false}
|
||||||
options={metricResourceTypeOptions}
|
options={metricResourceTypeOptions}
|
||||||
onChange={(options) => {
|
onChange={onMultiSelectFor(this.hiddenMetrics)}
|
||||||
this.hiddenMetrics.replace(options.map(opt => opt.value));
|
|
||||||
this.save();
|
|
||||||
}}
|
|
||||||
formatOptionLabel={(option) => (
|
formatOptionLabel={(option) => (
|
||||||
<div className="flex gaps align-center">
|
<div className="flex gaps align-center">
|
||||||
<span>{option.value}</span>
|
<span>{option.value}</span>
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
import "./select.scss";
|
import "./select.scss";
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
import type { ObservableSet } from "mobx";
|
||||||
import { action, computed, makeObservable } from "mobx";
|
import { action, computed, makeObservable } from "mobx";
|
||||||
import { observer } from "mobx-react";
|
import { observer } from "mobx-react";
|
||||||
import ReactSelect, { components, createFilter } from "react-select";
|
import ReactSelect, { components, createFilter } from "react-select";
|
||||||
@ -81,6 +82,28 @@ interface Dependencies {
|
|||||||
themeStore: ThemeStore;
|
themeStore: ThemeStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function onMultiSelectFor<Value, Option extends SelectOption<Value>, Group extends GroupBase<Option> = GroupBase<Option>>(collection: Set<Value> | ObservableSet<Value>): SelectProps<Value, Option, true, Group>["onChange"] {
|
||||||
|
return action((newValue, meta) => {
|
||||||
|
switch (meta.action) {
|
||||||
|
case "clear":
|
||||||
|
collection.clear();
|
||||||
|
break;
|
||||||
|
case "deselect-option":
|
||||||
|
case "remove-value":
|
||||||
|
case "pop-value":
|
||||||
|
if (meta.option) {
|
||||||
|
collection.delete(meta.option.value);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "select-option":
|
||||||
|
if (meta.option) {
|
||||||
|
collection.add(meta.option.value);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
class NonInjectedSelect<
|
class NonInjectedSelect<
|
||||||
Value,
|
Value,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user