Skip to content

Commit 289a7c0

Browse files
authored
[2.16] Fix minor issues for Direct Query Datasource (#7419)
* 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>
1 parent 23d2c5c commit 289a7c0

File tree

10 files changed

+718
-1045
lines changed

10 files changed

+718
-1045
lines changed

src/plugins/data_source_management/public/components/data_source_home_panel/__snapshots__/data_source_home_panel.test.tsx.snap

+12-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/plugins/data_source_management/public/components/data_source_home_panel/data_source_home_panel.test.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,23 @@ describe('DataSourceHomePanel', () => {
6767

6868
test('renders DataSourceTableWithRouter when manageOpensearchDataSources tab is selected', () => {
6969
const wrapper = mountComponent();
70-
wrapper.find(EuiTab).at(1).simulate('click');
70+
wrapper.find(EuiTab).at(0).simulate('click');
7171
expect(wrapper.find(DataSourceTableWithRouter)).toHaveLength(1);
7272
expect(wrapper.find(ManageDirectQueryDataConnectionsTable)).toHaveLength(0);
7373
});
7474

7575
test('renders ManageDirectQueryDataConnectionsTable when manageDirectQueryDataSources tab is selected', () => {
7676
const wrapper = mountComponent();
77-
wrapper.find(EuiTab).at(0).simulate('click');
77+
wrapper.find(EuiTab).at(1).simulate('click');
7878
expect(wrapper.find(ManageDirectQueryDataConnectionsTable)).toHaveLength(1);
7979
expect(wrapper.find(DataSourceTableWithRouter)).toHaveLength(0);
8080
});
8181

8282
test('handles tab changes', () => {
8383
const wrapper = mountComponent();
84-
expect(wrapper.find(ManageDirectQueryDataConnectionsTable)).toHaveLength(1);
85-
wrapper.find(EuiTab).at(1).simulate('click');
8684
expect(wrapper.find(DataSourceTableWithRouter)).toHaveLength(1);
85+
wrapper.find(EuiTab).at(1).simulate('click');
86+
expect(wrapper.find(ManageDirectQueryDataConnectionsTable)).toHaveLength(1);
8787
});
8888

8989
test('does not render OpenSearch connections tab when featureFlagStatus is false', () => {

src/plugins/data_source_management/public/components/data_source_home_panel/data_source_home_panel.tsx

+9-5
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ export const DataSourceHomePanel: React.FC<DataSourceHomePanelProps> = ({
3939
application,
4040
} = useOpenSearchDashboards<DataSourceManagementContext>().services;
4141

42-
const [selectedTabId, setSelectedTabId] = useState('manageDirectQueryDataSources');
42+
const defaultTabId = featureFlagStatus
43+
? 'manageOpensearchDataSources'
44+
: 'manageDirectQueryDataSources';
45+
const [selectedTabId, setSelectedTabId] = useState(defaultTabId);
4346
const canManageDataSource = !!application.capabilities?.dataSource?.canManage;
4447

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

5356
const tabs = [
54-
{
55-
id: 'manageDirectQueryDataSources',
56-
name: 'Direct query connections',
57-
},
5857
...(featureFlagStatus
5958
? [
6059
{
@@ -63,6 +62,10 @@ export const DataSourceHomePanel: React.FC<DataSourceHomePanelProps> = ({
6362
},
6463
]
6564
: []),
65+
{
66+
id: 'manageDirectQueryDataSources',
67+
name: 'Direct query connections',
68+
},
6669
];
6770

6871
const renderTabs = () => {
@@ -110,6 +113,7 @@ export const DataSourceHomePanel: React.FC<DataSourceHomePanelProps> = ({
110113
savedObjects={savedObjects}
111114
uiSettings={uiSettings}
112115
featureFlagStatus={featureFlagStatus}
116+
application={application}
113117
/>
114118
)}
115119
</EuiFlexItem>

src/plugins/data_source_management/public/components/direct_query_data_sources_components/connection_detail/direct_query_connection_detail.test.tsx

+9-13
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import '@testing-library/jest-dom';
99
import { MemoryRouter, Route } from 'react-router-dom';
1010
import { DirectQueryDataConnectionDetail } from './direct_query_connection_detail';
1111
import { ApplicationStart, HttpStart, NotificationsStart } from 'opensearch-dashboards/public';
12+
import { isPluginInstalled } from '../../utils';
1213

1314
jest.mock('../../../constants', () => ({
1415
DATACONNECTIONS_BASE: '/api/dataconnections',
@@ -61,19 +62,9 @@ jest.mock('../associated_object_management/utils/associated_objects_tab_utils',
6162
redirectToExplorerS3: jest.fn(),
6263
}));
6364

64-
beforeAll(() => {
65-
global.fetch = jest.fn(() =>
66-
Promise.resolve({
67-
json: () =>
68-
Promise.resolve({ status: { statuses: [{ id: 'plugin:observabilityDashboards' }] } }),
69-
})
70-
) as jest.Mock;
71-
});
72-
73-
afterAll(() => {
74-
global.fetch.mockClear();
75-
delete global.fetch;
76-
});
65+
jest.mock('../../utils', () => ({
66+
isPluginInstalled: jest.fn(),
67+
}));
7768

7869
const renderComponent = ({
7970
featureFlagStatus = false,
@@ -98,6 +89,11 @@ const renderComponent = ({
9889
};
9990

10091
describe('DirectQueryDataConnectionDetail', () => {
92+
beforeEach(() => {
93+
jest.clearAllMocks();
94+
(isPluginInstalled as jest.Mock).mockResolvedValue(true);
95+
});
96+
10197
test('renders without crashing', async () => {
10298
const mockHttp = {
10399
get: jest.fn().mockResolvedValue({

src/plugins/data_source_management/public/components/direct_query_data_sources_components/connection_detail/direct_query_connection_detail.tsx

+4-36
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import {
5353
IntegrationInstancesSearchResult,
5454
} from '../../../../framework/types';
5555
import { INTEGRATIONS_BASE } from '../../../../framework/utils/shared';
56+
import { isPluginInstalled } from '../../utils';
5657

5758
interface DirectQueryDataConnectionDetailProps {
5859
featureFlagStatus: boolean;
@@ -70,41 +71,6 @@ export const DirectQueryDataConnectionDetail: React.FC<DirectQueryDataConnection
7071
setBreadcrumbs,
7172
}) => {
7273
const [observabilityDashboardsExists, setObservabilityDashboardsExists] = useState(false);
73-
const checkIfSQLWorkbenchPluginIsInstalled = () => {
74-
fetch('/api/status', {
75-
headers: {
76-
'Content-Type': 'application/json',
77-
'osd-xsrf': 'true',
78-
'accept-language': 'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7,zh-TW;q=0.6',
79-
pragma: 'no-cache',
80-
'sec-fetch-dest': 'empty',
81-
'sec-fetch-mode': 'cors',
82-
'sec-fetch-site': 'same-origin',
83-
},
84-
method: 'GET',
85-
referrerPolicy: 'strict-origin-when-cross-origin',
86-
mode: 'cors',
87-
credentials: 'include',
88-
})
89-
.then(function (response) {
90-
return response.json();
91-
})
92-
.then((data) => {
93-
for (let i = 0; i < data.status.statuses.length; ++i) {
94-
if (data.status.statuses[i].id.includes('plugin:observabilityDashboards')) {
95-
setObservabilityDashboardsExists(true);
96-
}
97-
}
98-
})
99-
.catch((error) => {
100-
notifications.toasts.addDanger(
101-
'Error checking Dashboards Observability Plugin Installation status.'
102-
);
103-
// eslint-disable-next-line no-console
104-
console.error(error);
105-
});
106-
};
107-
10874
const { dataSourceName } = useParams<{ dataSourceName: string }>();
10975
const { search } = useLocation();
11076
const queryParams = new URLSearchParams(search);
@@ -211,7 +177,9 @@ export const DirectQueryDataConnectionDetail: React.FC<DirectQueryDataConnection
211177
};
212178

213179
useEffect(() => {
214-
checkIfSQLWorkbenchPluginIsInstalled();
180+
isPluginInstalled('plugin:observabilityDashboards', notifications, http).then(
181+
setObservabilityDashboardsExists
182+
);
215183
// eslint-disable-next-line react-hooks/exhaustive-deps
216184
}, []);
217185

0 commit comments

Comments
 (0)