-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Security Solution][Endpoint] Response Console framework support for argument value selectors #148693
[Security Solution][Endpoint] Response Console framework support for argument value selectors #148693
Conversation
…selectors (not working yet)
…EnteredState` action
… on command input
…mand + fix parseInput in store
…ipulating strings
…electors is updated correctly
… data value validations
Pinging @elastic/security-defend-workflows (Team:Defend Workflows) |
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.
Took an initial pass at reviewing this. The file selector popup UX looks awesome when I tried it out. 🤩
I noticed something that you probably already know but I thought I'll mention it since it's not listed in the limitations section. That is, whenever the file selector is empty (no files are selected) the popup opens up on every cursor move (left or right) no matter where the cursor is and even if I close the popup. I would expect that once I close the popup it should not show up unless I click on the file argument value ("click to select file"). See this clip. Once a file is selected the popup shows up again only when the file
argument value ("click to select file") is clicked.
For later UX consideration,
- Once a file is selected and the file selector popup is opened again I see the same message as when no file was selected. Maybe show a different message like "Select a file to replace the current one" or similar.
- When the command is executed, the
--file
argument value shows just the file name. Should we show the absolute path of the file instead if that's useful info?
.popoverAnchor { | ||
display: block; | ||
} |
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.
Curios why the display
style is needed?
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.
at some point I needed this, but looks like with the most current code, it's no longer needed. I will deleted it. Thanks for the feedback.
@@ -381,6 +323,70 @@ export const handleExecuteCommand: ConsoleStoreReducer< | |||
); | |||
} | |||
|
|||
if (argDefinition.mustHaveValue !== undefined && argDefinition.mustHaveValue !== false) { |
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.
This file is now showing me cyclomatic complexity warning now and that it is at 32 now and exceeds 20 which is the limit. Consider adding an eslint ignore.
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.
It's a warning right? so no need to ignore it. I'll have to come back at some point and break it up
/** | ||
* If the argument is required to be entered by the user. NOTE that this will only validate that | ||
* the user has entered the argument name - it does not validate that the argument must have a | ||
* value. Argument's that have no value entered by the user have (by default) a value of |
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.
nit: typo Arguments...
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.
Awesome modification! I got nothing major with my current understanding, only small findings/questions - but those can be managed in subsequent PRs.
/** | ||
* The instance of the argument in the current command. This is a zero-based number indicating | ||
* which instance of the argument is being rendered. | ||
*/ | ||
argInstance: number; |
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 name for this field is a bit misleading to me: should it be maybe argIndex
?
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 guess I could have renamed it argIndex
. I went with argInstance
to kind of match the value I was already using internally and I just exposed it to the argument value component. "Instance" to indicate which instance of the argument usage is being rendered.
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 see, thanks! would you consider to rename it? reading instance
indicates to me that this is an object, an object instance of a class, and definitely not a number.
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.
Ohh. I see what you meant by instance
. Yes, I will rename it
.../security_solution/public/management/components/console_argument_selectors/file_selector.tsx
Outdated
Show resolved
Hide resolved
return i18n.translate( | ||
'xpack.securitySolution.console.commandValidation.mustHaveNonBlankValue', | ||
{ | ||
defaultMessage: 'Argument --${argName} must have a value', |
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.
is this intentionally the same as the string for mustHaveValue
?
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.
🤦
No. It should not be a duplicate. I will change to use the one above.
type InputAreaStateAction = ConsoleDataAction & { | ||
type: | ||
| 'updateInputPopoverState' | ||
| 'updateInputHistoryState' | ||
| 'clearInputHistoryState' | ||
| 'updateInputTextEnteredState' | ||
| 'updateInputPlaceholderState' | ||
| 'setInputState'; | ||
| 'setInputState' | ||
| 'updateInputCommandArgState'; | ||
}; | ||
|
||
export const handleInputAreaState: ConsoleStoreReducer<InputAreaStateAction> = ( |
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.
for this function I'm seeing the eslint(complexity)
warning: Arrow function has a complexity of 31. Maximum allowed is 20.
I think this could be refactored in a subsequent PR
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.
correct. This one also needs to be refactored and broken down
@@ -131,16 +129,13 @@ const createCommandHistoryEntry = ( | |||
export const handleExecuteCommand: ConsoleStoreReducer< |
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.
this also has too large cyclomatic complexity according to the eslint rule
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.
yeah, I been meaning to break it out into separate functions to do the validations.
...lic/management/components/console/components/console_state/hooks/use_stored_input_history.ts
Show resolved
Hide resolved
...solution/public/management/components/console/components/command_input/lib/entered_input.tsx
Show resolved
Hide resolved
…le-arg-value-selector-support
…selector-support' into task/olm-5711-console-arg-value-selector-support
Thanks @ashokaditya for the feedback. Re:
Yeah, I noticed this as well. I did not spent too much time on the UX of the file picker as part of this PR and I do know that particular selector does need to be adjusted to be "smarter" about the states it supports. I might even have to introduce a "state store" per argument selector so that they can keep state for their own use cases. I added this item to the internal issue that is tracking this work for consideration **re: **
I did not see the need to change the text since it is generic. Do you find that it could be confusing to the user as to what the outcome will be by selecting another file? Re:
I don't think we have access to the full file path from the |
FYI - for this item: "...the file selector is empty (no files are selected) the popup opens up on every cursor move (left or right) no matter where the cursor is and even if I close the popup. I have made the change to the framework and the File picker to keep state, so the "I'm always open when you move the cursor" will not happen anymore. Thansk again for the feedback. |
…le-arg-value-selector-support
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Module Count
Async chunks
Unknown metric groupsESLint disabled in files
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: |
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.
🚢 it!
Summary
mustHaveValue
property to the definition of a command's argument. Usage (from JSDocs):PR Testing
Since there are currently no commands that use this new framework, the following can be used access a test command in the console:
&show_upload=1
. Example:http://localhost:5601/app/security/administration/endpoints?page_index=0&page_size=10&show_upload=1
upload
command for dev testing purposes only. It is defined with two arguments that have ArgumentSelector:--file
and--mock
More about Argument Selectors
When an argument, having an
SelectorComponent
defined, is typed into the console, the UI provided by that selector component will be inserted as the value to the argument name. It is up to the Argument Selector to provide the desired UI to the user. Argument Selectors have the following behaviors:--file
, which is replaced in the console's input with--file=[argument selector UI here]
[Left]
/[Right]
keys will jump over the entire argument. It does not move through each letter once the argument name has been replaced with the UI for displaying the argument selector[Delete]
/[Backspace]
keys will delete the entire argument from the input area[ArrowUP]
is clicked) and the console's command output area (after a command has been[Enter]
'd) will display a text representation of the value provided by the Argument Selector.[ArrowUp]
), the textual representation of any argument with Argument Selector will not be applied to the console's input area. Only the argument name will be entered (triggering the selector to be used again)Some limitations
Some current limitation that may be addressed in subsequent PR(s):
Checklist