-
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.
- Loading branch information
1 parent
a4b7e9c
commit 6d12d37
Showing
8 changed files
with
166 additions
and
6 deletions.
There are no files selected for viewing
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
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
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,28 @@ | ||
import React from 'react'; | ||
|
||
import ListView from '@components/ListView'; | ||
import ProviderLabel from '@components/ProviderLabel'; | ||
|
||
function HostInfoBox({ provider, agentVersion }) { | ||
return ( | ||
<div className="my-4 bg-white shadow rounded-lg px-8 py-4"> | ||
<ListView | ||
orientation="vertical" | ||
data={[ | ||
{ | ||
title: 'Provider', | ||
content: provider, | ||
render: (content) => <ProviderLabel provider={content} />, | ||
}, | ||
{ title: 'Agent version', content: agentVersion }, | ||
{ | ||
title: '', | ||
content: '', | ||
}, | ||
]} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
export default HostInfoBox; |
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,53 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import HostInfoBox from './HostInfoBox'; | ||
|
||
describe('Host Info Box', () => { | ||
const scenarios = [ | ||
{ | ||
agentVersion: '1.1.0+git.dev17.1660137228.fe5ba8a', | ||
provider: 'aws', | ||
providerText: 'AWS', | ||
}, | ||
{ | ||
agentVersion: '1.2.0+git.dev17.1660137228.fe5ba8a', | ||
provider: 'aws', | ||
providerText: 'AWS', | ||
}, | ||
{ | ||
agentVersion: '2.0.0+git.dev17.1660137228.fe5ba8a', | ||
provider: 'azure', | ||
providerText: 'Azure', | ||
}, | ||
{ | ||
agentVersion: '1.1.0', | ||
provider: 'gcp', | ||
providerText: 'GCP', | ||
}, | ||
{ | ||
agentVersion: '1.2.0', | ||
provider: 'kvm', | ||
providerText: 'KVM', | ||
}, | ||
{ | ||
agentVersion: '2.0.0', | ||
provider: 'vmware', | ||
providerText: 'VMware', | ||
}, | ||
{ | ||
agentVersion: '2.1.0', | ||
provider: 'nutanix', | ||
providerText: 'Nutanix', | ||
}, | ||
]; | ||
|
||
it.each(scenarios)( | ||
'should display host info box for $providerText', | ||
({ agentVersion, provider, providerText }) => { | ||
render(<HostInfoBox provider={provider} agentVersion={agentVersion} />); | ||
expect(screen.getByText(providerText)).toBeTruthy(); | ||
expect(screen.getByText(agentVersion)).toBeTruthy(); | ||
} | ||
); | ||
}); |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import HostDetails from './HostDetails'; | ||
import HostInfoBox from './HostInfoBox'; | ||
|
||
export { HostInfoBox }; | ||
export default HostDetails; |
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,74 @@ | ||
import React, { useEffect } from 'react'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { useParams } from 'react-router-dom'; | ||
|
||
import PageHeader from '@components/PageHeader'; | ||
import BackButton from '@components/BackButton'; | ||
import { HostInfoBox } from '@components/HostDetails'; | ||
|
||
import ChecksSelection from '@components/ChecksSelection/ChecksSelection'; | ||
|
||
import { updateCatalog } from '@state/actions/catalog'; | ||
import { getCatalog } from '@state/selectors/catalog'; | ||
import { getHost } from '@state/selectors'; | ||
|
||
function HostSettings() { | ||
const dispatch = useDispatch(); | ||
|
||
const { hostID } = useParams(); | ||
const host = useSelector(getHost(hostID)); | ||
|
||
const { | ||
data: catalog, | ||
error: catalogError, | ||
loading: catalogLoading, | ||
} = useSelector(getCatalog()); | ||
|
||
const catalogEnv = { | ||
provider: host?.provider, | ||
target_type: 'host', | ||
}; | ||
|
||
const onCatalogRefresh = () => { | ||
dispatch(updateCatalog(catalogEnv)); | ||
}; | ||
|
||
useEffect(() => { | ||
if (host) { | ||
onCatalogRefresh(); | ||
} | ||
}, [dispatch, host]); | ||
|
||
if (!host) { | ||
return <div>Loading...</div>; | ||
} | ||
|
||
return ( | ||
<div className="w-full px-2 sm:px-0"> | ||
<BackButton url={`/hosts/${hostID}`}>Back to Host Details</BackButton> | ||
<PageHeader> | ||
Check Settings for <span className="font-bold">{host?.hostname}</span> | ||
</PageHeader> | ||
<HostInfoBox provider={host.provider} agentVersion={host.agent_version} /> | ||
<ChecksSelection | ||
targetID={hostID} | ||
catalog={catalog} | ||
catalogError={catalogError} | ||
loading={catalogLoading} | ||
selected={host.selected_checks} | ||
onSave={(_selectedChecks, _hostID) => { | ||
// TODO: dispatch check selection for a host | ||
}} | ||
onUpdateCatalog={onCatalogRefresh} | ||
onClear={() => { | ||
// TODO: | ||
}} | ||
saving={false} | ||
error={null} | ||
success={false} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
export default HostSettings; |
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,3 @@ | ||
import HostSettings from './HostSettings'; | ||
|
||
export default HostSettings; |
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