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

[2.16] Fix minor issues for Direct Query Datasource #7419

Merged
merged 15 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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

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(1).simulate('click');
wrapper.find(EuiTab).at(0).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(0).simulate('click');
wrapper.find(EuiTab).at(1).simulate('click');
expect(wrapper.find(ManageDirectQueryDataConnectionsTable)).toHaveLength(1);
expect(wrapper.find(DataSourceTableWithRouter)).toHaveLength(0);
});

test('handles tab changes', () => {
const wrapper = mountComponent();
expect(wrapper.find(ManageDirectQueryDataConnectionsTable)).toHaveLength(1);
wrapper.find(EuiTab).at(1).simulate('click');
expect(wrapper.find(DataSourceTableWithRouter)).toHaveLength(1);
wrapper.find(EuiTab).at(1).simulate('click');
expect(wrapper.find(ManageDirectQueryDataConnectionsTable)).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,7 +39,10 @@ export const DataSourceHomePanel: React.FC<DataSourceHomePanelProps> = ({
application,
} = useOpenSearchDashboards<DataSourceManagementContext>().services;

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

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

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

const renderTabs = () => {
Expand Down Expand Up @@ -110,6 +113,7 @@ 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,6 +9,7 @@ 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 @@ -61,19 +62,9 @@ jest.mock('../associated_object_management/utils/associated_objects_tab_utils',
redirectToExplorerS3: 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;
});
jest.mock('../../utils', () => ({
isPluginInstalled: jest.fn(),
}));

const renderComponent = ({
featureFlagStatus = false,
Expand All @@ -98,6 +89,11 @@ 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,6 +53,7 @@ import {
IntegrationInstancesSearchResult,
} from '../../../../framework/types';
import { INTEGRATIONS_BASE } from '../../../../framework/utils/shared';
import { isPluginInstalled } from '../../utils';

interface DirectQueryDataConnectionDetailProps {
featureFlagStatus: boolean;
Expand All @@ -70,41 +71,6 @@ 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 @@ -211,7 +177,9 @@ export const DirectQueryDataConnectionDetail: React.FC<DirectQueryDataConnection
};

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

Expand Down
Loading
Loading