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

Convert some components to functional components #3973

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion __tests__/src/components/AccessTokenSender.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { render } from 'test-utils';
import { AccessTokenSender } from '../../../src/components/AccessTokenSender';
import AccessTokenSender from '../../../src/components/AccessTokenSender';

/**
* Helper function to create a shallow wrapper around ErrorDialog
Expand Down
2 changes: 1 addition & 1 deletion __tests__/src/components/AnnotationSettings.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { render, screen } from 'test-utils';
import userEvent from '@testing-library/user-event';
import { AnnotationSettings } from '../../../src/components/AnnotationSettings';
import AnnotationSettings from '../../../src/components/AnnotationSettings';

/** */
function createWrapper(props) {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/src/components/App.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { render, screen } from 'test-utils';

import { App } from '../../../src/components/App';
import App from '../../../src/components/App';

/** */
function createWrapper(props) {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/src/components/Branding.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { render, screen, within } from 'test-utils';
import { Branding } from '../../../src/components/Branding';
import Branding from '../../../src/components/Branding';

describe('Branding', () => {
it('renders', () => {
Expand Down
60 changes: 20 additions & 40 deletions src/components/AccessTokenSender.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,28 @@
import { Component } from 'react';
import PropTypes from 'prop-types';
import { useCallback } from 'react';
import { IIIFIFrameCommunication } from './IIIFIFrameCommunication';
/* eslint-disable react/prop-types */

/**
* Opens a new window for click
*/
export class AccessTokenSender extends Component {
/** */
constructor(props) {
super(props);
export default function AccessTokenSender({ handleAccessTokenMessage, url }) {
const onReceiveAccessTokenMessage = useCallback((e) => {
if (e.data && e.data.messageId && e.data.messageId === url) {
handleAccessTokenMessage(e.data);
}
}, [handleAccessTokenMessage, url]);

this.onReceiveAccessTokenMessage = this.onReceiveAccessTokenMessage.bind(this);
}
if (!url) return null;

/** @private */
onReceiveAccessTokenMessage(e) {
const { handleAccessTokenMessage, url } = this.props;
if (e.data && e.data.messageId && e.data.messageId === url) handleAccessTokenMessage(e.data);
}

/** */
render() {
const { url } = this.props;
if (!url) return null;

/**
login, clickthrough/kiosk open @id, wait for close
external, no-op
*/
return (
<IIIFIFrameCommunication
src={`${url}?origin=${window.origin}&messageId=${url}`}
title="AccessTokenSender"
handleReceiveMessage={this.onReceiveAccessTokenMessage}
/>
);
}
/**
login, clickthrough/kiosk open @id, wait for close
external, no-op
*/
return (
<IIIFIFrameCommunication
src={`${url}?origin=${window.origin}&messageId=${url}`}
title="AccessTokenSender"
handleReceiveMessage={onReceiveAccessTokenMessage}
/>
);
}

AccessTokenSender.propTypes = {
handleAccessTokenMessage: PropTypes.func.isRequired,
url: PropTypes.string,
};

AccessTokenSender.defaultProps = {
url: undefined,
};
49 changes: 18 additions & 31 deletions src/components/AnnotationSettings.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,26 @@
import { Component } from 'react';
import PropTypes from 'prop-types';
import VisibilityIcon from '@mui/icons-material/VisibilitySharp';
import VisibilityOffIcon from '@mui/icons-material/VisibilityOffSharp';
import MiradorMenuButton from '../containers/MiradorMenuButton';
/* eslint-disable react/prop-types */

/**
* AnnotationSettings is a component to handle various annotation
* display settings in the Annotation companion window
*/
export class AnnotationSettings extends Component {
/**
* Returns the rendered component
*/
render() {
const {
displayAll, displayAllDisabled, t, toggleAnnotationDisplay,
} = this.props;

return (
<MiradorMenuButton
aria-label={t(displayAll ? 'displayNoAnnotations' : 'highlightAllAnnotations')}
onClick={toggleAnnotationDisplay}
disabled={displayAllDisabled}
size="small"
>
{ displayAll ? <VisibilityIcon /> : <VisibilityOffIcon /> }
</MiradorMenuButton>
);
}
*/
export default function AnnotationSettings({
displayAll,
displayAllDisabled,
t,
toggleAnnotationDisplay,
}) {
return (
<MiradorMenuButton
aria-label={t(displayAll ? 'displayNoAnnotations' : 'highlightAllAnnotations')}
onClick={toggleAnnotationDisplay}
disabled={displayAllDisabled}
size="small"
>
{displayAll ? <VisibilityIcon /> : <VisibilityOffIcon />}
</MiradorMenuButton>
);
}

AnnotationSettings.propTypes = {
displayAll: PropTypes.bool.isRequired,
displayAllDisabled: PropTypes.bool.isRequired,
t: PropTypes.func.isRequired,
toggleAnnotationDisplay: PropTypes.func.isRequired,
windowId: PropTypes.string.isRequired, // eslint-disable-line react/no-unused-prop-types
};
59 changes: 16 additions & 43 deletions src/components/App.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,29 @@
import {
createRef, Component, lazy, Suspense,
createRef, lazy, Suspense,
} from 'react';
import PropTypes from 'prop-types';
import PluginProvider from '../extend/PluginProvider';
import AppProviders from '../containers/AppProviders';
import WorkspaceContext from '../contexts/WorkspaceContext';

const WorkspaceArea = lazy(() => import('../containers/WorkspaceArea'));
/* eslint-disable react/prop-types */

/**
* This is the top level Mirador component.
* @prop {Object} manifests
*/
export class App extends Component {
/** */
constructor(props) {
super(props);

this.areaRef = createRef();
}

/**
* render
* @return {String} - HTML markup for the component
*/
render() {
const { dndManager, plugins } = this.props;

return (
<PluginProvider plugins={plugins}>
<AppProviders dndManager={dndManager}>
<WorkspaceContext.Provider value={this.areaRef}>
<Suspense
fallback={<div />}
>
<WorkspaceArea areaRef={this.areaRef} />
</Suspense>
</WorkspaceContext.Provider>
</AppProviders>
</PluginProvider>
);
}
export default function App({ dndManager, plugins = [] }) {
const areaRef = createRef();

return (
<PluginProvider plugins={plugins}>
<AppProviders dndManager={dndManager}>
<WorkspaceContext.Provider value={areaRef}>
<Suspense fallback={<div />}>
<WorkspaceArea areaRef={areaRef} />
</Suspense>
</WorkspaceContext.Provider>
</AppProviders>
</PluginProvider>
);
}

App.propTypes = {
dndManager: PropTypes.object, // eslint-disable-line react/forbid-prop-types
plugins: PropTypes.array, // eslint-disable-line react/forbid-prop-types
};

App.defaultProps = {
dndManager: undefined,
plugins: [],
};

export default App;
62 changes: 26 additions & 36 deletions src/components/Branding.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,37 @@
import { Component } from 'react';
import PropTypes from 'prop-types';
import IconButton from '@mui/material/IconButton';
import Typography from '@mui/material/Typography';
import Stack from '@mui/material/Stack';
import MiradorIcon from './icons/MiradorIcon';

/* eslint-disable react/prop-types */
/**
* Display a branding icon
*/
export class Branding extends Component {
/** */
render() {
const { t, variant, ...ContainerProps } = this.props;

return (
<Stack alignItems="center" {...ContainerProps}>
{ variant === 'wide' && (
export default function Branding({ t = (k) => k, variant = 'default', ...ContainerProps }) {
return (
<Stack alignItems="center" {...ContainerProps}>
{variant === 'wide' && (
<div>
<Typography align="center" component="p" variant="h3">{t('mirador')}</Typography>
<Typography align="center" component="p" variant="h3">
{t('mirador')}
</Typography>
</div>
)}
<Typography align="center">
<IconButton
component="a"
href="https://projectmirador.org"
target="_blank"
rel="noopener"
size="large"
>
<MiradorIcon aria-label={t('aboutMirador')} titleAccess={t('aboutMirador')} fontSize="large" />
</IconButton>
</Typography>
</Stack>
);
}
)}
<Typography align="center">
<IconButton
component="a"
href="https://projectmirador.org"
target="_blank"
rel="noopener"
size="large"
>
<MiradorIcon
aria-label={t('aboutMirador')}
titleAccess={t('aboutMirador')}
fontSize="large"
/>
</IconButton>
</Typography>
</Stack>
);
}

Branding.propTypes = {
t: PropTypes.func,
variant: PropTypes.oneOf(['default', 'wide']),
};

Branding.defaultProps = {
t: k => k,
variant: 'default',
};
2 changes: 1 addition & 1 deletion src/components/IIIFAuthentication.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component } from 'react';
import PropTypes from 'prop-types';
import { AccessTokenSender } from './AccessTokenSender';
import AccessTokenSender from './AccessTokenSender';
import { NewWindow } from './NewWindow';
import WindowAuthenticationBar from '../containers/WindowAuthenticationBar';

Expand Down
2 changes: 1 addition & 1 deletion src/containers/AnnotationSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
getAnnotationResourcesByMotivation,
getWindow,
} from '../state/selectors';
import { AnnotationSettings } from '../components/AnnotationSettings';
import AnnotationSettings from '../components/AnnotationSettings';

/**
* Mapping redux state to component props using connect
Expand Down
2 changes: 1 addition & 1 deletion src/containers/Branding.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { withPlugins } from '../extend/withPlugins';
import { Branding } from '../components/Branding';
import Branding from '../components/Branding';

export default withPlugins('Branding')(Branding);
Loading