-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add upgradable packages list component (#2636)
- Loading branch information
1 parent
8c30a04
commit 66cc9a7
Showing
4 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
assets/js/common/UpgradablePackagesList/UpgradablePackagesList.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React from 'react'; | ||
import Table from '@common/Table'; | ||
|
||
const upgradablePackagesDefault = []; | ||
|
||
function UpgradablePackagesList({ | ||
upgradablePackages = upgradablePackagesDefault, | ||
}) { | ||
const config = { | ||
pagination: true, | ||
usePadding: false, | ||
columns: [ | ||
{ | ||
title: 'Installed Packages', | ||
key: 'installedPackage', | ||
render: (content, _) => <div className="font-bold">{content}</div>, | ||
}, | ||
{ | ||
title: 'Latest Package', | ||
key: 'latestPackage', | ||
render: (content, _) => <div>{content}</div>, | ||
}, | ||
{ | ||
title: 'Related Patches', | ||
key: 'patches', | ||
render: (content, { to_package_id }) => ( | ||
<div> | ||
{content.map(({ advisory_name }) => ( | ||
<div key={`${to_package_id}-${advisory_name}`}> | ||
{advisory_name} | ||
</div> | ||
))} | ||
</div> | ||
), | ||
}, | ||
], | ||
}; | ||
|
||
const data = upgradablePackages.map((packageDetails) => { | ||
const { name, from_version, from_release, to_version, to_release, arch } = | ||
packageDetails; | ||
|
||
return { | ||
...packageDetails, | ||
installedPackage: `${name}-${from_version}-${from_release}.${arch}`, | ||
latestPackage: `${name}-${to_version}-${to_release}.${arch}`, | ||
}; | ||
}); | ||
|
||
return ( | ||
<div className="bg-white rounded-lg shadow"> | ||
<Table config={config} data={data} /> | ||
</div> | ||
); | ||
} | ||
|
||
export default UpgradablePackagesList; |
27 changes: 27 additions & 0 deletions
27
assets/js/common/UpgradablePackagesList/UpgradablePackagesList.stories.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { upgradablePackageFactory } from '@lib/test-utils/factories/upgradablePackage'; | ||
import UpgradablePackagesList from './UpgradablePackagesList'; | ||
|
||
export default { | ||
title: 'Components/UpgradablePackagesList', | ||
component: UpgradablePackagesList, | ||
argTypes: { | ||
hostname: { | ||
type: 'string', | ||
control: { type: 'text' }, | ||
description: 'The name of the host', | ||
}, | ||
upgradablePackages: { | ||
control: { | ||
type: 'array', | ||
}, | ||
description: 'List of upgradable packages', | ||
}, | ||
}, | ||
}; | ||
|
||
export const Default = { | ||
args: { | ||
hostname: 'Example Host', | ||
upgradablePackages: upgradablePackageFactory.buildList(4), | ||
}, | ||
}; |
23 changes: 23 additions & 0 deletions
23
assets/js/common/UpgradablePackagesList/UpgradablePackagesList.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import { upgradablePackageFactory } from '@lib/test-utils/factories/upgradablePackage'; | ||
import UpgradablePackagesList from './UpgradablePackagesList'; | ||
|
||
describe('UpgradablePackagesList component', () => { | ||
it('should render the upgradable packages list', () => { | ||
const upgradablePackage = upgradablePackageFactory.build(); | ||
const { patches } = upgradablePackage; | ||
|
||
const expectedInstalledPackage = `${upgradablePackage.name}-${upgradablePackage.from_version}-${upgradablePackage.from_release}.${upgradablePackage.arch}`; | ||
const expectedLatestPackage = `${upgradablePackage.name}-${upgradablePackage.to_version}-${upgradablePackage.to_release}.${upgradablePackage.arch}`; | ||
|
||
render(<UpgradablePackagesList upgradablePackages={[upgradablePackage]} />); | ||
|
||
expect(screen.getByText(expectedInstalledPackage)).toBeVisible(); | ||
expect(screen.getByText(expectedLatestPackage)).toBeVisible(); | ||
patches.forEach(({ advisory_name }) => { | ||
expect(screen.getByText(advisory_name)).toBeVisible(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { faker } from '@faker-js/faker'; | ||
import { Factory } from 'fishery'; | ||
import { relevantPatchFactory } from './relevantPatches'; | ||
|
||
const releaseVersionFactory = () => | ||
`${faker.number.int({ min: 100000, max: 160000 })}.${faker.system.semver()}`; | ||
|
||
export const upgradablePackageFactory = Factory.define(() => ({ | ||
from_epoch: faker.date.anytime(), | ||
to_release: releaseVersionFactory(), | ||
name: faker.company.buzzNoun(), | ||
from_release: releaseVersionFactory(), | ||
to_epoch: faker.date.anytime(), | ||
arch: faker.airline.flightNumber(), | ||
to_package_id: faker.number.int({ min: 2000, max: 5000 }), | ||
from_version: faker.system.semver(), | ||
to_version: faker.system.semver(), | ||
from_arch: faker.airline.flightNumber(), | ||
to_arch: faker.airline.flightNumber(), | ||
patches: relevantPatchFactory.buildList(2), | ||
})); |