Skip to content

Commit

Permalink
ppl working better
Browse files Browse the repository at this point in the history
Signed-off-by: Kawika Avilla <[email protected]>
  • Loading branch information
kavilla committed Aug 25, 2024
1 parent 733a723 commit 19a00be
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
13 changes: 13 additions & 0 deletions src/plugins/data/public/query/query_string/query_string_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,19 @@ export class QueryStringManager {
};
};

public getInitialQueryByDataset = (newDataset: Dataset) => {
const curQuery = this.query$.getValue();
const languageId = curQuery.language;
const language = this.languageService.getLanguage(languageId);
const newQuery = { ...curQuery, dataset: newDataset };
const input = language?.getQueryString(newQuery) || '';

return {
...newQuery,
query: input,
};
};

private getDefaultLanguage() {
return (
this.storage.get('userQueryLanguage') ||
Expand Down
13 changes: 9 additions & 4 deletions src/plugins/data/public/ui/dataset_selector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@

import { useEffect, useState } from 'react';
import React from 'react';
import { Dataset } from '../../../common/datasets';
import { Dataset, Query, TimeRange } from '../../../common';
import { DatasetSelector } from './dataset_selector';
import { useOpenSearchDashboards } from '../../../../opensearch_dashboards_react/public';
import { IDataPluginServices } from '../../types';

const ConnectedDatasetSelector = () => {
interface ConnectedDatasetSelectorProps {
onSubmit: ((query: Query, dateRange?: TimeRange | undefined) => void) | undefined;
}

const ConnectedDatasetSelector = ({ onSubmit }: ConnectedDatasetSelectorProps) => {
const [selectedDataset, setSelectedDataset] = useState<Dataset | undefined>();
const { services } = useOpenSearchDashboards<IDataPluginServices>();
const queryString = services.data.query.queryString;
Expand All @@ -29,8 +33,9 @@ const ConnectedDatasetSelector = () => {
const handleDatasetChange = (dataset?: Dataset) => {
setSelectedDataset(dataset);
if (dataset) {
const query = queryString.getQuery();
queryString.setQuery({ ...query, dataset });
const query = queryString.getInitialQueryByDataset(dataset);
queryString.setQuery(query);
onSubmit!(queryString.getQuery());
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/public/ui/query_editor/query_editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ export default class QueryEditorUI extends Component<Props, State> {
onClick={() => this.setState({ isCollapsed: !this.state.isCollapsed })}
isCollapsed={!this.state.isCollapsed}
/>
<DatasetSelector />
<DatasetSelector onSubmit={this.props.onSubmit} />
<div className="osdQueryEditor__input">
{this.state.isCollapsed
? languageEditor.TopBar.Collapsed()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,6 @@ export default function QueryEditorTopRow(props: QueryEditorTopRowProps) {
} = opensearchDashboards.services;

const queryLanguage = props.query && props.query.language;
// const parsedQuery =
// !language || isValidQuery(props.query) ? props.query! : queryString.getInitialQuery();
// if (!isEqual(parsedQuery?.query, props.query?.query)) {
// onQueryChange(parsedQuery);
// onSubmit({ query: parsedQuery, dateRange: getDateRange() });
// }
const persistedLog: PersistedLog | undefined = React.useMemo(
() =>
queryLanguage && uiSettings && storage && appName
Expand Down

0 comments on commit 19a00be

Please sign in to comment.