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

[Graph] EUI-ification of search bar #45351

Merged
merged 21 commits into from
Sep 19, 2019
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
fb35a66
start implementing indexpattern modal
flash1293 Sep 10, 2019
7b2a0a1
Merge remote-tracking branch 'upstream/master' into graph/indexpatter…
flash1293 Sep 11, 2019
7f67468
style search bar
flash1293 Sep 11, 2019
663293a
add tooltip
flash1293 Sep 11, 2019
b28a547
remove unused translations
flash1293 Sep 11, 2019
c34cbc5
fix initial query handling
flash1293 Sep 11, 2019
1539f6c
Merge remote-tracking branch 'upstream/master' into graph/indexpatter…
flash1293 Sep 11, 2019
cc95842
add tests
flash1293 Sep 12, 2019
b9fa351
Merge remote-tracking branch 'upstream/master' into graph/indexpatter…
flash1293 Sep 13, 2019
f163636
Merge remote-tracking branch 'upstream/master' into graph/indexpatter…
flash1293 Sep 13, 2019
4b5a065
Merge remote-tracking branch 'upstream/master' into graph/indexpatter…
flash1293 Sep 16, 2019
c425db4
Merge remote-tracking branch 'upstream/master' into graph/indexpatter…
flash1293 Sep 17, 2019
28b1c3f
address feedback
flash1293 Sep 17, 2019
9e7d3e3
Merge remote-tracking branch 'upstream/master' into graph/indexpatter…
flash1293 Sep 17, 2019
2ed8d2f
resolve conflicts
flash1293 Sep 17, 2019
d31dc29
Merge remote-tracking branch 'upstream/master' into graph/indexpatter…
flash1293 Sep 18, 2019
d3f6958
fix css
flash1293 Sep 18, 2019
3b17714
Merge remote-tracking branch 'upstream/master' into graph/indexpatter…
flash1293 Sep 18, 2019
6ba5ee4
dont use popover
flash1293 Sep 18, 2019
a09f622
fix type error
flash1293 Sep 18, 2019
55ba4de
Merge remote-tracking branch 'upstream/master' into graph/indexpatter…
flash1293 Sep 19, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ describe('SavedObjectsFinder', () => {
.find(EuiListGroupItem)
.first()
.simulate('click');
expect(chooseStub.calledWith('1', 'search', `${doc.attributes.title} (Search)`)).toEqual(true);
expect(chooseStub.calledWith('1', 'search', `${doc.attributes.title} (Search)`, doc)).toEqual(
true
);
});

describe('sorting', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ interface BaseSavedObjectFinder {
onChoose?: (
id: SimpleSavedObject<SavedObjectAttributes>['id'],
type: SimpleSavedObject<SavedObjectAttributes>['type'],
name: string
name: string,
savedObject: SimpleSavedObject<SavedObjectAttributes>
) => void;
noItemsMessage?: React.ReactNode;
savedObjectMetaData: Array<SavedObjectMetaData<SavedObjectAttributes>>;
Expand Down Expand Up @@ -470,7 +471,7 @@ class SavedObjectFinder extends React.Component<SavedObjectFinderProps, SavedObj
onClick={
onChoose
? () => {
onChoose(item.id, item.type, fullName);
onChoose(item.id, item.type, fullName, item.savedObject);
}
: undefined
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
}

.gphGraph__menus, .gphGraph__bar {
cchaos marked this conversation as resolved.
Show resolved Hide resolved
margin: $euiSizeM $euiSizeM 0 $euiSizeM;
margin: $euiSizeS;
}

.gphGraph__flexGroup {
Expand Down
36 changes: 10 additions & 26 deletions x-pack/legacy/plugins/graph/public/angular/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
<div class="gphGraph__menus" ng-show="menus.showInspect">
<graph-inspect ng-show="menus.showInspect"></graph-inspect>
</div>

<graph-search-bar
current-index-pattern="selectedIndex"
on-index-pattern-selected="uiSelectIndex"
on-query-submit="submit"
saved-objects="pluginDependencies.savedObjects"
ui-settings="pluginDependencies.uiSettings"
is-loading="loading"
initial-query="initialQuery"
></graph-search-bar>

<div class="gphGraph__bar">
<div class="gphGraph__flexGroup">
<!-- Select index pattern. -->
<select class="form-control gphIndexSelect" name="mySelect" ng-change="uiSelectIndex()" ng-class="{'gphIndexSelect-unselected':selectedIndex === null}"
ng-options="option.attributes.title for option in indices" ng-model="grr.proposedIndex">
<option
value=""
i18n-id="xpack.graph.topNavMenu.selectIndexPatternOptionLabel"
i18n-default-message="Select index pattern…"
></option>
</select>

<!-- Added fields. -->
<span
class="gphNoUserSelect"
Expand Down Expand Up @@ -53,22 +53,6 @@
<span aria-hidden="true" class="kuiIcon fa-plus"></span>
</button>
</span>

<!-- Search. -->
<form ng-submit="submit()" name="graphBasicSearch" class="gphGraph__flexGroupFiller" style="width: 100%">
<div class="kuiLocalSearch">
<input name="searchTerm" type="text" class="kuiLocalSearchInput" ng-model="grr.searchTerm" ng-disabled="liveResponseFields.length === 0"
ng-focus="kbnTopNav.close()" placeholder="foo AND bar NOT baz" autocomplete="off">
<button
class="kuiLocalSearchButton"
type="submit"
ng-disabled="liveResponseFields.length === 0"
aria-label="{{ ::'xpack.graph.topNavMenu.searchButtonAriaLabel' | i18n: { defaultMessage: 'Search' } }}"
>
<span aria-hidden="true" class="kuiIcon fa-search"></span>
</button>
</div>
</form>
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
></div>

<div
class="list-group-item list-group-item--noBorder"
class="list-group-item"
ng-if="(workspace !== null)"
>
<small class="help-block">http://host:port/{{ selectedIndex.name }}/_graph/explore</small>
Expand Down
61 changes: 43 additions & 18 deletions x-pack/legacy/plugins/graph/public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { getReadonlyBadge } from './badge';
import { FormattedMessage } from '@kbn/i18n/react';

import { GraphListing } from './components/graph_listing';
import { GraphSearchBar } from './components/graph_search_bar';
import { GraphSettings } from './components/graph_settings/graph_settings';

import './angular/angular_venn_simple.js';
Expand All @@ -56,8 +57,9 @@ import {
outlinkEncoders,
} from './services/outlink_encoders';
import { getEditUrl, getNewPath, getEditPath, setBreadcrumbs, getHomePath } from './services/url';
import { appStateToSavedWorkspace, savedWorkspaceToAppState, lookupIndexPattern, mapFields } from './services/persistence';
import { openIndexPatternModal } from './services/source';
import { save } from './services/save_modal';
import { appStateToSavedWorkspace, savedWorkspaceToAppState, lookupIndexPattern, mapFields } from './services/persistence';
import { urlTemplateRegex } from './services/url_template';
import {
asAngularSyncedObservable,
Expand Down Expand Up @@ -92,6 +94,17 @@ app.directive('graphListing', function (reactDirective) {
return reactDirective(GraphListing);
});

app.directive('graphSearchBar', function (reactDirective) {
return reactDirective(GraphSearchBar, [
['currentIndexPattern', { watchDepth: 'reference' }],
['isLoading', { watchDepth: 'reference' }],
['onIndexPatternSelected', { watchDepth: 'reference' }],
['onQuerySubmit', { watchDepth: 'reference' }],
['savedObjects', { watchDepth: 'reference' }],
['uiSettings', { watchDepth: 'reference' }]
]);
});

if (uiRoutes.enable) {
uiRoutes.enable();
}
Expand Down Expand Up @@ -239,6 +252,10 @@ app.controller('graphuiPlugin', function (
$scope.allSavingDisabled = $scope.graphSavePolicy === 'none';
$scope.searchTerm = '';

$scope.pluginDependencies = npStart.core;

$scope.loading = false;

//So scope properties can be used consistently with ng-model
$scope.grr = $scope;

Expand Down Expand Up @@ -375,11 +392,9 @@ app.controller('graphuiPlugin', function (
}), confirmModalOptions);
}

$scope.uiSelectIndex = function () {
$scope.uiSelectIndex = function (proposedIndex) {
canWipeWorkspace(function () {
$scope.indexSelected($scope.proposedIndex);
}, function () {
$scope.proposedIndex = $scope.selectedIndex;
$scope.indexSelected(proposedIndex);
});
};

Expand Down Expand Up @@ -420,6 +435,7 @@ app.controller('graphuiPlugin', function (
index: indexName,
query: query
};
$scope.loading = true;
return $http.post('../api/graph/graphExplore', request)
.then(function (resp) {
if (resp.data.resp.timed_out) {
Expand All @@ -431,7 +447,10 @@ app.controller('graphuiPlugin', function (
}
responseHandler(resp.data.resp);
})
.catch(handleHttpError);
.catch(handleHttpError)
.finally(() => {
$scope.loading = false;
});
}


Expand All @@ -441,20 +460,24 @@ app.controller('graphuiPlugin', function (
index: indexName,
body: query
};
$scope.loading = true;
$http.post('../api/graph/searchProxy', request)
.then(function (resp) {
responseHandler(resp.data.resp);
})
.catch(handleHttpError);
.catch(handleHttpError)
.finally(() => {
$scope.loading = false;
});
};

$scope.submit = function () {
$scope.submit = function (searchTerm) {
$scope.hideAllConfigPanels();
initWorkspaceIfRequired();
const numHops = 2;
if ($scope.searchTerm.startsWith('{')) {
if (searchTerm.startsWith('{')) {
try {
const query = JSON.parse($scope.searchTerm);
const query = JSON.parse(searchTerm);
if (query.vertices) {
// Is a graph explore request
$scope.workspace.callElasticsearch(query);
Expand All @@ -468,7 +491,7 @@ app.controller('graphuiPlugin', function (
}
return;
}
$scope.workspace.simpleSearch($scope.searchTerm, $scope.liveResponseFields, numHops);
$scope.workspace.simpleSearch(searchTerm, $scope.liveResponseFields, numHops);
};

$scope.clearWorkspace = function () {
Expand Down Expand Up @@ -639,9 +662,6 @@ app.controller('graphuiPlugin', function (
}
}

$scope.indices = $route.current.locals.indexPatterns.filter(indexPattern => !indexPattern.attributes.type);


$scope.setDetail = function (data) {
$scope.detail = data;
};
Expand Down Expand Up @@ -713,7 +733,7 @@ app.controller('graphuiPlugin', function (
const managementUrl = npStart.core.chrome.navLinks.get('kibana:management').url;
const url = `${managementUrl}/kibana/index_patterns`;

if ($scope.indices.length === 0) {
if ($route.current.locals.indexPatterns.length === 0) {
toastNotifications.addWarning({
title: i18n.translate('xpack.graph.noDataSourceNotificationMessageTitle', {
defaultMessage: 'No data source',
Expand Down Expand Up @@ -755,7 +775,9 @@ app.controller('graphuiPlugin', function (
}),
run: function () {
canWipeWorkspace(function () {
kbnUrl.change('/workspace/', {});
$scope.$evalAsync(() => {
kbnUrl.change('/workspace/', {});
});
}); },
testId: 'graphNewButton',
});
Expand Down Expand Up @@ -911,13 +933,16 @@ app.controller('graphuiPlugin', function (
}
// Allow URLs to include a user-defined text query
if ($route.current.params.query) {
$scope.searchTerm = $route.current.params.query;
$scope.submit();
$scope.initialQuery = $route.current.params.query;
$scope.submit($route.current.params.query);
}
});
} else {
$route.current.locals.SavedWorkspacesProvider.get().then(function (newWorkspace) {
$scope.savedWorkspace = newWorkspace;
openIndexPatternModal(npStart.core, indexPattern => {
$scope.indexSelected(indexPattern);
});
});
}

Expand Down
1 change: 1 addition & 0 deletions x-pack/legacy/plugins/graph/public/components/_index.scss
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
@import './search_bar';
@import './graph_settings/index';
12 changes: 12 additions & 0 deletions x-pack/legacy/plugins/graph/public/components/_search_bar.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.gphSearchBar {
padding: 0 $euiSizeS;
}

.gphSearchBar__datasourceButton {
height: 100% !important;
border: none;
}

.gphSearchBar__datasourceButtonTooltip {
padding: 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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 { GraphSearchBar } from './graph_search_bar';
import { shallowWithIntl } from 'test_utils/enzyme_helpers';
import React, { ReactElement } from 'react';
import { CoreStart } from 'src/core/public';
import { IndexPatternSavedObject } from '../types';
import { act } from 'react-dom/test-utils';
import { EuiFieldText } from '@elastic/eui';

describe('graph_search_bar', () => {
it('should render search bar and submit queryies', () => {
const querySubmit = jest.fn();
const instance = shallowWithIntl(
<GraphSearchBar
isLoading={false}
onIndexPatternSelected={() => {}}
onQuerySubmit={querySubmit}
savedObjects={{} as CoreStart['savedObjects']}
uiSettings={{} as CoreStart['uiSettings']}
currentIndexPattern={{ attributes: { title: 'Testpattern' } } as IndexPatternSavedObject}
/>
);
act(() => {
instance.find(EuiFieldText).simulate('change', { target: { value: 'testQuery' } });
});

act(() => {
instance.find('form').simulate('submit', { preventDefault: () => {} });
});

expect(querySubmit).toHaveBeenCalledWith('testQuery');
});

it('should render index pattern picker', () => {
const indexPatternSelected = jest.fn();
const instance = shallowWithIntl(
<GraphSearchBar
isLoading={false}
onIndexPatternSelected={indexPatternSelected}
onQuerySubmit={() => {}}
savedObjects={{} as CoreStart['savedObjects']}
uiSettings={{} as CoreStart['uiSettings']}
currentIndexPattern={{ attributes: { title: 'Testpattern' } } as IndexPatternSavedObject}
/>
);

const newIndexpattern = {} as IndexPatternSavedObject;

// pick the GraphSourcePicker component out of the tree because
// it's part of a popover and thus not covered by enzyme
(instance
.find(EuiFieldText)
.prop('prepend') as ReactElement).props.children.props.onIndexPatternSelected(
newIndexpattern
);

expect(indexPatternSelected).toHaveBeenCalledWith(newIndexpattern);
});
});
Loading