From e05d297aaa2f140d227381f9f364f885f47850f3 Mon Sep 17 00:00:00 2001 From: Ashwin P Chandran Date: Tue, 10 Oct 2023 11:53:03 -0700 Subject: [PATCH 1/5] Adds popular field to discover (#5259) Signed-off-by: Ashwin P Chandran --- .../application/helpers/popularize_field.ts | 4 ++-- .../view_components/canvas/discover_table.tsx | 19 +++++++++++++++++-- .../view_components/panel/index.tsx | 11 +++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/plugins/discover/public/application/helpers/popularize_field.ts b/src/plugins/discover/public/application/helpers/popularize_field.ts index e7c4b900fa19..c41223c425ac 100644 --- a/src/plugins/discover/public/application/helpers/popularize_field.ts +++ b/src/plugins/discover/public/application/helpers/popularize_field.ts @@ -28,12 +28,12 @@ * under the License. */ -import { IndexPattern, IndexPatternsService } from '../../../../data/public'; +import { IndexPattern, IndexPatternsContract } from '../../../../data/public'; async function popularizeField( indexPattern: IndexPattern, fieldName: string, - indexPatternsService: IndexPatternsService + indexPatternsService: IndexPatternsContract ) { if (!indexPattern.id) return; const field = indexPattern.fields.getByName(fieldName); diff --git a/src/plugins/discover/public/application/view_components/canvas/discover_table.tsx b/src/plugins/discover/public/application/view_components/canvas/discover_table.tsx index 4e3f6bf04b24..3f7bbf4ec7b8 100644 --- a/src/plugins/discover/public/application/view_components/canvas/discover_table.tsx +++ b/src/plugins/discover/public/application/view_components/canvas/discover_table.tsx @@ -21,6 +21,7 @@ import { DocViewFilterFn } from '../../doc_views/doc_views_types'; import { SortOrder } from '../../../saved_searches/types'; import { DOC_HIDE_TIME_COLUMN_SETTING } from '../../../../common'; import { OpenSearchSearchHit } from '../../doc_views/doc_views_types'; +import { popularizeField } from '../../helpers/popularize_field'; interface Props { rows?: OpenSearchSearchHit[]; @@ -33,13 +34,27 @@ export const DiscoverTable = ({ rows }: Props) => { data: { query: { filterManager }, }, + capabilities, + indexPatterns, } = services; const { refetch$, indexPattern, savedSearch } = useDiscoverContext(); const { columns, sort } = useSelector((state) => state.discover); const dispatch = useDispatch(); - const onAddColumn = (col: string) => dispatch(addColumn({ column: col })); - const onRemoveColumn = (col: string) => dispatch(removeColumn(col)); + const onAddColumn = (col: string) => { + if (indexPattern && capabilities.discover?.save) { + popularizeField(indexPattern, col, indexPatterns); + } + + dispatch(addColumn({ column: col })); + }; + const onRemoveColumn = (col: string) => { + if (indexPattern && capabilities.discover?.save) { + popularizeField(indexPattern, col, indexPatterns); + } + + dispatch(removeColumn(col)); + }; const onSetColumns = (cols: string[]) => dispatch(setColumns({ columns: cols })); const onSetSort = (s: SortOrder[]) => { dispatch(setSort(s)); diff --git a/src/plugins/discover/public/application/view_components/panel/index.tsx b/src/plugins/discover/public/application/view_components/panel/index.tsx index 203b24b8819f..bbf5331fb16e 100644 --- a/src/plugins/discover/public/application/view_components/panel/index.tsx +++ b/src/plugins/discover/public/application/view_components/panel/index.tsx @@ -18,6 +18,7 @@ import { ResultStatus, SearchData } from '../utils/use_search'; import { IndexPatternField, opensearchFilters } from '../../../../../data/public'; import { useOpenSearchDashboards } from '../../../../../opensearch_dashboards_react/public'; import { DiscoverViewServices } from '../../../build_services'; +import { popularizeField } from '../../helpers/popularize_field'; // eslint-disable-next-line import/no-default-export export default function DiscoverPanel(props: ViewProps) { @@ -26,6 +27,8 @@ export default function DiscoverPanel(props: ViewProps) { data: { query: { filterManager }, }, + capabilities, + indexPatterns, } = services; const { data$, indexPattern } = useDiscoverContext(); const [fetchState, setFetchState] = useState(data$.getValue()); @@ -67,6 +70,10 @@ export default function DiscoverPanel(props: ViewProps) { fieldCounts={fetchState.fieldCounts || {}} hits={fetchState.rows || []} onAddField={(fieldName, index) => { + if (indexPattern && capabilities.discover?.save) { + popularizeField(indexPattern, fieldName, indexPatterns); + } + dispatch( addColumn({ column: fieldName, @@ -75,6 +82,10 @@ export default function DiscoverPanel(props: ViewProps) { ); }} onRemoveField={(fieldName) => { + if (indexPattern && capabilities.discover?.save) { + popularizeField(indexPattern, fieldName, indexPatterns); + } + dispatch(removeColumn(fieldName)); }} onReorderFields={(source, destination) => { From 5f45553344b70327da5514f10f417c05574aae60 Mon Sep 17 00:00:00 2001 From: Ashwin P Chandran Date: Tue, 10 Oct 2023 11:53:27 -0700 Subject: [PATCH 2/5] Fixes recently accessed (#5258) Signed-off-by: Ashwin P Chandran --- .../application/utils/state_management/index.ts | 3 +-- .../view_components/utils/use_index_pattern.ts | 8 ++++---- .../application/view_components/utils/use_search.ts | 12 ++++++++++-- .../discover/public/saved_searches/_saved_search.ts | 2 +- src/plugins/discover/public/saved_searches/types.ts | 5 ++++- 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/plugins/discover/public/application/utils/state_management/index.ts b/src/plugins/discover/public/application/utils/state_management/index.ts index 9e0d5bc64ffd..989b2662f0d4 100644 --- a/src/plugins/discover/public/application/utils/state_management/index.ts +++ b/src/plugins/discover/public/application/utils/state_management/index.ts @@ -6,7 +6,6 @@ import { TypedUseSelectorHook } from 'react-redux'; import { RootState, - Store as StoreType, setIndexPattern as updateIndexPattern, useTypedDispatch, useTypedSelector, @@ -21,4 +20,4 @@ export interface DiscoverRootState extends RootState { export const useSelector: TypedUseSelectorHook = useTypedSelector; export const useDispatch = useTypedDispatch; -export { StoreType, updateIndexPattern }; +export { updateIndexPattern }; diff --git a/src/plugins/discover/public/application/view_components/utils/use_index_pattern.ts b/src/plugins/discover/public/application/view_components/utils/use_index_pattern.ts index 10a795abac37..e8a81234278e 100644 --- a/src/plugins/discover/public/application/view_components/utils/use_index_pattern.ts +++ b/src/plugins/discover/public/application/view_components/utils/use_index_pattern.ts @@ -6,8 +6,8 @@ import { useEffect, useState } from 'react'; import { i18n } from '@osd/i18n'; import { IndexPattern } from '../../../../../data/public'; -import { useSelector, updateIndexPattern, StoreType } from '../../utils/state_management'; -import { DiscoverServices } from '../../../build_services'; +import { useSelector, updateIndexPattern } from '../../utils/state_management'; +import { DiscoverViewServices } from '../../../build_services'; import { getIndexPatternId } from '../../helpers/get_index_pattern_id'; /** @@ -24,10 +24,10 @@ import { getIndexPatternId } from '../../helpers/get_index_pattern_id'; * @param store - The redux store in data_explorer to dispatch actions. * @returns - The fetched index pattern. */ -export const useIndexPattern = (services: DiscoverServices, store: StoreType) => { +export const useIndexPattern = (services: DiscoverViewServices) => { const indexPatternIdFromState = useSelector((state) => state.metadata.indexPattern); const [indexPattern, setIndexPattern] = useState(undefined); - const { data, toastNotifications, uiSettings: config } = services; + const { data, toastNotifications, uiSettings: config, store } = services; useEffect(() => { let isMounted = true; diff --git a/src/plugins/discover/public/application/view_components/utils/use_search.ts b/src/plugins/discover/public/application/view_components/utils/use_search.ts index d8c25e1a98e7..7e284ef6f443 100644 --- a/src/plugins/discover/public/application/view_components/utils/use_search.ts +++ b/src/plugins/discover/public/application/view_components/utils/use_search.ts @@ -70,8 +70,8 @@ export const useSearch = (services: DiscoverViewServices) => { const initalSearchComplete = useRef(false); const [savedSearch, setSavedSearch] = useState(undefined); const { savedSearch: savedSearchId, sort, interval } = useSelector((state) => state.discover); - const { data, filterManager, getSavedSearchById, core, toastNotifications, store } = services; - const indexPattern = useIndexPattern(services, store); + const { data, filterManager, getSavedSearchById, core, toastNotifications, chrome } = services; + const indexPattern = useIndexPattern(services); const timefilter = data.query.timefilter.timefilter; const fetchStateRef = useRef<{ abortController: AbortController | undefined; @@ -284,6 +284,14 @@ export const useSearch = (services: DiscoverViewServices) => { filterManager.setAppFilters(actualFilters); data.query.queryString.setQuery(query); + + if (savedSearchInstance?.id) { + chrome.recentlyAccessed.add( + savedSearchInstance.getFullPath(), + savedSearchInstance.title, + savedSearchInstance.id + ); + } })(); return () => {}; diff --git a/src/plugins/discover/public/saved_searches/_saved_search.ts b/src/plugins/discover/public/saved_searches/_saved_search.ts index 9b43e3a89203..835055c65602 100644 --- a/src/plugins/discover/public/saved_searches/_saved_search.ts +++ b/src/plugins/discover/public/saved_searches/_saved_search.ts @@ -80,7 +80,7 @@ export function createSavedSearchClass(services: SavedObjectOpenSearchDashboards }); this.showInRecentlyAccessed = true; this.id = id; - this.getFullPath = () => `/app/discover#/view/${String(id)}`; + this.getFullPath = () => `/app/discover#/view/${String(this.id)}`; } } diff --git a/src/plugins/discover/public/saved_searches/types.ts b/src/plugins/discover/public/saved_searches/types.ts index 112d7d998c97..f67df00a900c 100644 --- a/src/plugins/discover/public/saved_searches/types.ts +++ b/src/plugins/discover/public/saved_searches/types.ts @@ -33,7 +33,10 @@ import { ISearchSource } from '../../../data/public'; export type SortOrder = [string, 'asc' | 'desc']; export interface SavedSearch - extends Pick { + extends Pick< + SavedObject, + 'id' | 'title' | 'copyOnSave' | 'destroy' | 'lastSavedTitle' | 'save' | 'getFullPath' + > { searchSource: ISearchSource; // This is optional in SavedObject, but required for SavedSearch description?: string; columns: string[]; From df0838785f7d758f6519caf5a36690ca89d4a65e Mon Sep 17 00:00:00 2001 From: Abilash inamdar Date: Wed, 11 Oct 2023 00:23:50 +0530 Subject: [PATCH 3/5] [Data Explorer] Removed X icon in data source selection. (#5238) * removed X icon in data source selection. Signed-off-by: Abhilash * updated changelog Signed-off-by: Abhilash * Update CHANGELOG.md Signed-off-by: Miki --------- Signed-off-by: Abhilash Signed-off-by: Ashwin P Chandran Signed-off-by: Miki Co-authored-by: Abhilash Co-authored-by: Ashwin P Chandran Co-authored-by: Miki --- CHANGELOG.md | 1 + .../data_sources/datasource_selector/datasource_selectable.tsx | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 56ca0743f81f..7c4b1bf70e1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - [Data Explorer][Discover] Allow data grid to auto adjust size based on fetched data count ([#5191](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5191)) - [BUG] Fix wrong test due to time conversion ([#5174](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5174)) - [BUG][Data Explorer][Discover] Allow filter and query persist when refresh page or paste url to a new tab ([#5206](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5206)) +- [Data Explorer] Remove the `X` icon in data source selection field ([#5238](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5238)) - [BUG][Fuctional Test] Make setDefaultAbsoluteRange more robust and update doc views tests ([#5242](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5242)) ### 🚞 Infrastructure diff --git a/src/plugins/data/public/data_sources/datasource_selector/datasource_selectable.tsx b/src/plugins/data/public/data_sources/datasource_selector/datasource_selectable.tsx index 77b44c206d6d..f522da79c129 100644 --- a/src/plugins/data/public/data_sources/datasource_selector/datasource_selectable.tsx +++ b/src/plugins/data/public/data_sources/datasource_selector/datasource_selectable.tsx @@ -128,6 +128,7 @@ export const DataSourceSelectable = ({ selectedOptions={selectedSources as any} onChange={handleSourceChange} singleSelection={singleSelection} + isClearable={false} async /> ); From b3104ce6ca1af405426f59a447effd15ab2a6d4c Mon Sep 17 00:00:00 2001 From: Anan Zhuang Date: Tue, 10 Oct 2023 12:27:29 -0700 Subject: [PATCH 4/5] [BUG][Discover] Allow default columns settings (#5261) * [BUG][Discover] Allow default columns settings This is a missing functionality * When user sets up `Default columns` in advanced settings, discover should display default columns if the selected idp has the columns. * If selected idp has no such columns, display `_source` column. Issue Resolve https://github.com/opensearch-project/OpenSearch-Dashboards/issues/5246 Signed-off-by: ananzh * fix unit test Signed-off-by: ananzh --------- Signed-off-by: ananzh --- .../utils/state_management/discover_slice.tsx | 5 ++++- .../view_components/utils/filter_columns.test.ts | 13 ++++++------- .../view_components/utils/filter_columns.ts | 6 ++++-- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/plugins/discover/public/application/utils/state_management/discover_slice.tsx b/src/plugins/discover/public/application/utils/state_management/discover_slice.tsx index 270198149e6b..f90d400ff3d5 100644 --- a/src/plugins/discover/public/application/utils/state_management/discover_slice.tsx +++ b/src/plugins/discover/public/application/utils/state_management/discover_slice.tsx @@ -11,7 +11,7 @@ import { RootState, DefaultViewState } from '../../../../../data_explorer/public import { buildColumns } from '../columns'; import * as utils from './common'; import { SortOrder } from '../../../saved_searches/types'; -import { PLUGIN_ID } from '../../../../common'; +import { DEFAULT_COLUMNS_SETTING, PLUGIN_ID } from '../../../../common'; export interface DiscoverState { /** @@ -57,6 +57,7 @@ const initialState: DiscoverState = { export const getPreloadedState = async ({ getSavedSearchById, + uiSettings: config, }: DiscoverServices): Promise> => { const preloadedState: DefaultViewState = { state: { @@ -86,6 +87,8 @@ export const getPreloadedState = async ({ savedSearchInstance.destroy(); // this instance is no longer needed, will create another one later } + } else if (config.get(DEFAULT_COLUMNS_SETTING)) { + preloadedState.state.columns = config.get(DEFAULT_COLUMNS_SETTING); } return preloadedState; diff --git a/src/plugins/discover/public/application/view_components/utils/filter_columns.test.ts b/src/plugins/discover/public/application/view_components/utils/filter_columns.test.ts index 5ab22f5fa363..c6694e141007 100644 --- a/src/plugins/discover/public/application/view_components/utils/filter_columns.test.ts +++ b/src/plugins/discover/public/application/view_components/utils/filter_columns.test.ts @@ -12,23 +12,22 @@ describe('filterColumns', () => { getAll: () => [{ name: 'a' }, { name: 'c' }, { name: 'd' }], }, } as IndexPattern; - const defaultColumns = ['_defaultColumn']; it('should return columns that exist in the index pattern fields', () => { const columns = ['a', 'b']; - const result = filterColumns(columns, indexPatternMock, defaultColumns); + const result = filterColumns(columns, indexPatternMock, ['a']); expect(result).toEqual(['a']); }); it('should return defaultColumns if no columns exist in the index pattern fields', () => { const columns = ['b', 'e']; - const result = filterColumns(columns, indexPatternMock, defaultColumns); - expect(result).toEqual(defaultColumns); + const result = filterColumns(columns, indexPatternMock, ['e']); + expect(result).toEqual(['_source']); }); - it('should return defaultColumns if no columns and indexPattern is null', () => { + it('should return defaultColumns if no columns and indexPattern is undefined', () => { const columns = ['b', 'e']; - const result = filterColumns(columns, null, defaultColumns); - expect(result).toEqual(defaultColumns); + const result = filterColumns(columns, undefined, ['a']); + expect(result).toEqual(['_source']); }); }); diff --git a/src/plugins/discover/public/application/view_components/utils/filter_columns.ts b/src/plugins/discover/public/application/view_components/utils/filter_columns.ts index 1b2c7554910a..f9776eb0151e 100644 --- a/src/plugins/discover/public/application/view_components/utils/filter_columns.ts +++ b/src/plugins/discover/public/application/view_components/utils/filter_columns.ts @@ -20,6 +20,8 @@ export function filterColumns( defaultColumns: string[] ) { const fieldsName = indexPattern?.fields.getAll().map((fld) => fld.name) || []; - const filteredColumns = columns.filter((column) => fieldsName.includes(column)); - return filteredColumns.length > 0 ? filteredColumns : defaultColumns; + // combine columns and defaultColumns without duplicates + const combinedColumns = [...new Set([...columns, ...defaultColumns])]; + const filteredColumns = combinedColumns.filter((column) => fieldsName.includes(column)); + return filteredColumns.length > 0 ? filteredColumns : ['_source']; } From 39d682864e97cf6d00cfb39243a43b9c52e016c3 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Wed, 11 Oct 2023 13:39:07 -0700 Subject: [PATCH 5/5] Add 2.11.0 release notes (#5234) (#5252) * Add 2.11.0 release notes Signed-off-by: Josh Romero * Add unsaved CHANGELOG updates Signed-off-by: Josh Romero --------- Signed-off-by: Josh Romero Co-authored-by: Sean Neumann <1413295+seanneumann@users.noreply.github.com> (cherry picked from commit 87a3a0fbbfa7a532671b71638e9118fec0560d75) Signed-off-by: github-actions[bot] # Conflicts: # CHANGELOG.md Co-authored-by: github-actions[bot] --- ...nsearch-dashboards.release-notes-2.11.0.md | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 release-notes/opensearch-dashboards.release-notes-2.11.0.md diff --git a/release-notes/opensearch-dashboards.release-notes-2.11.0.md b/release-notes/opensearch-dashboards.release-notes-2.11.0.md new file mode 100644 index 000000000000..1558d5efd3d0 --- /dev/null +++ b/release-notes/opensearch-dashboards.release-notes-2.11.0.md @@ -0,0 +1,39 @@ +## Version 2.10.0 Release Notes + +### 🛡 Security + +- [CVE-2022-25869] Remove AngularJS `1.8` ([#5086](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5086)) + +### 📈 Features/Enhancements + +- [Console] Add support for JSON with long numerals ([#4562](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4562)) +- [Data] Add `DataSource` service and `DataSourceSelector` for multiple datasource support ([#5167](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5167)) + +### 🐛 Bug Fixes + +- Bump `agentkeepalive` to `4.5.0` to solve a problem preventing the use `https://ip` in `opensearch.hosts` ([#4949](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4949)) +- [Data Explorer][Discover] Add `onQuerySubmit` to top nav and allow force update to embeddable ([#5160](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5160)) +- [Data Explorer][Discover] Automatically load default index pattern ([#5171](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5171)) +- [Data Explorer][Discover] Fix total hits issue for no time based data ([#5087](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5087)) +- [Data Explorer][Discover] Allow data grid to auto adjust size based on fetched data count ([#5191](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5191)) +- [Data Explorer][Discover] Allow filter and query persist when refresh page or paste url to a new tab ([#5206](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5206)) +- [Data Explorer][Discover] Fix misc navigation issues ([#5168](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5168)) +- [Data Explorer][Discover] Fix mobile view ([#5168](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5168)) +- [Table Visualization] Fix width of multiple tables when rendered in column view ([#4638](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4638)) +- [Table Visualization] Fix filter actions on data table vis cells ([#4837](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4837)) +- [Vis Augmenter] Fix errors in conditions for activating `vizAugmenter` ([#5213](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5213)) +- [Vis Augmenter] Fix `visAugmenter` forming empty key-value pairs in its calls to the `SavedObject` API ([#5190](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5190)) + +### 🚞 Infrastructure + +- [CI] Add `NODE_OPTIONS` and disable disk allocation threshold ([#5172](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5172)) + +### 🛠 Maintenance + +- [Version] Version increment from 2.10 to 2.11 ([#4975](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4975)) + +### 🔩 Tests + +- [Functional][Doc Views] Remove angular code from `plugin_functional` and update tests ([#5221](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5221)) +- [Unit][Data Explorer][Discover] Fix wrong test due to time conversion ([#5174](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5174)) +- [Unit][Data Explorer][Discover]Fix `buildPointSeriesData` unit test fails due to local timezone ([#4992](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4992))