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

feat(events-v2) Improve scrolling for event modal #13710

Merged
merged 2 commits into from
Jun 17, 2019
Merged
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
140 changes: 140 additions & 0 deletions src/sentry/static/sentry/app/components/modalDialog.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import React from 'react';
import styled from 'react-emotion';
import PropTypes from 'prop-types';

import InlineSvg from 'app/components/inlineSvg';
import space from 'app/styles/space';
import {callIfFunction} from 'app/utils/callIfFunction';

/**
* Simple/Naive implementation of a dialog/modal window.
*
* The API this component exposes is intentionally compatible with
* reach-ui/dialog as in the near future we should replace this component
* with that library. This implementation doesn't handle
* focus-lock and has poorer accessibility support.
*/
class ModalDialog extends React.Component {
static propTypes = {
/**
* Function that returns the close button element
* will be passed an object of options with `handleDismiss`
* event handler for closing the modal
*/
dismissButton: PropTypes.func,

/**
* Callback invoked when the modal is closed if set.
*/
onDismiss: PropTypes.func.isRequired,

/**
* Whether or not the modal should display open.
*/
isOpen: PropTypes.bool,

className: PropTypes.string,
};

static defaultProps = {
isOpen: true,
};

handleClose = event => {
event.preventDefault();
callIfFunction(this.props.onDismiss);
};

renderDismiss() {
const {dismissButton} = this.props;
if (dismissButton) {
return dismissButton({handleDismiss: this.handleClose});
}
return <DismissButton onClick={this.handleClose} size={30} />;
}

render() {
const {isOpen, children, className} = this.props;

if (!isOpen) {
return null;
}

return (
<ModalScrollTrap>
<ModalOverlay />
<ModalContainer aria-modal="true" className={className}>
{this.renderDismiss()}
{children}
</ModalContainer>
</ModalScrollTrap>
);
}
}

const ModalOverlay = styled('div')`
position: fixed;
top: 0px;
left: 0px;
right: 0px;
bottom: 0px;
background: ${p => p.theme.foreground};
opacity: 0.5;
z-index: ${p => p.theme.zIndex.modal};
`;

const ModalScrollTrap = styled('div')`
position: fixed;
top: 0px;
left: 0px;
right: 0px;
bottom: 0px;
overflow-x: hidden;
overflow-y: auto;
z-index: ${p => p.theme.zIndex.modal};
`;

// Define some basic styling. Each modal usage
// can pass a className prop with more styles.
const ModalContainer = styled('div')`
position: absolute;
background: #fff;

margin: ${space(3)};
padding: ${space(3)};

border: 1px solid ${p => p.theme.borderLight};
border-radius: ${p => p.theme.borderRadius};
box-shadow: ${p => p.theme.dropShadowHeavy};

z-index: ${p => p.theme.zIndex.modal};
`;

const CircleButton = styled('button')`
Copy link
Member

Choose a reason for hiding this comment

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

Should this be a generic component? Should it extend app/components/Button?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do we have more places we need circle buttons? I think the extension and general component would make sense if we had more places to use it. Another approach could be to have a shape property on button that accepts rect and circle.

background: #fff;
border-radius: ${p => p.size / 2}px;
padding: ${p => p.size / 4}px;
line-height: ${p => p.size * 0.4}px;
height: ${p => p.size}px;
box-shadow: ${p => p.theme.dropShadowLight};
border: 1px solid ${p => p.theme.borderDark};

position: absolute;
top: -${p => p.size / 2}px;
right: -${p => p.size / 2}px;
`;

const DismissButton = props => {
const iconSize = props.size * 0.4;
return (
<CircleButton size={props.size} onClick={props.onClick}>
<InlineSvg src="icon-close" size={`${iconSize}px`} />
</CircleButton>
);
};
DismissButton.propTypes = {
onClick: PropTypes.func,
size: PropTypes.number.isRequired,
};

export default ModalDialog;
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React from 'react';
import styled from 'react-emotion';
import {browserHistory} from 'react-router';
import PropTypes from 'prop-types';
import {omit} from 'lodash';
import {css} from 'react-emotion';

import SentryTypes from 'app/sentryTypes';
import AsyncComponent from 'app/components/asyncComponent';
import InlineSvg from 'app/components/inlineSvg';
import ModalDialog from 'app/components/modalDialog';
import withApi from 'app/utils/withApi';
import theme from 'app/utils/theme';
import space from 'app/styles/space';

import EventModalContent from './eventModalContent';
Expand All @@ -26,6 +27,19 @@ const slugValidator = function(props, propName, componentName) {
return null;
};

const modalStyles = css`
top: 0px;
left: 0px;
right: 0px;

margin: ${space(3)};
padding: ${space(3)};

@media (max-width: ${theme.breakpoints[1]}) {
margin: ${space(2)};
}
`;

class EventDetails extends AsyncComponent {
static propTypes = {
organization: SentryTypes.Organization.isRequired,
Expand Down Expand Up @@ -73,8 +87,7 @@ class EventDetails extends AsyncComponent {
];
}

handleClose = event => {
event.preventDefault();
onDismiss = () => {
const {location} = this.props;
// Remove modal related query parameters.
const query = omit(location.query, ['groupSlug', 'eventSlug']);
Expand All @@ -97,23 +110,12 @@ class EventDetails extends AsyncComponent {
throw new Error('Could not determine projectId');
}

componentDidMount() {
this.restoreOverflow = document.body.style.overflow;

document.body.style.overflow = 'hidden';
}

componentWillUnmount() {
document.body.style.overflow = this.restoreOverflow;
}

renderBody() {
const {organization, view, location} = this.props;
const {event} = this.state;

return (
<ModalContainer>
<CloseButton onClick={this.handleClose} size={30} />
<ModalDialog onDismiss={this.onDismiss} className={modalStyles}>
<EventModalContent
onTabChange={this.handleTabChange}
event={event}
Expand All @@ -122,67 +124,13 @@ class EventDetails extends AsyncComponent {
view={view}
location={location}
/>
</ModalContainer>
</ModalDialog>
);
}

renderLoading() {
return (
<ModalContainer>
<CloseButton onClick={this.handleClose} size={30} />
{super.renderLoading()}
</ModalContainer>
);
return <ModalDialog className={modalStyles}>{super.renderLoading()}</ModalDialog>;
}
}

const ModalContainer = styled('div')`
position: fixed;
top: 0px;
left: 0px;
right: 0px;
bottom: 0px;
background: #fff;

margin: ${space(3)};
padding: ${space(3)};

border: 1px solid ${p => p.theme.borderLight};
border-radius: ${p => p.theme.borderRadius};
box-shadow: ${p => p.theme.dropShadowHeavy};

z-index: ${p => p.theme.zIndex.modal};

@media (max-width: ${p => p.theme.breakpoints[1]}) {
margin: ${space(2)};
}
`;

const CircleButton = styled('button')`
background: #fff;
border-radius: ${p => p.size / 2}px;
padding: ${p => p.size / 4}px;
line-height: ${p => p.size * 0.4}px;
height: ${p => p.size}px;
box-shadow: ${p => p.theme.dropShadowLight};
border: 1px solid ${p => p.theme.borderDark};

position: absolute;
top: -${p => p.size / 2}px;
right: -${p => p.size / 2}px;
`;

const CloseButton = props => {
const iconSize = props.size * 0.4;
return (
<CircleButton size={props.size} onClick={props.onClick}>
<InlineSvg src="icon-close" size={`${iconSize}px`} />
</CircleButton>
);
};
CloseButton.propTypes = {
onClick: PropTypes.func,
size: PropTypes.number.isRequired,
};

export default withApi(EventDetails);
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ EventMetadata.propTypes = {
};

const OverflowHeader = styled('h2')`
line-height: 1.2;
${overflowEllipsis}
`;

Expand All @@ -121,8 +122,6 @@ const MetadataContainer = styled('div')`

const ColumnGrid = styled('div')`
display: grid;
max-height: 100%;
overflow: auto;

grid-template-columns: 70% 28%;
grid-template-rows: auto;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ describe('OrganizationEventsV2 > EventDetails', function() {
/>,
TestStubs.routerContext()
);
const button = wrapper.find('CloseButton');
const button = wrapper.find('DismissButton');
button.simulate('click');
expect(browserHistory.push).toHaveBeenCalledWith({
pathname: '/organizations/org-slug/events/',
Expand All @@ -163,7 +163,7 @@ describe('OrganizationEventsV2 > EventDetails', function() {
/>,
TestStubs.routerContext()
);
const button = wrapper.find('CloseButton');
const button = wrapper.find('DismissButton');
button.simulate('click');
expect(browserHistory.push).toHaveBeenCalledWith({
pathname: '/organizations/org-slug/events/',
Expand Down