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

[Fleet] disable upgrade action when package does not have upgrade available #111510

Merged

Conversation

hop-dev
Copy link
Contributor

@hop-dev hop-dev commented Sep 8, 2021

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.

Screenshot 2021-09-08 at 11 28 51

Checklist

@hop-dev hop-dev added v8.0.0 release_note:skip Skip the PR/issue when compiling release notes Team:Fleet Team label for Observability Data Collection Fleet team auto-backport Deprecated - use backport:version if exact versions are needed v7.16.0 labels Sep 8, 2021
@hop-dev hop-dev self-assigned this Sep 8, 2021
@hop-dev hop-dev requested a review from a team as a code owner September 8, 2021 10:51
@elasticmachine
Copy link
Contributor

Pinging @elastic/fleet (Team:Fleet)

const hasUpgrade =
!!updatableIntegrationRecord &&
updatableIntegrationRecord.policiesToUpgrade.some(
({ id }) => id === packagePolicy.policy_id
({ pkgPolicyId }) => pkgPolicyId === packagePolicy.id
Copy link
Contributor Author

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

Copy link
Contributor

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?

Copy link
Contributor Author

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 =
Copy link
Contributor Author

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

Copy link
Member

@nchaulet nchaulet left a 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)

@hop-dev
Copy link
Contributor Author

hop-dev commented Sep 10, 2021

@elasticmachine merge upstream

@hop-dev hop-dev closed this Sep 10, 2021
@hop-dev hop-dev reopened this Sep 10, 2021
};
}

test('Should disable upgrade button if package does not have upgrade', async () => {
Copy link
Contributor Author

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,
Copy link
Contributor Author

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?

Copy link
Member

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"
Copy link
Contributor Author

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

@hop-dev hop-dev requested a review from nchaulet September 10, 2021 16:08
Copy link
Member

@nchaulet nchaulet left a comment

Choose a reason for hiding this comment

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

🚀

@hop-dev
Copy link
Contributor Author

hop-dev commented Sep 13, 2021

@elasticmachine merge upstream

@hop-dev hop-dev enabled auto-merge (squash) September 13, 2021 08:59
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
fleet 1020.5KB 1020.1KB -404.0B

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @hop-dev

@hop-dev hop-dev merged commit 3f82b29 into elastic:master Sep 13, 2021
kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Sep 13, 2021
…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]>
kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Sep 13, 2021
…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]>
@kibanamachine
Copy link
Contributor

💚 Backport successful

Status Branch Result
7.15
7.x

The backport PRs will be merged automatically after passing CI.

kibanamachine added a commit that referenced this pull request Sep 13, 2021
…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]>
kibanamachine added a commit that referenced this pull request Sep 13, 2021
…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]>
@amolnater-qasource
Copy link

Hi @EricDavisX
We are validating this PR in lieu of reported issue at #111318
We have revalidated this on 7.15.0 Snapshot and found it fixed now.

Observations:

  • Upgrade package policy button is greyed out on Upgraded integration under Integration>Policies page.

Screenshot:
7

Build details:
Build: 44016
Commit: 6e24618

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed release_note:skip Skip the PR/issue when compiling release notes Team:Fleet Team label for Observability Data Collection Fleet team v7.15.0 v7.16.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Fleet]: Upgrade package policy button not greyed out on Upgraded integration under Integration>Policies page.
7 participants