Skip to content

Commit

Permalink
Revert "[2.16] Fix minor issues for Direct Query Datasource (opensear…
Browse files Browse the repository at this point in the history
…ch-project#7419)"

This reverts commit 289a7c0.
  • Loading branch information
ananzh committed Jul 24, 2024
1 parent 535f16a commit 0dc5cec
Show file tree
Hide file tree
Showing 10 changed files with 1,045 additions and 718 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,23 @@ describe('DataSourceHomePanel', () => {

test('renders DataSourceTableWithRouter when manageOpensearchDataSources tab is selected', () => {
const wrapper = mountComponent();
wrapper.find(EuiTab).at(0).simulate('click');
wrapper.find(EuiTab).at(1).simulate('click');
expect(wrapper.find(DataSourceTableWithRouter)).toHaveLength(1);
expect(wrapper.find(ManageDirectQueryDataConnectionsTable)).toHaveLength(0);
});

test('renders ManageDirectQueryDataConnectionsTable when manageDirectQueryDataSources tab is selected', () => {
const wrapper = mountComponent();
wrapper.find(EuiTab).at(1).simulate('click');
wrapper.find(EuiTab).at(0).simulate('click');
expect(wrapper.find(ManageDirectQueryDataConnectionsTable)).toHaveLength(1);
expect(wrapper.find(DataSourceTableWithRouter)).toHaveLength(0);
});

test('handles tab changes', () => {
const wrapper = mountComponent();
expect(wrapper.find(DataSourceTableWithRouter)).toHaveLength(1);
wrapper.find(EuiTab).at(1).simulate('click');
expect(wrapper.find(ManageDirectQueryDataConnectionsTable)).toHaveLength(1);
wrapper.find(EuiTab).at(1).simulate('click');
expect(wrapper.find(DataSourceTableWithRouter)).toHaveLength(1);
});

test('does not render OpenSearch connections tab when featureFlagStatus is false', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ export const DataSourceHomePanel: React.FC<DataSourceHomePanelProps> = ({
application,
} = useOpenSearchDashboards<DataSourceManagementContext>().services;

const defaultTabId = featureFlagStatus
? 'manageOpensearchDataSources'
: 'manageDirectQueryDataSources';
const [selectedTabId, setSelectedTabId] = useState(defaultTabId);
const [selectedTabId, setSelectedTabId] = useState('manageDirectQueryDataSources');
const canManageDataSource = !!application.capabilities?.dataSource?.canManage;

useEffect(() => {
Expand All @@ -54,6 +51,10 @@ export const DataSourceHomePanel: React.FC<DataSourceHomePanelProps> = ({
};

const tabs = [
{
id: 'manageDirectQueryDataSources',
name: 'Direct query connections',
},
...(featureFlagStatus
? [
{
Expand All @@ -62,10 +63,6 @@ export const DataSourceHomePanel: React.FC<DataSourceHomePanelProps> = ({
},
]
: []),
{
id: 'manageDirectQueryDataSources',
name: 'Direct query connections',
},
];

const renderTabs = () => {
Expand Down Expand Up @@ -113,7 +110,6 @@ export const DataSourceHomePanel: React.FC<DataSourceHomePanelProps> = ({
savedObjects={savedObjects}
uiSettings={uiSettings}
featureFlagStatus={featureFlagStatus}
application={application}
/>
)}
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import '@testing-library/jest-dom';
import { MemoryRouter, Route } from 'react-router-dom';
import { DirectQueryDataConnectionDetail } from './direct_query_connection_detail';
import { ApplicationStart, HttpStart, NotificationsStart } from 'opensearch-dashboards/public';
import { isPluginInstalled } from '../../utils';

jest.mock('../../../constants', () => ({
DATACONNECTIONS_BASE: '/api/dataconnections',
Expand Down Expand Up @@ -62,9 +61,19 @@ jest.mock('../associated_object_management/utils/associated_objects_tab_utils',
redirectToExplorerS3: jest.fn(),
}));

jest.mock('../../utils', () => ({
isPluginInstalled: jest.fn(),
}));
beforeAll(() => {
global.fetch = jest.fn(() =>
Promise.resolve({
json: () =>
Promise.resolve({ status: { statuses: [{ id: 'plugin:observabilityDashboards' }] } }),
})
) as jest.Mock;
});

afterAll(() => {
global.fetch.mockClear();
delete global.fetch;
});

const renderComponent = ({
featureFlagStatus = false,
Expand All @@ -89,11 +98,6 @@ const renderComponent = ({
};

describe('DirectQueryDataConnectionDetail', () => {
beforeEach(() => {
jest.clearAllMocks();
(isPluginInstalled as jest.Mock).mockResolvedValue(true);
});

test('renders without crashing', async () => {
const mockHttp = {
get: jest.fn().mockResolvedValue({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ import {
IntegrationInstancesSearchResult,
} from '../../../../framework/types';
import { INTEGRATIONS_BASE } from '../../../../framework/utils/shared';
import { isPluginInstalled } from '../../utils';

interface DirectQueryDataConnectionDetailProps {
featureFlagStatus: boolean;
Expand All @@ -71,6 +70,41 @@ export const DirectQueryDataConnectionDetail: React.FC<DirectQueryDataConnection
setBreadcrumbs,
}) => {
const [observabilityDashboardsExists, setObservabilityDashboardsExists] = useState(false);
const checkIfSQLWorkbenchPluginIsInstalled = () => {
fetch('/api/status', {
headers: {
'Content-Type': 'application/json',
'osd-xsrf': 'true',
'accept-language': 'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7,zh-TW;q=0.6',
pragma: 'no-cache',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-origin',
},
method: 'GET',
referrerPolicy: 'strict-origin-when-cross-origin',
mode: 'cors',
credentials: 'include',
})
.then(function (response) {
return response.json();
})
.then((data) => {
for (let i = 0; i < data.status.statuses.length; ++i) {
if (data.status.statuses[i].id.includes('plugin:observabilityDashboards')) {
setObservabilityDashboardsExists(true);
}
}
})
.catch((error) => {
notifications.toasts.addDanger(
'Error checking Dashboards Observability Plugin Installation status.'
);
// eslint-disable-next-line no-console
console.error(error);
});
};

const { dataSourceName } = useParams<{ dataSourceName: string }>();
const { search } = useLocation();
const queryParams = new URLSearchParams(search);
Expand Down Expand Up @@ -177,9 +211,7 @@ export const DirectQueryDataConnectionDetail: React.FC<DirectQueryDataConnection
};

useEffect(() => {
isPluginInstalled('plugin:observabilityDashboards', notifications, http).then(
setObservabilityDashboardsExists
);
checkIfSQLWorkbenchPluginIsInstalled();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

Expand Down
Loading

0 comments on commit 0dc5cec

Please sign in to comment.