-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Spaces] - Handle space renaming and deleting #22586
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5c042b9
handle space renaming and deleting
legrego fa98a92
address PR feedback
legrego b1d8e87
Enhanced confirmation when deleting a space. Removed bulk delete
legrego c1811df
bring back the Create Space button
legrego aa8325f
additional PR feedback
legrego 7fd292c
Merge branch 'spaces-phase-1' into update-space-name
legrego 6298ad7
Merge branch 'spaces-phase-1' into update-space-name
legrego File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,11 +12,13 @@ import { Space } from '../../common/model/space'; | |
export class SpacesManager extends EventEmitter { | ||
private httpAgent: any; | ||
private baseUrl: any; | ||
private rootBasePath: string; | ||
|
||
constructor(httpAgent: any, chrome: any) { | ||
constructor(httpAgent: any, chrome: any, rootBasePath: string) { | ||
super(); | ||
this.httpAgent = httpAgent; | ||
this.baseUrl = chrome.addBasePath(`/api/spaces/v1`); | ||
this.rootBasePath = rootBasePath; | ||
} | ||
|
||
public async getSpaces(): Promise<Space[]> { | ||
|
@@ -54,6 +56,10 @@ export class SpacesManager extends EventEmitter { | |
.catch(() => this._displayError()); | ||
} | ||
|
||
public redirectToSpaceSelector() { | ||
window.location.href = this.rootBasePath; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
public async requestRefresh() { | ||
this.emit('request_refresh'); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
x-pack/plugins/spaces/public/views/management/components/confirm_redirect_modal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
// @ts-ignore | ||
import { EuiConfirmModal, EuiOverlayMask } from '@elastic/eui'; | ||
import React from 'react'; | ||
import { Space } from '../../../../common/model/space'; | ||
|
||
interface Props { | ||
space?: Space; | ||
onCancel: () => void; | ||
onConfirm: () => void; | ||
} | ||
|
||
export const ConfirmRedirectModal = (props: Props) => { | ||
const { space } = props; | ||
|
||
const buttonText = `Delete current space`; | ||
|
||
const bodyQuestion = | ||
`You are about to delete your current space ` + | ||
`(${space.name}). If you continue, you will be redirected to select a different space.`; | ||
|
||
return ( | ||
<EuiOverlayMask> | ||
<EuiConfirmModal | ||
buttonColor={'danger'} | ||
cancelButtonText={'Cancel'} | ||
confirmButtonText={buttonText} | ||
onCancel={props.onCancel} | ||
onConfirm={props.onConfirm} | ||
title={`Delete your current space?`} | ||
defaultFocusedButton={'cancel'} | ||
> | ||
<p>{bodyQuestion}</p> | ||
</EuiConfirmModal> | ||
</EuiOverlayMask> | ||
); | ||
}; |
104 changes: 0 additions & 104 deletions
104
x-pack/plugins/spaces/public/views/management/components/delete_spaces_button.js
This file was deleted.
Oops, something went wrong.
150 changes: 150 additions & 0 deletions
150
x-pack/plugins/spaces/public/views/management/components/delete_spaces_button.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { EuiButton } from '@elastic/eui'; | ||
import React, { Component, Fragment } from 'react'; | ||
import { toastNotifications } from 'ui/notify'; | ||
import { Space } from '../../../../common/model/space'; | ||
import { SpacesManager } from '../../../lib/spaces_manager'; | ||
import { ConfirmDeleteModal } from './confirm_delete_modal'; | ||
import { ConfirmRedirectModal } from './confirm_redirect_modal'; | ||
|
||
interface Props { | ||
spaces: Space[]; | ||
spacesManager: SpacesManager; | ||
spacesNavState: any; | ||
onDelete: () => void; | ||
} | ||
|
||
interface State { | ||
showConfirmDeleteModal: boolean; | ||
showConfirmRedirectModal: boolean; | ||
} | ||
|
||
export class DeleteSpacesButton extends Component<Props, State> { | ||
public state = { | ||
showConfirmDeleteModal: false, | ||
showConfirmRedirectModal: false, | ||
}; | ||
|
||
public render() { | ||
const numSpaces = this.props.spaces.length; | ||
|
||
const buttonText = numSpaces > 1 ? `Delete ${numSpaces} spaces` : `Delete space`; | ||
|
||
return ( | ||
<Fragment> | ||
<EuiButton color={'danger'} onClick={this.onDeleteClick}> | ||
{buttonText} | ||
</EuiButton> | ||
{this.getConfirmDeleteModal()} | ||
{this.getConfirmRedirectModal()} | ||
</Fragment> | ||
); | ||
} | ||
|
||
public onDeleteClick = () => { | ||
this.setState({ | ||
showConfirmDeleteModal: true, | ||
}); | ||
}; | ||
|
||
public getConfirmDeleteModal = () => { | ||
if (!this.state.showConfirmDeleteModal) { | ||
return null; | ||
} | ||
|
||
const { spaces, spacesNavState } = this.props; | ||
|
||
const isDeletingCurrentSpace = !!this.locateCurrentSpace(); | ||
|
||
const performDelete = () => { | ||
this.deleteSpaces(() => { | ||
this.setState({ | ||
showConfirmDeleteModal: false, | ||
}); | ||
|
||
const message = | ||
spaces.length > 1 | ||
? `Deleted ${spaces.length} spaces.` | ||
: `Deleted "${spaces[0].name}" space.`; | ||
|
||
toastNotifications.addSuccess(message); | ||
|
||
if (this.props.onDelete) { | ||
this.props.onDelete(); | ||
} | ||
|
||
spacesNavState.refreshSpacesList(); | ||
}); | ||
}; | ||
|
||
const nextStep = isDeletingCurrentSpace ? this.showConfirmRedirectModal : performDelete; | ||
|
||
return ( | ||
<ConfirmDeleteModal | ||
spaces={this.props.spaces} | ||
onCancel={() => { | ||
this.setState({ | ||
showConfirmDeleteModal: false, | ||
}); | ||
}} | ||
onConfirm={nextStep} | ||
/> | ||
); | ||
}; | ||
|
||
public showConfirmRedirectModal = () => { | ||
this.setState({ | ||
showConfirmDeleteModal: false, | ||
showConfirmRedirectModal: true, | ||
}); | ||
}; | ||
|
||
public getConfirmRedirectModal = () => { | ||
if (!this.state.showConfirmRedirectModal) { | ||
return null; | ||
} | ||
|
||
const performDelete = () => { | ||
this.deleteSpaces(() => { | ||
this.props.spacesManager.redirectToSpaceSelector(); | ||
}); | ||
}; | ||
|
||
return ( | ||
<ConfirmRedirectModal | ||
space={this.locateCurrentSpace()} | ||
onCancel={() => { | ||
this.setState({ | ||
showConfirmRedirectModal: false, | ||
}); | ||
}} | ||
onConfirm={performDelete} | ||
/> | ||
); | ||
}; | ||
|
||
public deleteSpaces = (onComplete: () => void) => { | ||
const { spacesManager, spaces } = this.props; | ||
|
||
const deleteOperations = spaces.map(space => spacesManager.deleteSpace(space)); | ||
|
||
Promise.all(deleteOperations) | ||
.then(onComplete) | ||
.catch(error => { | ||
const { message = '' } = error.data || {}; | ||
|
||
toastNotifications.addDanger(`Error deleting space: ${message}`); | ||
}); | ||
}; | ||
|
||
private locateCurrentSpace = () => { | ||
return this.props.spaces.find( | ||
space => space.id === this.props.spacesNavState.getActiveSpace().id | ||
); | ||
}; | ||
} |
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would you feel about renaming this to "spaceSelectorURL" or something like that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea -- it better reflects the intent/usage of this variable