/** * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ import "./view.scss"; import { observer } from "mobx-react"; import React from "react"; import type { DialogProps } from "../../../dialog"; import { Dialog } from "../../../dialog"; import { Input } from "../../../input"; import { SubTitle } from "../../../layout/sub-title"; import { Wizard, WizardStep } from "../../../wizard"; import type { AddClusterRoleDialogState } from "./state.injectable"; import type { ClusterRoleStore } from "../store"; import type { ShowDetails } from "../../../kube-detail-params/show-details.injectable"; import { withInjectables } from "@ogre-tools/injectable-react"; import closeAddClusterRoleDialogInjectable from "./close.injectable"; import clusterRoleStoreInjectable from "../store.injectable"; import showDetailsInjectable from "../../../kube-detail-params/show-details.injectable"; import addClusterRoleDialogStateInjectable from "./state.injectable"; import type { ShowCheckedErrorNotification } from "../../../notifications/show-checked-error.injectable"; import showCheckedErrorNotificationInjectable from "../../../notifications/show-checked-error.injectable"; export interface AddClusterRoleDialogProps extends Partial { } interface Dependencies { state: AddClusterRoleDialogState; clusterRoleStore: ClusterRoleStore; showDetails: ShowDetails; closeAddClusterRoleDialog: () => void; showCheckedErrorNotification: ShowCheckedErrorNotification; } @observer class NonInjectedAddClusterRoleDialog extends React.Component { createRole = async () => { const { closeAddClusterRoleDialog, clusterRoleStore, showDetails, state, showCheckedErrorNotification, } = this.props; try { const role = await clusterRoleStore.create({ name: state.clusterRoleName.get() }); showDetails(role.selfLink); closeAddClusterRoleDialog(); } catch (error) { showCheckedErrorNotification(error, "Unknown error occured while creating the role"); } }; render() { const { closeAddClusterRoleDialog, clusterRoleStore, showDetails, state, ...dialogProps } = this.props; return ( Create ClusterRole} done={closeAddClusterRoleDialog} > state.clusterRoleName.set(v)} /> ); } } export const AddClusterRoleDialog = withInjectables(NonInjectedAddClusterRoleDialog, { getProps: (di, props) => ({ ...props, closeAddClusterRoleDialog: di.inject(closeAddClusterRoleDialogInjectable), clusterRoleStore: di.inject(clusterRoleStoreInjectable), showDetails: di.inject(showDetailsInjectable), state: di.inject(addClusterRoleDialogStateInjectable), showCheckedErrorNotification: di.inject(showCheckedErrorNotificationInjectable), }), });