/** * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ import React from "react"; import type { KubeObjectMenuProps } from "../kube-object-menu"; import type { StatefulSet, StatefulSetApi } from "../../../common/k8s-api/endpoints"; import { MenuItem } from "../menu"; import { Icon } from "../icon"; import { withInjectables } from "@ogre-tools/injectable-react"; import statefulSetApiInjectable from "../../../common/k8s-api/endpoints/stateful-set.api.injectable"; import type { OpenConfirmDialog } from "../confirm-dialog/open.injectable"; import openConfirmDialogInjectable from "../confirm-dialog/open.injectable"; import type { ShowCheckedErrorNotification } from "../notifications/show-checked-error.injectable"; import showCheckedErrorNotificationInjectable from "../notifications/show-checked-error.injectable"; export interface StatefulSetMenuProps extends KubeObjectMenuProps {} interface Dependencies { statefulsetApi: StatefulSetApi; openConfirmDialog: OpenConfirmDialog; showCheckedErrorNotification: ShowCheckedErrorNotification; } const NonInjectedStatefulSetMenu = ({ statefulsetApi, object, toolbar, showCheckedErrorNotification, openConfirmDialog, }: Dependencies & StatefulSetMenuProps) => ( <> openConfirmDialog({ ok: async () => { try { await statefulsetApi.restart({ namespace: object.getNs(), name: object.getName(), }); } catch (err) { showCheckedErrorNotification(err, "Unknown error occured while restarting statefulset"); } }, labelOk: "Restart", message: (

{"Are you sure you want to restart statefulset "} {object.getName()} ?

), })} > Restart
); export const StatefulSetMenu = withInjectables(NonInjectedStatefulSetMenu, { getProps: (di, props) => ({ ...props, showCheckedErrorNotification: di.inject(showCheckedErrorNotificationInjectable), statefulsetApi: di.inject(statefulSetApiInjectable), openConfirmDialog: di.inject(openConfirmDialogInjectable), }), });