Skip to content

Commit

Permalink
Merge branch 'main' into support-tls-13
Browse files Browse the repository at this point in the history
Signed-off-by: Kajetan Nobel <kajetan.nobel@eliatra.com>
  • Loading branch information
kajetan-nobel committed Oct 12, 2023
2 parents fcc940c + 39d6828 commit a0bc908
Show file tree
Hide file tree
Showing 14 changed files with 105 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,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
Expand Down
39 changes: 39 additions & 0 deletions release-notes/opensearch-dashboards.release-notes-2.11.0.md
Original file line number Diff line number Diff line change
@@ -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))
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export const DataSourceSelectable = ({
selectedOptions={selectedSources as any}
onChange={handleSourceChange}
singleSelection={singleSelection}
isClearable={false}
async
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -57,6 +57,7 @@ const initialState: DiscoverState = {

export const getPreloadedState = async ({
getSavedSearchById,
uiSettings: config,
}: DiscoverServices): Promise<DefaultViewState<DiscoverState>> => {
const preloadedState: DefaultViewState<DiscoverState> = {
state: {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import { TypedUseSelectorHook } from 'react-redux';
import {
RootState,
Store as StoreType,
setIndexPattern as updateIndexPattern,
useTypedDispatch,
useTypedSelector,
Expand All @@ -21,4 +20,4 @@ export interface DiscoverRootState extends RootState {

export const useSelector: TypedUseSelectorHook<DiscoverRootState> = useTypedSelector;
export const useDispatch = useTypedDispatch;
export { StoreType, updateIndexPattern };
export { updateIndexPattern };
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -26,6 +27,8 @@ export default function DiscoverPanel(props: ViewProps) {
data: {
query: { filterManager },
},
capabilities,
indexPatterns,
} = services;
const { data$, indexPattern } = useDiscoverContext();
const [fetchState, setFetchState] = useState<SearchData>(data$.getValue());
Expand Down Expand Up @@ -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,
Expand All @@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand All @@ -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<IndexPattern | undefined>(undefined);
const { data, toastNotifications, uiSettings: config } = services;
const { data, toastNotifications, uiSettings: config, store } = services;

useEffect(() => {
let isMounted = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ export const useSearch = (services: DiscoverViewServices) => {
const initalSearchComplete = useRef(false);
const [savedSearch, setSavedSearch] = useState<SavedSearch | undefined>(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;
Expand Down Expand Up @@ -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 () => {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`;
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/plugins/discover/public/saved_searches/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ import { ISearchSource } from '../../../data/public';

export type SortOrder = [string, 'asc' | 'desc'];
export interface SavedSearch
extends Pick<SavedObject, 'id' | 'title' | 'copyOnSave' | 'destroy' | 'lastSavedTitle' | 'save'> {
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[];
Expand Down

0 comments on commit a0bc908

Please sign in to comment.