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

ref(ui): Extract LoadingTriangle from LoadingIndicator #31118

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
9 changes: 6 additions & 3 deletions docs-ui/stories/components/loadingIndicator.stories.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import LoadingIndicator from 'sentry/components/loadingIndicator';
import LoadingTriangle from 'sentry/components/loadingTriangle';

export default {
title: 'Components/Loading Indicators',
Expand All @@ -15,9 +16,11 @@ export const All = () => (
Mini
<LoadingIndicator mini />
</div>
<div style={{position: 'relative'}}>
<div>
Triangle
<LoadingIndicator triangle />
<div style={{position: 'relative'}}>
<LoadingTriangle />
</div>
</div>
</div>
);
Expand Down Expand Up @@ -48,7 +51,7 @@ Mini.parameters = {

export const Triangle = () => (
<div style={{paddingBottom: 300}}>
<LoadingIndicator triangle>Loading message</LoadingIndicator>
<LoadingTriangle>Loading message</LoadingTriangle>
</div>
);

Expand Down
15 changes: 1 addition & 14 deletions static/app/components/loadingIndicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ import * as React from 'react';
import {withProfiler} from '@sentry/react';
import classNames from 'classnames';

import sentryLoader from 'sentry-images/sentry-loader.svg';

type Props = {
overlay?: boolean;
dark?: boolean;
mini?: boolean;
triangle?: boolean;
relative?: boolean;
hideMessage?: boolean;
hideSpinner?: boolean;
Expand All @@ -18,15 +15,10 @@ type Props = {
children?: React.ReactNode;
};

function renderLogoSpinner() {
return <img src={sentryLoader} />;
}

function LoadingIndicator(props: Props) {
const {
hideMessage,
mini,
triangle,
overlay,
dark,
children,
Expand All @@ -41,7 +33,6 @@ function LoadingIndicator(props: Props) {
dark,
loading: true,
mini,
triangle,
});

const loadingCx = classNames({
Expand All @@ -59,11 +50,7 @@ function LoadingIndicator(props: Props) {

return (
<div className={cx} style={style} data-test-id="loading-indicator">
{!hideSpinner && (
<div className={loadingCx} style={loadingStyle}>
{triangle && renderLogoSpinner()}
</div>
)}
{!hideSpinner && <div className={loadingCx} style={loadingStyle} />}
{!hideMessage && <div className="loading-message">{children}</div>}
</div>
);
Expand Down
44 changes: 44 additions & 0 deletions static/app/components/loadingTriangle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import styled from '@emotion/styled';

import sentryLoader from 'sentry-images/sentry-loader.svg';

import space from 'sentry/styles/space';

type Props = {
children?: React.ReactNode;
};

function LoadingTriangle({children}: Props) {
return (
<LoadingTriangleWrapper data-test-id="loading-indicator">
<CircleBackground>
<img src={sentryLoader} />
</CircleBackground>
{children && <div>{children}</div>}
</LoadingTriangleWrapper>
);
}

const LoadingTriangleWrapper = styled('div')`
position: absolute;
top: 50%;
left: 50%;
width: 500px;
transform: translate(-50%, -50%);
display: flex;
flex-direction: column;
align-items: center;
gap: ${space(3)};
`;

const CircleBackground = styled('div')`
height: 150px;
width: 150px;
display: flex;
align-items: center;
justify-content: center;
background: ${p => p.theme.white};
border-radius: 50%;
`;

export default LoadingTriangle;
6 changes: 2 additions & 4 deletions static/app/views/organizationContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import ProjectActions from 'sentry/actions/projectActions';
import {Client} from 'sentry/api';
import Alert from 'sentry/components/alert';
import LoadingError from 'sentry/components/loadingError';
import LoadingIndicator from 'sentry/components/loadingIndicator';
import LoadingTriangle from 'sentry/components/loadingTriangle';
import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
import Sidebar from 'sentry/components/sidebar';
import {ORGANIZATION_FETCH_ERROR_TYPES} from 'sentry/constants';
Expand Down Expand Up @@ -339,9 +339,7 @@ class OrganizationContextContainer extends React.Component<Props, State> {
render() {
if (this.isLoading()) {
return (
<LoadingIndicator triangle>
{t('Loading data for your organization.')}
</LoadingIndicator>
<LoadingTriangle>{t('Loading data for your organization.')}</LoadingTriangle>
);
}

Expand Down
8 changes: 4 additions & 4 deletions tests/js/spec/views/organizationContext.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ describe('OrganizationContext', function () {
organizations: [],
});

expect(wrapper.find('LoadingIndicator')).toHaveLength(1);
expect(wrapper.find('LoadingTriangle')).toHaveLength(1);

wrapper.setProps({
organizationsLoading: false,
Expand All @@ -253,7 +253,7 @@ describe('OrganizationContext', function () {
await tick(); // action to start fetch org
await tick(); // action after successfully fetching org
wrapper.update();
expect(wrapper.find('LoadingIndicator')).toHaveLength(0);
expect(wrapper.find('LoadingTriangle')).toHaveLength(0);

expect(getOrgMock).toHaveBeenCalled();
expect(getProjectsMock).toHaveBeenCalled();
Expand Down Expand Up @@ -285,7 +285,7 @@ describe('OrganizationContext', function () {
// await resolving api, and updating component
await tick();
wrapper.update();
expect(wrapper.find('LoadingIndicator')).toHaveLength(0);
expect(wrapper.find('LoadingTriangle')).toHaveLength(0);
expect(getOrgMock).toHaveBeenCalledTimes(1);

// Simulate OrganizationsStore being loaded *after* `OrganizationContext` finishes
Expand Down Expand Up @@ -314,7 +314,7 @@ describe('OrganizationContext', function () {
// await resolving api, and updating component
await tick();
wrapper.update();
expect(wrapper.find('LoadingIndicator')).toHaveLength(0);
expect(wrapper.find('LoadingTriangle')).toHaveLength(0);
expect(getOrgMock).toHaveBeenCalledTimes(1);

// Simulate OrganizationsStore being loaded *after* `OrganizationContext` finishes
Expand Down