Skip to content

Commit

Permalink
COMBINED
Browse files Browse the repository at this point in the history
  • Loading branch information
ananzh authored and AMoo-Miki committed Oct 19, 2024
1 parent bde23d9 commit 5876362
Show file tree
Hide file tree
Showing 24 changed files with 314 additions and 316 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/8650.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- Fix random big number when loading in query result ([#8650](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8650))
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ import { includes } from 'lodash';
import { IndexPatternsContract } from './index_patterns';
import { UiSettingsCommon } from '../types';

export type EnsureDefaultIndexPattern = (
shouldRedirect?: boolean
) => Promise<unknown | void> | undefined;
export type EnsureDefaultIndexPattern = () => Promise<unknown | void> | undefined;

export const createEnsureDefaultIndexPattern = (
uiSettings: UiSettingsCommon,
Expand All @@ -44,10 +42,7 @@ export const createEnsureDefaultIndexPattern = (
* Checks whether a default index pattern is set and exists and defines
* one otherwise.
*/
return async function ensureDefaultIndexPattern(
this: IndexPatternsContract,
shouldRedirect: boolean = true
) {
return async function ensureDefaultIndexPattern(this: IndexPatternsContract) {
const patterns = await this.getIds();
let defaultId = await uiSettings.get('defaultIndex');
let defined = !!defaultId;
Expand All @@ -67,6 +62,8 @@ export const createEnsureDefaultIndexPattern = (
defaultId = patterns[0];
await uiSettings.set('defaultIndex', defaultId);
} else {
const isEnhancementsEnabled = await uiSettings.get('query:enhancements:enabled');
const shouldRedirect = !isEnhancementsEnabled;
if (shouldRedirect) return onRedirectNoIndexPattern();
else return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ export const getDQLLanguageConfig = (
visualizable: true,
},
showDocLinks: true,
docLink: {
title: i18n.translate('data.dqlLanguage.docLink', {
defaultMessage: 'DQL documentation',
}),
url: 'https://opensearch.org/docs/latest/query-dsl/full-text/query-string/',
},
editorSupportedAppNames: ['discover'],
supportedAppNames: ['discover', 'dashboards', 'visualize', 'data-explorer', 'vis-builder', '*'],
sampleQueries: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ export const getLuceneLanguageConfig = (
visualizable: true,
},
showDocLinks: true,
docLink: {
title: i18n.translate('data.luceneLanguage.docLink', {
defaultMessage: 'Lucene documentation',
}),
url: 'https://opensearch.org/docs/latest/query-dsl/full-text/query-string/',
},
editorSupportedAppNames: ['discover'],
supportedAppNames: ['discover', 'dashboards', 'visualize', 'data-explorer', 'vis-builder', '*'],
sampleQueries: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,40 +41,42 @@ export function QueryResult(props: { queryStatus: QueryStatus }) {
setPopover(!isPopoverOpen);
};

const updateElapsedTime = () => {
const time = Date.now() - (props.queryStatus.startTime || 0);
if (time > BUFFER_TIME) {
setElapsedTime(time);
} else {
setElapsedTime(0);
}
};

useEffect(() => {
const updateElapsedTime = () => {
const currentTime = Date.now();
if (!props.queryStatus.startTime) {
return;
}
const elapsed = currentTime - props.queryStatus.startTime;
setElapsedTime(elapsed);
};

const interval = setInterval(updateElapsedTime, 1000);

return () => clearInterval(interval);
});
return () => {
clearInterval(interval);
setElapsedTime(0);
};
}, [props.queryStatus.startTime]);

if (props.queryStatus.status === ResultStatus.LOADING) {
if (elapsedTime < BUFFER_TIME) {
return null;
if (elapsedTime > BUFFER_TIME) {
if (props.queryStatus.status === ResultStatus.LOADING) {
const time = Math.floor(elapsedTime / 1000);
return (
<EuiButtonEmpty
color="text"
size="xs"
onClick={() => {}}
isLoading
data-test-subj="queryResultLoading"
>
{i18n.translate('data.query.languageService.queryResults.loadTime', {
defaultMessage: 'Loading {time} s',
values: { time },
})}
</EuiButtonEmpty>
);
}
const time = Math.floor(elapsedTime / 1000);
return (
<EuiButtonEmpty
color="text"
size="xs"
onClick={() => {}}
isLoading
data-test-subj="queryResultLoading"
>
{i18n.translate('data.query.languageService.queryResults.loadTime', {
defaultMessage: 'Loading {time} s',
values: { time },
})}
</EuiButtonEmpty>
);
}

if (props.queryStatus.status === ResultStatus.READY) {
Expand All @@ -85,7 +87,7 @@ export function QueryResult(props: { queryStatus: QueryStatus }) {
});
} else if (props.queryStatus.elapsedMs < 1000) {
message = i18n.translate(
'data.query.languageService.queryResults.completeTimeInMiliseconds',
'data.query.languageService.queryResults.completeTimeInMilliseconds',
{
defaultMessage: 'Completed in {timeMS} ms',
values: { timeMS: props.queryStatus.elapsedMs },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export interface LanguageConfig {
visualizable?: boolean;
};
showDocLinks?: boolean;
docLink?: {
title: string;
url: string;
};
editorSupportedAppNames?: string[];
supportedAppNames?: string[];
hideDatePicker?: boolean;
Expand Down
33 changes: 15 additions & 18 deletions src/plugins/data/public/ui/dataset_selector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { useCallback, useEffect } from 'react';
import { useCallback, useState, useEffect } from 'react';
import React from 'react';
import { Dataset, Query, TimeRange } from '../../../common';
import {
Expand All @@ -12,62 +12,59 @@ import {
DatasetSelectorUsingButtonProps,
DatasetSelectorAppearance,
} from './dataset_selector';
import { AdvancedSelector } from './advanced_selector';
import { useOpenSearchDashboards } from '../../../../opensearch_dashboards_react/public';
import { IDataPluginServices } from '../../types';

interface ConnectedDatasetSelectorProps {
onSubmit: ((query: Query, dateRange?: TimeRange | undefined) => void) | undefined;
selectedDataset?: Dataset;
setSelectedDataset: (data: Dataset | undefined) => void;
setIndexPattern: (id: string | undefined) => void;
services?: any;
}

const ConnectedDatasetSelector = ({
onSubmit,
selectedDataset,
setSelectedDataset,
setIndexPattern,
services,
...datasetSelectorProps
}: ConnectedDatasetSelectorProps &
(DatasetSelectorUsingButtonProps | DatasetSelectorUsingButtonEmptyProps)) => {
const { services } = useOpenSearchDashboards<IDataPluginServices>();
const queryString = services.data.query.queryString;
const [selectedDataset, setSelectedDataset] = useState<Dataset | undefined>(
() => queryString.getQuery().dataset || queryString.getDefaultQuery().dataset
);

useEffect(() => {
const subscription = queryString.getUpdates$().subscribe((query) => {
setSelectedDataset(query.dataset);
setIndexPattern(query.dataset?.id);
});

return () => {
subscription.unsubscribe();
};
}, [queryString, setSelectedDataset, setIndexPattern]);
}, [queryString]);

const handleDatasetChange = useCallback(
(dataset?: Dataset) => {
setSelectedDataset(dataset);
setIndexPattern(dataset?.id);
if (dataset) {
const query = queryString.getInitialQueryByDataset(dataset);
queryString.setQuery(query);
onSubmit!(queryString.getQuery());
queryString.getDatasetService().addRecentDataset(dataset);
}
},
[onSubmit, queryString, setSelectedDataset, setIndexPattern]
[onSubmit, queryString]
);

return (
<DatasetSelector
{...datasetSelectorProps}
selectedDataset={selectedDataset}
setSelectedDataset={setSelectedDataset}
setIndexPattern={setIndexPattern}
handleDatasetChange={handleDatasetChange}
setSelectedDataset={handleDatasetChange}
services={services}
/>
);
};

export { ConnectedDatasetSelector as DatasetSelector, AdvancedSelector, DatasetSelectorAppearance };
export {
ConnectedDatasetSelector as DatasetSelector,
ConnectedDatasetSelectorProps as DatasetSelectorProps,
DatasetSelectorAppearance,
};
5 changes: 2 additions & 3 deletions src/plugins/data/public/ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* under the License.
*/

export { UiEnhancements, IUiStart, IUiSetup } from './types';
export { IUiStart, IUiSetup } from './types';
export { IndexPatternSelectProps } from './index_pattern_select';
export { FilterLabel } from './filter_bar';
export { QueryStringInput, QueryStringInputProps } from './query_string_input';
Expand All @@ -51,5 +51,4 @@ export {
useQueryStringManager,
} from './search_bar';
export { SuggestionsComponent } from './typeahead';
export { DatasetSelector, AdvancedSelector, DatasetSelectorAppearance } from './dataset_selector';
export { NoIndexPatternsPanel } from './no_index_patterns';
export { DatasetSelector, DatasetSelectorAppearance } from './dataset_selector';
3 changes: 0 additions & 3 deletions src/plugins/data/public/ui/query_editor/_query_editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,6 @@
}

.osdQueryEditor__querycontrols {
float: right;
margin: $euiSizeS $euiSizeS;

.osdQueryEditor__extensionQueryControls {
display: flex;
padding: 0 $euiSizeS 0 $euiSizeXS;
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/data/public/ui/query_editor/query_editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import { SuggestionsListSize } from '../typeahead/suggestions_component';
import { QueryLanguageSelector } from './language_selector';
import { QueryEditorExtensions } from './query_editor_extensions';
import { getQueryService, getIndexPatterns } from '../../services';
import { DatasetSelector } from '../dataset_selector';
import { DefaultInputProps } from './editors';
import { MonacoCompatibleQuerySuggestion } from '../../autocomplete/providers/query_suggestion_provider';

Expand Down Expand Up @@ -454,7 +453,6 @@ export default class QueryEditorUI extends Component<Props, State> {
className={classNames('osdQueryEditor__banner', this.props.bannerClassName)}
/>
<div className="osdQueryEditor__topBar">
<DatasetSelector onSubmit={this.props.onSubmit} />
<div className="osdQueryEditor__input">
{this.state.isCollapsed
? languageEditor.TopBar.Collapsed()
Expand Down
37 changes: 28 additions & 9 deletions src/plugins/data/public/ui/query_editor/query_editor_top_row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@ import {
import classNames from 'classnames';
import React, { useState } from 'react';
import { createPortal } from 'react-dom';
import { IDataPluginServices, IIndexPattern, Query, TimeHistoryContract, TimeRange } from '../..';
import {
DatasetSelector,
DatasetSelectorAppearance,
IDataPluginServices,
IIndexPattern,
Query,
TimeHistoryContract,
TimeRange,
} from '../..';
import {
useOpenSearchDashboards,
withOpenSearchDashboards,
Expand Down Expand Up @@ -52,6 +60,7 @@ export interface QueryEditorTopRowProps {
isDirty: boolean;
timeHistory?: TimeHistoryContract;
indicateNoData?: boolean;
datasetSelectorRef?: React.RefObject<HTMLDivElement>;
datePickerRef?: React.RefObject<HTMLDivElement>;
savedQueryManagement?: any;
queryStatus?: QueryStatus;
Expand All @@ -63,14 +72,7 @@ export default function QueryEditorTopRow(props: QueryEditorTopRowProps) {
const [isDateRangeInvalid, setIsDateRangeInvalid] = useState(false);
const [isQueryEditorFocused, setIsQueryEditorFocused] = useState(false);
const opensearchDashboards = useOpenSearchDashboards<IDataPluginServices>();
const {
uiSettings,
storage,
appName,
data: {
query: { queryString },
},
} = opensearchDashboards.services;
const { uiSettings, storage, appName } = opensearchDashboards.services;

const queryLanguage = props.query && props.query.language;
const persistedLog: PersistedLog | undefined = React.useMemo(
Expand Down Expand Up @@ -170,6 +172,19 @@ export default function QueryEditorTopRow(props: QueryEditorTopRowProps) {
return valueAsMoment.toISOString();
}

function renderDatasetSelector() {
return (
<DatasetSelector
onSubmit={onInputSubmit}
appearance={DatasetSelectorAppearance.Button}
buttonProps={{
color: 'text',
fullWidth: true,
}}
/>
);
}

function renderQueryEditor() {
if (!shouldRenderQueryEditor()) return;
return (
Expand Down Expand Up @@ -315,6 +330,8 @@ export default function QueryEditorTopRow(props: QueryEditorTopRowProps) {
</EuiFlexGroup>
);

const datasetSelector = <>{renderDatasetSelector()}</>;

return (
<EuiFlexGroup
className={classes}
Expand All @@ -323,6 +340,8 @@ export default function QueryEditorTopRow(props: QueryEditorTopRowProps) {
direction="column"
justifyContent="flexEnd"
>
{props?.datasetSelectorRef?.current &&
createPortal(datasetSelector, props.datasetSelectorRef.current)}
{props?.datePickerRef?.current && uiSettings.get(UI_SETTINGS.QUERY_ENHANCEMENTS_ENABLED)
? createPortal(datePicker, props.datePickerRef.current)
: datePicker}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ export function createSearchBar({ core, storage, data }: StatefulSearchBarDeps)
onClearSavedQuery={defaultOnClearSavedQuery(props, clearSavedQuery)}
onSavedQueryUpdated={defaultOnSavedQueryUpdated(props, setSavedQuery)}
onSaved={defaultOnSavedQueryUpdated(props, setSavedQuery)}
datasetSelectorRef={props.datasetSelectorRef}
datePickerRef={props.datePickerRef}
isFilterBarPortable={props.isFilterBarPortable}
{...overrideDefaultBehaviors(props)}
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/data/public/ui/search_bar/search_bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export interface SearchBarOwnProps {
refreshInterval?: number;
dateRangeFrom?: string;
dateRangeTo?: string;
datasetSelectorRef?: React.RefObject<HTMLDivElement>;
datePickerRef?: React.RefObject<HTMLDivElement>;
// Query bar - should be in SearchBarInjectedDeps
query?: Query;
Expand Down Expand Up @@ -549,6 +550,7 @@ class SearchBarUI extends Component<SearchBarProps, State> {
filterBar={filterBar}
dataTestSubj={this.props.dataTestSubj}
indicateNoData={this.props.indicateNoData}
datasetSelectorRef={this.props.datasetSelectorRef}
datePickerRef={this.props.datePickerRef}
savedQueryManagement={searchBarMenu(false, true)}
queryStatus={this.props.queryStatus}
Expand Down
Loading

0 comments on commit 5876362

Please sign in to comment.