diff --git a/assets/js/components/BackButton/BackButton.jsx b/assets/js/components/BackButton/BackButton.jsx new file mode 100644 index 0000000000..864dc4857f --- /dev/null +++ b/assets/js/components/BackButton/BackButton.jsx @@ -0,0 +1,26 @@ +import React from 'react'; +import Button from '@components/Button'; +import { useNavigate } from 'react-router-dom'; +import { EOS_ARROW_BACK } from 'eos-icons-react'; + +export const BackButton = ({ children, url }) => { + const navigate = useNavigate(); + + return ( +
+
+ +
+
+ ); +}; + +export default BackButton; diff --git a/assets/js/components/BackButton/BackButton.test.jsx b/assets/js/components/BackButton/BackButton.test.jsx new file mode 100644 index 0000000000..9d2358dc52 --- /dev/null +++ b/assets/js/components/BackButton/BackButton.test.jsx @@ -0,0 +1,21 @@ +import React from 'react'; +import { render, screen, fireEvent } from '@testing-library/react'; +import '@testing-library/jest-dom'; +import * as router from 'react-router'; + +import BackButton from './'; + +const navigate = jest.fn(); + +describe('BackButton', () => { + it('should display a back button with correct text and url', () => { + jest.spyOn(router, 'useNavigate').mockImplementation(() => navigate); + + render(Back to hell!); + const backButton = screen.getByRole('button'); + expect(backButton).toHaveTextContent('Back to hell!'); + + fireEvent.click(backButton); + expect(navigate).toHaveBeenCalledWith('/back/hell'); + }); +}); diff --git a/assets/js/components/BackButton/index.js b/assets/js/components/BackButton/index.js new file mode 100644 index 0000000000..e82a0f3eae --- /dev/null +++ b/assets/js/components/BackButton/index.js @@ -0,0 +1,3 @@ +import BackButton from './BackButton'; + +export default BackButton; diff --git a/assets/js/components/ClusterDetails/ChecksResults.jsx b/assets/js/components/ClusterDetails/ChecksResults.jsx index dda20c8e51..6a054e60b6 100644 --- a/assets/js/components/ClusterDetails/ChecksResults.jsx +++ b/assets/js/components/ClusterDetails/ChecksResults.jsx @@ -4,17 +4,14 @@ import { useSelector, useDispatch } from 'react-redux'; import Modal from '@components/Modal'; -import { - EOS_ERROR, - EOS_ARROW_BACK, - EOS_SETTINGS, - EOS_PLAY_CIRCLE, -} from 'eos-icons-react'; +import { EOS_ERROR, EOS_SETTINGS, EOS_PLAY_CIRCLE } from 'eos-icons-react'; import NotificationBox from '../NotificationBox'; import LoadingBox from '../LoadingBox'; import Button from '@components/Button'; +import BackButton from '@components/BackButton'; + import { getCluster } from '@state/selectors'; import TrentoLogo from '../../../static/trento-icon.png'; import { @@ -62,7 +59,6 @@ export const ChecksResults = () => { const [modalOpen, setModalOpen] = useState(false); const [selectedCheck, setSelectedCheck] = useState(''); const dispatch = useDispatch(); - const navigate = useNavigate(); const { clusterID } = useParams(); const cluster = useSelector(getCluster(clusterID)); const [hasAlreadyChecksResults, setHasAlreadyChecksResults] = useState(false); @@ -241,19 +237,9 @@ export const ChecksResults = () => { {findCheckDataByID(selectedCheck)?.remediation} -
-
- -
-
+ + Back to Cluster Details +

Checks Results for cluster{' '} diff --git a/assets/js/components/ClusterDetails/ClusterSettings.jsx b/assets/js/components/ClusterDetails/ClusterSettings.jsx index 79a201a548..64f6c558f3 100644 --- a/assets/js/components/ClusterDetails/ClusterSettings.jsx +++ b/assets/js/components/ClusterDetails/ClusterSettings.jsx @@ -1,14 +1,14 @@ import React from 'react'; import { useSelector } from 'react-redux'; -import { useParams, useNavigate } from 'react-router-dom'; +import { useParams } from 'react-router-dom'; -import { EOS_ARROW_BACK, EOS_CANCEL, EOS_PLAY_CIRCLE } from 'eos-icons-react'; -import Button from '@components/Button'; +import { EOS_CANCEL, EOS_PLAY_CIRCLE } from 'eos-icons-react'; import classNames from 'classnames'; +import BackButton from '@components/BackButton'; import { Tab } from '@headlessui/react'; -import { ChecksSelection } from './ChecksSelection'; -import { ConnectionSettings } from './ConnectionSettings'; +import { ChecksSelection } from '@components/ClusterDetails/ChecksSelection'; +import { ConnectionSettings } from '@components/ClusterDetails/ConnectionSettings'; import { getCluster } from '@state/selectors'; import { TriggerChecksExecutionRequest, @@ -18,7 +18,6 @@ import { getClusterName } from '@components/ClusterLink'; export const ClusterSettings = () => { const { clusterID } = useParams(); - const navigate = useNavigate(); const cluster = useSelector(getCluster(clusterID)); @@ -33,6 +32,9 @@ export const ClusterSettings = () => { return (
+ + Back to Cluster Details +

Cluster Settings for{' '} @@ -40,16 +42,6 @@ export const ClusterSettings = () => { {getClusterName(cluster)}

-
- -