diff --git a/plugins/plugin-codeflare/src/components/ProfileExplorer.tsx b/plugins/plugin-codeflare/src/components/ProfileExplorer.tsx index 160941cd..23cf21b7 100644 --- a/plugins/plugin-codeflare/src/components/ProfileExplorer.tsx +++ b/plugins/plugin-codeflare/src/components/ProfileExplorer.tsx @@ -38,7 +38,7 @@ import ProfileSelect from "./ProfileSelect" import ProfileWatcher from "../tray/watchers/profile/list" // import ProfileStatusWatcher from "../tray/watchers/profile/status" // import UpdateFunction from "../tray/update" -import { handleNew, handleDelete, handleReset } from "../controller/profile/actions" +import { handleNew } from "../controller/profile/actions" import Icon from "@patternfly/react-icons/dist/esm/icons/clipboard-list-icon" @@ -278,12 +278,26 @@ class ProfileCard extends React.PureComponent { if (this.props.profile) { - await handleDelete(this.props.profile) + await this.executeKuiCommand( + `Are you sure you wish to delete the profile named ${this.props.profile}?`, + `codeflare delete profile ${this.props.profile}` + ) this.props.onSelectProfile(null) } } - private readonly _onReset = () => this.props.profile && handleReset(this.props.profile) + private executeKuiCommand(question: string, cmdline: string) { + import("@kui-shell/core").then((_) => + _.pexecInCurrentTab(`confirm --asking "${question}" "${cmdline}"`, undefined, false, true) + ) + } + + private readonly _onReset = () => + this.props.profile && + this.executeKuiCommand( + `Are you sure you wish to reset the profile named ${this.props.profile}?`, + `codeflare reset profile ${this.props.profile}` + ) private title() { return ( diff --git a/plugins/plugin-codeflare/src/controller/index.ts b/plugins/plugin-codeflare/src/controller/index.ts index 97fc46e0..79710335 100644 --- a/plugins/plugin-codeflare/src/controller/index.ts +++ b/plugins/plugin-codeflare/src/controller/index.ts @@ -64,6 +64,7 @@ export default function registerCodeflareCommands(registrar: Registrar) { height, }) + registrar.listen("/codeflare/reset/profile", (args) => import("./profile/reset").then((_) => _.default(args))) registrar.listen("/codeflare/delete/profile", (args) => import("./profile/delete").then((_) => _.default(args))) registrar.listen("/codeflare/rename/profile", (args) => import("./profile/rename").then((_) => _.default(args))) diff --git a/plugins/plugin-codeflare/src/controller/profile/reset.ts b/plugins/plugin-codeflare/src/controller/profile/reset.ts new file mode 100644 index 00000000..8244c477 --- /dev/null +++ b/plugins/plugin-codeflare/src/controller/profile/reset.ts @@ -0,0 +1,26 @@ +/* + * Copyright 2022 The Kubernetes Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Profiles } from "madwizard" +import { Arguments } from "@kui-shell/core" + +export default async function resetProfile(args: Arguments) { + const N = args.argvNoOptions.length - 1 + const src = args.argvNoOptions[N] + + await Profiles.reset({}, src) + return true +}