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

[Spaces WIP] Additional space management UI #18607

Merged
merged 10 commits into from
Apr 27, 2018
1 change: 1 addition & 0 deletions src/dev/jest/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default {
'<rootDir>/src/cli_plugin',
'<rootDir>/src/dev',
'<rootDir>/packages',
'<rootDir>/x-pack/plugins'
Copy link
Contributor

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.

Copy link
Member Author

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.

],
collectCoverageFrom: [
'packages/kbn-ui-framework/src/components/**/*.js',
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/spaces/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { validateConfig } from './server/lib/validate_config';
import { checkLicense } from './server/lib/check_license';
import { initSpacesApi } from './server/routes/api/v1/spaces';
import { mirrorPluginStatus } from '../../server/lib/mirror_plugin_status';
import mappings from './mappings.json';

export const spaces = (kibana) => new kibana.Plugin({
id: 'spaces',
Expand All @@ -32,6 +33,7 @@ export const spaces = (kibana) => new kibana.Plugin({
hidden: true,
}],
hacks: [],
mappings,
home: ['plugins/spaces/register_feature'],
injectDefaultVars: function () {
return { };
Expand Down
12 changes: 12 additions & 0 deletions x-pack/plugins/spaces/mappings.json
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still use $q even in React? I

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I keep forgetting that Promise.all exists on native Promises...I'll change to use that. I brought $q in to prevent pulling in another dependency, but it's a non-issue. I'll fix this too.

.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
};
Loading