1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/renderer/components/+user-management-roles/add-role-dialog.tsx
Jameel Al-Aziz a2f4fac720
Allow namespace to specified on role creation (#2020)
* Allow users to specify the namespace when creating a custom role.
* Default role namespace remains the "global" namespace allowing for
  cluster role creatoin.

Signed-off-by: Jameel Al-Aziz <me@jalaziz.io>
2021-02-02 14:53:46 +02:00

91 lines
2.2 KiB
TypeScript

import "./add-role-dialog.scss";
import React from "react";
import { observable } from "mobx";
import { observer } from "mobx-react";
import { Dialog, DialogProps } from "../dialog";
import { Wizard, WizardStep } from "../wizard";
import { SubTitle } from "../layout/sub-title";
import { Notifications } from "../notifications";
import { rolesStore } from "./roles.store";
import { Input } from "../input";
import { NamespaceSelect } from "../+namespaces/namespace-select";
import { showDetails } from "../kube-object";
interface Props extends Partial<DialogProps> {
}
@observer
export class AddRoleDialog extends React.Component<Props> {
@observable static isOpen = false;
@observable roleName = "";
@observable namespace = "";
static open() {
AddRoleDialog.isOpen = true;
}
static close() {
AddRoleDialog.isOpen = false;
}
close = () => {
AddRoleDialog.close();
};
reset = () => {
this.roleName = "";
this.namespace = "";
};
createRole = async () => {
try {
const role = await rolesStore.create({ name: this.roleName, namespace: this.namespace });
showDetails(role.selfLink);
this.reset();
this.close();
} catch (err) {
Notifications.error(err.toString());
}
};
render() {
const { ...dialogProps } = this.props;
const header = <h5>Create Role</h5>;
return (
<Dialog
{...dialogProps}
className="AddRoleDialog"
isOpen={AddRoleDialog.isOpen}
close={this.close}
>
<Wizard header={header} done={this.close}>
<WizardStep
contentClass="flex gaps column"
nextLabel="Create"
next={this.createRole}
>
<SubTitle title="Role Name" />
<Input
required autoFocus
placeholder={`Name`}
iconLeft="supervisor_account"
value={this.roleName}
onChange={v => this.roleName = v}
/>
<SubTitle title="Namespace" />
<NamespaceSelect
themeName="light"
value={this.namespace}
onChange={({ value }) => this.namespace = value}
/>
</WizardStep>
</Wizard>
</Dialog>
);
}
}