12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- import React from 'react';
- import styled from '@emotion/styled';
- import {Location} from 'history';
- import PropTypes from 'prop-types';
- import space from 'app/styles/space';
- import {Organization, Project} from 'app/types';
- import withLatestContext from 'app/utils/withLatestContext';
- import ScrollToTop from 'app/views/settings/components/scrollToTop';
- type Props = {
- location: Location;
- organization?: Organization;
- project?: Project;
- };
- type State = {
- lastAppContext: 'project' | 'organization' | null;
- };
- class SettingsWrapper extends React.Component<Props, State> {
- static childContextTypes = {
- lastAppContext: PropTypes.oneOf(['project', 'organization']),
- };
- // save current context
- state: State = {
- lastAppContext: this.getLastAppContext(),
- };
- getChildContext() {
- return {
- lastAppContext: this.state.lastAppContext,
- };
- }
- getLastAppContext() {
- const {project, organization} = this.props;
- if (!!project) {
- return 'project';
- }
- if (!!organization) {
- return 'organization';
- }
- return null;
- }
- handleShouldDisableScrollToTop = (location: Location, prevLocation: Location) => {
- // we do not want to scroll to top when user just perform a search
- return (
- location.pathname === prevLocation.pathname &&
- location.query?.query !== prevLocation.query?.query
- );
- };
- render() {
- const {location, children} = this.props;
- return (
- <StyledSettingsWrapper>
- <ScrollToTop location={location} disable={this.handleShouldDisableScrollToTop}>
- {children}
- </ScrollToTop>
- </StyledSettingsWrapper>
- );
- }
- }
- export default withLatestContext(SettingsWrapper);
- const StyledSettingsWrapper = styled('div')`
- display: flex;
- flex: 1;
- font-size: ${p => p.theme.fontSizeLarge};
- color: ${p => p.theme.textColor};
- margin-bottom: -${space(3)}; /* to account for footer margin top */
- line-height: 1;
- .messages-container {
- margin: 0;
- }
- `;
|