From c5da6fb9ab5c58071a57a55616763d4324e1fc7a Mon Sep 17 00:00:00 2001 From: Frank <29271979+FrankyHollywood@users.noreply.github.com> Date: Wed, 20 Dec 2023 13:10:50 +0100 Subject: [PATCH 1/4] Dialog for metadata details --- .../src/metadata/common/LinkedDataLink.js | 61 +++++++++++++++---- 1 file changed, 49 insertions(+), 12 deletions(-) diff --git a/projects/mercury/src/metadata/common/LinkedDataLink.js b/projects/mercury/src/metadata/common/LinkedDataLink.js index d012092b16..da386846e1 100644 --- a/projects/mercury/src/metadata/common/LinkedDataLink.js +++ b/projects/mercury/src/metadata/common/LinkedDataLink.js @@ -1,28 +1,65 @@ +/* eslint-disable */ import React, {useContext} from 'react'; -import {Link as RouterLink} from "react-router-dom"; import * as PropTypes from "prop-types"; -import {Link} from '@mui/material'; -import {METADATA_PATH} from "../../constants"; +import {Box, Modal, Tooltip} from '@mui/material'; +import CloseIcon from '@mui/icons-material/Close'; +import LinkedDataEntityPage from "./LinkedDataEntityPage"; +import {MetadataWrapper} from '../LinkedDataWrapper'; import UserContext from '../../users/UserContext'; - /** * Renders a link to the metadata editor. * * @param props * @constructor */ + +const styleModalDialog = { + position: 'absolute', + top: '50%', + left: '50%', + transform: 'translate(-50%, -50%)', + width: 800, + bgcolor: 'background.paper', + border: '2px solid #000', + boxShadow: 24, + p: 4, +}; +const styleCloseButton = { + float: 'right' +} + +const getModal = (open, handleClose, uri) => ( + + + + + + + + + + +) + const LinkedDataLink = ({uri, children}) => { + const [open, setOpen] = React.useState(false); + const handleOpen = () => setOpen(true); + const handleClose = () => setOpen(false); + const {currentUser} = useContext(UserContext); if (currentUser && currentUser.canViewPublicMetadata) { return ( - - {children} - +
+
+ {children} +
+ {getModal(open, handleClose, uri)} +
); } return children; From 95d9e427e20b41afcf8abadbc3b9ee75826c3935 Mon Sep 17 00:00:00 2001 From: Frank <29271979+FrankyHollywood@users.noreply.github.com> Date: Wed, 20 Dec 2023 13:16:45 +0100 Subject: [PATCH 2/4] cleanup --- .../mercury/src/metadata/common/LinkedDataLink.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/projects/mercury/src/metadata/common/LinkedDataLink.js b/projects/mercury/src/metadata/common/LinkedDataLink.js index da386846e1..c2507b46b2 100644 --- a/projects/mercury/src/metadata/common/LinkedDataLink.js +++ b/projects/mercury/src/metadata/common/LinkedDataLink.js @@ -1,10 +1,8 @@ -/* eslint-disable */ import React, {useContext} from 'react'; import * as PropTypes from "prop-types"; import {Box, Modal, Tooltip} from '@mui/material'; import CloseIcon from '@mui/icons-material/Close'; import LinkedDataEntityPage from "./LinkedDataEntityPage"; -import {MetadataWrapper} from '../LinkedDataWrapper'; import UserContext from '../../users/UserContext'; /** * Renders a link to the metadata editor. @@ -26,7 +24,7 @@ const styleModalDialog = { }; const styleCloseButton = { float: 'right' -} +}; const getModal = (open, handleClose, uri) => ( ( > - + - - - + -) +); const LinkedDataLink = ({uri, children}) => { const [open, setOpen] = React.useState(false); From 7cdb27bcdcc9e5ab6a45147e88dca1ba77d9e5b2 Mon Sep 17 00:00:00 2001 From: Frank <29271979+FrankyHollywood@users.noreply.github.com> Date: Thu, 21 Dec 2023 10:50:56 +0100 Subject: [PATCH 3/4] small styling improvements --- .../src/metadata/common/LinkedDataLink.js | 34 +++++-------------- .../metadata/common/LinkedDataLink.styles.js | 22 ++++++++++++ 2 files changed, 31 insertions(+), 25 deletions(-) create mode 100644 projects/mercury/src/metadata/common/LinkedDataLink.styles.js diff --git a/projects/mercury/src/metadata/common/LinkedDataLink.js b/projects/mercury/src/metadata/common/LinkedDataLink.js index c2507b46b2..666755a409 100644 --- a/projects/mercury/src/metadata/common/LinkedDataLink.js +++ b/projects/mercury/src/metadata/common/LinkedDataLink.js @@ -1,48 +1,32 @@ import React, {useContext} from 'react'; import * as PropTypes from "prop-types"; import {Box, Modal, Tooltip} from '@mui/material'; +import withStyles from '@mui/styles/withStyles'; import CloseIcon from '@mui/icons-material/Close'; import LinkedDataEntityPage from "./LinkedDataEntityPage"; import UserContext from '../../users/UserContext'; +import styles from './LinkedDataLink.styles'; /** - * Renders a link to the metadata editor. - * - * @param props - * @constructor + * Renders a link to the metadata editor in a modal dialog when clicked. */ -const styleModalDialog = { - position: 'absolute', - top: '50%', - left: '50%', - transform: 'translate(-50%, -50%)', - width: 800, - bgcolor: 'background.paper', - border: '2px solid #000', - boxShadow: 24, - p: 4, -}; -const styleCloseButton = { - float: 'right' -}; - -const getModal = (open, handleClose, uri) => ( +const getModal = (classes, open, handleClose, uri) => ( - + - + ); -const LinkedDataLink = ({uri, children}) => { +const LinkedDataLink = ({classes, uri, children}) => { const [open, setOpen] = React.useState(false); const handleOpen = () => setOpen(true); const handleClose = () => setOpen(false); @@ -54,7 +38,7 @@ const LinkedDataLink = ({uri, children}) => {
{children}
- {getModal(open, handleClose, uri)} + {getModal(classes, open, handleClose, uri)} ); } @@ -66,4 +50,4 @@ LinkedDataLink.propTypes = { children: PropTypes.any.isRequired }; -export default LinkedDataLink; +export default withStyles(styles)(LinkedDataLink); diff --git a/projects/mercury/src/metadata/common/LinkedDataLink.styles.js b/projects/mercury/src/metadata/common/LinkedDataLink.styles.js new file mode 100644 index 0000000000..9dcdafdc2f --- /dev/null +++ b/projects/mercury/src/metadata/common/LinkedDataLink.styles.js @@ -0,0 +1,22 @@ +const styles = (theme) => ({ + styleModalDialog: { + background: theme.palette.grey['200'], + position: 'absolute', + top: '50%', + left: '50%', + transform: 'translate(-50%, -50%)', + width: 800, + bgcolor: 'background.paper', + border: '0px solid #000', + boxShadow: 0, + p: 4, + }, + styleCloseButton: { + float: 'right', + marginTop: 8, + marginRight: 8 + + } +}); + +export default styles; From 5cfda7ddbe45ef261d957f1001aa7a053d8a87d7 Mon Sep 17 00:00:00 2001 From: ewelinagr Date: Wed, 27 Dec 2023 10:48:01 +0100 Subject: [PATCH 4/4] Fix tests and styling of the linked data dialog. --- .../src/metadata/common/LinkedDataLink.js | 10 +-- .../metadata/common/LinkedDataLink.styles.js | 11 ++- .../common/__tests__/LinkedDataLink.js | 89 +++++++------------ 3 files changed, 44 insertions(+), 66 deletions(-) diff --git a/projects/mercury/src/metadata/common/LinkedDataLink.js b/projects/mercury/src/metadata/common/LinkedDataLink.js index 666755a409..68758cd033 100644 --- a/projects/mercury/src/metadata/common/LinkedDataLink.js +++ b/projects/mercury/src/metadata/common/LinkedDataLink.js @@ -10,16 +10,16 @@ import styles from './LinkedDataLink.styles'; * Renders a link to the metadata editor in a modal dialog when clicked. */ -const getModal = (classes, open, handleClose, uri) => ( +const renderModal = (classes, open, handleClose, uri) => ( - + - + @@ -35,10 +35,10 @@ const LinkedDataLink = ({classes, uri, children}) => { if (currentUser && currentUser.canViewPublicMetadata) { return (
-
+
{children}
- {getModal(classes, open, handleClose, uri)} + {renderModal(classes, open, handleClose, uri)}
); } diff --git a/projects/mercury/src/metadata/common/LinkedDataLink.styles.js b/projects/mercury/src/metadata/common/LinkedDataLink.styles.js index 9dcdafdc2f..e044c26eeb 100644 --- a/projects/mercury/src/metadata/common/LinkedDataLink.styles.js +++ b/projects/mercury/src/metadata/common/LinkedDataLink.styles.js @@ -1,5 +1,5 @@ const styles = (theme) => ({ - styleModalDialog: { + modalDialog: { background: theme.palette.grey['200'], position: 'absolute', top: '50%', @@ -9,13 +9,20 @@ const styles = (theme) => ({ bgcolor: 'background.paper', border: '0px solid #000', boxShadow: 0, + outline: "none", p: 4, }, - styleCloseButton: { + closeButton: { float: 'right', marginTop: 8, marginRight: 8 + }, + clickableDiv: { + 'cursor': 'pointer', + '&:hover': { + textDecoration: 'underline' + } } }); diff --git a/projects/mercury/src/metadata/common/__tests__/LinkedDataLink.js b/projects/mercury/src/metadata/common/__tests__/LinkedDataLink.js index 758cd7a740..e0675a18d6 100644 --- a/projects/mercury/src/metadata/common/__tests__/LinkedDataLink.js +++ b/projects/mercury/src/metadata/common/__tests__/LinkedDataLink.js @@ -1,88 +1,59 @@ /* eslint-disable jsx-a11y/anchor-has-content */ import React from 'react'; -import {configure, mount} from "enzyme"; +import {configure} from "enzyme"; import Adapter from "@wojtekmaj/enzyme-adapter-react-17"; - -import {Router} from 'react-router-dom'; // eslint-disable-next-line import/no-extraneous-dependencies -import {createMemoryHistory} from 'history'; import LinkedDataLink from "../LinkedDataLink"; -import {METADATA_PATH} from "../../../constants"; +import {fireEvent, render} from "@testing-library/react"; +import theme from "../../../App.theme"; +import {ThemeProvider} from "@mui/material/styles"; import UserContext from '../../../users/UserContext'; // Enzyme is obsolete, the Adapter allows running our old tests. // For new tests use React Testing Library. Consider migrating enzyme tests when refactoring. configure({adapter: new Adapter()}); +jest.mock('../LinkedDataEntityPage', () => () =>
Mocked Metadata Page
); describe('LinkedDataLink', () => { - it('should render internal link for any uri', () => { - const history: History = createMemoryHistory(); - history.push = jest.fn(); - - const wrapper = mount( + it('renders LinkedDataLink without crashing', () => { + const { getByText } = render( - - Go - + + Test Content + ); - - expect(wrapper.find('a').isEmpty()).toBeFalsy(); - const anchor = wrapper.find('a').first(); - const expectedLocation = `${METADATA_PATH}?iri=${encodeURIComponent("http://google.nl/some-path?search#hash")}`; - expect(anchor.prop('href')).toEqual(expectedLocation); - expect(anchor.text()).toEqual('Go'); - expect(anchor.prop('onClick')).toBeTruthy(); - - anchor.prop('onClick')(new MouseEvent('click')); - expect(history.push).toBeCalledTimes(1); - expect(history.push).toBeCalledWith({ - pathname: METADATA_PATH, - search: `?iri=${encodeURIComponent("http://google.nl/some-path?search#hash")}` - }); + expect(getByText('Test Content')).toBeInTheDocument(); }); - it('should display child elements for users without access to public metadata', () => { - const history: History = createMemoryHistory(); - history.push = jest.fn(); - - const wrapper = mount( - - - Go - + it('shows the modal when clicked', () => { + const { getByText, queryByText } = render( + + + Test Content + ); + expect(queryByText('Mocked Metadata Page')).not.toBeInTheDocument(); - expect(wrapper.find('a').isEmpty()).toBeTruthy(); - expect(wrapper.text()).toEqual('Go'); + fireEvent.click(getByText('Test Content')); + expect(getByText('Mocked Metadata Page')).toBeInTheDocument(); }); - it('should not break on an invalid url (return children only)', () => { - const uri = `some-invalid-url`; - const history: History = createMemoryHistory(); - history.push = jest.fn(); - - const wrapper = mount( + it('closes the modal when close icon is clicked', () => { + const { getByText, getByTestId, queryByText } = render( - - something - + + Test Content + ); - expect(wrapper.find('a').isEmpty()).toBeFalsy(); - const anchor = wrapper.find('a').first(); - const expectedLocation = `${METADATA_PATH}?iri=${encodeURIComponent(uri)}`; - expect(anchor.prop('href')).toEqual(expectedLocation); - expect(anchor.text()).toEqual('something'); - expect(anchor.prop('onClick')).toBeTruthy(); + fireEvent.click(getByText('Test Content')); + expect(getByText('Mocked Metadata Page')).toBeInTheDocument(); - anchor.prop('onClick')(new MouseEvent('click')); - expect(history.push).toBeCalledTimes(1); - expect(history.push).toBeCalledWith({ - pathname: METADATA_PATH, - search: `?iri=${encodeURIComponent(uri)}` - }); + const close = getByTestId('CloseIcon'); + fireEvent.click(close); + expect(queryByText('Mocked Metadata Page')).not.toBeInTheDocument(); }); });