-
Notifications
You must be signed in to change notification settings - Fork 744
refactor(toolkit): add support for async showWhen and skipping prompter backward and forward direction #6166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
justinmk3
merged 7 commits into
aws:master
from
vicheey:add-nested-wizard-prompter-full-support
Dec 12, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7912123
add support for skipping prompter backward and forward direction
vicheey 6b41090
address comment
vicheey 71ad18d
Add test for NestedWizard class
vicheey 4d8ff98
correct typo
vicheey 4c5e48d
move NestedWizard logic to Wizzard class
vicheey 83cc0ff
Update typo
vicheey 77f402f
[revert] move NestedWizard logic to Wizard class
vicheey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,63 @@ | ||
| /*! | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { Wizard, WizardOptions } from '../wizards/wizard' | ||
| import { Prompter } from './prompter' | ||
| import { WizardPrompter } from './wizardPrompter' | ||
| import { createHash } from 'crypto' | ||
|
|
||
vicheey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /** | ||
| * An abstract class that extends the base Wizard class plus the ability to | ||
| * use other wizard classes as prompters | ||
| */ | ||
| export abstract class NestedWizard<T> extends Wizard<T> { | ||
vicheey marked this conversation as resolved.
Show resolved
Hide resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This name seems confusing, unless I'm mistaken. This class is a Wizard that contains nested wizards, it's not itself nested. Right? So maybe a better name is |
||
| /** | ||
| * Map to store memoized wizard instances using SHA-256 hashed keys | ||
| */ | ||
| private wizardInstances: Map<string, any> = new Map() | ||
vicheey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| public constructor(options?: WizardOptions<T>) { | ||
| super(options) | ||
| } | ||
|
|
||
| /** | ||
| * Creates a prompter for a wizard instance with memoization. | ||
| * | ||
| * @template TWizard - The type of wizard, must extend Wizard<TState> | ||
| * @template TState - The type of state managed by the wizard | ||
| * | ||
| * @param wizardClass - The wizard class constructor | ||
| * @param args - Constructor arguments for the wizard instance | ||
| * | ||
| * @returns A wizard prompter to be used as prompter | ||
| * | ||
| * @example | ||
| * // Create a prompter for SyncWizard | ||
| * const prompter = this.createWizardPrompter<SyncWizard, SyncParams>( | ||
| * SyncWizard, | ||
| * template.uri, | ||
| * syncUrl | ||
| * ) | ||
| * | ||
| * @remarks | ||
| * - Instances are memoized using a SHA-256 hash of the wizard class name and arguments | ||
| * - The same wizard instance is reused for identical constructor parameters for restoring wizard prompter | ||
| * states during back button click event | ||
| */ | ||
| protected createWizardPrompter<TWizard extends Wizard<TState>, TState>( | ||
| wizardClass: new (...args: any[]) => TWizard, | ||
| ...args: ConstructorParameters<new (...args: any[]) => TWizard> | ||
| ): Prompter<TState> { | ||
| const memoizeKey = createHash('sha256') | ||
| .update(wizardClass.name + JSON.stringify(args)) | ||
vicheey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .digest('hex') | ||
|
|
||
| if (!this.wizardInstances.get(memoizeKey)) { | ||
| this.wizardInstances.set(memoizeKey, new wizardClass(...args)) | ||
vicheey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| return new WizardPrompter(this.wizardInstances.get(memoizeKey)) as Prompter<TState> | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous implementation supports resolving the value
valit was assigned in the beginning. but this is removed in the new solution. Is this intended?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Since we have SKIP signal. Resolving value was a workaround.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would there be a case we actually want it to resolve some default value?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A straight forward case would be in
bindPrompter, we have multiple if/else based on previous states, and maybe there are two case leads to skip prompter, but we want different value for this field even though it is skipped.With previous solution we will be able to do as the follows
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous workaround for skipping prompter was to automatically resolve the value and skip displaying UI to customer. However, that did not work for backward direction since the auto resolve always revert the backward flow to forward flow.
So we are splitting the skipping case from setting default value case. For how to use the SkipPrompter, please follow this example: aws-toolkit-vscode/packages/core/src/dev/activation.ts at master · vicheey/aws-toolkit-vscode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can consider resolving the value when forward and skip when backwards right?