-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deploy and un deploy functionality (#3073)
* deploy and undeploy functionality Signed-off-by: msivasubramaniaan <msivasub@redhat.com> * shown response in the UI Signed-off-by: msivasubramaniaan <msivasub@redhat.com> --------- Signed-off-by: msivasubramaniaan <msivasub@redhat.com>
- Loading branch information
1 parent
48c7457
commit b847944
Showing
8 changed files
with
464 additions
and
96 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/*----------------------------------------------------------------------------------------------- | ||
* Copyright (c) Red Hat, Inc. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE file in the project root for license information. | ||
*-----------------------------------------------------------------------------------------------*/ | ||
|
||
/* eslint-disable max-classes-per-file */ | ||
import { QuickPickItem, window, Disposable, QuickInput, QuickInputButton } from 'vscode'; | ||
|
||
interface QuickPickParameters<T extends QuickPickItem> { | ||
title: string; | ||
items: T[]; | ||
activeItem?: T; | ||
placeholder: string; | ||
buttons?: QuickInputButton[]; | ||
} | ||
|
||
interface InputBoxParameters { | ||
title: string; | ||
value?: string; | ||
prompt: string; | ||
password: boolean; | ||
validate: (value: string) => string; | ||
buttons?: QuickInputButton[]; | ||
placeholder?: string; | ||
reattemptForLogin?: boolean; | ||
} | ||
|
||
class MultiStepInput { | ||
public current?: QuickInput; | ||
|
||
async showQuickPick<T extends QuickPickItem, P extends QuickPickParameters<T>>({ title, items, activeItem, placeholder }: P) { | ||
const disposables: Disposable[] = []; | ||
try { | ||
return await new Promise<T | (P extends { buttons: (infer I)[] } ? I : never)>((resolve) => { | ||
const input = window.createQuickPick<T>(); | ||
input.title = title; | ||
input.placeholder = placeholder; | ||
input.items = items; | ||
input.ignoreFocusOut = true; | ||
if (activeItem) { | ||
input.activeItems = [activeItem]; | ||
} | ||
disposables.push( | ||
// eslint-disable-next-line @typescript-eslint/no-shadow | ||
input.onDidChangeSelection((items) => { | ||
resolve(items[0]); | ||
this.current.dispose(); | ||
}), | ||
input.onDidHide(() => { | ||
resolve(null); | ||
}), | ||
); | ||
if (this.current) { | ||
this.current.dispose(); | ||
} | ||
this.current = input; | ||
this.current.show(); | ||
}); | ||
} finally { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return | ||
disposables.forEach((d) => d.dispose()); | ||
} | ||
} | ||
|
||
async showInputBox<P extends InputBoxParameters>({ | ||
title, | ||
value, | ||
prompt, | ||
password, | ||
validate, | ||
placeholder, | ||
reattemptForLogin, | ||
}: P) { | ||
const disposables: Disposable[] = []; | ||
try { | ||
return await new Promise<string | (P extends { buttons: (infer I)[] } ? I : never)>((resolve) => { | ||
const input = window.createInputBox(); | ||
input.title = title; | ||
input.value = value || ''; | ||
input.prompt = prompt; | ||
input.password = password; | ||
input.ignoreFocusOut = true; | ||
input.placeholder = placeholder || ''; | ||
let validating = validate(''); | ||
if (reattemptForLogin) { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
input.validationMessage = 'Incorrect credentials, please try again'; | ||
} | ||
disposables.push( | ||
input.onDidAccept(() => { | ||
// eslint-disable-next-line @typescript-eslint/no-shadow | ||
const { value } = input; | ||
input.enabled = false; | ||
input.busy = true; | ||
if (!validate(value)) { | ||
resolve(value); | ||
this.current.dispose(); | ||
} | ||
input.enabled = true; | ||
input.busy = false; | ||
}), | ||
input.onDidChangeValue((text) => { | ||
const current = validate(text); | ||
validating = current; | ||
const validationMessage = current; | ||
if (current === validating) { | ||
input.validationMessage = validationMessage; | ||
} | ||
}), | ||
input.onDidHide(() => { | ||
resolve(null); | ||
}), | ||
); | ||
if (this.current) { | ||
this.current.dispose(); | ||
} | ||
this.current = input; | ||
this.current.show(); | ||
}); | ||
} finally { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return | ||
disposables.forEach((d) => d.dispose()); | ||
} | ||
} | ||
} | ||
|
||
export const multiStep = new MultiStepInput(); |
Oops, something went wrong.