Skip to content

Commit

Permalink
[Discover] Fix link from dashboard saved search to Discover
Browse files Browse the repository at this point in the history
  • Loading branch information
wylieconlon committed Feb 25, 2021
1 parent 1f58bc2 commit 6ed0143
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ describe('Doc Table', () => {
setServices({
uiSettings: core.uiSettings,
filterManager: dataMock.query.filterManager,
addBasePath: (path) => path,
});

setDocViewsRegistry({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,16 @@ export function createTableRowDirective($compile: ng.ICompileService) {
$scope.row._id,
$scope.indexPattern.id,
$scope.columns,
getServices().filterManager
getServices().filterManager,
getServices().addBasePath
);
};

$scope.getSingleDocHref = () => {
return getServices().addBasePath(
`/app/discover#/doc/${$scope.indexPattern.id}/${
$scope.row._index
}?id=${encodeURIComponent($scope.row._id)}`
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<a
class="euiLink"
data-test-subj="docTableRowAction"
ng-href="#/doc/{{indexPattern.id}}/{{row._index}}?id={{uriEncodedId}}"
ng-href="{{ getSingleDocHref() }}"
i18n-id="discover.docTable.tableRow.viewSingleDocumentLinkText"
i18n-default-message="View single document"
></a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</div>
</div>
<div class="kbnDocTable__container kbnDocTable__padBottom">
<table class="kbnDocTable table" ng-if="indexPattern">
<table class="kbnDocTable table" ng-if="indexPattern" data-test-subj="docTable">
<thead
kbn-table-header
columns="columns"
Expand All @@ -44,6 +44,7 @@
index-pattern="indexPattern"
filter="filter"
class="kbnDocTable__row"
data-test-subj="docTableRow{{ row['$$_isAnchor'] ? ' docTableAnchorRow' : ''}}"
on-add-column="onAddColumn"
on-remove-column="onRemoveColumn"
use-new-fields-api="useNewFieldsApi"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ describe('Discover flyout', function () {
onClose={onClose}
onFilter={jest.fn()}
onRemoveColumn={jest.fn()}
services={({ filterManager: createFilterManagerMock() } as unknown) as DiscoverServices}
services={
({
filterManager: createFilterManagerMock(),
addBasePath: (path: string) => path,
} as unknown) as DiscoverServices
}
/>
);

Expand All @@ -53,7 +58,12 @@ describe('Discover flyout', function () {
onClose={onClose}
onFilter={jest.fn()}
onRemoveColumn={jest.fn()}
services={({ filterManager: createFilterManagerMock() } as unknown) as DiscoverServices}
services={
({
filterManager: createFilterManagerMock(),
addBasePath: (path: string) => path,
} as unknown) as DiscoverServices
}
/>
);

Expand All @@ -63,7 +73,7 @@ describe('Discover flyout', function () {
`"#/doc/index-pattern-with-timefield-id/i?id=1"`
);
expect(actions.last().prop('href')).toMatchInlineSnapshot(
`"#/context/index-pattern-with-timefield-id/1?_g=(filters:!())&_a=(columns:!(date),filters:!())"`
`"/app/discover#/context/index-pattern-with-timefield-id/1?_g=(filters:!())&_a=(columns:!(date),filters:!())"`
);
findTestSubject(component, 'euiFlyoutCloseButton').simulate('click');
expect(onClose).toHaveBeenCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@ export function DiscoverGridFlyout({
<EuiButtonEmpty
size="xs"
iconType="documents"
href={getContextUrl(hit._id, indexPattern.id, columns, services.filterManager)}
href={getContextUrl(
hit._id,
indexPattern.id,
columns,
services.filterManager,
services.addBasePath
)}
data-test-subj="docTableRowAction"
>
{i18n.translate('discover.grid.tableRow.viewSurroundingDocumentsLinkTextSimple', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,32 @@ const filterManager = ({
getGlobalFilters: () => [],
getAppFilters: () => [],
} as unknown) as FilterManager;
const addBasePath = (path: string) => `/base/${path}`;

describe('Get context url', () => {
test('returning a valid context url', async () => {
const url = await getContextUrl('docId', 'ipId', ['test1', 'test2'], filterManager);
const url = await getContextUrl(
'docId',
'ipId',
['test1', 'test2'],
filterManager,
addBasePath
);
expect(url).toMatchInlineSnapshot(
`"#/context/ipId/docId?_g=(filters:!())&_a=(columns:!(test1,test2),filters:!())"`
`"/base//app/discover#/context/ipId/docId?_g=(filters:!())&_a=(columns:!(test1,test2),filters:!())"`
);
});

test('returning a valid context url when docId contains whitespace', async () => {
const url = await getContextUrl('doc Id', 'ipId', ['test1', 'test2'], filterManager);
const url = await getContextUrl(
'doc Id',
'ipId',
['test1', 'test2'],
filterManager,
addBasePath
);
expect(url).toMatchInlineSnapshot(
`"#/context/ipId/doc%20Id?_g=(filters:!())&_a=(columns:!(test1,test2),filters:!())"`
`"/base//app/discover#/context/ipId/doc%20Id?_g=(filters:!())&_a=(columns:!(test1,test2),filters:!())"`
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { stringify } from 'query-string';
import rison from 'rison-node';
import { url } from '../../../../kibana_utils/common';
import { esFilters, FilterManager } from '../../../../data/public';
import { DiscoverServices } from '../../build_services';

/**
* Helper function to generate an URL to a document in Discover's context view
Expand All @@ -18,7 +19,8 @@ export function getContextUrl(
documentId: string,
indexPatternId: string,
columns: string[],
filterManager: FilterManager
filterManager: FilterManager,
addBasePath: DiscoverServices['addBasePath']
) {
const globalFilters = filterManager.getGlobalFilters();
const appFilters = filterManager.getAppFilters();
Expand All @@ -36,7 +38,9 @@ export function getContextUrl(
{ encode: false, sort: false }
);

return `#/context/${encodeURIComponent(indexPatternId)}/${encodeURIComponent(
documentId
)}?${hash}`;
return addBasePath(
`/app/discover#/context/${encodeURIComponent(indexPatternId)}/${encodeURIComponent(
documentId
)}?${hash}`
);
}
31 changes: 30 additions & 1 deletion test/functional/apps/context/_discover_navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,17 @@ export default function ({ getService, getPageObjects }) {
const retry = getService('retry');
const docTable = getService('docTable');
const filterBar = getService('filterBar');
const PageObjects = getPageObjects(['common', 'discover', 'timePicker', 'context']);
const PageObjects = getPageObjects([
'common',
'discover',
'timePicker',
'settings',
'dashboard',
'context',
'header',
]);
const testSubjects = getService('testSubjects');
const dashboardAddPanel = getService('dashboardAddPanel');

describe('context link in discover', () => {
before(async () => {
Expand Down Expand Up @@ -94,5 +103,25 @@ export default function ({ getService, getPageObjects }) {
await PageObjects.discover.waitForDiscoverAppOnScreen();
await PageObjects.discover.waitForDocTableLoadingComplete();
});

it('navigates to context view from embeddable', async () => {
await PageObjects.common.navigateToApp('discover');
await PageObjects.discover.saveSearch('my search');
await PageObjects.header.waitUntilLoadingHasFinished();

await PageObjects.common.navigateToApp('dashboard');
await PageObjects.dashboard.gotoDashboardLandingPage();
await PageObjects.dashboard.clickNewDashboard();

await dashboardAddPanel.addSavedSearch('my search');
await PageObjects.header.waitUntilLoadingHasFinished();

await docTable.clickRowToggle({ rowIndex: 0 });
const rowActions = await docTable.getRowActions({ rowIndex: 0 });
await rowActions[1].click();
await PageObjects.header.waitUntilLoadingHasFinished();
const contextFields = await docTable.getFields();
expect(contextFields.length).to.be.greaterThan(0);
});
});
}
31 changes: 30 additions & 1 deletion test/functional/apps/discover/_data_grid_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const filterBar = getService('filterBar');
const dataGrid = getService('dataGrid');
const docTable = getService('docTable');
const PageObjects = getPageObjects(['common', 'discover', 'timePicker', 'settings']);
const PageObjects = getPageObjects([
'common',
'discover',
'timePicker',
'settings',
'dashboard',
'header',
]);
const defaultSettings = { defaultIndex: 'logstash-*', 'doc_table:legacy': false };
const kibanaServer = getService('kibanaServer');
const esArchiver = getService('esArchiver');
const dashboardAddPanel = getService('dashboardAddPanel');

describe('discover data grid context tests', () => {
before(async () => {
Expand Down Expand Up @@ -78,5 +86,26 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
}
expect(disabledFilterCounter).to.be(TEST_FILTER_COLUMN_NAMES.length);
});

// Skipped because there is a bug in the data grid row expansion
it.skip('navigates to context view from embeddable', async () => {
await PageObjects.common.navigateToApp('discover');
await PageObjects.discover.saveSearch('my search');
await PageObjects.header.waitUntilLoadingHasFinished();

await PageObjects.common.navigateToApp('dashboard');
await PageObjects.dashboard.gotoDashboardLandingPage();
await PageObjects.dashboard.clickNewDashboard();

await dashboardAddPanel.addSavedSearch('my search');
await PageObjects.header.waitUntilLoadingHasFinished();

await dataGrid.clickRowToggle({ rowIndex: 0 });
const rowActions = await docTable.getRowActions({ rowIndex: 0 });
await rowActions[1].click();
await PageObjects.header.waitUntilLoadingHasFinished();
const contextFields = await docTable.getFields();
expect(contextFields.length).to.be.greaterThan(0);
});
});
}

0 comments on commit 6ed0143

Please sign in to comment.