-
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
[Fleet] disable upgrade action when package does not have upgrade available #111510
[Fleet] disable upgrade action when package does not have upgrade available #111510
Conversation
Pinging @elastic/fleet (Team:Fleet) |
const hasUpgrade = | ||
!!updatableIntegrationRecord && | ||
updatableIntegrationRecord.policiesToUpgrade.some( | ||
({ id }) => id === packagePolicy.policy_id | ||
({ pkgPolicyId }) => pkgPolicyId === packagePolicy.id |
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 is line is the fix to disable the button
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.
So policy_id was an incorrect field?
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, updatableIntegration.policiesToUpgrade contains information about the agent policy (Default policy in this case) and the package policy (which has an upgrade available), where id
is the ID of the agent policy and pkgPolicyId
is the ID of the package policy.
Previously we were incorrectly comparing the agent policy IDs so every package policy in an agent policy would show as needing to upgrade. I have changed it so that we compare the package policy ID so that only the out of date packages show as needing an upgrade.
packagePolicy.package?.name ?? '' | ||
); | ||
|
||
const hasUpgrade = |
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.
InMemoryPackagePolicy has a hasUpgrade property so we don't need to duplicate the logic here
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.
🚀 Do you think it will make sense to write a test here? (something like rendering the menu with different scenarios)
@elasticmachine merge upstream |
…-disabled' into bugfix-111318-upgrade-button-not-disabled
}; | ||
} | ||
|
||
test('Should disable upgrade button if package does not have upgrade', async () => { |
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.
@nchaulet these test were much simpler to write :D
viewDataStep, | ||
showAddAgent, | ||
upgradePackagePolicyHref, | ||
isOpen = 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.
I have added this isOpen prop to aid testing, I could've fired a click event but I didn't think it was unreasonable for the component to have this prop?
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.
@hop-dev nitpick what do you think of naming this defaultIsOpen
as the way I saw it it's the default value for the state correct?
@@ -84,6 +92,7 @@ export const PackagePolicyActionsMenu: React.FunctionComponent<{ | |||
disabled={!packagePolicy.hasUpgrade} | |||
icon="refresh" | |||
href={upgradePackagePolicyHref} | |||
key="packagePolicyUpgrade" |
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 warning was being logged because this menu item didn't have a key
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.
🚀
@elasticmachine merge upstream |
💚 Build Succeeded
Metrics [docs]Async chunks
History
To update your PR or re-run it, just comment with: cc @hop-dev |
…ilable (elastic#111510) * fix: consolidate hasUpgrade logic * tidy: move type defs to top of file * test: add unit tests for actions menu * tidy: PR feedback Co-authored-by: Kibana Machine <[email protected]>
…ilable (elastic#111510) * fix: consolidate hasUpgrade logic * tidy: move type defs to top of file * test: add unit tests for actions menu * tidy: PR feedback Co-authored-by: Kibana Machine <[email protected]>
…ilable (#111510) (#111940) * fix: consolidate hasUpgrade logic * tidy: move type defs to top of file * test: add unit tests for actions menu * tidy: PR feedback Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Mark Hopkin <[email protected]>
…ade available (#111510) (#111939) * [Fleet] disable upgrade action when package does not have upgrade available (#111510) * fix: consolidate hasUpgrade logic * tidy: move type defs to top of file * test: add unit tests for actions menu * tidy: PR feedback Co-authored-by: Kibana Machine <[email protected]> * test: fix tests to match 7.15 UI Co-authored-by: Mark Hopkin <[email protected]>
Hi @EricDavisX Observations:
Build details: Thanks |
Summary
Fixes #111318
The upgrade package policy action was not disabled for the latest version of a package.
I had missed this when solving a previous issue in this area because the
hasUpgrade
logic was duplicated in this component, I have now consolidated this logic.Checklist