-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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 mapping #18778
Merged
Merged
Spaces mapping #18778
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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,19 @@ | ||
export function setupBasePathProvider(server, config) { | ||
|
||
server.decorate('request', 'setBasePath', function (basePath) { | ||
const request = this; | ||
if (request.app._basePath) { | ||
throw new Error(`Request basePath was previously set. Setting multiple times is not supported.`); | ||
} | ||
request.app._basePath = basePath; | ||
}); | ||
|
||
server.decorate('request', 'getBasePath', function () { | ||
const request = this; | ||
|
||
const serverBasePath = config.get('server.basePath'); | ||
const requestBasePath = request.app._basePath || ''; | ||
|
||
return `${serverBasePath}${requestBasePath}`; | ||
}); | ||
} |
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
15 changes: 15 additions & 0 deletions
15
.../plugins/spaces/public/views/management/components/__snapshots__/page_header.test.js.snap
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,15 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`it renders without crashing 1`] = ` | ||
<div | ||
className="euiHeader" | ||
> | ||
<div | ||
className="euiHeaderSection euiHeaderSection--left" | ||
> | ||
<div | ||
className="euiHeaderBreadcrumbs" | ||
/> | ||
</div> | ||
</div> | ||
`; |
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
35 changes: 35 additions & 0 deletions
35
x-pack/plugins/spaces/public/views/management/components/page_header.test.js
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,35 @@ | ||
/* | ||
* 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 { PageHeader } from './page_header'; | ||
import { render } from 'enzyme'; | ||
import renderer from 'react-test-renderer'; | ||
|
||
test('it renders without crashing', () => { | ||
const component = renderer.create( | ||
<PageHeader breadcrumbs={[]}/> | ||
); | ||
expect(component).toMatchSnapshot(); | ||
}); | ||
|
||
test('it renders breadcrumbs', () => { | ||
const component = render( | ||
<PageHeader breadcrumbs={[{ | ||
id: 'id-1', | ||
href: 'myhref-1', | ||
current: false | ||
}, { | ||
id: 'id-2', | ||
href: 'myhref-2', | ||
current: true | ||
}]} | ||
/> | ||
); | ||
|
||
expect(component.find('a')).toHaveLength(2); | ||
|
||
}); |
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
97 changes: 97 additions & 0 deletions
97
x-pack/plugins/spaces/public/views/management/components/url_context.js
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,97 @@ | ||
/* | ||
* 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 { | ||
EuiFormRow, | ||
EuiLink, | ||
EuiFieldText, | ||
EuiCallOut, | ||
EuiSpacer | ||
} from '@elastic/eui'; | ||
|
||
export class UrlContext extends Component { | ||
textFieldRef = null; | ||
|
||
state = { | ||
editing: false | ||
}; | ||
|
||
render() { | ||
const { | ||
urlContext = '' | ||
} = this.props.space; | ||
|
||
return ( | ||
<Fragment> | ||
<EuiFormRow | ||
label={this.getLabel()} | ||
helpText={this.getHelpText()} | ||
> | ||
<div> | ||
<EuiFieldText | ||
readOnly={!this.state.editing} | ||
placeholder={this.state.editing ? null : 'give your space a name to see its URL Context'} | ||
value={urlContext} | ||
onChange={this.onChange} | ||
inputRef={(ref) => this.textFieldRef = ref} | ||
/> | ||
{this.getCallOut()} | ||
</div> | ||
</EuiFormRow> | ||
</Fragment> | ||
); | ||
} | ||
|
||
getLabel = () => { | ||
const editLinkText = this.state.editing ? `[stop editing]` : `[edit]`; | ||
return (<p>URL Context <EuiLink onClick={this.onEditClick}>{editLinkText}</EuiLink></p>); | ||
}; | ||
|
||
getHelpText = () => { | ||
return (<p>Links within Kibana will include this space identifier</p>); | ||
}; | ||
|
||
getCallOut = () => { | ||
if (this.props.editingExistingSpace && this.state.editing) { | ||
return ( | ||
<Fragment> | ||
<EuiSpacer /> | ||
<EuiCallOut | ||
color={'warning'} | ||
size={'s'} | ||
title={'Changing the URL Context will invalidate all existing links and bookmarks to this space'} | ||
/> | ||
</Fragment> | ||
); | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
onEditClick = () => { | ||
this.setState({ | ||
editing: !this.state.editing | ||
}, () => { | ||
if (this.textFieldRef && this.state.editing) { | ||
this.textFieldRef.focus(); | ||
} | ||
}); | ||
}; | ||
|
||
onChange = (e) => { | ||
if (!this.state.editing) return; | ||
this.props.onChange(e); | ||
}; | ||
} | ||
|
||
UrlContext.propTypes = { | ||
space: PropTypes.object.isRequired, | ||
editable: PropTypes.bool.isRequired, | ||
editingExistingSpace: PropTypes.bool.isRequired, | ||
onChange: PropTypes.func | ||
}; |
13 changes: 13 additions & 0 deletions
13
x-pack/plugins/spaces/public/views/management/lib/url_context_utils.js
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,13 @@ | ||
/* | ||
* 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 function toUrlContext(value = '') { | ||
return value.toLowerCase().replace(/[^a-z0-9]/g, '-'); | ||
} | ||
|
||
export function isValidUrlContext(value = '') { | ||
return value === toUrlContext(value); | ||
} |
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.
Do we still need this?
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.
There might be a better way to do this, but I need the
spaces
var here so that angular can inject it here. The default isn't really used, but I make use of the override available here.This allows the Space Selection screen to have all the information it needs to render, instead of having the client make another ajax call once the page loads. We'd end up with another loading screen while we waited for the Space Selector to load the available spaces.
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.
Interesting... so if we don't define it here we can't provide it via the render call? That's super weird...
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.
Yeah - the Angular controller would actually fail because there isn't a "spacesProvider" registered with the system. At least that's what happened with my testing...I could be overlooking a better solution.
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've seen crazier things, it works for me!