-
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 WIP] Additional space management UI #18607
Changes from 9 commits
0da9dbd
8a72f4a
b5d8202
4c892f5
a7a285d
168f364
e95b380
55519a7
447dadf
75fb146
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"space": { | ||
"properties": { | ||
"name": { | ||
"type": "text" | ||
}, | ||
"description": { | ||
"type": "text" | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { | ||
EuiOverlayMask, | ||
EuiConfirmModal, | ||
} from '@elastic/eui'; | ||
|
||
export const ConfirmDeleteModal = (props) => { | ||
const { | ||
spaces | ||
} = props; | ||
|
||
const buttonText = spaces.length > 1 | ||
? `Delete ${spaces.length} spaces` | ||
: `Delete space`; | ||
|
||
const bodyQuestion = spaces.length > 1 | ||
? `Are you sure you want to delete these ${spaces.length} spaces?` | ||
: `Are you sure you want to delete this space?`; | ||
|
||
return ( | ||
<EuiOverlayMask> | ||
<EuiConfirmModal | ||
buttonColor={'danger'} | ||
cancelButtonText={'Cancel'} | ||
confirmButtonText={buttonText} | ||
onCancel={props.onCancel} | ||
onConfirm={props.onConfirm} | ||
title={`Confirm Delete`} | ||
defaultFocusedButton={'cancel'} | ||
> | ||
<p>{bodyQuestion}</p> | ||
<p>This operation cannot be undone!</p> | ||
</EuiConfirmModal> | ||
</EuiOverlayMask> | ||
); | ||
}; | ||
|
||
ConfirmDeleteModal.propTypes = { | ||
spaces: PropTypes.array.isRequired, | ||
onCancel: PropTypes.func.isRequired, | ||
onConfirm: PropTypes.func.isRequired | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* 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 React, { Component, Fragment } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { ConfirmDeleteModal } from './confirm_delete_modal'; | ||
import { | ||
EuiButton | ||
} from '@elastic/eui'; | ||
import { toastNotifications } from 'ui/notify'; | ||
|
||
export class DeleteSpacesButton extends Component { | ||
state = { | ||
showConfirmModal: false | ||
}; | ||
|
||
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()} | ||
</Fragment> | ||
); | ||
} | ||
|
||
onDeleteClick = () => { | ||
this.setState({ | ||
showConfirmModal: true | ||
}); | ||
}; | ||
|
||
getConfirmDeleteModal = () => { | ||
if (!this.state.showConfirmModal) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<ConfirmDeleteModal | ||
spaces={this.props.spaces} | ||
onCancel={() => { | ||
this.setState({ | ||
showConfirmModal: false | ||
}); | ||
}} | ||
onConfirm={this.deleteSpaces} | ||
/> | ||
); | ||
}; | ||
|
||
deleteSpaces = () => { | ||
const { | ||
httpAgent, | ||
chrome, | ||
spaces, | ||
$q | ||
} = this.props; | ||
|
||
console.log(this.props, spaces); | ||
|
||
const deleteOperations = spaces.map(space => { | ||
return httpAgent.delete( | ||
chrome.addBasePath(`/api/spaces/v1/spaces/${encodeURIComponent(space.id)}`) | ||
); | ||
}); | ||
|
||
$q.all(deleteOperations) | ||
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. Do we still use 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. I keep forgetting that |
||
.then(() => { | ||
this.setState({ | ||
showConfirmModal: 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(); | ||
} | ||
}) | ||
.catch(error => { | ||
const { | ||
message = '' | ||
} = error.data || {}; | ||
|
||
toastNotifications.addDanger(`Error deleting space: ${message}`); | ||
}); | ||
}; | ||
} | ||
|
||
DeleteSpacesButton.propTypes = { | ||
$q: PropTypes.func.isRequired, | ||
spaces: PropTypes.array.isRequired, | ||
httpAgent: PropTypes.func.isRequired, | ||
chrome: PropTypes.object.isRequired, | ||
onDelete: PropTypes.func | ||
}; |
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.
I don't think we want this here, as all the x-pack tests are run inside of x-pack itself and this would make the OSS tests automatically pick up the x-pack jest tests.
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.
Oops, good catch! I'll remove this.