Skip to content

Commit

Permalink
Use getContextUrl in legacy doc table
Browse files Browse the repository at this point in the history
  • Loading branch information
kertal committed Dec 1, 2020
1 parent eb0dade commit af7ca07
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,13 @@
*/

import { find, template } from 'lodash';
import { stringify } from 'query-string';
import $ from 'jquery';
import rison from 'rison-node';
import '../../doc_viewer';

import openRowHtml from './table_row/open.html';
import detailsHtml from './table_row/details.html';

import { dispatchRenderComplete, url } from '../../../../../../kibana_utils/public';
import { dispatchRenderComplete } from '../../../../../../kibana_utils/public';
import { DOC_HIDE_TIME_COLUMN_SETTING } from '../../../../../common';
import cellTemplateHtml from '../components/table_row/cell.html';
import truncateByHeightTemplateHtml from '../components/table_row/truncate_by_height.html';
import { esFilters } from '../../../../../../data/public';
import { getServices } from '../../../../kibana_services';

const TAGS_WITH_WS = />\s+</g;
Expand Down Expand Up @@ -115,25 +109,7 @@ export function createTableRowDirective($compile: ng.ICompileService) {
};

$scope.getContextAppHref = () => {
const globalFilters: any = getServices().filterManager.getGlobalFilters();
const appFilters: any = getServices().filterManager.getAppFilters();

const hash = stringify(
url.encodeQuery({
_g: rison.encode({
filters: globalFilters || [],
}),
_a: rison.encode({
columns: $scope.columns,
filters: (appFilters || []).map(esFilters.disableFilter),
}),
}),
{ encode: false, sort: false }
);

return `#/context/${encodeURIComponent($scope.indexPattern.id)}/${encodeURIComponent(
$scope.row._id
)}?${hash}`;
return getContextUrl($scope.indexPattern.id, $scope.row._id, getServices().filterManager);
};

// create a tr element that lists the value for each *column*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,23 @@

import { getContextUrl } from './get_context_url';
import { FilterManager } from '../../../../data/public/query/filter_manager';
const filterManager = ({
getGlobalFilters: () => [],
getAppFilters: () => [],
} as unknown) as FilterManager;

describe('Get context url', () => {
test('returns a valid context url', async () => {
const filterManager = ({
getGlobalFilters: () => [],
getAppFilters: () => [],
} as unknown) as FilterManager;
test('returning a valid context url', async () => {
const url = await getContextUrl('docId', 'ipId', ['test1', 'test2'], filterManager);
expect(url).toMatchInlineSnapshot(
`"#/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);
expect(url).toMatchInlineSnapshot(
`"#/context/ipId/doc%20Id?_g=(filters:!())&_a=(columns:!(test1,test2),filters:!())"`
);
});
});

0 comments on commit af7ca07

Please sign in to comment.