mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
parent
bf45684c39
commit
1ebe51b6c4
13 changed files with 89 additions and 68 deletions
|
@ -68,7 +68,7 @@ describe('context app', function () {
|
|||
it('should use the `fetch` method of the SearchSource', function () {
|
||||
const searchSourceStub = new SearchSourceStub();
|
||||
|
||||
return fetchAnchor('INDEX_PATTERN_ID', 'doc', 'id', [{ '@timestamp': 'desc' }, { '_doc': 'asc' }])
|
||||
return fetchAnchor('INDEX_PATTERN_ID', 'id', [{ '@timestamp': 'desc' }, { '_doc': 'desc' }])
|
||||
.then(() => {
|
||||
expect(searchSourceStub.fetch.calledOnce).to.be(true);
|
||||
});
|
||||
|
@ -77,7 +77,7 @@ describe('context app', function () {
|
|||
it('should configure the SearchSource to not inherit from the implicit root', function () {
|
||||
const searchSourceStub = new SearchSourceStub();
|
||||
|
||||
return fetchAnchor('INDEX_PATTERN_ID', 'doc', 'id', [{ '@timestamp': 'desc' }, { '_doc': 'asc' }])
|
||||
return fetchAnchor('INDEX_PATTERN_ID', 'id', [{ '@timestamp': 'desc' }, { '_doc': 'desc' }])
|
||||
.then(() => {
|
||||
const setParentSpy = searchSourceStub.setParent;
|
||||
expect(setParentSpy.calledOnce).to.be(true);
|
||||
|
@ -88,7 +88,7 @@ describe('context app', function () {
|
|||
it('should set the SearchSource index pattern', function () {
|
||||
const searchSourceStub = new SearchSourceStub();
|
||||
|
||||
return fetchAnchor('INDEX_PATTERN_ID', 'doc', 'id', [{ '@timestamp': 'desc' }, { '_doc': 'asc' }])
|
||||
return fetchAnchor('INDEX_PATTERN_ID', 'id', [{ '@timestamp': 'desc' }, { '_doc': 'desc' }])
|
||||
.then(() => {
|
||||
const setFieldSpy = searchSourceStub.setField;
|
||||
expect(setFieldSpy.firstCall.args[1].id).to.eql('INDEX_PATTERN_ID');
|
||||
|
@ -98,7 +98,7 @@ describe('context app', function () {
|
|||
it('should set the SearchSource version flag to true', function () {
|
||||
const searchSourceStub = new SearchSourceStub();
|
||||
|
||||
return fetchAnchor('INDEX_PATTERN_ID', 'doc', 'id', [{ '@timestamp': 'desc' }, { '_doc': 'asc' }])
|
||||
return fetchAnchor('INDEX_PATTERN_ID', 'id', [{ '@timestamp': 'desc' }, { '_doc': 'desc' }])
|
||||
.then(() => {
|
||||
const setVersionSpy = searchSourceStub.setField.withArgs('version');
|
||||
expect(setVersionSpy.calledOnce).to.be(true);
|
||||
|
@ -109,7 +109,7 @@ describe('context app', function () {
|
|||
it('should set the SearchSource size to 1', function () {
|
||||
const searchSourceStub = new SearchSourceStub();
|
||||
|
||||
return fetchAnchor('INDEX_PATTERN_ID', 'doc', 'id', [{ '@timestamp': 'desc' }, { '_doc': 'asc' }])
|
||||
return fetchAnchor('INDEX_PATTERN_ID', 'id', [{ '@timestamp': 'desc' }, { '_doc': 'desc' }])
|
||||
.then(() => {
|
||||
const setSizeSpy = searchSourceStub.setField.withArgs('size');
|
||||
expect(setSizeSpy.calledOnce).to.be(true);
|
||||
|
@ -120,7 +120,7 @@ describe('context app', function () {
|
|||
it('should set the SearchSource query to an ids query', function () {
|
||||
const searchSourceStub = new SearchSourceStub();
|
||||
|
||||
return fetchAnchor('INDEX_PATTERN_ID', 'doc', 'id', [{ '@timestamp': 'desc' }, { '_doc': 'asc' }])
|
||||
return fetchAnchor('INDEX_PATTERN_ID', 'id', [{ '@timestamp': 'desc' }, { '_doc': 'desc' }])
|
||||
.then(() => {
|
||||
const setQuerySpy = searchSourceStub.setField.withArgs('query');
|
||||
expect(setQuerySpy.calledOnce).to.be(true);
|
||||
|
@ -129,7 +129,6 @@ describe('context app', function () {
|
|||
constant_score: {
|
||||
filter: {
|
||||
ids: {
|
||||
type: 'doc',
|
||||
values: ['id'],
|
||||
},
|
||||
}
|
||||
|
@ -143,13 +142,13 @@ describe('context app', function () {
|
|||
it('should set the SearchSource sort order', function () {
|
||||
const searchSourceStub = new SearchSourceStub();
|
||||
|
||||
return fetchAnchor('INDEX_PATTERN_ID', 'doc', 'id', [{ '@timestamp': 'desc' }, { '_doc': 'asc' }])
|
||||
return fetchAnchor('INDEX_PATTERN_ID', 'id', [{ '@timestamp': 'desc' }, { '_doc': 'desc' }])
|
||||
.then(() => {
|
||||
const setSortSpy = searchSourceStub.setField.withArgs('sort');
|
||||
expect(setSortSpy.calledOnce).to.be(true);
|
||||
expect(setSortSpy.firstCall.args[1]).to.eql([
|
||||
{ '@timestamp': 'desc' },
|
||||
{ '_doc': 'asc' },
|
||||
{ '_doc': 'desc' },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
@ -158,7 +157,7 @@ describe('context app', function () {
|
|||
const searchSourceStub = new SearchSourceStub();
|
||||
searchSourceStub._stubHits = [];
|
||||
|
||||
return fetchAnchor('INDEX_PATTERN_ID', 'doc', 'id', [{ '@timestamp': 'desc' }, { '_doc': 'asc' }])
|
||||
return fetchAnchor('INDEX_PATTERN_ID', 'id', [{ '@timestamp': 'desc' }, { '_doc': 'desc' }])
|
||||
.then(
|
||||
() => {
|
||||
expect().fail('expected the promise to be rejected');
|
||||
|
@ -176,7 +175,7 @@ describe('context app', function () {
|
|||
{ property2: 'value2' },
|
||||
];
|
||||
|
||||
return fetchAnchor('INDEX_PATTERN_ID', 'doc', 'id', [{ '@timestamp': 'desc' }, { '_doc': 'asc' }])
|
||||
return fetchAnchor('INDEX_PATTERN_ID', 'id', [{ '@timestamp': 'desc' }, { '_doc': 'desc' }])
|
||||
.then((anchorDocument) => {
|
||||
expect(anchorDocument).to.have.property('property1', 'value1');
|
||||
expect(anchorDocument).to.have.property('$$_isAnchor', true);
|
||||
|
|
|
@ -28,7 +28,6 @@ export function fetchAnchorProvider(indexPatterns, Private) {
|
|||
|
||||
return async function fetchAnchor(
|
||||
indexPatternId,
|
||||
anchorType,
|
||||
anchorId,
|
||||
sort
|
||||
) {
|
||||
|
@ -43,7 +42,6 @@ export function fetchAnchorProvider(indexPatterns, Private) {
|
|||
constant_score: {
|
||||
filter: {
|
||||
ids: {
|
||||
type: anchorType,
|
||||
values: [anchorId],
|
||||
},
|
||||
},
|
||||
|
|
|
@ -54,7 +54,6 @@ module.directive('contextApp', function ContextApp() {
|
|||
controllerAs: 'contextApp',
|
||||
restrict: 'E',
|
||||
scope: {
|
||||
anchorType: '=',
|
||||
anchorId: '=',
|
||||
columns: '=',
|
||||
indexPattern: '=',
|
||||
|
@ -109,7 +108,6 @@ function ContextAppController($scope, config, Private) {
|
|||
const { queryParameters } = this.state;
|
||||
if (
|
||||
(newQueryParameters.indexPatternId !== queryParameters.indexPatternId)
|
||||
|| (newQueryParameters.anchorType !== queryParameters.anchorType)
|
||||
|| (newQueryParameters.anchorId !== queryParameters.anchorId)
|
||||
|| (!_.isEqual(newQueryParameters.sort, queryParameters.sort))
|
||||
) {
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<context-app
|
||||
anchor-type="contextAppRoute.anchorType"
|
||||
anchor-id="contextAppRoute.anchorId"
|
||||
columns="contextAppRoute.state.columns"
|
||||
discover-url="contextAppRoute.discoverUrl"
|
||||
|
|
|
@ -29,26 +29,34 @@ import { getRootBreadcrumbs } from '../discover/breadcrumbs';
|
|||
import { npStart } from 'ui/new_platform';
|
||||
import { subscribeWithScope } from 'ui/utils/subscribe_with_scope';
|
||||
|
||||
uiRoutes
|
||||
.when('/context/:indexPatternId/:type/:id*', {
|
||||
controller: ContextAppRouteController,
|
||||
k7Breadcrumbs($route) {
|
||||
const { indexPattern } = $route.current.locals;
|
||||
const { id } = $route.current.params;
|
||||
const k7Breadcrumbs = $route => {
|
||||
const { indexPattern } = $route.current.locals;
|
||||
const { id } = $route.current.params;
|
||||
|
||||
return [
|
||||
...getRootBreadcrumbs(),
|
||||
{
|
||||
text: i18n.translate('kbn.context.breadcrumb', {
|
||||
defaultMessage: 'Context of {indexPatternTitle}#{docId}',
|
||||
values: {
|
||||
indexPatternTitle: indexPattern.title,
|
||||
docId: id
|
||||
}
|
||||
})
|
||||
}
|
||||
];
|
||||
return [
|
||||
...getRootBreadcrumbs(),
|
||||
{
|
||||
text: i18n.translate('kbn.context.breadcrumb', {
|
||||
defaultMessage: 'Context of {indexPatternTitle}#{docId}',
|
||||
values: {
|
||||
indexPatternTitle: indexPattern.title,
|
||||
docId: id,
|
||||
},
|
||||
}),
|
||||
},
|
||||
];
|
||||
};
|
||||
|
||||
|
||||
uiRoutes
|
||||
// deprecated route, kept for compatibility
|
||||
// should be removed in the future
|
||||
.when('/context/:indexPatternId/:type/:id*', {
|
||||
redirectTo: '/context/:indexPatternId/:id'
|
||||
})
|
||||
.when('/context/:indexPatternId/:id*', {
|
||||
controller: ContextAppRouteController,
|
||||
k7Breadcrumbs,
|
||||
controllerAs: 'contextAppRoute',
|
||||
resolve: {
|
||||
indexPattern: function ($route, indexPatterns) {
|
||||
|
@ -58,37 +66,30 @@ uiRoutes
|
|||
template: contextAppRouteTemplate,
|
||||
});
|
||||
|
||||
|
||||
function ContextAppRouteController(
|
||||
$routeParams,
|
||||
$scope,
|
||||
AppState,
|
||||
config,
|
||||
indexPattern,
|
||||
Private,
|
||||
) {
|
||||
function ContextAppRouteController($routeParams, $scope, AppState, config, indexPattern, Private) {
|
||||
const queryFilter = Private(FilterBarQueryFilterProvider);
|
||||
|
||||
this.state = new AppState(createDefaultAppState(config, indexPattern));
|
||||
this.state.save(true);
|
||||
|
||||
$scope.$watchGroup([
|
||||
'contextAppRoute.state.columns',
|
||||
'contextAppRoute.state.predecessorCount',
|
||||
'contextAppRoute.state.successorCount',
|
||||
], () => this.state.save(true));
|
||||
$scope.$watchGroup(
|
||||
[
|
||||
'contextAppRoute.state.columns',
|
||||
'contextAppRoute.state.predecessorCount',
|
||||
'contextAppRoute.state.successorCount',
|
||||
],
|
||||
() => this.state.save(true)
|
||||
);
|
||||
|
||||
const updateSubsciption = subscribeWithScope($scope, queryFilter.getUpdates$(), {
|
||||
next: () => {
|
||||
this.filters = _.cloneDeep(queryFilter.getFilters());
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
$scope.$on('$destroy', function () {
|
||||
updateSubsciption.unsubscribe();
|
||||
});
|
||||
|
||||
this.anchorType = $routeParams.type;
|
||||
this.anchorId = $routeParams.id;
|
||||
this.indexPattern = indexPattern;
|
||||
this.discoverUrl = npStart.core.chrome.navLinks.get('kibana:discover').url;
|
||||
|
|
|
@ -58,7 +58,7 @@ export function QueryActionsProvider(Private, Promise) {
|
|||
);
|
||||
|
||||
const fetchAnchorRow = (state) => () => {
|
||||
const { queryParameters: { indexPatternId, anchorType, anchorId, sort, tieBreakerField } } = state;
|
||||
const { queryParameters: { indexPatternId, anchorId, sort, tieBreakerField } } = state;
|
||||
|
||||
if (!tieBreakerField) {
|
||||
return Promise.reject(setFailedStatus(state)('anchor', {
|
||||
|
@ -69,7 +69,7 @@ export function QueryActionsProvider(Private, Promise) {
|
|||
setLoadingStatus(state)('anchor');
|
||||
|
||||
return Promise.try(() => (
|
||||
fetchAnchor(indexPatternId, anchorType, anchorId, [_.zipObject([sort]), { [tieBreakerField]: sort[1] }])
|
||||
fetchAnchor(indexPatternId, anchorId, [_.zipObject([sort]), { [tieBreakerField]: sort[1] }])
|
||||
))
|
||||
.then(
|
||||
(anchorDocument) => {
|
||||
|
|
|
@ -42,7 +42,6 @@ describe('context app', function () {
|
|||
});
|
||||
|
||||
setQueryParameters(state)({
|
||||
anchorType: 'ANCHOR_TYPE',
|
||||
anchorId: 'ANCHOR_ID',
|
||||
columns: ['column'],
|
||||
defaultStepSize: 3,
|
||||
|
@ -55,7 +54,6 @@ describe('context app', function () {
|
|||
|
||||
expect(state.queryParameters).to.eql({
|
||||
additionalParameter: 'ADDITIONAL_PARAMETER',
|
||||
anchorType: 'ANCHOR_TYPE',
|
||||
anchorId: 'ANCHOR_ID',
|
||||
columns: ['column'],
|
||||
defaultStepSize: 3,
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
export function createInitialQueryParametersState(defaultStepSize, tieBreakerField) {
|
||||
return {
|
||||
anchorId: null,
|
||||
columns: [],
|
||||
defaultStepSize,
|
||||
filters: [],
|
||||
indexPatternId: null,
|
||||
predecessorCount: 0,
|
||||
successorCount: 0,
|
||||
sort: [],
|
||||
tieBreakerField,
|
||||
};
|
||||
}
|
|
@ -109,9 +109,8 @@ module.directive('kbnTableRow', function ($compile, $httpParamSerializer, kbnUrl
|
|||
};
|
||||
|
||||
$scope.getContextAppHref = () => {
|
||||
const path = kbnUrl.eval('#/context/{{ indexPattern }}/{{ anchorType }}/{{ anchorId }}', {
|
||||
const path = kbnUrl.eval('#/context/{{ indexPattern }}/{{ anchorId }}', {
|
||||
anchorId: $scope.row._id,
|
||||
anchorType: $scope.row._type,
|
||||
indexPattern: $scope.indexPattern.id,
|
||||
});
|
||||
const hash = $httpParamSerializer({
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
import expect from '@kbn/expect';
|
||||
|
||||
const TEST_INDEX_PATTERN = 'date-nanos';
|
||||
const TEST_ANCHOR_TYPE = '_doc';
|
||||
const TEST_DEFAULT_CONTEXT_SIZE = 1;
|
||||
const TEST_STEP_SIZE = 3;
|
||||
|
||||
|
@ -45,7 +44,7 @@ export default function ({ getService, getPageObjects }) {
|
|||
});
|
||||
|
||||
it('displays predessors - anchor - successors in right order ', async function () {
|
||||
await PageObjects.context.navigateTo(TEST_INDEX_PATTERN, TEST_ANCHOR_TYPE, 'AU_x3-TaGFA8no6Qj999Z');
|
||||
await PageObjects.context.navigateTo(TEST_INDEX_PATTERN, 'AU_x3-TaGFA8no6Qj999Z');
|
||||
const actualRowsText = await docTable.getRowsText();
|
||||
const expectedRowsText = [
|
||||
'Sep 18, 2019 @ 06:50:13.000000000-2',
|
||||
|
@ -56,7 +55,7 @@ export default function ({ getService, getPageObjects }) {
|
|||
});
|
||||
|
||||
it('displays correctly when predecessors and successors are loaded', async function () {
|
||||
await PageObjects.context.navigateTo(TEST_INDEX_PATTERN, TEST_ANCHOR_TYPE, 'AU_x3-TaGFA8no6Qjisd');
|
||||
await PageObjects.context.navigateTo(TEST_INDEX_PATTERN, 'AU_x3-TaGFA8no6Qjisd');
|
||||
await PageObjects.context.clickPredecessorLoadMoreButton();
|
||||
await PageObjects.context.clickSuccessorLoadMoreButton();
|
||||
const actualRowsText = await docTable.getRowsText();
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
import expect from '@kbn/expect';
|
||||
|
||||
const TEST_INDEX_PATTERN = 'logstash-*';
|
||||
const TEST_ANCHOR_TYPE = '_doc';
|
||||
const TEST_ANCHOR_ID = 'AU_x3_BrGFA8no6QjjaI';
|
||||
const TEST_ANCHOR_FILTER_FIELD = 'geo.src';
|
||||
const TEST_ANCHOR_FILTER_VALUE = 'IN';
|
||||
|
@ -35,7 +34,7 @@ export default function ({ getService, getPageObjects }) {
|
|||
|
||||
describe('context filters', function contextSize() {
|
||||
beforeEach(async function () {
|
||||
await PageObjects.context.navigateTo(TEST_INDEX_PATTERN, TEST_ANCHOR_TYPE, TEST_ANCHOR_ID, {
|
||||
await PageObjects.context.navigateTo(TEST_INDEX_PATTERN, TEST_ANCHOR_ID, {
|
||||
columns: TEST_COLUMN_NAMES,
|
||||
});
|
||||
});
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
import expect from '@kbn/expect';
|
||||
|
||||
const TEST_INDEX_PATTERN = 'logstash-*';
|
||||
const TEST_ANCHOR_TYPE = '_doc';
|
||||
const TEST_ANCHOR_ID = 'AU_x3_BrGFA8no6QjjaI';
|
||||
const TEST_DEFAULT_CONTEXT_SIZE = 7;
|
||||
const TEST_STEP_SIZE = 3;
|
||||
|
@ -40,7 +39,7 @@ export default function ({ getService, getPageObjects }) {
|
|||
});
|
||||
|
||||
it('should default to the `context:defaultSize` setting', async function () {
|
||||
await PageObjects.context.navigateTo(TEST_INDEX_PATTERN, TEST_ANCHOR_TYPE, TEST_ANCHOR_ID);
|
||||
await PageObjects.context.navigateTo(TEST_INDEX_PATTERN, TEST_ANCHOR_ID);
|
||||
|
||||
await retry.try(async function () {
|
||||
expect(await docTable.getRowsText()).to.have.length(2 * TEST_DEFAULT_CONTEXT_SIZE + 1);
|
||||
|
@ -56,7 +55,7 @@ export default function ({ getService, getPageObjects }) {
|
|||
});
|
||||
|
||||
it('should increase according to the `context:step` setting when clicking the `load newer` button', async function () {
|
||||
await PageObjects.context.navigateTo(TEST_INDEX_PATTERN, TEST_ANCHOR_TYPE, TEST_ANCHOR_ID);
|
||||
await PageObjects.context.navigateTo(TEST_INDEX_PATTERN, TEST_ANCHOR_ID);
|
||||
await PageObjects.context.clickPredecessorLoadMoreButton();
|
||||
|
||||
await retry.try(async function () {
|
||||
|
@ -67,7 +66,7 @@ export default function ({ getService, getPageObjects }) {
|
|||
});
|
||||
|
||||
it('should increase according to the `context:step` setting when clicking the `load older` button', async function () {
|
||||
await PageObjects.context.navigateTo(TEST_INDEX_PATTERN, TEST_ANCHOR_TYPE, TEST_ANCHOR_ID);
|
||||
await PageObjects.context.navigateTo(TEST_INDEX_PATTERN, TEST_ANCHOR_ID);
|
||||
await PageObjects.context.clickSuccessorLoadMoreButton();
|
||||
|
||||
await retry.try(async function () {
|
||||
|
|
|
@ -34,14 +34,14 @@ export function ContextPageProvider({ getService, getPageObjects }) {
|
|||
const log = getService('log');
|
||||
|
||||
class ContextPage {
|
||||
async navigateTo(indexPattern, anchorType, anchorId, overrideInitialState = {}) {
|
||||
async navigateTo(indexPattern, anchorId, overrideInitialState = {}) {
|
||||
const initialState = rison.encode({
|
||||
...DEFAULT_INITIAL_STATE,
|
||||
...overrideInitialState,
|
||||
});
|
||||
const appUrl = getUrl.noAuth(config.get('servers.kibana'), {
|
||||
...config.get('apps.context'),
|
||||
hash: `${config.get('apps.context.hash')}/${indexPattern}/${anchorType}/${anchorId}?_a=${initialState}`,
|
||||
hash: `${config.get('apps.context.hash')}/${indexPattern}/${anchorId}?_a=${initialState}`,
|
||||
});
|
||||
|
||||
log.debug(`browser.get(${appUrl})`);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue