Skip to content

Commit

Permalink
🪟 🎨 Add loading backdrop for sync catalog table (#15671)
Browse files Browse the repository at this point in the history
  • Loading branch information
dizel852 authored Aug 17, 2022
1 parent 722d751 commit d3cefac
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@use "../../scss/colors";

%cover {
width: 100%;
height: 100%;
}

.loadingBackdropContainer {
@extend %cover;
position: relative;

.backdrop {
@extend %cover;
position: absolute;
background-color: colors.$white;
opacity: 0.6;
z-index: 1;
}

.spinnerContainer {
@extend %cover;
position: absolute;
display: flex;
align-items: center;
justify-content: center;
z-index: 2;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { render } from "@testing-library/react";

import { LoadingBackdrop } from "./LoadingBackdrop";

describe("<LoadingBackdrop />", () => {
it("loading backdrop is active", () => {
const { getByTestId } = render(<LoadingBackdrop loading />);

expect(getByTestId("loading-backdrop")).toBeInTheDocument();
});

it("loading backdrop is not active", () => {
const { queryByTestId } = render(<LoadingBackdrop loading={false} />);

expect(queryByTestId("loading-backdrop")).toBeNull();
});
});
24 changes: 24 additions & 0 deletions airbyte-webapp/src/components/LoadingBackdrop/LoadingBackdrop.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from "react";

import Spinner from "../Spinner/Spinner";
import styles from "./LoadingBackdrop.module.scss";

interface LoadingBackdropProps {
loading: boolean;
small?: boolean;
}
export const LoadingBackdrop: React.FC<LoadingBackdropProps> = ({ loading, small, children }) => {
return (
<div className={styles.loadingBackdropContainer}>
{loading && (
<>
<div className={styles.backdrop} data-testid="loading-backdrop" />
<div className={styles.spinnerContainer}>
<Spinner small={small} />
</div>
</>
)}
{children}
</div>
);
};
23 changes: 23 additions & 0 deletions airbyte-webapp/src/components/LoadingBackdrop/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ComponentStory, ComponentMeta } from "@storybook/react";

import { LoadingBackdrop } from "./LoadingBackdrop";

export default {
title: "Ui/LoadingBackdrop",
component: LoadingBackdrop,
argTypes: {
loading: { type: "boolean", required: true },
small: { type: "boolean", required: false },
},
} as ComponentMeta<typeof LoadingBackdrop>;

const Template: ComponentStory<typeof LoadingBackdrop> = (args) => (
<div style={{ height: 200, width: 200, border: "1px solid blue" }}>
<LoadingBackdrop {...args}>
<div style={{ padding: 15 }}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore
</div>
</LoadingBackdrop>
</div>
);
export const Primary = Template.bind({});
1 change: 1 addition & 0 deletions airbyte-webapp/src/components/LoadingBackdrop/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { LoadingBackdrop } from "./LoadingBackdrop";
16 changes: 6 additions & 10 deletions airbyte-webapp/src/components/LoadingPage/LoadingPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from "react";
import styled, { useTheme } from "styled-components";
import { Theme } from "theme";
import styled from "styled-components";

import Spinner from "components/Spinner";

Expand All @@ -17,13 +16,10 @@ const Container = styled.div<IProps>`
align-items: center;
`;

const LoadingPage: React.FC<IProps> = ({ full }) => {
const theme = useTheme() as Theme;
return (
<Container full={full}>
<Spinner backgroundColor={theme.backgroundColor} />
</Container>
);
};
const LoadingPage: React.FC<IProps> = ({ full }) => (
<Container full={full}>
<Spinner />
</Container>
);

export default LoadingPage;
23 changes: 23 additions & 0 deletions airbyte-webapp/src/components/Spinner/Spinner.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@use "../../scss/colors";

@keyframes spin {
from {
transform: rotate(0);
}
to {
transform: rotate(359deg);
}
}
.spinner {
width: 42px;
height: 42px;
border: 4px solid colors.$blue-100;
border-top: 4px solid transparent;
border-radius: 50%;
animation: spin 1.5s linear 0s infinite;
}

.small {
width: 30px;
height: 30px;
}
11 changes: 11 additions & 0 deletions airbyte-webapp/src/components/Spinner/Spinner.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { render } from "@testing-library/react";

import Spinner from "./Spinner";

describe("<Spinner />", () => {
it("should render without crash", () => {
const { asFragment } = render(<Spinner />);

expect(asFragment()).toMatchSnapshot();
});
});
41 changes: 6 additions & 35 deletions airbyte-webapp/src/components/Spinner/Spinner.tsx
Original file line number Diff line number Diff line change
@@ -1,43 +1,14 @@
import classnames from "classnames";
import React from "react";
import styled, { keyframes } from "styled-components";

interface IProps {
backgroundColor?: string;
import styles from "./Spinner.module.scss";

interface SpinnerProps {
small?: boolean;
}

export const SpinAnimation = keyframes`
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
`;

const SpinnerWheel = styled.div<{ small?: boolean }>`
display: inline-block;
height: ${({ small }) => (small ? 30 : 42)}px;
width: ${({ small }) => (small ? 30 : 42)}px;
border-radius: 50%;
border: 4px solid ${({ theme }) => theme.primaryColor12};
position: relative;
animation: ${SpinAnimation} 1.5s linear 0s infinite;
`;

const BreakRec = styled.div<IProps>`
width: 13px;
height: 7px;
background: ${({ theme, backgroundColor }) => (backgroundColor ? backgroundColor : theme.whiteColor)};
top: -4px;
position: relative;
margin: 0 auto;
`;

const Spinner: React.FC<IProps> = ({ backgroundColor, small }) => (
<SpinnerWheel small={small}>
<BreakRec backgroundColor={backgroundColor} />
</SpinnerWheel>
const Spinner: React.FC<SpinnerProps> = ({ small }) => (
<div className={classnames(styles.spinner, { [styles.small]: small })} />
);

export default Spinner;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<Spinner /> should render without crash 1`] = `
<DocumentFragment>
<div
class="spinner"
/>
</DocumentFragment>
`;
15 changes: 15 additions & 0 deletions airbyte-webapp/src/components/Spinner/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ComponentStory, ComponentMeta } from "@storybook/react";

import SpinnerComponent from "./Spinner";

export default {
title: "Ui/Spinner",
component: SpinnerComponent,
argTypes: {
small: { type: "boolean", required: false },
},
} as ComponentMeta<typeof SpinnerComponent>;

const Template: ComponentStory<typeof SpinnerComponent> = (args) => <SpinnerComponent {...args} />;

export const Primary = Template.bind({});
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ const ConnectionForm: React.FC<ConnectionFormProps> = ({
destinationSupportedSyncModes={destDefinition.supportedDestinationSyncModes}
additionalControl={additionalSchemaControl}
component={SchemaField}
isSubmitting={isSubmitting}
mode={mode}
/>
</StyledSection>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { FormattedMessage } from "react-intl";
import styled from "styled-components";

import { CheckBox, H5 } from "components";
import { LoadingBackdrop } from "components/LoadingBackdrop";
import { Cell, Header } from "components/SimpleTableComponents";

import { useConfig } from "config";
Expand Down Expand Up @@ -70,6 +71,7 @@ const LearnMoreLink = styled.a`
interface SchemaViewProps extends FieldProps<SyncSchemaStream[]> {
additionalControl?: React.ReactNode;
destinationSupportedSyncModes: DestinationSyncMode[];
isSubmitting: boolean;
mode?: ConnectionFormMode;
}

Expand Down Expand Up @@ -172,6 +174,7 @@ const SyncCatalogField: React.FC<SchemaViewProps> = ({
additionalControl,
field,
form,
isSubmitting,
mode,
}) => {
const { value: streams, name: fieldName } = field;
Expand Down Expand Up @@ -209,7 +212,7 @@ const SyncCatalogField: React.FC<SchemaViewProps> = ({

return (
<BatchEditProvider nodes={streams} update={onChangeSchema}>
<div>
<LoadingBackdrop loading={isSubmitting}>
<HeaderBlock>
{mode !== "readonly" ? (
<>
Expand All @@ -236,7 +239,7 @@ const SyncCatalogField: React.FC<SchemaViewProps> = ({
mode={mode}
/>
</TreeViewContainer>
</div>
</LoadingBackdrop>
</BatchEditProvider>
);
};
Expand Down

0 comments on commit d3cefac

Please sign in to comment.