Skip to content
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

Present an Option to Confirm Send #538

Merged
merged 37 commits into from
Mar 25, 2020
Merged

Conversation

ChayimFriedman2
Copy link
Contributor

Solve issue #478.
I've chosen the following format:
Confirm with a custom message:

@confirm-send(Do you want to send?)
https://github.com

Confirm without a custom message, the default message is "Are you sure?" and it's customizable through setting:

@confirm-send()
https://github.com

Or:

@confirm-send
https://github.com

The command must be on the first line, without any spaces before or after it.

@ChayimFriedman2
Copy link
Contributor Author

What's happening? Do you not accept PRs?

@Huachao
Copy link
Owner

Huachao commented Mar 17, 2020

@ChayimFriedman2 actually PRs are warmly welcomed, however, I will consider this feature/bug fix acceptable to me. And I'd like to thank for your contribution and usage. Back to your PR, firstly, I think this feature is reasonable since we need to let users know that some APIs are dangerous operations and need to be careful. So we need to come up with a syntax for request that users think dangerous (not only DELETE request). Secondly, the syntax @confirm-send() is a bit ambiguous with the file variable definition. Maybe I prefer a syntax like request variable definition that inlined in comment lines and just above the request, like # @note. The name note is just an example. Thirdly, I think the users don't need to customize the message info in setting, if we follow step 2, the syntax can be extended to following

# @name deleteUser
# @note Don't do this until you are convinced
DELETE https://example.org/users/1

@ChayimFriedman2
Copy link
Contributor Author

I think this feature is reasonable since we need to let users know that some APIs are dangerous operations and need to be careful. So we need to come up with a syntax for request that users think dangerous (not only DELETE request)

What do you mean?

@Huachao
Copy link
Owner

Huachao commented Mar 17, 2020

I think this feature is reasonable since we need to let users know that some APIs are dangerous operations and need to be careful. So we need to come up with a syntax for request that users think dangerous (not only DELETE request)

What do you mean?

I mean this plan should be designed for all requests that users think need to be confirmed, not only for deletion confirmation.

@ChayimFriedman2
Copy link
Contributor Author

I'v completed the work on your suggestions :)

About your comment, in the first PR I already implemented it for every request type - not just DELETE.

Copy link
Owner

@Huachao Huachao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I add some comments and open for discussion.

@@ -77,4 +77,6 @@ export const RequestVariableDefinitionWithNameRegexFactory = (name: string, flag

export const RequestVariableDefinitionRegex: RegExp = RequestVariableDefinitionWithNameRegexFactory("\\w+", "m");

export const DangerousNoteDefinitionRegex = /^\s*(?:#{1,}|\/{2,})\s+@note\s+(.+)\s*$/m;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the customized message is normally optional, even I am considering why we should expose this to user? My idea is if user put the note metadata, we always put the same message like Are you sure you want to send this request?. If the request has name(defined by @name), we should use its name like Are you sure you want to send this request {{requestName}}?

@@ -77,4 +77,6 @@ export const RequestVariableDefinitionWithNameRegexFactory = (name: string, flag

export const RequestVariableDefinitionRegex: RegExp = RequestVariableDefinitionWithNameRegexFactory("\\w+", "m");

export const DangerousNoteDefinitionRegex = /^\s*(?:#{1,}|\/{2,})\s+@note\s+(.+)\s*$/m;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about the name note or confirmation, or any other ideas 😄

Comment on lines 81 to 86
if (undefined !== httpRequest.confirmSendMsg) {
const userConfirmed = await window.showQuickPick(['Yes', 'No'], { canPickMany: false, placeHolder: httpRequest.confirmSendMsg });
if ('Yes' !== userConfirmed) {
return;
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should move this logic to the run method, since rerun method doesn't need to rely on this logic personally.

@@ -11,7 +11,8 @@ export class HttpRequest {
public headers: RequestHeaders,
public body: string | Stream | undefined,
public rawBody: string | undefined,
public requestVariableCacheKey?: RequestVariableCacheKey) {
public requestVariableCacheKey?: RequestVariableCacheKey,
public confirmSendMsg?: string) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The confirmSendMsg field is only used for request send confirmation, I think we don't need to put it in the request text.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And what's about serialization?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think no, we don't need to show this info for history

@ChayimFriedman2
Copy link
Contributor Author

Changes made.

src/common/constants.ts Outdated Show resolved Hide resolved
src/utils/selector.ts Outdated Show resolved Hide resolved
syntaxes/http.tmLanguage Outdated Show resolved Hide resolved
@@ -124,7 +124,7 @@
</dict>
<dict>
<key>match</key>
<string>^\s*#{1,}\s*(?:((@)name)\s+(\S+))?.*$</string>
<string>^\s*/{2,}\s*(?:((@)name)\s+(.+)|((@)note))?.*$</string>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the code that both # @name and // @name exist in the http.tmLanguage. You need to update both. And shall we create a separate match for note.

@Huachao Huachao merged commit 98e52b5 into Huachao:master Mar 25, 2020
@Huachao
Copy link
Owner

Huachao commented Mar 25, 2020

@ChayimFriedman2 merged, thanks.

@ChayimFriedman2 ChayimFriedman2 deleted the confirm-send branch March 25, 2020 08:36
@Huachao Huachao linked an issue Jun 12, 2020 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DELETE confirmation
2 participants