Skip to content

Commit

Permalink
Merge pull request #249 from uselagoon/btn-redirect-update
Browse files Browse the repository at this point in the history
Change: Redirects on environment deletion + confirmation messaging on environment creation
  • Loading branch information
tobybellwood authored May 16, 2024
2 parents 29251bf + 07e4002 commit 3cb5e54
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cypress/support/actions/envOverview/EnvOverviewAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class EnvOverviewAction {

cy.wait('@gqldeleteEnvironmentMutation');

environment.getDeleteInfo().invoke('text').should('eq', 'Delete queued');
cy.url().should('include', '/projects/lagoon-demo');
}

doDeleteEnvironmentError(branch: string) {
Expand Down
4 changes: 3 additions & 1 deletion src/components/DeleteConfirm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export const DeleteConfirm = ({
open,
openModal,
closeModal,
loading,
data,
}) => {
return (
<React.Fragment>
Expand All @@ -38,7 +40,7 @@ export const DeleteConfirm = ({
cancel
</button>
<Button disabled={inputValue !== deleteName} action={onDelete} variant="red" testId="deleteConfirm">
Delete
{loading ? 'Deleting...' : data ? 'Success' : 'Delete'}
</Button>
</div>
</React.Fragment>
Expand Down
2 changes: 2 additions & 0 deletions src/components/DeleteConfirm/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export const WithConfirmationBlocked = ({
open={openBoolean}
openModal={openModalFunction}
closeModal={closeModalFunction}
loading={false}
data={''}
/>
);

Expand Down
26 changes: 21 additions & 5 deletions src/components/Environment/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ const Environment = ({ environment }) => {

Router.push(taskNavObject.urlObject, taskNavObject.asPath);
};

const handleEnvironmentDelete = () => {
const projectName = environment.project.name;

const navigationObject = {
urlObject: {
pathname: '/project',
query: { projectName: projectName },
},
asPath: `/projects/${projectName}`,
};

Router.push(navigationObject.urlObject, navigationObject.asPath);
};
return (
<StyledEnvironmentDetails className="details" data-cy="env-details">
<div className="field-wrapper environmentType">
Expand Down Expand Up @@ -189,20 +203,22 @@ const Environment = ({ environment }) => {
}}
</Mutation>
)}
<Mutation mutation={DeleteEnvironmentMutation} onError={e => console.error(e)}>
<Mutation
mutation={DeleteEnvironmentMutation}
onCompleted={handleEnvironmentDelete}
onError={e => console.error(e)}
>
{(deleteEnvironment, { loading, called, error, data }) => {
if (error) {
return <div>{error.message}</div>;
}

if (called) {
return <div>Delete queued</div>;
}

return (
<DeleteConfirm
deleteType="environment"
deleteName={environment.name}
loading={loading}
data={data}
onDelete={() =>
deleteEnvironment({
variables: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const NewEnvButton = ({ action, loading, error, disabled, data }) => {
<>
{contextHolder}
<Button testId="create-env" action={action} loading={loading} disabled={disabled} variant="primary">
{loading ? 'Creating' : 'Create'}
{loading ? 'Creating' : data ? 'Success' : 'Create'}
</Button>
{error && openNotificationWithIcon(data.deployEnvironmentBranch)}
</>
Expand Down

0 comments on commit 3cb5e54

Please sign in to comment.