From a5f648338ac9587dbd7159eba8d928e4c9cd9b78 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Thu, 13 Jan 2022 16:47:38 +0100 Subject: [PATCH] ref(ui): Extract LoadingTriangle from LoadingIndicator This reverts commit 7f9fc2a181a6abeb5232dc98fdeb68e1905c0f7b. --- .../components/loadingIndicator.stories.js | 9 ++-- static/app/components/loadingIndicator.tsx | 15 +------ static/app/components/loadingTriangle.tsx | 44 +++++++++++++++++++ static/app/views/organizationContext.tsx | 6 +-- .../spec/views/organizationContext.spec.jsx | 8 ++-- 5 files changed, 57 insertions(+), 25 deletions(-) create mode 100644 static/app/components/loadingTriangle.tsx diff --git a/docs-ui/stories/components/loadingIndicator.stories.js b/docs-ui/stories/components/loadingIndicator.stories.js index 5924814e7f3601..d478ce51054264 100644 --- a/docs-ui/stories/components/loadingIndicator.stories.js +++ b/docs-ui/stories/components/loadingIndicator.stories.js @@ -1,4 +1,5 @@ import LoadingIndicator from 'sentry/components/loadingIndicator'; +import LoadingTriangle from 'sentry/components/loadingTriangle'; export default { title: 'Components/Loading Indicators', @@ -15,9 +16,11 @@ export const All = () => ( Mini -
+
Triangle - +
+ +
); @@ -48,7 +51,7 @@ Mini.parameters = { export const Triangle = () => (
- Loading message + Loading message
); diff --git a/static/app/components/loadingIndicator.tsx b/static/app/components/loadingIndicator.tsx index 37a72eb6d528f1..cd16dab8970eec 100644 --- a/static/app/components/loadingIndicator.tsx +++ b/static/app/components/loadingIndicator.tsx @@ -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; @@ -18,15 +15,10 @@ type Props = { children?: React.ReactNode; }; -function renderLogoSpinner() { - return ; -} - function LoadingIndicator(props: Props) { const { hideMessage, mini, - triangle, overlay, dark, children, @@ -41,7 +33,6 @@ function LoadingIndicator(props: Props) { dark, loading: true, mini, - triangle, }); const loadingCx = classNames({ @@ -59,11 +50,7 @@ function LoadingIndicator(props: Props) { return (
- {!hideSpinner && ( -
- {triangle && renderLogoSpinner()} -
- )} + {!hideSpinner &&
} {!hideMessage &&
{children}
}
); diff --git a/static/app/components/loadingTriangle.tsx b/static/app/components/loadingTriangle.tsx new file mode 100644 index 00000000000000..f1d2ce5d6c0f9d --- /dev/null +++ b/static/app/components/loadingTriangle.tsx @@ -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 ( + + + + + {children &&
{children}
} +
+ ); +} + +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; diff --git a/static/app/views/organizationContext.tsx b/static/app/views/organizationContext.tsx index e6e097046f7fd9..02057e4bb8e4b4 100644 --- a/static/app/views/organizationContext.tsx +++ b/static/app/views/organizationContext.tsx @@ -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'; @@ -339,9 +339,7 @@ class OrganizationContextContainer extends React.Component { render() { if (this.isLoading()) { return ( - - {t('Loading data for your organization.')} - + {t('Loading data for your organization.')} ); } diff --git a/tests/js/spec/views/organizationContext.spec.jsx b/tests/js/spec/views/organizationContext.spec.jsx index b831f9cac8d6af..47782103f53d0a 100644 --- a/tests/js/spec/views/organizationContext.spec.jsx +++ b/tests/js/spec/views/organizationContext.spec.jsx @@ -240,7 +240,7 @@ describe('OrganizationContext', function () { organizations: [], }); - expect(wrapper.find('LoadingIndicator')).toHaveLength(1); + expect(wrapper.find('LoadingTriangle')).toHaveLength(1); wrapper.setProps({ organizationsLoading: false, @@ -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(); @@ -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 @@ -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