mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Remove usages of legacy global clusterRoleBindingStore
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
d122e68dc2
commit
4a60a91ffd
@ -4,7 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { ClusterRoleBindingDialog } from "../dialog";
|
import { ClusterRoleBindingDialog } from "../dialog/view";
|
||||||
import { ClusterRole } from "../../../../../common/k8s-api/endpoints";
|
import { ClusterRole } from "../../../../../common/k8s-api/endpoints";
|
||||||
import userEvent from "@testing-library/user-event";
|
import userEvent from "@testing-library/user-event";
|
||||||
import { getDiForUnitTesting } from "../../../../getDiForUnitTesting";
|
import { getDiForUnitTesting } from "../../../../getDiForUnitTesting";
|
||||||
|
|||||||
@ -15,18 +15,22 @@ import { AddRemoveButtons } from "../../add-remove-buttons";
|
|||||||
import { DrawerTitle } from "../../drawer";
|
import { DrawerTitle } from "../../drawer";
|
||||||
import type { KubeObjectDetailsProps } from "../../kube-object-details";
|
import type { KubeObjectDetailsProps } from "../../kube-object-details";
|
||||||
import { Table, TableCell, TableHead, TableRow } from "../../table";
|
import { Table, TableCell, TableHead, TableRow } from "../../table";
|
||||||
import { ClusterRoleBindingDialog } from "./dialog";
|
|
||||||
import { clusterRoleBindingStore } from "./legacy-store";
|
|
||||||
import { hashSubject } from "../hashers";
|
import { hashSubject } from "../hashers";
|
||||||
import type { OpenConfirmDialog } from "../../confirm-dialog/open.injectable";
|
import type { OpenConfirmDialog } from "../../confirm-dialog/open.injectable";
|
||||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||||
import openConfirmDialogInjectable from "../../confirm-dialog/open.injectable";
|
import openConfirmDialogInjectable from "../../confirm-dialog/open.injectable";
|
||||||
|
import type { ClusterRoleBindingStore } from "./store";
|
||||||
|
import type { OpenClusterRoleBindingDialog } from "./dialog/open.injectable";
|
||||||
|
import openClusterRoleBindingDialogInjectable from "./dialog/open.injectable";
|
||||||
|
import clusterRoleBindingStoreInjectable from "./store.injectable";
|
||||||
|
|
||||||
export interface ClusterRoleBindingDetailsProps extends KubeObjectDetailsProps<ClusterRoleBinding> {
|
export interface ClusterRoleBindingDetailsProps extends KubeObjectDetailsProps<ClusterRoleBinding> {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Dependencies {
|
interface Dependencies {
|
||||||
openConfirmDialog: OpenConfirmDialog;
|
openConfirmDialog: OpenConfirmDialog;
|
||||||
|
openClusterRoleBindingDialog: OpenClusterRoleBindingDialog;
|
||||||
|
clusterRoleBindingStore: ClusterRoleBindingStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
@ -47,7 +51,7 @@ class NonInjectedClusterRoleBindingDetails extends React.Component<ClusterRoleBi
|
|||||||
}
|
}
|
||||||
|
|
||||||
removeSelectedSubjects() {
|
removeSelectedSubjects() {
|
||||||
const { object: clusterRoleBinding, openConfirmDialog } = this.props;
|
const { object: clusterRoleBinding, openConfirmDialog, clusterRoleBindingStore } = this.props;
|
||||||
const { selectedSubjects } = this;
|
const { selectedSubjects } = this;
|
||||||
|
|
||||||
openConfirmDialog({
|
openConfirmDialog({
|
||||||
@ -65,7 +69,7 @@ class NonInjectedClusterRoleBindingDetails extends React.Component<ClusterRoleBi
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { selectedSubjects } = this;
|
const { selectedSubjects } = this;
|
||||||
const { object: clusterRoleBinding } = this.props;
|
const { object: clusterRoleBinding, openClusterRoleBindingDialog } = this.props;
|
||||||
|
|
||||||
if (!clusterRoleBinding) {
|
if (!clusterRoleBinding) {
|
||||||
return null;
|
return null;
|
||||||
@ -121,7 +125,7 @@ class NonInjectedClusterRoleBindingDetails extends React.Component<ClusterRoleBi
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
<AddRemoveButtons
|
<AddRemoveButtons
|
||||||
onAdd={() => ClusterRoleBindingDialog.open(clusterRoleBinding)}
|
onAdd={() => openClusterRoleBindingDialog(clusterRoleBinding)}
|
||||||
onRemove={selectedSubjects.size ? this.removeSelectedSubjects : undefined}
|
onRemove={selectedSubjects.size ? this.removeSelectedSubjects : undefined}
|
||||||
addTooltip={`Add bindings to ${roleRef.name}`}
|
addTooltip={`Add bindings to ${roleRef.name}`}
|
||||||
removeTooltip={`Remove selected bindings from ${roleRef.name}`}
|
removeTooltip={`Remove selected bindings from ${roleRef.name}`}
|
||||||
@ -135,5 +139,7 @@ export const ClusterRoleBindingDetails = withInjectables<Dependencies, ClusterRo
|
|||||||
getProps: (di, props) => ({
|
getProps: (di, props) => ({
|
||||||
...props,
|
...props,
|
||||||
openConfirmDialog: di.inject(openConfirmDialogInjectable),
|
openConfirmDialog: di.inject(openConfirmDialogInjectable),
|
||||||
|
openClusterRoleBindingDialog: di.inject(openClusterRoleBindingDialogInjectable),
|
||||||
|
clusterRoleBindingStore: di.inject(clusterRoleBindingStoreInjectable),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
@ -0,0 +1,27 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
|
import { action } from "mobx";
|
||||||
|
import editClusterRoleBindingNameStateInjectable from "./edit-name-state.injectable";
|
||||||
|
import clusterRoleBindingDialogStateInjectable from "./state.injectable";
|
||||||
|
|
||||||
|
export type CloseClusterRoleBindingDialog = () => void;
|
||||||
|
|
||||||
|
const closeClusterRoleBindingDialogInjectable = getInjectable({
|
||||||
|
id: "close-cluster-role-binding-dialog",
|
||||||
|
instantiate: (di): CloseClusterRoleBindingDialog => {
|
||||||
|
const state = di.inject(clusterRoleBindingDialogStateInjectable);
|
||||||
|
const editNameState = di.inject(editClusterRoleBindingNameStateInjectable);
|
||||||
|
|
||||||
|
return action(() => {
|
||||||
|
state.set({
|
||||||
|
isOpen: false,
|
||||||
|
});
|
||||||
|
editNameState.set("");
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default closeClusterRoleBindingDialogInjectable;
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
|
import { observable } from "mobx";
|
||||||
|
|
||||||
|
const editClusterRoleBindingNameStateInjectable = getInjectable({
|
||||||
|
id: "edit-cluster-role-binding-name-state",
|
||||||
|
instantiate: () => observable.box(""),
|
||||||
|
});
|
||||||
|
|
||||||
|
export default editClusterRoleBindingNameStateInjectable;
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
|
import { action } from "mobx";
|
||||||
|
import type { ClusterRoleBinding } from "../../../../../common/k8s-api/endpoints";
|
||||||
|
import editClusterRoleBindingNameStateInjectable from "./edit-name-state.injectable";
|
||||||
|
import clusterRoleBindingDialogStateInjectable from "./state.injectable";
|
||||||
|
|
||||||
|
export type OpenClusterRoleBindingDialog = (clusterRoleBinding?: ClusterRoleBinding) => void;
|
||||||
|
|
||||||
|
const openClusterRoleBindingDialogInjectable = getInjectable({
|
||||||
|
id: "open-cluster-role-binding-dialog",
|
||||||
|
instantiate: (di): OpenClusterRoleBindingDialog => {
|
||||||
|
const state = di.inject(clusterRoleBindingDialogStateInjectable);
|
||||||
|
const editNameState = di.inject(editClusterRoleBindingNameStateInjectable);
|
||||||
|
|
||||||
|
return action((clusterRoleBinding) => {
|
||||||
|
state.set({
|
||||||
|
isOpen: true,
|
||||||
|
clusterRoleBinding,
|
||||||
|
});
|
||||||
|
editNameState.set(clusterRoleBinding?.getName() ?? "");
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default openClusterRoleBindingDialogInjectable;
|
||||||
@ -0,0 +1,24 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
|
import { observable } from "mobx";
|
||||||
|
import type { ClusterRoleBinding } from "../../../../../common/k8s-api/endpoints";
|
||||||
|
|
||||||
|
export type ClusterRoleBindingDialogState = {
|
||||||
|
isOpen: false;
|
||||||
|
clusterRoleBinding?: undefined;
|
||||||
|
} | {
|
||||||
|
isOpen: true;
|
||||||
|
clusterRoleBinding: ClusterRoleBinding | undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
const clusterRoleBindingDialogStateInjectable = getInjectable({
|
||||||
|
id: "cluster-role-binding-dialog-state",
|
||||||
|
instantiate: () => observable.box<ClusterRoleBindingDialogState>({
|
||||||
|
isOpen: false,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
export default clusterRoleBindingDialogStateInjectable;
|
||||||
@ -3,75 +3,73 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import "./dialog.scss";
|
import "./view.scss";
|
||||||
|
|
||||||
import { action, computed, makeObservable, observable, reaction } from "mobx";
|
import type { IObservableValue } from "mobx";
|
||||||
import { disposeOnUnmount, observer } from "mobx-react";
|
import { action, computed, makeObservable, observable } from "mobx";
|
||||||
|
import { observer } from "mobx-react";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
import { serviceAccountStore } from "../+service-accounts/legacy-store";
|
import type { ClusterRole, ServiceAccount } from "../../../../../common/k8s-api/endpoints";
|
||||||
import type { ClusterRole, ClusterRoleBinding, ServiceAccount } from "../../../../common/k8s-api/endpoints";
|
import type { DialogProps } from "../../../dialog";
|
||||||
import type { DialogProps } from "../../dialog";
|
import { Dialog } from "../../../dialog";
|
||||||
import { Dialog } from "../../dialog";
|
import { EditableList } from "../../../editable-list";
|
||||||
import { EditableList } from "../../editable-list";
|
import { Icon } from "../../../icon";
|
||||||
import { Icon } from "../../icon";
|
import { SubTitle } from "../../../layout/sub-title";
|
||||||
import { showDetails } from "../../kube-detail-params";
|
import { Notifications } from "../../../notifications";
|
||||||
import { SubTitle } from "../../layout/sub-title";
|
import { onMultiSelectFor, Select } from "../../../select";
|
||||||
import { Notifications } from "../../notifications";
|
import { Wizard, WizardStep } from "../../../wizard";
|
||||||
import { onMultiSelectFor, Select } from "../../select";
|
import { ObservableHashSet, nFircate } from "../../../../utils";
|
||||||
import { Wizard, WizardStep } from "../../wizard";
|
import { Input } from "../../../input";
|
||||||
import { clusterRoleBindingStore } from "./legacy-store";
|
import { TooltipPosition } from "../../../tooltip";
|
||||||
import { clusterRoleStore } from "../+cluster-roles/legacy-store";
|
import type { Subject } from "../../../../../common/k8s-api/endpoints/types/subject";
|
||||||
import { ObservableHashSet, nFircate } from "../../../utils";
|
import type { ClusterRoleBindingDialogState } from "./state.injectable";
|
||||||
import { Input } from "../../input";
|
import type { ClusterRoleStore } from "../../+cluster-roles/store";
|
||||||
import { TooltipPosition } from "../../tooltip";
|
import type { ServiceAccountStore } from "../../+service-accounts/store";
|
||||||
import type { Subject } from "../../../../common/k8s-api/endpoints/types/subject";
|
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||||
|
import clusterRoleStoreInjectable from "../../+cluster-roles/store.injectable";
|
||||||
|
import editClusterRoleBindingNameStateInjectable from "./edit-name-state.injectable";
|
||||||
|
import serviceAccountStoreInjectable from "../../+service-accounts/store.injectable";
|
||||||
|
import clusterRoleBindingDialogStateInjectable from "./state.injectable";
|
||||||
|
import type { CloseClusterRoleBindingDialog } from "./close.injectable";
|
||||||
|
import type { OpenClusterRoleBindingDialog } from "./open.injectable";
|
||||||
|
import openClusterRoleBindingDialogInjectable from "./open.injectable";
|
||||||
|
import closeClusterRoleBindingDialogInjectable from "./close.injectable";
|
||||||
|
import type { ShowDetails } from "../../../kube-detail-params/show-details.injectable";
|
||||||
|
import type { ClusterRoleBindingStore } from "../store";
|
||||||
|
import clusterRoleBindingStoreInjectable from "../store.injectable";
|
||||||
|
import showDetailsInjectable from "../../../kube-detail-params/show-details.injectable";
|
||||||
|
|
||||||
export interface ClusterRoleBindingDialogProps extends Partial<DialogProps> {
|
export interface ClusterRoleBindingDialogProps extends Partial<DialogProps> {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface DialogState {
|
interface Dependencies {
|
||||||
isOpen: boolean;
|
state: IObservableValue<ClusterRoleBindingDialogState>;
|
||||||
data?: ClusterRoleBinding;
|
editBindingNameState: IObservableValue<string>;
|
||||||
|
clusterRoleStore: ClusterRoleStore;
|
||||||
|
serviceAccountStore: ServiceAccountStore;
|
||||||
|
clusterRoleBindingStore: ClusterRoleBindingStore;
|
||||||
|
closeClusterRoleBindingDialog: CloseClusterRoleBindingDialog;
|
||||||
|
openClusterRoleBindingDialog: OpenClusterRoleBindingDialog;
|
||||||
|
showDetails: ShowDetails;
|
||||||
}
|
}
|
||||||
|
|
||||||
const dialogState = observable.object<DialogState>({
|
|
||||||
isOpen: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class ClusterRoleBindingDialog extends React.Component<ClusterRoleBindingDialogProps> {
|
class NonInjectedClusterRoleBindingDialog extends React.Component<ClusterRoleBindingDialogProps & Dependencies> {
|
||||||
constructor(props: ClusterRoleBindingDialogProps) {
|
constructor(props: ClusterRoleBindingDialogProps & Dependencies) {
|
||||||
super(props);
|
super(props);
|
||||||
makeObservable(this);
|
makeObservable(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
|
||||||
disposeOnUnmount(this, [
|
|
||||||
reaction(() => this.isEditing, () => {
|
|
||||||
this.bindingName = dialogState.data?.getName() ?? "";
|
|
||||||
}),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
static open(roleBinding?: ClusterRoleBinding) {
|
|
||||||
dialogState.isOpen = true;
|
|
||||||
dialogState.data = roleBinding;
|
|
||||||
}
|
|
||||||
|
|
||||||
static close() {
|
|
||||||
dialogState.isOpen = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@computed get clusterRoleOptions() {
|
@computed get clusterRoleOptions() {
|
||||||
return clusterRoleStore.items.map(clusterRole => ({
|
return this.props.clusterRoleStore.items.map(clusterRole => ({
|
||||||
value: clusterRole,
|
value: clusterRole,
|
||||||
label: clusterRole.getName(),
|
label: clusterRole.getName(),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@computed get serviceAccountOptions() {
|
@computed get serviceAccountOptions() {
|
||||||
return serviceAccountStore.items.map(serviceAccount => ({
|
return this.props.serviceAccountStore.items.map(serviceAccount => ({
|
||||||
value: serviceAccount,
|
value: serviceAccount,
|
||||||
label: `${serviceAccount.getName()} (${serviceAccount.getNs()})`,
|
label: `${serviceAccount.getName()} (${serviceAccount.getNs()})`,
|
||||||
isSelected: this.selectedAccounts.has(serviceAccount),
|
isSelected: this.selectedAccounts.has(serviceAccount),
|
||||||
@ -79,7 +77,7 @@ export class ClusterRoleBindingDialog extends React.Component<ClusterRoleBinding
|
|||||||
}
|
}
|
||||||
|
|
||||||
get clusterRoleBinding() {
|
get clusterRoleBinding() {
|
||||||
return dialogState.data;
|
return this.props.state.get().clusterRoleBinding;
|
||||||
}
|
}
|
||||||
|
|
||||||
get isEditing() {
|
get isEditing() {
|
||||||
@ -87,7 +85,6 @@ export class ClusterRoleBindingDialog extends React.Component<ClusterRoleBinding
|
|||||||
}
|
}
|
||||||
|
|
||||||
@observable selectedRoleRef: ClusterRole | undefined = undefined;
|
@observable selectedRoleRef: ClusterRole | undefined = undefined;
|
||||||
@observable bindingName = "";
|
|
||||||
selectedAccounts = new ObservableHashSet<ServiceAccount>([], sa => sa.metadata.uid);
|
selectedAccounts = new ObservableHashSet<ServiceAccount>([], sa => sa.metadata.uid);
|
||||||
selectedUsers = observable.set<string>([]);
|
selectedUsers = observable.set<string>([]);
|
||||||
selectedGroups = observable.set<string>([]);
|
selectedGroups = observable.set<string>([]);
|
||||||
@ -121,16 +118,15 @@ export class ClusterRoleBindingDialog extends React.Component<ClusterRoleBinding
|
|||||||
return this.reset();
|
return this.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.selectedRoleRef = clusterRoleStore
|
this.selectedRoleRef = this.props.clusterRoleStore
|
||||||
.items
|
.items
|
||||||
.find(item => item.getName() === binding.roleRef.name);
|
.find(item => item.getName() === binding.roleRef.name);
|
||||||
this.bindingName = binding.getName();
|
|
||||||
|
|
||||||
const [saSubjects, uSubjects, gSubjects] = nFircate(binding.getSubjects(), "kind", ["ServiceAccount", "User", "Group"]);
|
const [saSubjects, uSubjects, gSubjects] = nFircate(binding.getSubjects(), "kind", ["ServiceAccount", "User", "Group"]);
|
||||||
const accountNames = new Set(saSubjects.map(acc => acc.name));
|
const accountNames = new Set(saSubjects.map(acc => acc.name));
|
||||||
|
|
||||||
this.selectedAccounts.replace(
|
this.selectedAccounts.replace(
|
||||||
serviceAccountStore.items
|
this.props.serviceAccountStore.items
|
||||||
.filter(sa => accountNames.has(sa.getName())),
|
.filter(sa => accountNames.has(sa.getName())),
|
||||||
);
|
);
|
||||||
this.selectedUsers.replace(uSubjects.map(user => user.name));
|
this.selectedUsers.replace(uSubjects.map(user => user.name));
|
||||||
@ -139,14 +135,19 @@ export class ClusterRoleBindingDialog extends React.Component<ClusterRoleBinding
|
|||||||
|
|
||||||
reset = action(() => {
|
reset = action(() => {
|
||||||
this.selectedRoleRef = undefined;
|
this.selectedRoleRef = undefined;
|
||||||
this.bindingName = "";
|
|
||||||
this.selectedAccounts.clear();
|
this.selectedAccounts.clear();
|
||||||
this.selectedUsers.clear();
|
this.selectedUsers.clear();
|
||||||
this.selectedGroups.clear();
|
this.selectedGroups.clear();
|
||||||
});
|
});
|
||||||
|
|
||||||
createBindings = async () => {
|
createBindings = async () => {
|
||||||
const { selectedRoleRef, selectedBindings, bindingName, clusterRoleBinding } = this;
|
const {
|
||||||
|
closeClusterRoleBindingDialog,
|
||||||
|
clusterRoleBindingStore,
|
||||||
|
editBindingNameState,
|
||||||
|
showDetails,
|
||||||
|
} = this.props;
|
||||||
|
const { selectedRoleRef, selectedBindings, clusterRoleBinding } = this;
|
||||||
|
|
||||||
if (!clusterRoleBinding || !selectedRoleRef) {
|
if (!clusterRoleBinding || !selectedRoleRef) {
|
||||||
return;
|
return;
|
||||||
@ -155,7 +156,7 @@ export class ClusterRoleBindingDialog extends React.Component<ClusterRoleBinding
|
|||||||
try {
|
try {
|
||||||
const { selfLink } = this.isEditing
|
const { selfLink } = this.isEditing
|
||||||
? await clusterRoleBindingStore.updateSubjects(clusterRoleBinding, selectedBindings)
|
? await clusterRoleBindingStore.updateSubjects(clusterRoleBinding, selectedBindings)
|
||||||
: await clusterRoleBindingStore.create({ name: bindingName }, {
|
: await clusterRoleBindingStore.create({ name: editBindingNameState.get() }, {
|
||||||
subjects: selectedBindings,
|
subjects: selectedBindings,
|
||||||
roleRef: {
|
roleRef: {
|
||||||
name: selectedRoleRef.getName(),
|
name: selectedRoleRef.getName(),
|
||||||
@ -164,7 +165,7 @@ export class ClusterRoleBindingDialog extends React.Component<ClusterRoleBinding
|
|||||||
});
|
});
|
||||||
|
|
||||||
showDetails(selfLink);
|
showDetails(selfLink);
|
||||||
ClusterRoleBindingDialog.close();
|
closeClusterRoleBindingDialog();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
Notifications.checkedError(err, `Unknown error occured while ${this.isEditing ? "editing the" : "creating a"} ClusterRoleBinding`);
|
Notifications.checkedError(err, `Unknown error occured while ${this.isEditing ? "editing the" : "creating a"} ClusterRoleBinding`);
|
||||||
}
|
}
|
||||||
@ -198,9 +199,10 @@ export class ClusterRoleBindingDialog extends React.Component<ClusterRoleBinding
|
|||||||
)}
|
)}
|
||||||
onChange={option => {
|
onChange={option => {
|
||||||
this.selectedRoleRef = option?.value;
|
this.selectedRoleRef = option?.value;
|
||||||
|
const bindingName = this.props.editBindingNameState.get();
|
||||||
|
|
||||||
if (!this.selectedRoleRef || this.bindingName === this.selectedRoleRef.getName()) {
|
if (!this.selectedRoleRef || bindingName === this.selectedRoleRef.getName()) {
|
||||||
this.bindingName = option?.value?.getName() ?? "";
|
this.props.editBindingNameState.set(option?.value?.getName() ?? "");
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
@ -209,8 +211,8 @@ export class ClusterRoleBindingDialog extends React.Component<ClusterRoleBinding
|
|||||||
<Input
|
<Input
|
||||||
placeholder="Name of ClusterRoleBinding ..."
|
placeholder="Name of ClusterRoleBinding ..."
|
||||||
disabled={this.isEditing}
|
disabled={this.isEditing}
|
||||||
value={this.bindingName}
|
value={this.props.editBindingNameState.get()}
|
||||||
onChange={val => this.bindingName = val}
|
onChange={val => this.props.editBindingNameState.set(val)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<SubTitle title="Binding targets" />
|
<SubTitle title="Binding targets" />
|
||||||
@ -252,16 +254,24 @@ export class ClusterRoleBindingDialog extends React.Component<ClusterRoleBinding
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { ...dialogProps } = this.props;
|
const {
|
||||||
|
closeClusterRoleBindingDialog,
|
||||||
|
openClusterRoleBindingDialog,
|
||||||
|
clusterRoleStore,
|
||||||
|
editBindingNameState,
|
||||||
|
serviceAccountStore,
|
||||||
|
state,
|
||||||
|
...dialogProps
|
||||||
|
} = this.props;
|
||||||
const [action, nextLabel] = this.isEditing ? ["Edit", "Update"] : ["Add", "Create"];
|
const [action, nextLabel] = this.isEditing ? ["Edit", "Update"] : ["Add", "Create"];
|
||||||
const disableNext = !this.selectedRoleRef || !this.selectedBindings.length || !this.bindingName;
|
const disableNext = !this.selectedRoleRef || !this.selectedBindings.length || !editBindingNameState.get();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog
|
<Dialog
|
||||||
{...dialogProps}
|
{...dialogProps}
|
||||||
className="AddClusterRoleBindingDialog"
|
className="AddClusterRoleBindingDialog"
|
||||||
isOpen={dialogState.isOpen}
|
isOpen={state.get().isOpen}
|
||||||
close={ClusterRoleBindingDialog.close}
|
close={closeClusterRoleBindingDialog}
|
||||||
onClose={this.reset}
|
onClose={this.reset}
|
||||||
onOpen={this.onOpen}
|
onOpen={this.onOpen}
|
||||||
>
|
>
|
||||||
@ -271,7 +281,7 @@ export class ClusterRoleBindingDialog extends React.Component<ClusterRoleBinding
|
|||||||
{`${action} ClusterRoleBinding`}
|
{`${action} ClusterRoleBinding`}
|
||||||
</h5>
|
</h5>
|
||||||
)}
|
)}
|
||||||
done={ClusterRoleBindingDialog.close}
|
done={closeClusterRoleBindingDialog}
|
||||||
>
|
>
|
||||||
<WizardStep
|
<WizardStep
|
||||||
nextLabel={nextLabel}
|
nextLabel={nextLabel}
|
||||||
@ -285,3 +295,17 @@ export class ClusterRoleBindingDialog extends React.Component<ClusterRoleBinding
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const ClusterRoleBindingDialog = withInjectables<Dependencies, ClusterRoleBindingDialogProps>(NonInjectedClusterRoleBindingDialog, {
|
||||||
|
getProps: (di, props) => ({
|
||||||
|
...props,
|
||||||
|
clusterRoleStore: di.inject(clusterRoleStoreInjectable),
|
||||||
|
editBindingNameState: di.inject(editClusterRoleBindingNameStateInjectable),
|
||||||
|
serviceAccountStore: di.inject(serviceAccountStoreInjectable),
|
||||||
|
state: di.inject(clusterRoleBindingDialogStateInjectable),
|
||||||
|
clusterRoleBindingStore: di.inject(clusterRoleBindingStoreInjectable),
|
||||||
|
openClusterRoleBindingDialog: di.inject(openClusterRoleBindingDialogInjectable),
|
||||||
|
closeClusterRoleBindingDialog: di.inject(closeClusterRoleBindingDialogInjectable),
|
||||||
|
showDetails: di.inject(showDetailsInjectable),
|
||||||
|
}),
|
||||||
|
});
|
||||||
@ -4,4 +4,4 @@
|
|||||||
*/
|
*/
|
||||||
export * from "./view";
|
export * from "./view";
|
||||||
export * from "./details";
|
export * from "./details";
|
||||||
export * from "./dialog";
|
export * from "./dialog/view";
|
||||||
|
|||||||
@ -1,12 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { asLegacyGlobalForExtensionApi } from "../../../../extensions/as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api";
|
|
||||||
import clusterRoleBindingStoreInjectable from "./store.injectable";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated use `di.inject(clusterRoleBindingStoreInjectable)` instead
|
|
||||||
*/
|
|
||||||
export const clusterRoleBindingStore = asLegacyGlobalForExtensionApi(clusterRoleBindingStoreInjectable);
|
|
||||||
@ -9,12 +9,16 @@ import { observer } from "mobx-react";
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { KubeObjectListLayout } from "../../kube-object-list-layout";
|
import { KubeObjectListLayout } from "../../kube-object-list-layout";
|
||||||
import { KubeObjectStatusIcon } from "../../kube-object-status-icon";
|
import { KubeObjectStatusIcon } from "../../kube-object-status-icon";
|
||||||
import { ClusterRoleBindingDialog } from "./dialog";
|
import { ClusterRoleBindingDialog } from "./dialog/view";
|
||||||
import { clusterRoleBindingStore } from "./legacy-store";
|
|
||||||
import { clusterRoleStore } from "../+cluster-roles/legacy-store";
|
|
||||||
import { serviceAccountStore } from "../+service-accounts/legacy-store";
|
|
||||||
import { SiblingsInTabLayout } from "../../layout/siblings-in-tab-layout";
|
import { SiblingsInTabLayout } from "../../layout/siblings-in-tab-layout";
|
||||||
import { KubeObjectAge } from "../../kube-object/age";
|
import { KubeObjectAge } from "../../kube-object/age";
|
||||||
|
import type { ClusterRoleBindingStore } from "./store";
|
||||||
|
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||||
|
import clusterRoleBindingStoreInjectable from "./store.injectable";
|
||||||
|
import type { ClusterRoleStore } from "../+cluster-roles/store";
|
||||||
|
import type { ServiceAccountStore } from "../+service-accounts/store";
|
||||||
|
import clusterRoleStoreInjectable from "../+cluster-roles/store.injectable";
|
||||||
|
import serviceAccountStoreInjectable from "../+service-accounts/store.injectable";
|
||||||
|
|
||||||
enum columnId {
|
enum columnId {
|
||||||
name = "name",
|
name = "name",
|
||||||
@ -23,9 +27,21 @@ enum columnId {
|
|||||||
age = "age",
|
age = "age",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface Dependencies {
|
||||||
|
clusterRoleBindingStore: ClusterRoleBindingStore;
|
||||||
|
clusterRoleStore: ClusterRoleStore;
|
||||||
|
serviceAccountStore: ServiceAccountStore;
|
||||||
|
}
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class ClusterRoleBindings extends React.Component {
|
class NonInjectedClusterRoleBindings extends React.Component<Dependencies> {
|
||||||
render() {
|
render() {
|
||||||
|
const {
|
||||||
|
clusterRoleBindingStore,
|
||||||
|
clusterRoleStore,
|
||||||
|
serviceAccountStore,
|
||||||
|
} = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SiblingsInTabLayout>
|
<SiblingsInTabLayout>
|
||||||
<KubeObjectListLayout
|
<KubeObjectListLayout
|
||||||
@ -66,3 +82,12 @@ export class ClusterRoleBindings extends React.Component {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const ClusterRoleBindings = withInjectables<Dependencies>(NonInjectedClusterRoleBindings, {
|
||||||
|
getProps: (di, props) => ({
|
||||||
|
...props,
|
||||||
|
clusterRoleBindingStore: di.inject(clusterRoleBindingStoreInjectable),
|
||||||
|
clusterRoleStore: di.inject(clusterRoleStoreInjectable),
|
||||||
|
serviceAccountStore: di.inject(serviceAccountStoreInjectable),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user