Skip to content

Commit

Permalink
[2.16] Fix minor issues for Direct Query Datasource (#7419)
Browse files Browse the repository at this point in the history
* Switch the tab orders

Signed-off-by: Ryan Liang <jiallian@amazon.com>

* Add delete with MDS support

Signed-off-by: Ryan Liang <jiallian@amazon.com>

* Add acc creation action in data connection table

Signed-off-by: Ryan Liang <jiallian@amazon.com>

* Fix snapshots

Signed-off-by: Ryan Liang <jiallian@amazon.com>

* mute the table row for integration action when feature flag is disabled and no obs installed

Signed-off-by: Ryan Liang <jiallian@amazon.com>

* add integration flyout in dataconnection table

Signed-off-by: Ryan Liang <jiallian@amazon.com>

* Add discover forwarding action in connections table

Signed-off-by: Ryan Liang <jiallian@amazon.com>

* Disable query in observability logs in data connections table action menu

Signed-off-by: Ryan Liang <jiallian@amazon.com>

* Update the test of connection table

Signed-off-by: Ryan Liang <jiallian@amazon.com>

* Update the test of home panel

Signed-off-by: Ryan Liang <jiallian@amazon.com>

* Fix the then for checking observability dashboards

Signed-off-by: Ryan Liang <jiallian@amazon.com>

* Fix delete

Signed-off-by: Ryan Liang <jiallian@amazon.com>

* fix check plugin

Signed-off-by: Ryan Liang <jiallian@amazon.com>

* fix check plugin 2

Signed-off-by: Ryan Liang <jiallian@amazon.com>

* fix check plugin 3 test

Signed-off-by: Ryan Liang <jiallian@amazon.com>

---------

Signed-off-by: Ryan Liang <jiallian@amazon.com>
  • Loading branch information
RyanL1997 authored Jul 24, 2024
1 parent 23d2c5c commit 289a7c0
Show file tree
Hide file tree
Showing 10 changed files with 718 additions and 1,045 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(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

0 comments on commit 289a7c0

Please sign in to comment.