From 9601c6c979ac3bac9ddbd9bcee9827b7d1b2cf78 Mon Sep 17 00:00:00 2001 From: Anan Zhuang Date: Tue, 3 Oct 2023 13:57:37 -0700 Subject: [PATCH 1/8] [BUG][Data Explorer][Discover] Automatically load solo added default index pattern (#5171) * [BUG][Data Explorer][Discover] Automatically load solo added default index pattern This fix ensures that when add a default index pattern, Discover will automatically select and load its details. Issue Resolve https://github.com/opensearch-project/OpenSearch-Dashboards/issues/5128 --------- Signed-off-by: ananzh --- CHANGELOG.md | 1 + src/plugins/data_explorer/public/index.ts | 8 +- .../utils/state_management/index.ts | 9 +- .../view_components/canvas/discover_table.tsx | 3 +- .../utils/use_index_pattern.ts | 82 ++++++++++++------- .../view_components/utils/use_search.ts | 4 +- 6 files changed, 73 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8330075b7173..a9210c679f17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,6 +59,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - [BUG][Data Explorer][Discover] Add onQuerySubmit to top nav and allow force update to embeddable ([#5160](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5160)) - [BUG][Discover] Fix misc navigation issues ([#5168](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5168)) - [BUG][Discover] Fix mobile view ([#5168](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5168)) +- [BUG][Data Explorer][Discover] Automatically load solo added default index pattern ([#5171](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5171)) ### 🚞 Infrastructure diff --git a/src/plugins/data_explorer/public/index.ts b/src/plugins/data_explorer/public/index.ts index 635a0ec285db..cb33d2b7d90c 100644 --- a/src/plugins/data_explorer/public/index.ts +++ b/src/plugins/data_explorer/public/index.ts @@ -14,4 +14,10 @@ export function plugin() { } export { DataExplorerPluginSetup, DataExplorerPluginStart, DataExplorerServices } from './types'; export { ViewProps, ViewDefinition, DefaultViewState } from './services/view_service'; -export { RootState, useTypedSelector, useTypedDispatch } from './utils/state_management'; +export { + RootState, + Store, + useTypedSelector, + useTypedDispatch, + setIndexPattern, +} from './utils/state_management'; 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 d72cc772e6c4..9e0d5bc64ffd 100644 --- a/src/plugins/discover/public/application/utils/state_management/index.ts +++ b/src/plugins/discover/public/application/utils/state_management/index.ts @@ -4,7 +4,13 @@ */ import { TypedUseSelectorHook } from 'react-redux'; -import { RootState, useTypedDispatch, useTypedSelector } from '../../../../../data_explorer/public'; +import { + RootState, + Store as StoreType, + setIndexPattern as updateIndexPattern, + useTypedDispatch, + useTypedSelector, +} from '../../../../../data_explorer/public'; import { DiscoverState } from './discover_slice'; export * from './discover_slice'; @@ -15,3 +21,4 @@ export interface DiscoverRootState extends RootState { export const useSelector: TypedUseSelectorHook = useTypedSelector; export const useDispatch = useTypedDispatch; +export { StoreType, updateIndexPattern }; 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 3cdf48a30dfc..e57a0b7c7668 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 @@ -35,7 +35,7 @@ export const DiscoverTable = ({ history }: Props) => { query: { filterManager }, }, } = services; - const { data$, refetch$, indexPattern } = useDiscoverContext(); + const { data$, refetch$, indexPattern, savedSearch } = useDiscoverContext(); const [fetchState, setFetchState] = useState({ status: data$.getValue().status, rows: [], @@ -71,7 +71,6 @@ export const DiscoverTable = ({ history }: Props) => { ); const { rows } = fetchState || {}; - const { savedSearch } = useSearch(services); useEffect(() => { const subscription = data$.subscribe((next) => { 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 872639107987..10a795abac37 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,46 +6,72 @@ import { useEffect, useState } from 'react'; import { i18n } from '@osd/i18n'; import { IndexPattern } from '../../../../../data/public'; -import { useSelector } from '../../utils/state_management'; +import { useSelector, updateIndexPattern, StoreType } from '../../utils/state_management'; import { DiscoverServices } from '../../../build_services'; +import { getIndexPatternId } from '../../helpers/get_index_pattern_id'; -export const useIndexPattern = (services: DiscoverServices) => { - const indexPatternId = useSelector((state) => state.metadata.indexPattern); +/** + * Custom hook to fetch and manage the index pattern based on the provided services. + * + * This hook does the following: + * 1. Check if there's an `indexPatternId` from the state. + * 2. If not, fetch a list of index patterns, determine the default, and update the store with it. + * 3. Once an `indexPatternId` is determined (either from the state or by fetching the default), + * it fetches the details of the index pattern. + * 4. If there's any error fetching the index pattern details, a warning notification is shown. + * + * @param services - The services needed to fetch the index patterns and show notifications. + * @param store - The redux store in data_explorer to dispatch actions. + * @returns - The fetched index pattern. + */ +export const useIndexPattern = (services: DiscoverServices, store: StoreType) => { + const indexPatternIdFromState = useSelector((state) => state.metadata.indexPattern); const [indexPattern, setIndexPattern] = useState(undefined); - const { data, toastNotifications } = services; + const { data, toastNotifications, uiSettings: config } = services; useEffect(() => { let isMounted = true; - if (!indexPatternId) return; - const indexPatternMissingWarning = i18n.translate( - 'discover.valueIsNotConfiguredIndexPatternIDWarningTitle', - { - defaultMessage: '{id} is not a configured index pattern ID', - values: { - id: `"${indexPatternId}"`, - }, - } - ); - data.indexPatterns - .get(indexPatternId) - .then((result) => { - if (isMounted) { - setIndexPattern(result); - } - }) - .catch(() => { - if (isMounted) { - toastNotifications.addDanger({ - title: indexPatternMissingWarning, - }); - } + const fetchIndexPatternDetails = (id: string) => { + data.indexPatterns + .get(id) + .then((result) => { + if (isMounted) { + setIndexPattern(result); + } + }) + .catch(() => { + if (isMounted) { + const indexPatternMissingWarning = i18n.translate( + 'discover.valueIsNotConfiguredIndexPatternIDWarningTitle', + { + defaultMessage: '{id} is not a configured index pattern ID', + values: { + id: `"${id}"`, + }, + } + ); + toastNotifications.addDanger({ + title: indexPatternMissingWarning, + }); + } + }); + }; + + if (!indexPatternIdFromState) { + data.indexPatterns.getCache().then((indexPatternList) => { + const newId = getIndexPatternId('', indexPatternList, config.get('defaultIndex')); + store!.dispatch(updateIndexPattern(newId)); + fetchIndexPatternDetails(newId); }); + } else { + fetchIndexPatternDetails(indexPatternIdFromState); + } return () => { isMounted = false; }; - }, [indexPatternId, data.indexPatterns, toastNotifications]); + }, [indexPatternIdFromState, data.indexPatterns, toastNotifications, config, store]); return indexPattern; }; 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 4066d0063a3a..d8c25e1a98e7 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 indexPattern = useIndexPattern(services); - const { data, filterManager, getSavedSearchById, core, toastNotifications } = services; + const { data, filterManager, getSavedSearchById, core, toastNotifications, store } = services; + const indexPattern = useIndexPattern(services, store); const timefilter = data.query.timefilter.timefilter; const fetchStateRef = useRef<{ abortController: AbortController | undefined; From 677fdf53052c6e116e5daf0cad98d73345116517 Mon Sep 17 00:00:00 2001 From: Anan Zhuang Date: Tue, 3 Oct 2023 16:33:10 -0700 Subject: [PATCH 2/8] [BUG][Data Explorer][Discover] Allow data grid to auto adjust size based on fetched data count (#5191) * This PR adds a new rows state to the DiscoverCanvas component and updated it whenever the data$ observable emitted new row data. * The DiscoverTable component was then refactored to accept rows as a prop, making it dependent on the parent component to provide the correct set of data. This ensures that the table renders correctly based on the current data and doesn't rely on its internal state, which could be outdated. Issue Resolve https://github.com/opensearch-project/OpenSearch-Dashboards/issues/5181 Signed-off-by: ananzh --- CHANGELOG.md | 1 + .../components/data_grid/data_grid_table.tsx | 1 - .../view_components/canvas/discover_table.tsx | 31 +++---------- .../view_components/canvas/index.tsx | 43 +++++++++++++------ 4 files changed, 36 insertions(+), 40 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9210c679f17..58aa2e13207b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -60,6 +60,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - [BUG][Discover] Fix misc navigation issues ([#5168](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5168)) - [BUG][Discover] Fix mobile view ([#5168](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5168)) - [BUG][Data Explorer][Discover] Automatically load solo added default index pattern ([#5171](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5171)) +- [BUG][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)) ### 🚞 Infrastructure diff --git a/src/plugins/discover/public/application/components/data_grid/data_grid_table.tsx b/src/plugins/discover/public/application/components/data_grid/data_grid_table.tsx index 298643e2a2b7..b285b4739361 100644 --- a/src/plugins/discover/public/application/components/data_grid/data_grid_table.tsx +++ b/src/plugins/discover/public/application/components/data_grid/data_grid_table.tsx @@ -29,7 +29,6 @@ export interface DataGridTableProps { onSetColumns: (columns: string[]) => void; sort: SortOrder[]; displayTimeColumn: boolean; - services: DiscoverServices; title?: string; description?: string; isToolbarVisible?: boolean; 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 e57a0b7c7668..a7db2ce3034f 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 @@ -3,8 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import React, { useState, useEffect, useCallback, useMemo } from 'react'; -import { History } from 'history'; +import React, { useCallback, useMemo } from 'react'; import { DiscoverViewServices } from '../../../build_services'; import { useOpenSearchDashboards } from '../../../../../opensearch_dashboards_react/public'; import { DataGridTable } from '../../components/data_grid/data_grid_table'; @@ -17,17 +16,18 @@ import { useDispatch, useSelector, } from '../../utils/state_management'; -import { ResultStatus, SearchData, useSearch } from '../utils/use_search'; +import { useSearch } from '../utils/use_search'; import { IndexPatternField, opensearchFilters } from '../../../../../data/public'; 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'; interface Props { - history: History; + rows: OpenSearchSearchHit[]; } -export const DiscoverTable = ({ history }: Props) => { +export const DiscoverTable = ({ rows }: Props) => { const { services } = useOpenSearchDashboards(); const { uiSettings, @@ -35,12 +35,8 @@ export const DiscoverTable = ({ history }: Props) => { query: { filterManager }, }, } = services; - const { data$, refetch$, indexPattern, savedSearch } = useDiscoverContext(); - const [fetchState, setFetchState] = useState({ - status: data$.getValue().status, - rows: [], - }); + const { refetch$, indexPattern, savedSearch } = useDiscoverContext(); const { columns, sort } = useSelector((state) => state.discover); const dispatch = useDispatch(); const onAddColumn = (col: string) => dispatch(addColumn({ column: col })); @@ -70,20 +66,6 @@ export const DiscoverTable = ({ history }: Props) => { [indexPattern, uiSettings] ); - const { rows } = fetchState || {}; - - useEffect(() => { - const subscription = data$.subscribe((next) => { - if (next.status === ResultStatus.LOADING) return; - if (next.status !== fetchState.status || (next.rows && next.rows !== fetchState.rows)) { - setFetchState({ ...fetchState, ...next }); - } - }); - return () => { - subscription.unsubscribe(); - }; - }, [data$, fetchState]); - if (indexPattern === undefined) { // TODO: handle better return null; @@ -106,7 +88,6 @@ export const DiscoverTable = ({ history }: Props) => { sort={sort} rows={rows} displayTimeColumn={displayTimeColumn} - services={services} title={savedSearch?.id ? savedSearch.title : ''} description={savedSearch?.id ? savedSearch.description : ''} /> diff --git a/src/plugins/discover/public/application/view_components/canvas/index.tsx b/src/plugins/discover/public/application/view_components/canvas/index.tsx index 7be8cc8585c0..1d994c92a2ea 100644 --- a/src/plugins/discover/public/application/view_components/canvas/index.tsx +++ b/src/plugins/discover/public/application/view_components/canvas/index.tsx @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import React, { useEffect, useState, useRef, useCallback } from 'react'; +import React, { useEffect, useState, useRef, useCallback, useMemo } from 'react'; import { EuiPanel } from '@elastic/eui'; import { TopNav } from './top_nav'; import { ViewProps } from '../../../../../data_explorer/public'; @@ -19,6 +19,7 @@ import { DiscoverViewServices } from '../../../build_services'; import { useOpenSearchDashboards } from '../../../../../opensearch_dashboards_react/public'; import { filterColumns } from '../utils/filter_columns'; import { DEFAULT_COLUMNS_SETTING } from '../../../../common'; +import { OpenSearchSearchHit } from '../../../application/doc_views/doc_views_types'; import './discover_canvas.scss'; // eslint-disable-next-line import/no-default-export @@ -42,7 +43,6 @@ export default function DiscoverCanvas({ setHeaderActionMenu, history }: ViewPro bucketInterval: {}, }); - const { status } = fetchState; const onQuerySubmit = useCallback( (payload, isUpdate) => { if (isUpdate === false) { @@ -51,18 +51,30 @@ export default function DiscoverCanvas({ setHeaderActionMenu, history }: ViewPro }, [refetch$] ); + const [rows, setRows] = useState(undefined); useEffect(() => { const subscription = data$.subscribe((next) => { - if ( - next.status !== fetchState.status || - (next.hits && next.hits !== fetchState.hits) || - (next.bucketInterval && next.bucketInterval !== fetchState.bucketInterval) || - (next.chartData && next.chartData !== fetchState.chartData) - ) { + if (next.status === ResultStatus.LOADING) return; + + let shouldUpdateState = false; + + if (next.status !== fetchState.status) shouldUpdateState = true; + if (next.hits && next.hits !== fetchState.hits) shouldUpdateState = true; + if (next.bucketInterval && next.bucketInterval !== fetchState.bucketInterval) + shouldUpdateState = true; + if (next.chartData && next.chartData !== fetchState.chartData) shouldUpdateState = true; + if (next.rows && next.rows !== fetchState.rows) { + shouldUpdateState = true; + setRows(next.rows); + } + + // Update the state if any condition is met. + if (shouldUpdateState) { setFetchState({ ...fetchState, ...next }); } }); + return () => { subscription.unsubscribe(); }; @@ -77,6 +89,9 @@ export default function DiscoverCanvas({ setHeaderActionMenu, history }: ViewPro const timeField = indexPattern?.timeFieldName ? indexPattern.timeFieldName : undefined; + const MemoizedDiscoverTable = React.memo(DiscoverTable); + const MemoizedDiscoverChartContainer = React.memo(DiscoverChartContainer); + return ( - {status === ResultStatus.NO_RESULTS && ( + {fetchState.status === ResultStatus.NO_RESULTS && ( )} - {status === ResultStatus.UNINITIALIZED && ( + {fetchState.status === ResultStatus.UNINITIALIZED && ( refetch$.next()} /> )} - {status === ResultStatus.LOADING && } - {status === ResultStatus.READY && ( + {fetchState.status === ResultStatus.LOADING && } + {fetchState.status === ResultStatus.READY && ( <> - + - + )} From c27d2f5b774c92c25cefde8c7cdf0c16b1e974e9 Mon Sep 17 00:00:00 2001 From: Miki Date: Tue, 3 Oct 2023 19:32:57 -0700 Subject: [PATCH 3/8] Fix `visAugmenter` forming empty key-value pairs in its calls to the `SavedObject` API (#5190) Fixes #5187 Signed-off-by: Miki --- CHANGELOG.md | 18 ++++++++++-------- .../vis_augmenter/public/utils/utils.test.ts | 8 ++++---- .../vis_augmenter/public/utils/utils.ts | 12 ++++++------ 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58aa2e13207b..081b20c4eab3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,18 +49,20 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - [TSVB, Dashboards] Fix inconsistent dark mode code editor themes ([#4609](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4609)) - [Table Visualization] Fix width of multiple tables when rendered in column view ([#4638](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4638)) - [Legacy Maps] Fix dark mode style overrides ([#4658](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4658)) -- [BUG] Fix management overview page duplicate rendering ([#4636](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4636)) +- Fix management overview page duplicate rendering ([#4636](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4636)) - Bump `agentkeepalive` to v4.5.0 to solve a problem preventing the use `https://ip` in `opensearch.hosts` ([#4949](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4949)) - [Table Vis] Fix filter actions on data table vis cells ([#4837](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4837)) - Fix broken app when management is turned off ([#4891](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4891)) - Correct the generated path for downloading plugins by their names on Windows ([#4953](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4953)) -- [BUG] Fix buildPointSeriesData unit test fails due to local timezone ([#4992](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4992)) -- [BUG][Data Explorer][Discover] Fix total hits issue for no time based data ([#5087](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5087)) -- [BUG][Data Explorer][Discover] Add onQuerySubmit to top nav and allow force update to embeddable ([#5160](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5160)) -- [BUG][Discover] Fix misc navigation issues ([#5168](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5168)) -- [BUG][Discover] Fix mobile view ([#5168](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5168)) -- [BUG][Data Explorer][Discover] Automatically load solo added default index pattern ([#5171](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5171)) -- [BUG][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)) +- Fix `buildPointSeriesData` unit test fails due to local timezone ([#4992](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4992)) +- [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] Add onQuerySubmit to top nav and allow force update to embeddable ([#5160](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5160)) +- [Discover] Fix misc navigation issues ([#5168](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5168)) +- [Discover] Fix mobile view ([#5168](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5168)) +- Fix `visAugmenter` forming empty key-value pairs in its calls to the `SavedObject` API ([#5190](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5190)) +- [Data Explorer][Discover] Automatically load solo added default index pattern ([#5171](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5171)) +- [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)) + ### 🚞 Infrastructure diff --git a/src/plugins/vis_augmenter/public/utils/utils.test.ts b/src/plugins/vis_augmenter/public/utils/utils.test.ts index d8ebe41b087f..f831deef3955 100644 --- a/src/plugins/vis_augmenter/public/utils/utils.test.ts +++ b/src/plugins/vis_augmenter/public/utils/utils.test.ts @@ -372,12 +372,12 @@ describe('utils', () => { expect(loader.findAll).toHaveBeenCalledWith( '', 100, - [], + undefined, { type: 'visualization', id: visId1 as string, }, - [] + undefined ); }); it('single plugin resource is propagated to findAll()', async () => { @@ -391,7 +391,7 @@ describe('utils', () => { expect(loader.findAll).toHaveBeenCalledWith( 'resource-1', 100, - [], + undefined, { type: 'visualization', id: visId1 as string, @@ -411,7 +411,7 @@ describe('utils', () => { expect(loader.findAll).toHaveBeenCalledWith( 'resource-1|resource-2', 100, - [], + undefined, { type: 'visualization', id: visId1 as string, diff --git a/src/plugins/vis_augmenter/public/utils/utils.ts b/src/plugins/vis_augmenter/public/utils/utils.ts index f1c18ce15b79..c8ebde337757 100644 --- a/src/plugins/vis_augmenter/public/utils/utils.ts +++ b/src/plugins/vis_augmenter/public/utils/utils.ts @@ -72,19 +72,19 @@ export const getAugmentVisSavedObjs = async ( ); } try { - // If there is specified plugin resource IDs, add a search string and search field - // into findAll() fn call + // If there are any plugin resource IDs specified, add a search string and search field + // into findAll() call const pluginResourceIdsSpecified = - pluginResourceIds !== undefined && pluginResourceIds.length > 0; + Array.isArray(pluginResourceIds) && pluginResourceIds.length > 0; const resp = await loader?.findAll( - pluginResourceIdsSpecified ? pluginResourceIds.join('|') : '', + pluginResourceIdsSpecified ? pluginResourceIds!.join('|') : '', 100, - [], + undefined, { type: 'visualization', id: visId as string, }, - pluginResourceIdsSpecified ? ['pluginResource.id'] : [] + pluginResourceIdsSpecified ? ['pluginResource.id'] : undefined ); return (get(resp, 'hits', []) as any[]) as ISavedAugmentVis[]; } catch (e) { From 3024c6a8afbd3e19529bb660ee176b3862296742 Mon Sep 17 00:00:00 2001 From: "Qingyang(Abby) Hu" Date: Tue, 3 Oct 2023 22:41:54 -0700 Subject: [PATCH 4/8] Add subject test id for testing data-shared-attribute (#5196) Signed-off-by: abbyhu2000 --- .../public/application/components/data_grid/data_grid_table.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/plugins/discover/public/application/components/data_grid/data_grid_table.tsx b/src/plugins/discover/public/application/components/data_grid/data_grid_table.tsx index b285b4739361..fcb786b23e86 100644 --- a/src/plugins/discover/public/application/components/data_grid/data_grid_table.tsx +++ b/src/plugins/discover/public/application/components/data_grid/data_grid_table.tsx @@ -176,6 +176,7 @@ export const DataGridTable = ({ data-shared-item="" data-title={title} data-description={description} + data-test-subj="discoverTable" > From dc6a7ece09b2fb971e5e59dd4e53c4482964d14c Mon Sep 17 00:00:00 2001 From: Kawika Avilla Date: Tue, 3 Oct 2023 23:27:52 -0700 Subject: [PATCH 5/8] [CI][Cypress][Bug] use default SOURCE inputs (#5197) https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5134 Incorrectly uses the source of the code to pull down to BASE REF, which would likely be `main` or `2.x`, etc. It should be pulling down the PR branch. Cypress tests at the time of merging were failing due to unrelated issue of disk allocation. Not setting the env variables causes the workflow to rely on the default values which is a return back to the original implementation and if the env is set then it will be not empty. Signed-off-by: Kawika Avilla --- .github/workflows/cypress_workflow.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/cypress_workflow.yml b/.github/workflows/cypress_workflow.yml index adb62209e433..02d1064fb8e1 100644 --- a/.github/workflows/cypress_workflow.yml +++ b/.github/workflows/cypress_workflow.yml @@ -28,8 +28,6 @@ on: type: string env: - SOURCE_REPO: ${{ github.repository }} - SOURCE_BRANCH: "${{ github.base_ref }}" TEST_REPO: ${{ inputs.test_repo != '' && inputs.test_repo || 'opensearch-project/opensearch-dashboards-functional-test' }} TEST_BRANCH: "${{ inputs.test_branch != '' && inputs.test_branch || github.base_ref }}" FTR_PATH: 'ftr' From 0ffd2abc4c58fe4f2e885ab96c150574d2fed0e0 Mon Sep 17 00:00:00 2001 From: Ashwin P Chandran Date: Wed, 4 Oct 2023 01:13:40 -0700 Subject: [PATCH 6/8] Fixes mobile layout (#5195) Signed-off-by: Ashwin P Chandran --- .../config/global_selectors.json | 3 +- .../config/restricted_properties.json | 4 +-- .../public/components/app_container.scss | 5 +++ .../components/sidebar/discover_field.scss | 16 +++++----- .../components/sidebar/discover_field.tsx | 2 +- .../components/sidebar/discover_sidebar.scss | 5 +++ .../canvas/discover_canvas.scss | 31 +++++++++++++++++++ 7 files changed, 54 insertions(+), 12 deletions(-) diff --git a/packages/osd-stylelint-config/config/global_selectors.json b/packages/osd-stylelint-config/config/global_selectors.json index d89561a04cbc..ef2ec5f9252b 100644 --- a/packages/osd-stylelint-config/config/global_selectors.json +++ b/packages/osd-stylelint-config/config/global_selectors.json @@ -23,7 +23,8 @@ "src/plugins/vis_builder/public/application/components/searchable_dropdown.scss", "src/plugins/vis_builder/public/application/components/side_nav.scss", "packages/osd-ui-framework/src/components/button/button_group/_button_group.scss", - "src/plugins/discover/public/application/components/data_grid/data_grid_table_cell_value.scss" + "src/plugins/discover/public/application/components/data_grid/data_grid_table_cell_value.scss", + "src/plugins/discover/public/application/view_components/canvas/discover_canvas.scss" ] } } \ No newline at end of file diff --git a/packages/osd-stylelint-config/config/restricted_properties.json b/packages/osd-stylelint-config/config/restricted_properties.json index d229764c8d88..5b1262328200 100644 --- a/packages/osd-stylelint-config/config/restricted_properties.json +++ b/packages/osd-stylelint-config/config/restricted_properties.json @@ -2,7 +2,6 @@ "font-family": { "explanation": "All \"font-family\" styles should be inherited from OUI themes and components. Remove the rule.", "approved": [ - "src/plugins/discover_legacy/public/application/_discover.scss", "src/plugins/maps_legacy/public/map/_leaflet_overrides.scss", "src/plugins/maps_legacy/public/map/_legend.scss", "src/plugins/opensearch_dashboards_legacy/public/font_awesome/font_awesome.scss", @@ -12,8 +11,7 @@ "src/plugins/data/public/ui/typeahead/_suggestion.scss", "src/plugins/vis_type_timeseries/public/application/components/_error.scss", "packages/osd-ui-framework/src/components/form/check_box/_check_box.scss", - "src/plugins/discover/public/application/components/doc_viewer/doc_viewer.scss", - "src/plugins/discover_legacy/public/application/components/doc_viewer/doc_viewer.scss" + "src/plugins/discover/public/application/components/doc_viewer/doc_viewer.scss" ] } } \ No newline at end of file diff --git a/src/plugins/data_explorer/public/components/app_container.scss b/src/plugins/data_explorer/public/components/app_container.scss index d289e7d4be3e..d5b6df038208 100644 --- a/src/plugins/data_explorer/public/components/app_container.scss +++ b/src/plugins/data_explorer/public/components/app_container.scss @@ -3,6 +3,11 @@ $osdHeaderOffset: $euiHeaderHeightCompensation; .deSidebar { max-width: 462px; min-width: 400px; + + @include ouiBreakpoint("xs", "s", "m") { + max-width: initial; + width: 100%; + } } .deLayout { diff --git a/src/plugins/discover/public/application/components/sidebar/discover_field.scss b/src/plugins/discover/public/application/components/sidebar/discover_field.scss index 5512136431b4..39cacdcd0c97 100644 --- a/src/plugins/discover/public/application/components/sidebar/discover_field.scss +++ b/src/plugins/discover/public/application/components/sidebar/discover_field.scss @@ -3,16 +3,18 @@ max-width: 300px; } -.dscSidebarField__actionButton { - opacity: 0; - transition: opacity $ouiAnimSpeedExtraFast; +.dscSidebarField { + &__actionButton { + opacity: 0; + transition: opacity $euiAnimSpeedFast; - &:hover, - &:focus { - opacity: 1; + @include ouiBreakpoint("xs", "s", "m") { + opacity: 1; + } } - @include ouiBreakpoint("xs", "s", "m") { + &:hover &__actionButton, + &:focus &__actionButton { opacity: 1; } } diff --git a/src/plugins/discover/public/application/components/sidebar/discover_field.tsx b/src/plugins/discover/public/application/components/sidebar/discover_field.tsx index a924191c88f1..b7aa9cf7b36e 100644 --- a/src/plugins/discover/public/application/components/sidebar/discover_field.tsx +++ b/src/plugins/discover/public/application/components/sidebar/discover_field.tsx @@ -195,7 +195,7 @@ export const DiscoverField = ({ } return ( - + .euiFlexItem { + width: 100% !important; + + &:first-child { + order: 1; + } + } + + .osdQueryBar__datePickerWrapper { + max-width: initial; + width: 100%; + + .euiSuperDatePicker__flexWrapper { + width: auto; + } + } + } + } +} From 5623cef4587104afa92eeb099dfe7a2f2369b3a7 Mon Sep 17 00:00:00 2001 From: Anan Zhuang Date: Wed, 4 Oct 2023 11:05:06 -0700 Subject: [PATCH 7/8] [BUG][Data Explorer][Discover] Allow filter and query persist when refresh page or paste url to a new tab (#5206) Issue Resolve https://github.com/opensearch-project/OpenSearch-Dashboards/issues/5179 https://github.com/opensearch-project/OpenSearch-Dashboards/issues/5071 Signed-off-by: ananzh --- CHANGELOG.md | 1 + .../application/view_components/canvas/top_nav.tsx | 7 +++++++ .../application/view_components/context/index.tsx | 13 +------------ 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 081b20c4eab3..17750e4af783 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Fix `visAugmenter` forming empty key-value pairs in its calls to the `SavedObject` API ([#5190](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5190)) - [Data Explorer][Discover] Automatically load solo added default index pattern ([#5171](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5171)) - [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][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)) ### 🚞 Infrastructure diff --git a/src/plugins/discover/public/application/view_components/canvas/top_nav.tsx b/src/plugins/discover/public/application/view_components/canvas/top_nav.tsx index b75a48d3acff..feb7b91e7c5e 100644 --- a/src/plugins/discover/public/application/view_components/canvas/top_nav.tsx +++ b/src/plugins/discover/public/application/view_components/canvas/top_nav.tsx @@ -13,6 +13,7 @@ import { IndexPattern } from '../../../opensearch_dashboards_services'; import { getTopNavLinks } from '../../components/top_nav/get_top_nav_links'; import { useDiscoverContext } from '../context'; import { getRootBreadcrumbs } from '../../helpers/breadcrumbs'; +import { opensearchFilters, connectStorageToQueryState } from '../../../../../data/public'; export interface TopNavProps { opts: { @@ -35,10 +36,16 @@ export const TopNav = ({ opts }: TopNavProps) => { }, data, chrome, + osdUrlStateStorage, } = services; const topNavLinks = savedSearch ? getTopNavLinks(services, inspectorAdapters, savedSearch) : []; + connectStorageToQueryState(services.data.query, osdUrlStateStorage, { + filters: opensearchFilters.FilterStateStore.APP_STATE, + query: true, + }); + useEffect(() => { let isMounted = true; const getDefaultIndexPattern = async () => { diff --git a/src/plugins/discover/public/application/view_components/context/index.tsx b/src/plugins/discover/public/application/view_components/context/index.tsx index 7052ed2887f9..f4180d16b196 100644 --- a/src/plugins/discover/public/application/view_components/context/index.tsx +++ b/src/plugins/discover/public/application/view_components/context/index.tsx @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import React, { useEffect } from 'react'; +import React from 'react'; import { DataExplorerServices, ViewProps } from '../../../../../data_explorer/public'; import { OpenSearchDashboardsContextProvider, @@ -11,7 +11,6 @@ import { } from '../../../../../opensearch_dashboards_react/public'; import { getServices } from '../../../opensearch_dashboards_services'; import { useSearch, SearchContextValue } from '../utils/use_search'; -import { connectStorageToQueryState, opensearchFilters } from '../../../../../data/public'; const SearchContext = React.createContext({} as SearchContextValue); @@ -24,16 +23,6 @@ export default function DiscoverContext({ children }: React.PropsWithChildren { - connectStorageToQueryState(services.data.query, osdUrlStateStorage, { - filters: opensearchFilters.FilterStateStore.APP_STATE, - query: true, - }); - }, [osdUrlStateStorage, services.data.query, services.uiSettings]); - return ( {children} From c70125f13ffe306be5c3fcb5bb4296ffe6dfd3fe Mon Sep 17 00:00:00 2001 From: Ashwin P Chandran Date: Wed, 4 Oct 2023 11:05:25 -0700 Subject: [PATCH 8/8] fixes DataTable rendering in doscover (#5207) Signed-off-by: Ashwin P Chandran --- .../application/view_components/canvas/discover_table.tsx | 3 +-- .../public/application/view_components/canvas/index.tsx | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) 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 a7db2ce3034f..4e3f6bf04b24 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 @@ -16,7 +16,6 @@ import { useDispatch, useSelector, } from '../../utils/state_management'; -import { useSearch } from '../utils/use_search'; import { IndexPatternField, opensearchFilters } from '../../../../../data/public'; import { DocViewFilterFn } from '../../doc_views/doc_views_types'; import { SortOrder } from '../../../saved_searches/types'; @@ -24,7 +23,7 @@ import { DOC_HIDE_TIME_COLUMN_SETTING } from '../../../../common'; import { OpenSearchSearchHit } from '../../doc_views/doc_views_types'; interface Props { - rows: OpenSearchSearchHit[]; + rows?: OpenSearchSearchHit[]; } export const DiscoverTable = ({ rows }: Props) => { diff --git a/src/plugins/discover/public/application/view_components/canvas/index.tsx b/src/plugins/discover/public/application/view_components/canvas/index.tsx index 1d994c92a2ea..fabe2373bfea 100644 --- a/src/plugins/discover/public/application/view_components/canvas/index.tsx +++ b/src/plugins/discover/public/application/view_components/canvas/index.tsx @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import React, { useEffect, useState, useRef, useCallback, useMemo } from 'react'; +import React, { useEffect, useState, useRef, useCallback } from 'react'; import { EuiPanel } from '@elastic/eui'; import { TopNav } from './top_nav'; import { ViewProps } from '../../../../../data_explorer/public'; @@ -89,9 +89,6 @@ export default function DiscoverCanvas({ setHeaderActionMenu, history }: ViewPro const timeField = indexPattern?.timeFieldName ? indexPattern.timeFieldName : undefined; - const MemoizedDiscoverTable = React.memo(DiscoverTable); - const MemoizedDiscoverChartContainer = React.memo(DiscoverChartContainer); - return ( ); } + +const MemoizedDiscoverTable = React.memo(DiscoverTable); +const MemoizedDiscoverChartContainer = React.memo(DiscoverChartContainer);