Skip to content

Commit

Permalink
Moving Query Workbench to Dev Tools (#349) (#356)
Browse files Browse the repository at this point in the history
* Migrate to devTools

Signed-off-by: Adam Tackett <[email protected]>

* MDS working changed how ID passed

Signed-off-by: Adam Tackett <[email protected]>

* Chagned name to dataSourceMDSId

Signed-off-by: Adam Tackett <[email protected]>

* remove console log

Signed-off-by: Adam Tackett <[email protected]>

* add support for backward URLs

Signed-off-by: Shenoy Pratik <[email protected]>

* update nav coditionally and set breadcrumbs

Signed-off-by: Shenoy Pratik <[email protected]>

* fix lint error

Signed-off-by: Shenoy Pratik <[email protected]>

* update breadcrumb only when nav is enabled

Signed-off-by: Shenoy Pratik <[email protected]>

* fix URL for new nav is disabled

Signed-off-by: Shenoy Pratik <[email protected]>

---------

Signed-off-by: Adam Tackett <[email protected]>
Signed-off-by: Shenoy Pratik <[email protected]>
Co-authored-by: Adam Tackett <[email protected]>
Co-authored-by: Shenoy Pratik <[email protected]>
(cherry picked from commit 7aba1fd)

Co-authored-by: Adam Tackett <[email protected]>
  • Loading branch information
ps48 and TackAdam authored Jul 19, 2024
1 parent 7523bbf commit e578ec4
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 55 deletions.
31 changes: 31 additions & 0 deletions common/utils/legacy_route_helper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

export const convertLegacyWorkbenchUrl = (location: Location) => {
// Update pathname to new structure
let pathname = location.pathname.replace(
'app/opensearch-query-workbench',
'app/dev_tools#/opensearch-query-workbench'
);

// If the pathname ends with '/', remove it before appending the hash
if (pathname.endsWith('/')) {
pathname = pathname.slice(0, -1);
}

// Adjust the hash part of the URL
let hash = location.hash.replace('#/', '/');

// If hash contains "accelerate" or any random text, handle it properly
if (hash.includes('accelerate/')) {
hash = hash.replace('#/', '/');
} else if (hash.startsWith('#/')) {
hash = hash.replace('#/', '/');
}

const finalUrl = `${pathname}${hash}`;

return finalUrl;
};
15 changes: 5 additions & 10 deletions opensearch_dashboards.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,13 @@
"opensearchDashboardsVersion": "2.16.0",
"server": true,
"ui": true,
"supportedOSDataSourceVersions": ">=1.0.0",
"requiredOSDataSourcePlugins": ["opensearch-sql"],
"requiredPlugins": [
"devTools",
"navigation",
"opensearchDashboardsReact",
"opensearchDashboardsUtils"
],
"optionalPlugins": [
"observabilityDashboards",
"dataSource",
"dataSourceManagement"
],
"supportedOSDataSourceVersions": ">=1.0.0",
"requiredOSDataSourcePlugins": [
"opensearch-sql"
]
}
"optionalPlugins": ["observabilityDashboards", "dataSource", "dataSourceManagement"]
}
4 changes: 2 additions & 2 deletions public/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/


import React from 'react';
import ReactDOM from 'react-dom';
import { AppMountParameters, CoreStart } from '../../../src/core/public';
Expand All @@ -14,7 +13,7 @@ import { AppPluginStartDependencies } from './types';
export const renderApp = (
{ notifications, http, chrome, savedObjects }: CoreStart,
{ navigation, dataSource }: AppPluginStartDependencies,
{ appBasePath, element, setHeaderActionMenu }: AppMountParameters,
{ appBasePath, element, setHeaderActionMenu, dataSourceId }: AppMountParameters,
dataSourceManagement: DataSourceManagementPluginSetup
) => {
ReactDOM.render(
Expand All @@ -28,6 +27,7 @@ export const renderApp = (
dataSourceEnabled={!!dataSource}
dataSourceManagement={dataSourceManagement}
setActionMenu={setHeaderActionMenu}
dataSourceMDSId={dataSourceId}
/>,
element
);
Expand Down
41 changes: 23 additions & 18 deletions public/components/Main/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { AsyncApiResponse, AsyncQueryStatus } from '../../../common/types';
import { executeAsyncQuery } from '../../../common/utils/async_query_helpers';
import { fetchDataSources } from '../../../common/utils/fetch_datasources';
import * as pluginManifest from '../../../opensearch_dashboards.json';
import { coreRefs } from '../../framework/core_refs';
import { MESSAGE_TAB_LABEL } from '../../utils/constants';
import {
Tree,
Expand Down Expand Up @@ -114,6 +115,7 @@ interface MainProps {
notifications: NotificationsStart;
dataSourceEnabled: boolean;
dataSourceManagement: DataSourceManagementPluginSetup;
dataSourceMDSId: string;
setActionMenu: (menuMount: MountPoint | undefined) => void;
}

Expand Down Expand Up @@ -290,7 +292,7 @@ export class Main extends React.Component<MainProps, MainState> {
isCallOutVisible: false,
cluster: 'Indexes',
dataSourceOptions: [],
selectedMDSDataConnectionId: '',
selectedMDSDataConnectionId: this.props.dataSourceMDSId,
mdsClusterName: '',
flintDataConnections: false,
};
Expand All @@ -301,19 +303,22 @@ export class Main extends React.Component<MainProps, MainState> {
}

componentDidMount() {
this.props.setBreadcrumbs([
{
text: 'Query Workbench',
href: '#',
},
]);
if (!coreRefs?.chrome?.navGroup.getNavGroupEnabled()) {
this.props.setBreadcrumbs([
{
text: 'Query Workbench',
href: '#',
},
]);
}

this.fetchFlintDataSources();
}

fetchFlintDataSources = () => {
fetchDataSources(
this.httpClient,
this.state.selectedMDSDataConnectionId,
this.props.dataSourceMDSId,
this.props.urlDataSource,
(dataOptions) => {
if (dataOptions.length > 0) {
Expand Down Expand Up @@ -435,7 +440,7 @@ export class Main extends React.Component<MainProps, MainState> {
const endpoint = '/api/sql_console/' + (_.isEqual(language, 'SQL') ? 'sqlquery' : 'pplquery');
let query = {};
if (this.props.dataSourceEnabled) {
query = { dataSourceMDSId: this.state.selectedMDSDataConnectionId };
query = { dataSourceMDSId: this.props.dataSourceMDSId };
}
const responsePromise = Promise.all(
queries.map((eachQuery: string) =>
Expand Down Expand Up @@ -570,7 +575,7 @@ export class Main extends React.Component<MainProps, MainState> {
});
}
},
this.state.selectedMDSDataConnectionId,
this.props.dataSourceMDSId,
(errorDetails: string) => {
this.setState({
asyncLoading: false,
Expand Down Expand Up @@ -599,7 +604,7 @@ export class Main extends React.Component<MainProps, MainState> {
if (queries.length > 0) {
let query = {};
if (this.props.dataSourceEnabled) {
query = { dataSourceMDSId: this.state.selectedMDSDataConnectionId };
query = { dataSourceMDSId: this.props.dataSourceMDSId };
}
const endpoint =
'/api/sql_console/' + (_.isEqual(language, 'SQL') ? 'translatesql' : 'translateppl');
Expand Down Expand Up @@ -651,7 +656,7 @@ export class Main extends React.Component<MainProps, MainState> {
if (queries.length > 0) {
let query = {};
if (this.props.dataSourceEnabled) {
query = { dataSourceMDSId: this.state.selectedMDSDataConnectionId };
query = { dataSourceMDSId: this.props.dataSourceMDSId };
}
Promise.all(
queries.map((eachQuery: string) =>
Expand Down Expand Up @@ -688,7 +693,7 @@ export class Main extends React.Component<MainProps, MainState> {
if (queries.length > 0) {
let query = {};
if (this.props.dataSourceEnabled) {
query = { dataSourceMDSId: this.state.selectedMDSDataConnectionId };
query = { dataSourceMDSId: this.props.dataSourceMDSId };
}
const endpoint = '/api/sql_console/' + (_.isEqual(language, 'SQL') ? 'sqlquery' : 'pplquery');
Promise.all(
Expand Down Expand Up @@ -726,7 +731,7 @@ export class Main extends React.Component<MainProps, MainState> {
if (queries.length > 0) {
let query = {};
if (this.props.dataSourceEnabled) {
query = { dataSourceMDSId: this.state.selectedMDSDataConnectionId };
query = { dataSourceMDSId: this.props.dataSourceMDSId };
}
const endpoint = '/api/sql_console/' + (_.isEqual(language, 'SQL') ? 'sqlcsv' : 'pplcsv');
Promise.all(
Expand Down Expand Up @@ -764,7 +769,7 @@ export class Main extends React.Component<MainProps, MainState> {
if (queries.length > 0) {
let query = {};
if (this.props.dataSourceEnabled) {
query = { dataSourceMDSId: this.state.selectedMDSDataConnectionId };
query = { dataSourceMDSId: this.props.dataSourceMDSId };
}
const endpoint = '/api/sql_console/' + (_.isEqual(language, 'SQL') ? 'sqltext' : 'ppltext');
Promise.all(
Expand Down Expand Up @@ -947,7 +952,7 @@ export class Main extends React.Component<MainProps, MainState> {
openAccelerationFlyout={
this.props.isAccelerationFlyoutOpen && !this.state.isAccelerationFlyoutOpened
}
dataSourceMDSId={this.state.selectedMDSDataConnectionId}
dataSourceMDSId={this.props.dataSourceMDSId}
setIsAccelerationFlyoutOpened={this.setIsAccelerationFlyoutOpened}
/>
);
Expand Down Expand Up @@ -1086,7 +1091,7 @@ export class Main extends React.Component<MainProps, MainState> {
onSelect={this.handleDataSelect}
urlDataSource={this.props.urlDataSource}
asyncLoading={this.state.asyncLoading}
dataSourceMDSId={this.state.selectedMDSDataConnectionId}
dataSourceMDSId={this.props.dataSourceMDSId}
/>
</EuiFlexItem>
<EuiFlexItem grow={false}>
Expand All @@ -1105,7 +1110,7 @@ export class Main extends React.Component<MainProps, MainState> {
updateSQLQueries={this.updateSQLQueries}
refreshTree={this.state.refreshTree}
dataSourceEnabled={this.props.dataSourceEnabled}
dataSourceMDSId={this.state.selectedMDSDataConnectionId}
dataSourceMDSId={this.props.dataSourceMDSId}
clusterTab={this.state.cluster}
language={this.state.language}
updatePPLQueries={this.updatePPLQueries}
Expand Down
15 changes: 12 additions & 3 deletions public/components/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { CoreStart, MountPoint } from '../../../../src/core/public';
import { DataSourceManagementPluginSetup } from '../../../../src/plugins/data_source_management/public';
import { NavigationPublicPluginStart } from '../../../../src/plugins/navigation/public';

import { coreRefs } from '../framework/core_refs';
import { Main } from './Main';

interface WorkbenchAppDeps {
Expand All @@ -24,6 +25,7 @@ interface WorkbenchAppDeps {
savedObjects: CoreStart['savedObjects'];
dataSourceEnabled: boolean;
dataSourceManagement: DataSourceManagementPluginSetup;
dataSourceMDSId: string;
setActionMenu: (menuMount: MountPoint | undefined) => void;
}

Expand All @@ -36,8 +38,12 @@ export const WorkbenchApp = ({
savedObjects,
dataSourceEnabled,
dataSourceManagement,
dataSourceMDSId: dataSourceId,
setActionMenu,
}: WorkbenchAppDeps) => {
const isNavGroupEnabled = coreRefs?.chrome?.navGroup.getNavGroupEnabled();
const basePath = isNavGroupEnabled ? 'opensearch-query-workbench' : '';

return (
<HashRouter>
<I18nProvider>
Expand All @@ -47,7 +53,7 @@ export const WorkbenchApp = ({
<Switch>
<Route
exact
path="/"
path={`/${basePath}`}
render={(props) => (
<Main
httpClient={http}
Expand All @@ -59,13 +65,14 @@ export const WorkbenchApp = ({
savedObjects={savedObjects}
dataSourceEnabled={dataSourceEnabled}
dataSourceManagement={dataSourceManagement}
dataSourceMDSId={dataSourceId}
setActionMenu={setActionMenu}
/>
)}
/>
<Route
exact
path="/:dataSource"
path={`/${basePath}/:dataSource`}
render={(props) => (
<Main
httpClient={http}
Expand All @@ -77,13 +84,14 @@ export const WorkbenchApp = ({
savedObjects={savedObjects}
dataSourceEnabled={dataSourceEnabled}
dataSourceManagement={dataSourceManagement}
dataSourceMDSId={dataSourceId}
setActionMenu={setActionMenu}
/>
)}
/>
<Route
exact
path="/accelerate/:dataSource"
path={`/${basePath}/accelerate/:dataSource`}
render={(props) => (
<Main
httpClient={http}
Expand All @@ -95,6 +103,7 @@ export const WorkbenchApp = ({
savedObjects={savedObjects}
dataSourceEnabled={dataSourceEnabled}
dataSourceManagement={dataSourceManagement}
dataSourceMDSId={dataSourceId}
setActionMenu={setActionMenu}
/>
)}
Expand Down
Loading

0 comments on commit e578ec4

Please sign in to comment.