-
Notifications
You must be signed in to change notification settings - Fork 541
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
Hide overrides key if empty, display comment for flags if empty #7986
Conversation
Test summaryRun details
View run in Cypress Dashboard ➡️ This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard |
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.
Hey frontend reviewers 👋 This is my first frontend PR with significant-ish changes, so let me know if I missed anything, especially regarding formatting/conventions/etc. The change seems to work well from manually playing with it locally, but if you feel it's missing anything or could be done a simpler/better way, please let me know, I'm not super familiar with typescript and react (nor with our frontend codebase and tooling!).
This PR is cut off from #7979 and includes those changes (as I had to target the main
branch for CI to work properly), but to see just this PR's changes, you can click here: mna-7377-agent-options-cliflags-2...mna-7377-agent-options-cliflags-3-frontend
@@ -26,7 +26,7 @@ const Agents = ({ | |||
const { ADMIN_TEAMS } = paths; | |||
|
|||
const [formData, setFormData] = useState<any>({ | |||
agentOptions: yaml.dump(appConfig.agent_options) || {}, | |||
agentOptions: agentOptionsToYaml(appConfig.agent_options) || {}, |
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 just modified the code that was already there, but shouldn't the || {}
be inside the parens? I.e. to yaml-encode an empty object if appConfig.agent_options
is null/undefined? Because yaml.dump
returns a string, it seems weird to me to change an empty string to an object if the string is empty.
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 you're right, moreover, agentOptions
is being assigned to a string
below, so it doesn't make sense to assign an object here.
A fun fact about the JS ecosystem (but I don't think it applies here): many libraries have their type definitions separated from their source code, so you can't fully trust them, the return type might say string
, but the actual behavior of the library might be undefined
(for example) so a case like this one might be intentional
@@ -43,7 +43,7 @@ const AgentOptionsPage = ({ | |||
|
|||
if (selected) { | |||
setFormData({ | |||
osquery_options: yaml.dump(selected.agent_options), | |||
osquery_options: agentOptionsToYaml(selected.agent_options), |
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.
Should we have the same || {}
(presumably inside the parens) here too?
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.
if yaml.dump
gracefully handles falsey values, I'd be inclined to just leave it like this. Otherwise yes, I vote to add the safety || {}
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 ended up moving the check inside agentOptionsToYaml
instead.
frontend/utilities/helpers.ts
Outdated
@@ -200,6 +200,7 @@ export const formatConfigDataForServer = (config: any): any => { | |||
}; | |||
|
|||
// TODO: Finalize interface for config - see frontend\interfaces\config.ts | |||
// TODO(mna): this appears to be unused? |
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.
If we're unsure I can just remove my comment. Never seems to be called from a code search but there may be more to it to be sure.
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'd say remove it. I dont see any use of it in the codebase
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.
LGTM, super cool way of handling things. I left a couple of questions
return `${yamlError.name}: ${yamlError.reason} at line ${yamlError.line}`; | ||
}; | ||
|
||
export const agentOptionsToYaml = (agentOpts: any) => { |
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 there any chance of agentOpts
being undefined
or null
?
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.
Currently this was done (or meant to be done, I guess) at the callsite with the || {}
but you're right, maybe it should be done here inside this function instead.
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.
we dont have the best typing in some parts of the app atm. I'd look at where this code is used to determine if that's a possiblity.
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.
Added the check inside the func. Regarding the type, agent_options
is not strictly defined even on the backend, it can have arbitrary keys as those are passed to the osquery agent ultimately, so I left it as any
.
@@ -43,7 +43,7 @@ const AgentOptionsPage = ({ | |||
|
|||
if (selected) { | |||
setFormData({ | |||
osquery_options: yaml.dump(selected.agent_options), | |||
osquery_options: agentOptionsToYaml(selected.agent_options), |
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.
if yaml.dump
gracefully handles falsey values, I'd be inclined to just leave it like this. Otherwise yes, I vote to add the safety || {}
76f1e5f
to
a668bac
Compare
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.
FE bit looks good
frontend/utilities/helpers.ts
Outdated
@@ -200,6 +200,7 @@ export const formatConfigDataForServer = (config: any): any => { | |||
}; | |||
|
|||
// TODO: Finalize interface for config - see frontend\interfaces\config.ts | |||
// TODO(mna): this appears to be unused? |
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'd say remove it. I dont see any use of it in the codebase
return `${yamlError.name}: ${yamlError.reason} at line ${yamlError.line}`; | ||
}; | ||
|
||
export const agentOptionsToYaml = (agentOpts: any) => { |
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.
we dont have the best typing in some parts of the app atm. I'd look at where this code is used to determine if that's a possiblity.
a668bac
to
4ded49f
Compare
@gillespi314, could you please review these code changes? |
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.
Since there are no copy changes, I asked the on-call engineer to review the code.
#7377 (frontend portion)
NOTE: This builds on top of #7979 (contains commits of both). This one is for the frontend only, and to see the diff just for this PR, see here: mna-7377-agent-options-cliflags-2...mna-7377-agent-options-cliflags-3-frontend
Checklist for submitter
If some of the following don't apply, delete the relevant line.