Skip to content

Commit

Permalink
Merge pull request #175 from uselagoon/new_env_error_handling
Browse files Browse the repository at this point in the history
Include error handling for New Environment functionality
  • Loading branch information
tobybellwood authored Oct 12, 2023
2 parents cbb9db3 + 461d0e1 commit d12f5dd
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 16 deletions.
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

0 comments on commit d12f5dd

Please sign in to comment.