-
Notifications
You must be signed in to change notification settings - Fork 917
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Workspace] Enable direct query connections to support in workspace (#…
…7839) * add dqc Signed-off-by: yubonluo <[email protected]> * add dircet query connections on the detail page Signed-off-by: yubonluo <[email protected]> * Changeset file for PR #7839 created/updated * delete useless code Signed-off-by: yubonluo <[email protected]> * optimize the code Signed-off-by: yubonluo <[email protected]> * optimize the code Signed-off-by: yubonluo <[email protected]> * Refactor association modal Signed-off-by: Kapian1234 <[email protected]> * Integrate modal with workspace detail page Signed-off-by: Lin Wang <[email protected]> * Fix parent data source unchecked Signed-off-by: Lin Wang <[email protected]> * Remove all tab and sort connections by name alphabetical Signed-off-by: Lin Wang <[email protected]> * optimzie Signed-off-by: yubonluo <[email protected]> * Fix checked status disappear after modal tab change Signed-off-by: Lin Wang <[email protected]> * optimize the dqc table Signed-off-by: yubonluo <[email protected]> * optimize the code Signed-off-by: yubonluo <[email protected]> * update the table css Signed-off-by: yubonluo <[email protected]> * Simplify options update logic Signed-off-by: Lin Wang <[email protected]> * Add unit tests for AssociationDataSourceModal Signed-off-by: Lin Wang <[email protected]> * add unit test Signed-off-by: yubonluo <[email protected]> * optimize the code Signed-off-by: yubonluo <[email protected]> * Add nested support in associate data source modal Signed-off-by: Lin Wang <[email protected]> * delete useless code Signed-off-by: yubonluo <[email protected]> * Change back type Signed-off-by: Lin Wang <[email protected]> * Update type in modal UT Signed-off-by: Lin Wang <[email protected]> * optimize the code Signed-off-by: yubonluo <[email protected]> --------- Signed-off-by: yubonluo <[email protected]> Signed-off-by: Kapian1234 <[email protected]> Signed-off-by: Lin Wang <[email protected]> Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> Co-authored-by: Kapian1234 <[email protected]> Co-authored-by: Lin Wang <[email protected]> Co-authored-by: Yulong Ruan <[email protected]> (cherry picked from commit 0798865) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
9d5bf9a
commit d0633f7
Showing
24 changed files
with
1,426 additions
and
401 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
fix: | ||
- Enable direct query connections to support in workspace ([#7839](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7839)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion
2
...workspace/public/components/workspace_detail/__snapshots__/workspace_detail.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
181 changes: 181 additions & 0 deletions
181
...ugins/workspace/public/components/workspace_detail/association_data_source_modal.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
import { fireEvent, render, screen, waitFor } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { IntlProvider } from 'react-intl'; | ||
|
||
import { DataSourceConnectionType } from '../../../common/types'; | ||
import { chromeServiceMock, coreMock } from '../../../../../core/public/mocks'; | ||
import * as utilsExports from '../../utils'; | ||
|
||
import { | ||
AssociationDataSourceModal, | ||
AssociationDataSourceModalProps, | ||
} from './association_data_source_modal'; | ||
import { AssociationDataSourceModalMode } from 'src/plugins/workspace/common/constants'; | ||
|
||
const setupAssociationDataSourceModal = ({ | ||
mode, | ||
assignedConnections, | ||
handleAssignDataSourceConnections, | ||
}: Partial<AssociationDataSourceModalProps> = {}) => { | ||
const coreServices = coreMock.createStart(); | ||
jest.spyOn(utilsExports, 'getDataSourcesList').mockResolvedValue([]); | ||
jest.spyOn(utilsExports, 'fetchDataSourceConnections').mockResolvedValue([ | ||
{ | ||
id: 'ds1', | ||
name: 'Data Source 1', | ||
connectionType: DataSourceConnectionType.OpenSearchConnection, | ||
type: 'OpenSearch', | ||
relatedConnections: [ | ||
{ | ||
id: 'ds1-dqc1', | ||
name: 'dqc1', | ||
parentId: 'ds1', | ||
connectionType: DataSourceConnectionType.DirectQueryConnection, | ||
type: 'Amazon S3', | ||
}, | ||
], | ||
}, | ||
{ | ||
id: 'ds1-dqc1', | ||
name: 'dqc1', | ||
parentId: 'ds1', | ||
connectionType: DataSourceConnectionType.DirectQueryConnection, | ||
type: 'Amazon S3', | ||
}, | ||
{ | ||
id: 'ds2', | ||
name: 'Data Source 2', | ||
connectionType: DataSourceConnectionType.OpenSearchConnection, | ||
type: 'OpenSearch', | ||
}, | ||
]); | ||
const { logos } = chromeServiceMock.createStartContract(); | ||
render( | ||
<IntlProvider locale="en"> | ||
<AssociationDataSourceModal | ||
logos={logos} | ||
mode={mode ?? AssociationDataSourceModalMode.OpenSearchConnections} | ||
http={coreServices.http} | ||
notifications={coreServices.notifications} | ||
savedObjects={coreServices.savedObjects} | ||
closeModal={jest.fn()} | ||
assignedConnections={assignedConnections ?? []} | ||
handleAssignDataSourceConnections={handleAssignDataSourceConnections ?? jest.fn()} | ||
/> | ||
</IntlProvider> | ||
); | ||
return {}; | ||
}; | ||
|
||
describe('AssociationDataSourceModal', () => { | ||
const originalOffsetHeight = Object.getOwnPropertyDescriptor( | ||
HTMLElement.prototype, | ||
'offsetHeight' | ||
); | ||
const originalOffsetWidth = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'offsetWidth'); | ||
beforeEach(() => { | ||
Object.defineProperty(HTMLElement.prototype, 'offsetHeight', { | ||
configurable: true, | ||
value: 600, | ||
}); | ||
Object.defineProperty(HTMLElement.prototype, 'offsetWidth', { | ||
configurable: true, | ||
value: 600, | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
Object.defineProperty( | ||
HTMLElement.prototype, | ||
'offsetHeight', | ||
originalOffsetHeight as PropertyDescriptor | ||
); | ||
Object.defineProperty( | ||
HTMLElement.prototype, | ||
'offsetWidth', | ||
originalOffsetWidth as PropertyDescriptor | ||
); | ||
}); | ||
|
||
it('should display opensearch connections', async () => { | ||
setupAssociationDataSourceModal(); | ||
expect(screen.getByText('Associate OpenSearch connections')).toBeInTheDocument(); | ||
expect( | ||
screen.getByText( | ||
'Add data sources that will be available in the workspace. If a selected data source has related Direct Query connection, they will also be available in the workspace.' | ||
) | ||
).toBeInTheDocument(); | ||
await waitFor(() => { | ||
expect(screen.getByRole('option', { name: 'Data Source 1' })).toBeInTheDocument(); | ||
expect(screen.getByRole('option', { name: 'Data Source 2' })).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('should display direct query connections after opensearch connection selected', async () => { | ||
setupAssociationDataSourceModal({ | ||
mode: AssociationDataSourceModalMode.DirectQueryConnections, | ||
}); | ||
expect(screen.getByText('Associate direct query connections')).toBeInTheDocument(); | ||
await waitFor(() => { | ||
expect(screen.queryByRole('option', { name: 'dqc1' })).not.toBeInTheDocument(); | ||
fireEvent.click(screen.getByRole('option', { name: 'Data Source 1' })); | ||
expect(screen.getByRole('option', { name: 'dqc1' })).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('should hide associated connections', async () => { | ||
setupAssociationDataSourceModal({ | ||
assignedConnections: [ | ||
{ | ||
id: 'ds2', | ||
name: 'Data Source 2', | ||
connectionType: DataSourceConnectionType.OpenSearchConnection, | ||
type: 'OpenSearch', | ||
}, | ||
], | ||
}); | ||
expect( | ||
screen.getByText( | ||
'Add data sources that will be available in the workspace. If a selected data source has related Direct Query connection, they will also be available in the workspace.' | ||
) | ||
).toBeInTheDocument(); | ||
await waitFor(() => { | ||
expect(screen.getByRole('option', { name: 'Data Source 1' })).toBeInTheDocument(); | ||
expect(screen.queryByRole('option', { name: 'Data Source 2' })).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('should call handleAssignDataSourceConnections with opensearch connections after assigned', async () => { | ||
const handleAssignDataSourceConnectionsMock = jest.fn(); | ||
setupAssociationDataSourceModal({ | ||
handleAssignDataSourceConnections: handleAssignDataSourceConnectionsMock, | ||
}); | ||
|
||
await waitFor(() => { | ||
fireEvent.click(screen.getByRole('option', { name: 'Data Source 1' })); | ||
fireEvent.click(screen.getByRole('button', { name: 'Associate data sources' })); | ||
}); | ||
|
||
expect(handleAssignDataSourceConnectionsMock).toHaveBeenCalledWith([ | ||
{ | ||
id: 'ds1', | ||
name: 'Data Source 1', | ||
connectionType: DataSourceConnectionType.OpenSearchConnection, | ||
type: 'OpenSearch', | ||
relatedConnections: [ | ||
{ | ||
id: 'ds1-dqc1', | ||
name: 'dqc1', | ||
parentId: 'ds1', | ||
connectionType: DataSourceConnectionType.DirectQueryConnection, | ||
type: 'Amazon S3', | ||
}, | ||
], | ||
}, | ||
]); | ||
}); | ||
}); |
Oops, something went wrong.