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

[Discover] Enable sharing for text based languages #156652

Merged
merged 2 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -131,6 +131,13 @@ test('getTopNavLinks result for sql mode', () => {
"run": [Function],
"testId": "discoverOpenButton",
},
Object {
"description": "Share Search",
"id": "share",
"label": "Share",
"run": [Function],
"testId": "shareTopNavButton",
},
Object {
"description": "Open Inspector for search",
"id": "inspect",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,23 @@ export const getTopNavLinks = ({
}),
testId: 'shareTopNavButton',
run: async (anchorElement: HTMLElement) => {
const updatedDataView = await persistDataView(dataView);
if (!services.share || !updatedDataView) {
if (!services.share) {
return;
}
const sharingData = await getSharingData(searchSource, state.appState.getState(), services);
// this prompts the user to save the dataview if adhoc dataview is detected
// for text based languages we don't want this check
if (!isPlainRecord) {
const updatedDataView = await persistDataView(dataView);
if (!updatedDataView) {
return;
}
}
const sharingData = await getSharingData(
searchSource,
state.appState.getState(),
services,
isPlainRecord
);

services.share.toggleShareContextMenu({
anchorElement,
Expand Down Expand Up @@ -208,7 +220,7 @@ export const getTopNavLinks = ({
...(services.capabilities.advancedSettings.save ? [options] : []),
newSearch,
openSearch,
...(!isPlainRecord ? [shareSearch] : []),
shareSearch,
...(services.triggersActionsUi &&
services.capabilities.management?.insightsAndAlerting?.triggersActions &&
!isPlainRecord
Expand Down
35 changes: 35 additions & 0 deletions src/plugins/discover/public/utils/get_sharing_data.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,41 @@ describe('getSharingData', () => {
`);
});

test('fields do not have prepended timeField for text based languages', async () => {
const index = { ...dataViewMock } as DataView;
index.timeFieldName = 'cool-timefield';

const searchSourceMock = createSearchSourceMock({ index });
const result = await getSharingData(
searchSourceMock,
{
columns: [
'cool-field-1',
'cool-field-2',
'cool-field-3',
'cool-field-4',
'cool-field-5',
'cool-field-6',
],
},
services,
true
);
expect(result).toMatchInlineSnapshot(`
Object {
"columns": Array [
"cool-field-1",
"cool-field-2",
"cool-field-3",
"cool-field-4",
"cool-field-5",
"cool-field-6",
],
"getSearchSource": [Function],
}
`);
});

test('fields conditionally do not have prepended timeField', async () => {
services.uiSettings = {
get: (key: string) => {
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/discover/public/utils/get_sharing_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import {
export async function getSharingData(
currentSearchSource: ISearchSource,
state: DiscoverAppState | SavedSearch,
services: { uiSettings: IUiSettingsClient; data: DataPublicPluginStart }
services: { uiSettings: IUiSettingsClient; data: DataPublicPluginStart },
isPlainRecord?: boolean
) {
const { uiSettings: config, data } = services;
const searchSource = currentSearchSource.createCopy();
Expand All @@ -57,7 +58,7 @@ export async function getSharingData(
// conditionally add the time field column:
let timeFieldName: string | undefined;
const hideTimeColumn = config.get(DOC_HIDE_TIME_COLUMN_SETTING);
if (!hideTimeColumn && index && index.timeFieldName) {
if (!hideTimeColumn && index && index.timeFieldName && !isPlainRecord) {
timeFieldName = index.timeFieldName;
}
if (timeFieldName && !columns.includes(timeFieldName)) {
Expand Down
2 changes: 1 addition & 1 deletion test/functional/apps/discover/group2/_sql_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
expect(await testSubjects.exists('unifiedHistogramChart')).to.be(false);
expect(await testSubjects.exists('unifiedHistogramQueryHits')).to.be(true);
expect(await testSubjects.exists('discoverAlertsButton')).to.be(false);
expect(await testSubjects.exists('shareTopNavButton')).to.be(false);
expect(await testSubjects.exists('shareTopNavButton')).to.be(true);
expect(await testSubjects.exists('docTableExpandToggleColumn')).to.be(false);
expect(await testSubjects.exists('dataGridColumnSortingButton')).to.be(false);
expect(await testSubjects.exists('fieldListFiltersFieldTypeFilterToggle')).to.be(true);
Expand Down