/** * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ import "./details.scss"; import { reaction } from "mobx"; import { disposeOnUnmount, observer } from "mobx-react"; import React from "react"; import type { RoleBinding, RoleBindingSubject } from "../../../../common/k8s-api/endpoints"; import { prevDefault, boundMethod } from "../../../utils"; import { AddRemoveButtons } from "../../add-remove-buttons"; import { ConfirmDialog } from "../../confirm-dialog"; import { DrawerTitle } from "../../drawer"; import type { KubeObjectDetailsProps } from "../../kube-object-details"; import { KubeObjectMeta } from "../../kube-object-meta"; import { Table, TableCell, TableHead, TableRow } from "../../table"; import { RoleBindingDialog } from "./dialog"; import { roleBindingsStore } from "./store"; import { ObservableHashSet } from "../../../../common/utils/hash-set"; import { hashRoleBindingSubject } from "./hashers"; export interface RoleBindingDetailsProps extends KubeObjectDetailsProps { } @observer export class RoleBindingDetails extends React.Component { selectedSubjects = new ObservableHashSet([], hashRoleBindingSubject); async componentDidMount() { disposeOnUnmount(this, [ reaction(() => this.props.object, () => { this.selectedSubjects.clear(); }), ]); } @boundMethod removeSelectedSubjects() { const { object: roleBinding } = this.props; const { selectedSubjects } = this; ConfirmDialog.open({ ok: () => roleBindingsStore.removeSubjects(roleBinding, selectedSubjects.toJSON()), labelOk: `Remove`, message: (

Remove selected bindings for {roleBinding.getName()}?

), }); } render() { const { selectedSubjects } = this; const { object: roleBinding } = this.props; if (!roleBinding) { return null; } const { roleRef } = roleBinding; const subjects = roleBinding.getSubjects(); return (
Kind Name API Group {roleRef.kind} {roleRef.name} {roleRef.apiGroup}
{subjects.length > 0 && ( Type Name Namespace { subjects.map((subject, i) => { const { kind, name, namespace } = subject; const isSelected = selectedSubjects.has(subject); return ( this.selectedSubjects.toggle(subject))} > {kind} {name} {namespace || "-"} ); }) }
)} RoleBindingDialog.open(roleBinding)} onRemove={selectedSubjects.size ? this.removeSelectedSubjects : null} addTooltip={`Edit bindings of ${roleRef.name}`} removeTooltip={`Remove selected bindings from ${roleRef.name}`} />
); } }