Skip to content

Commit 767cc08

Browse files
committed
fix: ask user to confirm profile reset and delete
1 parent 6803db5 commit 767cc08

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

plugins/plugin-codeflare/src/components/ProfileExplorer.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import ProfileSelect from "./ProfileSelect"
3838
import ProfileWatcher from "../tray/watchers/profile/list"
3939
// import ProfileStatusWatcher from "../tray/watchers/profile/status"
4040
// import UpdateFunction from "../tray/update"
41-
import { handleNew, handleDelete, handleReset } from "../controller/profile/actions"
41+
import { handleNew } from "../controller/profile/actions"
4242

4343
import Icon from "@patternfly/react-icons/dist/esm/icons/clipboard-list-icon"
4444

@@ -278,12 +278,26 @@ class ProfileCard extends React.PureComponent<ProfileCardProps, ProfileCardState
278278
/** Delete selected profile */
279279
private readonly _onDelete = async () => {
280280
if (this.props.profile) {
281-
await handleDelete(this.props.profile)
281+
await this.executeKuiCommand(
282+
`Are you sure you wish to delete the profile named ${this.props.profile}?`,
283+
`codeflare delete profile ${this.props.profile}`
284+
)
282285
this.props.onSelectProfile(null)
283286
}
284287
}
285288

286-
private readonly _onReset = () => this.props.profile && handleReset(this.props.profile)
289+
private executeKuiCommand(question: string, cmdline: string) {
290+
import("@kui-shell/core").then((_) =>
291+
_.pexecInCurrentTab(`confirm --asking "${question}" "${cmdline}"`, undefined, false, true)
292+
)
293+
}
294+
295+
private readonly _onReset = () =>
296+
this.props.profile &&
297+
this.executeKuiCommand(
298+
`Are you sure you wish to reset the profile named ${this.props.profile}?`,
299+
`codeflare reset profile ${this.props.profile}`
300+
)
287301

288302
private title() {
289303
return (

plugins/plugin-codeflare/src/controller/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export default function registerCodeflareCommands(registrar: Registrar) {
6464
height,
6565
})
6666

67+
registrar.listen("/codeflare/reset/profile", (args) => import("./profile/reset").then((_) => _.default(args)))
6768
registrar.listen("/codeflare/delete/profile", (args) => import("./profile/delete").then((_) => _.default(args)))
6869
registrar.listen("/codeflare/rename/profile", (args) => import("./profile/rename").then((_) => _.default(args)))
6970

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2022 The Kubernetes Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { Profiles } from "madwizard"
18+
import { Arguments } from "@kui-shell/core"
19+
20+
export default async function resetProfile(args: Arguments) {
21+
const N = args.argvNoOptions.length - 1
22+
const src = args.argvNoOptions[N]
23+
24+
await Profiles.reset({}, src)
25+
return true
26+
}

0 commit comments

Comments
 (0)