-
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
Sid linking from clusters #1715
Changes from all commits
2e513c5
e86d2bf
5468011
93cf974
0f6ec93
029883f
205711b
4eecbeb
8e1eebb
f6133ba
3c67110
57ba6f2
89c76ed
557eaf2
e0c2723
49a8a1d
454ae81
bb46bcf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,13 @@ import Tags from '@components/Tags'; | |
import PageHeader from '@components/PageHeader'; | ||
import { addTagToCluster, removeTagFromCluster } from '@state/clusters'; | ||
import ClusterLink from '@components/ClusterLink'; | ||
import SapSystemLink from '@components/SapSystemLink'; | ||
import { ExecutionIcon } from '@components/ClusterDetails'; | ||
import { post, del } from '@lib/network'; | ||
import { useSearchParams } from 'react-router-dom'; | ||
import HealthSummary from '@components/HealthSummary/HealthSummary'; | ||
import { getCounters } from '@components/HealthSummary/summarySelection'; | ||
import { getAllSAPInstances } from '@state/selectors'; | ||
|
||
const getClusterTypeLabel = (type) => { | ||
switch (type) { | ||
|
@@ -24,6 +26,9 @@ const getClusterTypeLabel = (type) => { | |
} | ||
}; | ||
|
||
const getSapSystemBySID = (instances, sid) => | ||
instances.find((instance) => instance.sid === sid); | ||
|
||
const addTag = (tag, clusterId) => { | ||
post(`/clusters/${clusterId}/tags`, { | ||
value: tag, | ||
|
@@ -36,6 +41,7 @@ const removeTag = (tag, clusterId) => { | |
|
||
function ClustersList() { | ||
const clusters = useSelector((state) => state.clustersList.clusters); | ||
const allInstances = useSelector(getAllSAPInstances()); | ||
const dispatch = useDispatch(); | ||
const [searchParams, setSearchParams] = useSearchParams(); | ||
|
||
|
@@ -71,7 +77,24 @@ function ClustersList() { | |
filterFromParams: true, | ||
filter: (filter, key) => (element) => | ||
element[key].some((sid) => filter.includes(sid)), | ||
render: (_, { sid }) => sid.join(', '), | ||
render: (_, { sid, id }) => { | ||
const sidsArray = sid.map((singleSid, index) => { | ||
const sapSystemData = getSapSystemBySID(allInstances, singleSid); | ||
|
||
return [ | ||
index > 0 && ', ', | ||
<SapSystemLink | ||
key={`${id}-${singleSid}`} | ||
systemType={sapSystemData?.type} | ||
sapSystemId={sapSystemData?.sap_system_id} | ||
> | ||
{singleSid} | ||
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. What happens on multiple sids here? 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. 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. After speaking with @dottorblaster we decided it might look better if we add the coma back. @jagabomb wdyt? |
||
</SapSystemLink>, | ||
]; | ||
}); | ||
|
||
return sidsArray; | ||
}, | ||
}, | ||
{ | ||
title: 'Hosts', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import React from 'react'; | ||
import { EOS_WARNING_OUTLINED } from 'eos-icons-react'; | ||
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. Are we sure we want to change this component? 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. As I was looking how to add this I noticed that we have already a bunch of of *Link components that to basically very similar things. I'm leaning more towards keeping less components and add more when we need them. Wdyt? |
||
|
||
import Tooltip from '@components/Tooltip'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
function SapSystemLink({ systemType, sapSystemId, children }) { | ||
return sapSystemId ? ( | ||
return sapSystemId && systemType ? ( | ||
<Link | ||
key={sapSystemId} | ||
className="text-jungle-green-500 hover:opacity-75" | ||
|
@@ -12,7 +14,15 @@ function SapSystemLink({ systemType, sapSystemId, children }) { | |
{children} | ||
</Link> | ||
) : ( | ||
<span>{children}</span> | ||
<Tooltip content="SAP System currently not registered." place="bottom"> | ||
<span className="group flex items-center relative"> | ||
<EOS_WARNING_OUTLINED | ||
size="base" | ||
className="centered fill-yellow-500" | ||
/> | ||
<span className="ml-1 truncate max-w-[100px]">{children}</span> | ||
</span> | ||
</Tooltip> | ||
); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React from 'react'; | ||
import { act, screen, render } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import '@testing-library/jest-dom'; | ||
import { renderWithRouter } from '@lib/test-utils'; | ||
import { sapSystemFactory } from '@lib/test-utils/factories'; | ||
import SapSystemLink from '@components/SapSystemLink'; | ||
|
||
describe('SapSystemLink', () => { | ||
it('renders Link when sapSystemId and systemType are provided', () => { | ||
const { id, sid } = sapSystemFactory.build(); | ||
|
||
renderWithRouter( | ||
<SapSystemLink systemType="databases" sapSystemId={id}> | ||
{sid} | ||
</SapSystemLink> | ||
); | ||
|
||
const sapSystemLinkElement = screen.getByRole('link', { sid }); | ||
|
||
expect(sapSystemLinkElement).toBeInTheDocument(); | ||
expect(sapSystemLinkElement).toHaveAttribute('href', `/databases/${id}`); | ||
}); | ||
|
||
it('renders tooltip when sapSystemId or systemType are not provided', async () => { | ||
const user = userEvent.setup(); | ||
const { sid } = sapSystemFactory.build(); | ||
|
||
render(<SapSystemLink>{sid}</SapSystemLink>); | ||
|
||
const sidElement = screen.getByText(sid); | ||
|
||
await act(async () => user.hover(sidElement)); | ||
|
||
expect( | ||
screen.getByText('SAP System currently not registered.') | ||
).toBeInTheDocument(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { getAllSAPInstances } from '.'; | ||
|
||
describe('getAllSAPInstances selector', () => { | ||
it('should correctly merge and format applicationInstances and databaseInstances', () => { | ||
const state = { | ||
sapSystemsList: { | ||
applicationInstances: [ | ||
{ id: 1, name: 'APP1' }, | ||
{ id: 2, name: 'APP2' }, | ||
], | ||
databaseInstances: [ | ||
{ id: 3, name: 'DB1' }, | ||
{ id: 4, name: 'DB2' }, | ||
], | ||
}, | ||
}; | ||
|
||
const expectedOutput = [ | ||
{ id: 1, name: 'APP1', type: 'sap_systems' }, | ||
{ id: 2, name: 'APP2', type: 'sap_systems' }, | ||
{ id: 3, name: 'DB1', type: 'databases' }, | ||
{ id: 4, name: 'DB2', type: 'databases' }, | ||
]; | ||
|
||
expect(getAllSAPInstances()(state)).toEqual(expectedOutput); | ||
}); | ||
}); |
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.
map
ping and returning JSX elements should require a key prop to be passed, can you do that?