Skip to content

Commit

Permalink
fix: ask user to confirm profile reset and delete
Browse files Browse the repository at this point in the history
  • Loading branch information
starpit committed Nov 18, 2022
1 parent 6803db5 commit 767cc08
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
20 changes: 17 additions & 3 deletions plugins/plugin-codeflare/src/components/ProfileExplorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -278,12 +278,26 @@ class ProfileCard extends React.PureComponent<ProfileCardProps, ProfileCardState
/** Delete selected profile */
private readonly _onDelete = async () => {
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 (
Expand Down
1 change: 1 addition & 0 deletions plugins/plugin-codeflare/src/controller/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

Expand Down
26 changes: 26 additions & 0 deletions plugins/plugin-codeflare/src/controller/profile/reset.ts
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 767cc08

Please sign in to comment.