-
Notifications
You must be signed in to change notification settings - Fork 15
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
Display cluster details by type #1456
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
98cfe7d
Update ClusterLink for ascs/ers cluster types
arbulu89 8100907
Rename ClusterDetails to HanaClusterDetails
arbulu89 2e20f3f
Choose between details view depending on the type
arbulu89 7156d14
Add basic test to see correct cluster type is used
arbulu89 bffa688
Update HANA storybook story to match changes
arbulu89 4054af5
Move cluster types constant to model lib
arbulu89 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,17 +2,13 @@ import React, { useEffect } from 'react'; | |
import { useNavigate, useParams } from 'react-router-dom'; | ||
import { useSelector, useDispatch } from 'react-redux'; | ||
|
||
import { | ||
getCluster, | ||
getClusterHosts, | ||
getClusterHostIDs, | ||
} from '@state/selectors/cluster'; | ||
import { getCluster, getClusterHosts } from '@state/selectors/cluster'; | ||
import { | ||
updateLastExecution, | ||
executionRequested, | ||
} from '@state/actions/lastExecutions'; | ||
import { getLastExecution } from '@state/selectors/lastExecutions'; | ||
import ClusterDetails from './ClusterDetails'; | ||
import HanaClusterDetails from './HanaClusterDetails'; | ||
import { getClusterName } from '../ClusterLink'; | ||
|
||
export function ClusterDetailsPage() { | ||
|
@@ -23,7 +19,6 @@ export function ClusterDetailsPage() { | |
|
||
const dispatch = useDispatch(); | ||
const lastExecution = useSelector(getLastExecution(clusterID)); | ||
const hosts = useSelector(getClusterHostIDs(clusterID)); | ||
useEffect(() => { | ||
dispatch(updateLastExecution(clusterID)); | ||
}, [dispatch]); | ||
|
@@ -34,33 +29,35 @@ export function ClusterDetailsPage() { | |
return <div>Loading...</div>; | ||
} | ||
|
||
const renderedNodes = cluster.details?.nodes?.map((node) => ({ | ||
...node, | ||
...clusterHosts.find(({ hostname }) => hostname === node.name), | ||
})); | ||
|
||
const hasSelectedChecks = cluster.selected_checks.length > 0; | ||
|
||
return ( | ||
<ClusterDetails | ||
clusterID={clusterID} | ||
clusterName={getClusterName(cluster)} | ||
selectedChecks={cluster.selected_checks} | ||
hasSelectedChecks={hasSelectedChecks} | ||
hosts={hosts} | ||
clusterType={cluster.type} | ||
cibLastWritten={cluster.cib_last_written} | ||
sid={cluster.sid} | ||
provider={cluster.provider} | ||
clusterNodes={renderedNodes} | ||
details={cluster.details} | ||
lastExecution={lastExecution} | ||
onStartExecution={(_, hostList, checks, navigateFunction) => | ||
dispatch( | ||
executionRequested(clusterID, hostList, checks, navigateFunction) | ||
) | ||
} | ||
navigate={navigate} | ||
/> | ||
); | ||
switch (cluster.type) { | ||
case 'hana_scale_up': | ||
case 'hana_scale_out': | ||
return ( | ||
<HanaClusterDetails | ||
clusterID={clusterID} | ||
clusterName={getClusterName(cluster)} | ||
selectedChecks={cluster.selected_checks} | ||
hasSelectedChecks={hasSelectedChecks} | ||
hosts={clusterHosts} | ||
clusterType={cluster.type} | ||
cibLastWritten={cluster.cib_last_written} | ||
sid={cluster.sid} | ||
provider={cluster.provider} | ||
details={cluster.details} | ||
lastExecution={lastExecution} | ||
onStartExecution={(_, hostList, checks, navigateFunction) => | ||
dispatch( | ||
executionRequested(clusterID, hostList, checks, navigateFunction) | ||
) | ||
} | ||
navigate={navigate} | ||
/> | ||
); | ||
case 'ascs_ers': | ||
return <div>ASCS/ERS</div>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Simple placeholder by now. I will have the |
||
default: | ||
return <div>Unknown cluster type</div>; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
assets/js/components/ClusterDetails/ClusterDetailsPage.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,41 @@ | ||
import React from 'react'; | ||
|
||
import { screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import { withState, renderWithRouterMatch } from '@lib/test-utils'; | ||
|
||
import { clusterFactory } from '@lib/test-utils/factories'; | ||
|
||
import { ClusterDetailsPage } from './ClusterDetailsPage'; | ||
|
||
describe('ClusterDetails ClusterDetailsPage component', () => { | ||
it.each([ | ||
{ type: 'hana_scale_up', label: 'HANA scale-up' }, | ||
{ type: 'ascs_ers', label: 'ASCS/ERS' }, | ||
{ type: 'unknwon', label: 'Unknown cluster type' }, | ||
])( | ||
'should display the $type details based on cluster type', | ||
({ type, label }) => { | ||
const cluster = clusterFactory.build({ type }); | ||
const initialState = { | ||
clustersList: { clusters: [cluster] }, | ||
hostsList: { hosts: [] }, | ||
lastExecutions: { | ||
[cluster.id]: { data: null, loading: false, error: null }, | ||
}, | ||
}; | ||
|
||
const [statefulClusterDetailsPage, _] = withState( | ||
<ClusterDetailsPage />, | ||
initialState | ||
); | ||
|
||
renderWithRouterMatch(statefulClusterDetailsPage, { | ||
path: 'clusters/:clusterID', | ||
route: `/clusters/${cluster.id}`, | ||
}); | ||
|
||
expect(screen.getByText(label)).toBeInTheDocument(); | ||
} | ||
); | ||
}); |
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
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,42 @@ | ||
import React from 'react'; | ||
|
||
import { screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import { renderWithRouter } from '@lib/test-utils'; | ||
|
||
import { clusterFactory } from '@lib/test-utils/factories'; | ||
|
||
import ClusterLink from './ClusterLink'; | ||
|
||
describe('ClusterLink component', () => { | ||
it.each(['hana_scale_up', 'hana_scale_out', 'ascs_ers'])( | ||
'should render a link if the cluster type is %s', | ||
(type) => { | ||
const cluster = clusterFactory.build({ type }); | ||
|
||
renderWithRouter(<ClusterLink cluster={cluster} />); | ||
|
||
const link = screen.getByRole('link'); | ||
|
||
expect(link).toHaveTextContent(cluster.name); | ||
expect(link).toHaveAttribute('href', `/clusters/${cluster.id}`); | ||
} | ||
); | ||
|
||
it('should show a simple text if the cluster type is unknown', () => { | ||
const cluster = clusterFactory.build({ type: 'unknown' }); | ||
|
||
renderWithRouter(<ClusterLink cluster={cluster} />); | ||
|
||
expect(screen.queryByRole('link')).not.toBeInTheDocument(); | ||
expect(screen.getByText(cluster.name)).toBeInTheDocument(); | ||
}); | ||
|
||
it('should show the cluster ID if the name is not available', () => { | ||
const cluster = clusterFactory.build({ name: '' }); | ||
|
||
renderWithRouter(<ClusterLink cluster={cluster} />); | ||
|
||
expect(screen.getByText(cluster.id)).toBeInTheDocument(); | ||
}); | ||
}); |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving this to the
HanaClusterDetails
view, as it depends on thedetails
format, which in this case is HANA related.ASCS/ERS
clusters have other details, so better to do the enrichment specifically for each type