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

Include error handling for New Environment functionality #175

Merged
merged 1 commit into from
Oct 12, 2023
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
45 changes: 45 additions & 0 deletions src/components/NewEnvironment/NewEnvironmentButton/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from 'react';
import { notification } from 'antd';
import Button from 'components/Button';

export const NewEnvButton = ({ action, loading, error, disabled, data }) => {
const [api, contextHolder] = notification.useNotification();

const openNotificationWithIcon = errorMessage => {
api['error']({
message: 'There was a problem creating an Environment.',
description: errorMessage,
placement: 'top',
duration: 0,
style: { width: '500px' },
});
};
return (
<>
{contextHolder}
<Button action={action} loading={loading} disabled={disabled} variant="primary">
{loading ? "Creating" : "Create"}
</Button>
{error && openNotificationWithIcon(data.deployEnvironmentBranch)}
</>
);
};

const NewEnvironmentButton = ({ deployEnvironmentBranch, inputBranchName, inputProjectName, loading, error, disabled, data }) => (
<NewEnvButton
action={() => {
deployEnvironmentBranch({
variables: {
branch: inputBranchName,
project: inputProjectName,
},
});
}}
loading={loading}
error={error}
disabled={disabled}
data={data}
/>
);

export default NewEnvironmentButton;
28 changes: 12 additions & 16 deletions src/components/NewEnvironment/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {useQuery} from "@apollo/react-hooks";
import ProjectByNameWithDeployKeyQuery from "../../lib/query/ProjectByNameWithDeployKey";
import { Footer } from '../Organizations/SharedStyles';
import getConfig from "next/config";
import NewEnvironmentButton from "./NewEnvironmentButton";
const { WEBHOOK_URL } = getConfig().publicRuntimeConfig;

const DEPLOY_ENVIRONMENT_BRANCH_MUTATION = gql`
Expand Down Expand Up @@ -94,8 +95,8 @@ const NewEnvironment = ({
if (error) {
return <div>{error.message}</div>;
}
if (data) {
refresh().then(setClear).then(closeModal);
if (data && !data.deployEnvironmentBranch.includes("Skipped")) {
refresh().then(setClear).then(closeModal);
}

return (
Expand Down Expand Up @@ -217,22 +218,17 @@ const NewEnvironment = ({
}</span> environment: <b>{inputBranchName}</b></div>
: null
}
<Button
<NewEnvironmentButton
disabled={inputBranchName === ''}
action={() => {
deployEnvironmentBranch({
variables: {
branch: inputBranchName,
project: inputProjectName,
},
});
}}
variant="primary"
>
{loading ? <div className="loader"></div> : "Create"}
</Button>
deployEnvironmentBranch={deployEnvironmentBranch}
inputBranchName={inputBranchName}
inputProjectName={inputProjectName}
loading={loading}
error={data && data.deployEnvironmentBranch.includes("Skipped")}
data={data}
/>

<Button action={() => closeModal()} variant="ghost">
<Button action={() => [setClear(), closeModal()]} variant="ghost">
Cancel
</Button>
</Footer>
Expand Down