Skip to content

Commit

Permalink
use filter instead of reduce
Browse files Browse the repository at this point in the history
  • Loading branch information
neptunian committed Apr 30, 2020
1 parent 15001d4 commit 03d0735
Showing 1 changed file with 4 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,9 @@ function InstalledPackages() {
? allPackages.response.filter(pkg => pkg.status === 'installed')
: [];

const updatablePackages = allInstalledPackages.reduce<PackageListItem[]>((acc, item) => {
if ('savedObject' in item) {
if (item.version > item.savedObject.attributes.version) {
return acc.concat(item);
}
}
return acc;
}, []);

const packages =
selectedCategory === 'updates_available' ? [...updatablePackages] : [...allInstalledPackages];
const updatablePackages = allInstalledPackages.filter(
item => 'savedObject' in item && item.version > item.savedObject.attributes.version
);

const categories = [
{
Expand Down Expand Up @@ -119,7 +111,7 @@ function InstalledPackages() {
isLoading={isLoadingPackages}
controls={controls}
title={title}
list={packages}
list={selectedCategory === 'updates_available' ? updatablePackages : allInstalledPackages}
/>
);
}
Expand Down

0 comments on commit 03d0735

Please sign in to comment.