From eefa04a5ef7cf73915ca8907f2c90bd47e426b84 Mon Sep 17 00:00:00 2001 From: Stratoula Kalafateli Date: Thu, 4 May 2023 11:29:17 +0300 Subject: [PATCH 1/2] [Discover] Enable sharing for text based languages --- .../top_nav/get_top_nav_links.test.ts | 7 ++++ .../components/top_nav/get_top_nav_links.tsx | 20 ++++++++--- .../public/utils/get_sharing_data.test.ts | 35 +++++++++++++++++++ .../discover/public/utils/get_sharing_data.ts | 5 +-- 4 files changed, 61 insertions(+), 6 deletions(-) diff --git a/src/plugins/discover/public/application/main/components/top_nav/get_top_nav_links.test.ts b/src/plugins/discover/public/application/main/components/top_nav/get_top_nav_links.test.ts index 0503fd4ff37e9..fcd52f1563acf 100644 --- a/src/plugins/discover/public/application/main/components/top_nav/get_top_nav_links.test.ts +++ b/src/plugins/discover/public/application/main/components/top_nav/get_top_nav_links.test.ts @@ -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", diff --git a/src/plugins/discover/public/application/main/components/top_nav/get_top_nav_links.tsx b/src/plugins/discover/public/application/main/components/top_nav/get_top_nav_links.tsx index 59723e5b1225f..3707e83697fb5 100644 --- a/src/plugins/discover/public/application/main/components/top_nav/get_top_nav_links.tsx +++ b/src/plugins/discover/public/application/main/components/top_nav/get_top_nav_links.tsx @@ -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, @@ -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 diff --git a/src/plugins/discover/public/utils/get_sharing_data.test.ts b/src/plugins/discover/public/utils/get_sharing_data.test.ts index d1d636a2d1c83..ef707d70d9515 100644 --- a/src/plugins/discover/public/utils/get_sharing_data.test.ts +++ b/src/plugins/discover/public/utils/get_sharing_data.test.ts @@ -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) => { diff --git a/src/plugins/discover/public/utils/get_sharing_data.ts b/src/plugins/discover/public/utils/get_sharing_data.ts index 6863a01ed13fa..c9c8dd5c7bb1c 100644 --- a/src/plugins/discover/public/utils/get_sharing_data.ts +++ b/src/plugins/discover/public/utils/get_sharing_data.ts @@ -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(); @@ -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)) { From b35c678c0c077b70a2f9bf8aa4978bba7a086275 Mon Sep 17 00:00:00 2001 From: Stratoula Kalafateli Date: Thu, 4 May 2023 12:40:51 +0300 Subject: [PATCH 2/2] Fix FT --- test/functional/apps/discover/group2/_sql_view.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/apps/discover/group2/_sql_view.ts b/test/functional/apps/discover/group2/_sql_view.ts index 0cc3882bcb00d..535f6e83a432f 100644 --- a/test/functional/apps/discover/group2/_sql_view.ts +++ b/test/functional/apps/discover/group2/_sql_view.ts @@ -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);