-
Notifications
You must be signed in to change notification settings - Fork 445
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
Conversation
Add '$' at the regex end
I want to apply the confirmation also to CURL requests. The shared place between HttpRequestParser and CurlRequestParser is IRequestParser.
What's happening? Do you not accept PRs? |
@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 # @name deleteUser
# @note Don't do this until you are convinced
DELETE https://example.org/users/1 |
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. |
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. |
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.
I add some comments and open for discussion.
src/common/constants.ts
Outdated
@@ -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; |
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.
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}}?
src/common/constants.ts
Outdated
@@ -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; |
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.
What do you think about the name note
or confirmation
, or any other ideas 😄
src/controllers/requestController.ts
Outdated
if (undefined !== httpRequest.confirmSendMsg) { | ||
const userConfirmed = await window.showQuickPick(['Yes', 'No'], { canPickMany: false, placeHolder: httpRequest.confirmSendMsg }); | ||
if ('Yes' !== userConfirmed) { | ||
return; | ||
} | ||
} |
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.
I think we should move this logic to the run
method, since rerun
method doesn't need to rely on this logic personally.
src/models/httpRequest.ts
Outdated
@@ -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) { |
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 confirmSendMsg
field is only used for request send confirmation, I think we don't need to put it in the request text.
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.
And what's about serialization?
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.
I think no, we don't need to show this info for history
Change 'bool' to 'boolean'
Changes made. |
syntaxes/http.tmLanguage
Outdated
@@ -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> |
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.
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
.
@ChayimFriedman2 merged, thanks. |
Solve issue #478.
I've chosen the following format:
Confirm with a custom message:
Confirm without a custom message, the default message is "Are you sure?" and it's customizable through setting:
Or:
The command must be on the first line, without any spaces before or after it.