Skip to content

Commit

Permalink
Refactor naming
Browse files Browse the repository at this point in the history
  • Loading branch information
EMaksy committed Nov 7, 2024
1 parent d393f9f commit 9f7055a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function UpgradablePackagesList({
};

const sortByLatestPackage = createStringSortingPredicate(
'latest_package',
'latestPackage',
sortDirection
);

Expand All @@ -33,20 +33,20 @@ function UpgradablePackagesList({
columns: [
{
title: 'Installed Packages',
key: 'installed_package',
key: 'installedPackage',
render: (content, _) => <div className="font-bold">{content}</div>,
},
{
title: 'Latest Package',
key: 'latest_package',
key: 'latestPackage',
sortable: true,
sortDirection,
handleClick: () => toggleSortDirection(),
render: (content, _) => <div>{content}</div>,
},
{
title: 'Related Patches',
key: 'original_patches',
key: 'patches',
render: (content, { to_package_id }) => {
if (patchesLoading) {
return (
Expand Down
32 changes: 22 additions & 10 deletions assets/js/pages/UpgradablePackagesPage/UpgradablePackages.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,35 @@ export default function UpgradablePackages({
const { name, from_version, from_release, to_version, to_release, arch } =
packageDetails;
const patches = get(packageDetails, 'patches', []);
const advisories = patches.map(({ advisory }) => advisory).join(',');

return {
...packageDetails,
installed_package: `${name}-${from_version}-${from_release}.${arch}`,
latest_package: `${name}-${to_version}-${to_release}.${arch}`,
patches: advisories,
original_patches: patches,
installedPackage: `${name}-${from_version}-${from_release}.${arch}`,
latestPackage: `${name}-${to_version}-${to_release}.${arch}`,
patches,
};
});
const displayedPackages = enrichedPackages.filter(
({ name, original_patches }) =>

const filteredPackages = enrichedPackages.filter(
({ name, patches }) =>
containsSubstring(name, search) ||
original_patches
patches
.map(({ advisory }) => containsSubstring(advisory, search))
.includes(true)
);

const csvContent = enrichedPackages.map(
({ installedPackage, latestPackage, patches }) => {
const advisories = patches.map(({ advisory }) => advisory).join(',');

return {
installed_package: installedPackage,
latest_package: latestPackage,
patches: advisories,
};
}
);

useEffect(() => {
// Ensure to revoke previous scvUrls
if (csvURL) {
Expand All @@ -53,7 +65,7 @@ export default function UpgradablePackages({
Papa.unparse(
{
fields: ['installed_package', 'latest_package', 'patches'],
data: enrichedPackages,
data: csvContent,
},
{ header: true }
),
Expand Down Expand Up @@ -96,7 +108,7 @@ export default function UpgradablePackages({
</div>
<UpgradablePackagesList
patchesLoading={patchesLoading}
upgradablePackages={displayedPackages}
upgradablePackages={filteredPackages}
onPatchClick={onPatchClick}
onLoad={onLoad}
/>
Expand Down

0 comments on commit 9f7055a

Please sign in to comment.