Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates create accelerations flyout usage and side tree #285

Merged
merged 9 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions common/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@
Waiting = 'waiting',
}

export enum CachedDataSourceStatus {
Updated = 'Updated',
Failed = 'Failed',
Empty = 'Empty',
}

export type TreeItemType =
| 'covering_index'
| 'skipping_index'
Expand All @@ -121,7 +127,7 @@
interface AsyncApiDataResponse {
status: string;
schema?: Array<{ name: string; type: string }>;
datarows?: any;

Check warning on line 130 in common/types/index.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
total?: number;
size?: number;
error?: string;
Expand Down
8 changes: 4 additions & 4 deletions opensearch_dashboards.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"id": "queryWorkbenchDashboards",
"version": "3.0.0.0",
"opensearchDashboardsVersion": "3.0.0",
"version": "2.13.0.0",
ps48 marked this conversation as resolved.
Show resolved Hide resolved
"opensearchDashboardsVersion": "2.13.0",
"server": true,
"ui": true,
"requiredPlugins": ["navigation", "opensearchDashboardsReact"],
"optionalPlugins": []
"requiredPlugins": ["navigation", "opensearchDashboardsReact", "opensearchDashboardsUtils"],
"optionalPlugins": ["observabilityDashboards"]
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "opensearch-query-workbench",
"version": "3.0.0.0",
"version": "2.13.0.0",
"description": "Query Workbench",
"main": "index.js",
"license": "Apache-2.0",
Expand Down Expand Up @@ -50,4 +50,4 @@
"semver": "^7.5.2",
"@cypress/request": "^3.0.0"
}
}
}
10,600 changes: 2,925 additions & 7,675 deletions public/components/Main/__snapshots__/main.test.tsx.snap

Large diffs are not rendered by default.

61 changes: 53 additions & 8 deletions public/components/Main/main.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,46 @@

const setBreadcrumbsMock = jest.fn();

jest.mock('../../dependencies/register_observability_dependencies', () => ({
getRenderAccelerationDetailsFlyout: jest.fn(() => jest.fn()),
getRenderCreateAccelerationFlyout: jest.fn(() => jest.fn()),
setRenderAccelerationDetailsFlyout: jest.fn(() => jest.fn()),
setRenderCreateAccelerationFlyout: jest.fn(() => jest.fn()),
}));

jest.mock('../../framework/catalog_cache_refs', () => ({
catalogCacheRefs: {
CatalogCacheManager: {
addOrUpdateAccelerationsByDataSource: () => ({
dbCache: { status: 'empty' },
}),
getOrCreateDataSource: () => ({
dsCache: { status: 'empty' },
}),
},
useLoadDatabasesToCache: () => ({
loadStatus: 'Scheduled',
startLoading: jest.fn(),
stopLoading: jest.fn(),
}),
useLoadTablesToCache: () => ({
loadStatus: 'Scheduled',
startLoading: jest.fn(),
stopLoading: jest.fn(),
}),
useLoadTableColumnsToCache: () => ({
loadStatus: 'Scheduled',
startLoading: jest.fn(),
stopLoading: jest.fn(),
}),
useLoadAccelerationsToCache: () => ({
loadStatus: 'Scheduled',
startLoading: jest.fn(),
stopLoading: jest.fn(),
}),
},
}));

describe('<Main /> spec', () => {
it('renders the component', async () => {
const client = httpClientMock;
Expand All @@ -45,9 +85,9 @@
const asyncTest = () => {
fireEvent.click(pplButton);
};
waitFor(()=>{
waitFor(() => {
asyncTest();
})
});
expect(document.body.children[0]).toMatchSnapshot();
});
it('renders the component and checks if Opensearch is selected', async () => {
Expand All @@ -68,22 +108,24 @@
<Main httpClient={client} setBreadcrumbs={setBreadcrumbsMock} />
);
expect(getByText('OpenSearch')).toBeInTheDocument();
fireEvent.click(getByText('OpenSearch'))
fireEvent.click(getByText('OpenSearch'));
await waitFor(() => {
expect(getByText('glue_1')).toBeInTheDocument();
});
expect(document.body.children[0]).toMatchSnapshot();
});
it('renders the component for s3 glue and check sample query button ', async () => {

Check failure on line 117 in public/components/Main/main.test.tsx

View workflow job for this annotation

GitHub Actions / Lint

should not have leading or trailing spaces
const client = httpClientMock;
client.post = jest.fn().mockResolvedValue(mockHttpQuery);
client.get = jest.fn().mockResolvedValue(mockDataSelectQuery);
const { getByText } = await render(
<Main httpClient={client} setBreadcrumbs={setBreadcrumbsMock} />
);
expect(getByText('OpenSearch')).toBeInTheDocument();
fireEvent.click(getByText('OpenSearch'))
fireEvent.click(getByText('glue_1'))
await waitFor(() => {
expect(getByText('OpenSearch')).toBeInTheDocument();
});
fireEvent.click(getByText('OpenSearch'));
fireEvent.click(getByText('glue_1'));
await waitFor(() => {
expect(getByText('Sample Query')).toBeInTheDocument();
});
Expand All @@ -100,7 +142,10 @@
const { getByText } = await render(
<Main httpClient={client} setBreadcrumbs={setBreadcrumbsMock} />
);
expect(getByText('.kibana_1')).toBeInTheDocument();

await waitFor(() => {
expect(getByText('.kibana_1')).toBeInTheDocument();
});

expect(document.body.children[0]).toMatchSnapshot();
});
Expand Down Expand Up @@ -217,4 +262,4 @@
await asyncTest();
expect(document.body.children[0]).toMatchSnapshot();
});
});
});
23 changes: 20 additions & 3 deletions public/components/Main/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
EuiText,
} from '@elastic/eui';
import { IHttpResponse } from 'angular';
import { createBrowserHistory } from 'history';
import _ from 'lodash';
import React from 'react';
import { ChromeBreadcrumb, CoreStart } from '../../../../../src/core/public';
Expand All @@ -39,7 +40,7 @@ import { QueryResults } from '../QueryResults/QueryResults';
import { CreateButton } from '../SQLPage/CreateButton';
import { DataSelect } from '../SQLPage/DataSelect';
import { SQLPage } from '../SQLPage/SQLPage';
import { TableView } from '../SQLPage/table_view';
import { CatalogTree } from '../SQLPage/sql_catalog_tree/catalog_tree';

interface ResponseData {
ok: boolean;
Expand Down Expand Up @@ -230,6 +231,7 @@ export function getQueryResultsForTable(

export class Main extends React.Component<MainProps, MainState> {
httpClient: CoreStart['http'];
historyFromRedirection = createBrowserHistory();

constructor(props: MainProps) {
super(props);
Expand Down Expand Up @@ -759,6 +761,21 @@ export class Main extends React.Component<MainProps, MainState> {
});
}

checkHistoryState = () => {
if (!this.historyFromRedirection.location.state) return;

const { language, queryToRun }: any = this.historyFromRedirection.location.state;
if (language === 'sql') {
this.updateSQLQueries(queryToRun);

// Clear the state after use
this.historyFromRedirection.replace({
...location,
state: null,
});
}
};

handleDataSelect = (selectedItems: EuiComboBoxOptionOption[]) => {
this.updateSQLQueries('');
this.updatePPLQueries('');
Expand All @@ -769,6 +786,7 @@ export class Main extends React.Component<MainProps, MainState> {
this.setState({
selectedDatasource: selectedItems,
});
this.checkHistoryState();
};

handleReloadTree = () => {
Expand Down Expand Up @@ -940,8 +958,7 @@ export class Main extends React.Component<MainProps, MainState> {
}}
>
<EuiFlexItem grow={false}>
<TableView
http={this.httpClient}
<CatalogTree
selectedItems={this.state.selectedDatasource}
updateSQLQueries={this.updateSQLQueries}
refreshTree={this.state.refreshTree}
Expand Down
9 changes: 8 additions & 1 deletion public/components/SQLPage/SQLPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ import { fireEvent, render } from '@testing-library/react';
import React from 'react';
import { SQLPage } from './SQLPage';

jest.mock('../../dependencies/register_observability_dependencies', () => ({
getRenderAccelerationDetailsFlyout: jest.fn(() => jest.fn()),
getRenderCreateAccelerationFlyout: jest.fn(() => jest.fn()),
setRenderAccelerationDetailsFlyout: jest.fn(() => jest.fn()),
setRenderCreateAccelerationFlyout: jest.fn(() => jest.fn()),
}));

describe('<SQLPage /> spec', () => {
it('renders the component', () => {
render(
Expand Down Expand Up @@ -53,4 +60,4 @@ describe('<SQLPage /> spec', () => {
fireEvent.click(getByText('Explain'));
expect(onTranslate).toHaveBeenCalledTimes(1);
});
});
});
39 changes: 16 additions & 23 deletions public/components/SQLPage/SQLPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import 'brace/mode/sql';
import React from 'react';
import { CoreStart } from '../../../../../src/core/public';
import { SAMPLE_SQL_QUERY } from '../../../common/constants';
import { getRenderCreateAccelerationFlyout } from '../../dependencies/register_observability_dependencies';
import { ResponseDetail, TranslateResult } from '../Main/main';
import { CreateAcceleration } from '../acceleration/create/create_acceleration';

interface SQLPageProps {
http: CoreStart['http'];
Expand All @@ -45,7 +45,7 @@ interface SQLPageState {
sqlQuery: string;
translation: string;
isModalVisible: boolean;
flyoutComponent: JSX.Element;
queryToRun: string;
}

export class SQLPage extends React.Component<SQLPageProps, SQLPageState> {
Expand All @@ -55,31 +55,19 @@ export class SQLPage extends React.Component<SQLPageProps, SQLPageState> {
sqlQuery: this.props.sqlQuery,
translation: '',
isModalVisible: false,
flyoutComponent: <></>,
queryToRun: '',
};
}
renderCreateAccelerationFlyout = getRenderCreateAccelerationFlyout();

setIsModalVisible(visible: boolean): void {
this.setState({
isModalVisible: visible,
});
}

resetFlyout = () => {
this.setState({ flyoutComponent: <></> });
};

setAccelerationFlyout = () => {
this.setState({
flyoutComponent: (
<CreateAcceleration
http={this.props.http}
selectedDatasource={this.props.selectedDatasource}
resetFlyout={this.resetFlyout}
updateQueries={this.props.updateSQLQueries}
/>
),
});
this.renderCreateAccelerationFlyout(this.props.selectedDatasource[0].label);
};

componentDidUpdate(prevProps: SQLPageProps) {
Expand Down Expand Up @@ -148,7 +136,7 @@ export class SQLPage extends React.Component<SQLPageProps, SQLPageState> {
>
<EuiSpacer size="s" />
<EuiCodeEditor
data-test-subj='sqlCodeEditor'
data-test-subj="sqlCodeEditor"
mode="sql"
theme="textmate"
width="100%"
Expand All @@ -167,7 +155,7 @@ export class SQLPage extends React.Component<SQLPageProps, SQLPageState> {
<EuiFlexGroup justifyContent="spaceBetween">
<EuiFlexItem>
<EuiFlexGroup className="action-container" gutterSize="m">
<EuiFlexItem grow={false} >
<EuiFlexItem grow={false}>
<EuiButton
data-test-subj="sqlRunButton"
fill={true}
Expand All @@ -185,7 +173,11 @@ export class SQLPage extends React.Component<SQLPageProps, SQLPageState> {
this.props.onClear();
}}
>
<EuiButton data-test-subj="sqlClearButton" className="sql-editor-button" isDisabled={this.props.asyncLoading}>
<EuiButton
data-test-subj="sqlClearButton"
className="sql-editor-button"
isDisabled={this.props.asyncLoading}
>
Clear
</EuiButton>
</EuiFlexItem>
Expand Down Expand Up @@ -220,7 +212,9 @@ export class SQLPage extends React.Component<SQLPageProps, SQLPageState> {
<EuiFlexItem grow={false}>
<EuiButton
className="sql-accelerate-button"
onClick={this.setAccelerationFlyout}
onClick={() =>
this.renderCreateAccelerationFlyout(this.props.selectedDatasource[0].label)
}
isDisabled={this.props.asyncLoading}
>
Accelerate Table
Expand All @@ -230,8 +224,7 @@ export class SQLPage extends React.Component<SQLPageProps, SQLPageState> {
</EuiFlexGroup>
</EuiPanel>
{modal}
{this.state.flyoutComponent}
</>
);
}
}
}
35 changes: 35 additions & 0 deletions public/components/SQLPage/sql_catalog_tree/catalog_tree.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { EuiComboBoxOptionOption } from '@elastic/eui';
import React from 'react';
import { OSTree } from './os_tree';
import { S3Tree } from './s3_tree';

interface CatalogTreeProps {
selectedItems: EuiComboBoxOptionOption[];
updateSQLQueries: (query: string) => void;
refreshTree: boolean;
}

export const CatalogTree = ({ selectedItems, updateSQLQueries, refreshTree }: CatalogTreeProps) => {
return (
<>
{selectedItems !== undefined && selectedItems[0].label === 'OpenSearch' ? (
<OSTree
selectedItems={selectedItems}
updateSQLQueries={updateSQLQueries}
refreshTree={refreshTree}
/>
) : (
<S3Tree
dataSource={selectedItems[0].label}
updateSQLQueries={updateSQLQueries}
refreshTree={refreshTree}
/>
)}
</>
);
};
Loading
Loading