Skip to content
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

Merged
merged 18 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion assets/js/components/ClustersList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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';
Expand All @@ -24,6 +25,26 @@ const getClusterTypeLabel = (type) => {
}
};

const getSapSystemLinkBySID = (
applicationInstances,
databaseInstances,
sid
) => {
const foundInstance = applicationInstances
rtorrero marked this conversation as resolved.
Show resolved Hide resolved
.map((instance) => ({ ...instance, type: 'sap_systems' }))
.concat(
databaseInstances.map((instance) => ({
...instance,
type: 'databases',
}))
)
.find((instance) => instance.sid === sid);

return foundInstance
? { sap_system_id: foundInstance.sap_system_id, type: foundInstance.type }
: null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can directly return foundInstance without any fuss

};

const addTag = (tag, clusterId) => {
post(`/clusters/${clusterId}/tags`, {
value: tag,
Expand All @@ -36,6 +57,9 @@ const removeTag = (tag, clusterId) => {

function ClustersList() {
const clusters = useSelector((state) => state.clustersList.clusters);
const { applicationInstances, databaseInstances } = useSelector(
(state) => state.sapSystemsList
);
const dispatch = useDispatch();
const [searchParams, setSearchParams] = useSearchParams();

Expand Down Expand Up @@ -71,7 +95,23 @@ function ClustersList() {
filterFromParams: true,
filter: (filter, key) => (element) =>
element[key].some((sid) => filter.includes(sid)),
render: (_, { sid }) => sid.join(', '),
render: (_, { sid }) =>
sid.map((singleSid) => {
const linkData = getSapSystemLinkBySID(
applicationInstances,
databaseInstances,
singleSid
);

return (
<SapSystemLink
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mapping and returning JSX elements should require a key prop to be passed, can you do that?

systemType={linkData ? linkData.type : null}
sapSystemId={linkData ? linkData.sap_system_id : null}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use lodash's get function to get type and sap_system_id out of linkData

>
{singleSid}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens on multiple sids here?
Are they separated by spaces?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've used the tests to render how it would look like:

Captura desde 2023-08-21 13-40-38

Captura desde 2023-08-21 13-50-23

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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?
Captura desde 2023-08-21 15-37-22

</SapSystemLink>
);
}),
},
{
title: 'Hosts',
Expand Down
3 changes: 2 additions & 1 deletion assets/js/components/ClustersList.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ describe('ClustersList component', () => {

renderWithRouter(StatefulClustersList);

expect(screen.getByText('HA1, HA2')).toBeVisible();
expect(screen.getByText('HA1')).toBeVisible();
expect(screen.getByText('HA2')).toBeVisible();
rtorrero marked this conversation as resolved.
Show resolved Hide resolved
});

it('should put the filters values in the query string when filters are selected', () => {
Expand Down
14 changes: 12 additions & 2 deletions assets/js/components/SapSystemLink.jsx
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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure we want to change this component?
In the past, for this exact feature (adding a not registered tooltip to the link) we have created a new component, to not change the behaviour of this one (ClusterNodeLink).
Maybe we should follow the same pattern

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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"
Expand All @@ -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>
);
}

Expand Down
35 changes: 35 additions & 0 deletions assets/js/components/SapSystemLink.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react';
import { screen, render, fireEvent } from '@testing-library/react';
rtorrero marked this conversation as resolved.
Show resolved Hide resolved
import '@testing-library/jest-dom';
import { renderWithRouter } from '@lib/test-utils';
import SapSystemLink from '@components/SapSystemLink';
rtorrero marked this conversation as resolved.
Show resolved Hide resolved
import { sapSystemFactory } from '@lib/test-utils/factories';

describe('SapSystemLink', () => {
it('renders Link when sapSystemId and systemType is provided', () => {
rtorrero marked this conversation as resolved.
Show resolved Hide resolved
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 warning span when sapSystemId or systemType are not provided', () => {
rtorrero marked this conversation as resolved.
Show resolved Hide resolved
const { sid } = sapSystemFactory.build();

render(<SapSystemLink>{sid}</SapSystemLink>);

const sidElement = screen.getByText(sid);
fireEvent.mouseOver(sidElement);
expect(
screen.getByText('SAP System currently not registered.')
).toBeInTheDocument();
});
});