-
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) (#8010) * add dqc * add dircet query connections on the detail page * Changeset file for PR #7839 created/updated * delete useless code * optimize the code * optimize the code * Refactor association modal * Integrate modal with workspace detail page * Fix parent data source unchecked * Remove all tab and sort connections by name alphabetical * optimzie * Fix checked status disappear after modal tab change * optimize the dqc table * optimize the code * update the table css * Simplify options update logic * Add unit tests for AssociationDataSourceModal * add unit test * optimize the code * Add nested support in associate data source modal * delete useless code * Change back type * Update type in modal UT * optimize the code --------- (cherry picked from commit 0798865) Signed-off-by: yubonluo <[email protected]> Signed-off-by: Kapian1234 <[email protected]> Signed-off-by: Lin Wang <[email protected]> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> 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]>
- Loading branch information
1 parent
a49876b
commit d88e3b0
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.