Skip to content

Commit

Permalink
move spaces plugin to kibana
Browse files Browse the repository at this point in the history
  • Loading branch information
legrego committed Apr 26, 2018
1 parent b95b3f4 commit 0b58acf
Show file tree
Hide file tree
Showing 25 changed files with 860 additions and 1 deletion.
4 changes: 3 additions & 1 deletion x-pack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { licenseManagement } from './plugins/license_management';
import { cloud } from './plugins/cloud';
import { indexManagement } from './plugins/index_management';
import { consoleExtensions } from './plugins/console_extensions';
import { spaces } from './plugins/spaces';

module.exports = function (kibana) {
return [
Expand All @@ -40,6 +41,7 @@ module.exports = function (kibana) {
licenseManagement(kibana),
cloud(kibana),
indexManagement(kibana),
consoleExtensions(kibana)
consoleExtensions(kibana),
spaces(kibana)
];
};
22 changes: 22 additions & 0 deletions x-pack/plugins/spaces/common/mock_spaces.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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.
*/

export const mockSpaces = [{
id: 'engineering',
name: 'Engineering',
description: 'This is the Engineering Space',
logo: 'logoKubernetes'
}, {
id: 'sales',
name: 'Sales',
description: 'This is the Sales Space',
logo: 'logoElastic'
}, {
id: 'support',
name: 'Support',
description: 'This is the Support Space',
logo: 'logoElasticStack'
}];
55 changes: 55 additions & 0 deletions x-pack/plugins/spaces/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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 { resolve } from 'path';
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';

export const spaces = (kibana) => new kibana.Plugin({
id: 'spaces',
configPrefix: 'xpack.spaces',
publicDir: resolve(__dirname, 'public'),
require: ['kibana', 'elasticsearch', 'xpack_main'],

config(Joi) {
return Joi.object({
enabled: Joi.boolean().default(true),
}).default();
},

uiExports: {
chromeNavControls: ['plugins/spaces/views/nav_control'],
managementSections: ['plugins/spaces/views/management'],
apps: [{
id: 'space_selector',
title: 'Spaces',
main: 'plugins/spaces/views/space_selector',
hidden: true,
}],
hacks: [],
home: ['plugins/spaces/register_feature'],
injectDefaultVars: function () {
return { };
}
},

async init(server) {
const thisPlugin = this;
const xpackMainPlugin = server.plugins.xpack_main;
mirrorPluginStatus(xpackMainPlugin, thisPlugin);

// Register a function that is called whenever the xpack info changes,
// to re-compute the license check results for this plugin
xpackMainPlugin.info.feature(thisPlugin.id).registerLicenseCheckResultsGenerator(checkLicense);

const config = server.config();
validateConfig(config, message => server.log(['spaces', 'warning'], message));

initSpacesApi(server);
}
});
Binary file added x-pack/plugins/spaces/public/images/demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions x-pack/plugins/spaces/public/register_feature.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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 { FeatureCatalogueRegistryProvider, FeatureCatalogueCategory } from 'ui/registry/feature_catalogue';

FeatureCatalogueRegistryProvider.register(() => {
return {
id: 'spaces',
title: 'Spaces',
description: 'You know, for space.',
icon: '/plugins/kibana/assets/app_security.svg',
path: '/app/kibana#/management/spaces/list',
showOnHomePage: true,
category: FeatureCatalogueCategory.ADMIN
};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* 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.
*/

export { SpacesGridPage } from './spaces_grid_page';
export { ManageSpacePage } from './manage_space_page';
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/*
* 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 {
EuiText,
EuiSpacer,
EuiPageContent,
EuiForm,
EuiFormRow,
EuiFieldText,
EuiFlexGroup,
EuiFlexItem,
EuiButton,
} from '@elastic/eui';

import { Notifier, toastNotifications } from 'ui/notify';

export class ManageSpacePage extends React.Component {
state = {
space: {},
error: null
}

componentDidMount() {
this.notifier = new Notifier({ location: 'Spaces' });

const {
space,
httpAgent,
chrome
} = this.props;

if (space) {
httpAgent
.get(chrome.addBasePath(`/api/spaces/v1/spaces/${space}`))
.then(result => {
if (result.data) {
this.setState({
space: result.data
});
}
})
.catch(error => {
this.setState({
error
});
});
}
}

render() {
const {
name = '',
description = ''
} = this.state.space;

return (
<EuiPageContent>
<EuiForm>
<EuiText><h1>{this.getTitle()}</h1></EuiText>
<EuiSpacer />
<EuiFormRow
label="Name"
helpText="Name your space"
>
<EuiFieldText
name="name"
placeholder={'Awesome space'}
value={name}
onChange={this.onNameChange}
/>
</EuiFormRow>
<EuiFormRow
label="Description"
helpText="Describe your space"
>
<EuiFieldText
name="description"
placeholder={'This is where the magic happens'}
value={description}
onChange={this.onDescriptionChange}
/>
</EuiFormRow>

<EuiFlexGroup>
<EuiFlexItem grow={false}>
<EuiButton fill onClick={this.saveSpace}>Save</EuiButton>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButton onClick={this.backToSpacesList}>
Cancel
</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>

{this.getActionButtons}
</EuiForm>
</EuiPageContent>
);
}

getTitle = () => {
const isEditing = !!this.props.space;
if (isEditing) {
return `Edit space`;
}
return `Create a space`;
}

onNameChange = (e) => {
this.setState({
space: {
...this.state.space,
name: e.target.value
}
});
}

onDescriptionChange = (e) => {
this.setState({
space: {
...this.state.space,
description: e.target.value
}
});
}

saveSpace = () => {
const {
name = '',
id = name.toLowerCase(),
description
} = this.state.space;

const { httpAgent, chrome } = this.props;

if (name && description) {
console.log(this.state.space);
httpAgent
.post(chrome.addBasePath(`/api/spaces/v1/spaces/${encodeURIComponent(id)}`), { id, name, description })
.then(result => {
toastNotifications.addSuccess(`Saved '${result.data.id}'`);
window.location.hash = `#/management/spaces/list`;
})
.catch(error => {
toastNotifications.addError(error);
});
}
}

backToSpacesList = () => {
window.location.hash = `#/management/spaces/list`;
}
}

ManageSpacePage.propTypes = {
space: PropTypes.string,
httpAgent: PropTypes.func.isRequired,
chrome: PropTypes.object
};
Loading

0 comments on commit 0b58acf

Please sign in to comment.