-
Notifications
You must be signed in to change notification settings - Fork 920
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
[Workspace]Import sample data to current workspace #6105
Merged
SuZhou-Joe
merged 32 commits into
opensearch-project:main
from
wanglam:feat-import-sample-data-to-workspace
May 24, 2024
Merged
Changes from 30 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
4321cb4
Import sample data to workspace
wanglam d29f691
Enable workspace ui plugin
wanglam 54adb59
Add changelog for import sample data to current workspace
wanglam 5240160
Merge remote-tracking branch 'origin/main' into feat-import-sample-da…
wanglam ee39682
Merge branch 'main' into feat-import-sample-data-to-workspace
wanglam b1da07e
Merge branch 'main' into feat-import-sample-data-to-workspace
SuZhou-Joe b4c0c27
feat: register sample data as standalone app (#8)
SuZhou-Joe 0d44b0f
Merge branch 'main' into feat-import-sample-data-to-workspace
wanglam e4a6c74
Merge branch 'main' into feat-import-sample-data-to-workspace
wanglam 9b3be8f
Retrieve workspace id from request
wanglam 5098c09
Remove workspace id in query
wanglam 58adba2
Move changelog to fragments
wanglam 0e7c5e1
Merge branch 'main' into feat-import-sample-data-to-workspace
wanglam f11844f
Fix sample data list unit tests
wanglam efc5b1c
Remove no need workspaces deps
wanglam 8b67b94
Remove manual created changelogs
wanglam e87cb72
Changeset file for PR #6105 created/updated
opensearch-changeset-bot[bot] 799f475
Enable sample data in workspace overview page (#9)
Hailong-am fb4c3a2
Merge branch 'main' into feat-import-sample-data-to-workspace
wanglam 5767ffc
Add unit tests for getFinalSavedObjects in data sets util file
wanglam eda80ff
Merge branch 'main' into feat-import-sample-data-to-workspace
wanglam dd998f3
Add unit tests for renderImportSampleDataApp destroy
wanglam 7d7a831
Merge branch 'main' into feat-import-sample-data-to-workspace
wanglam a7e8c72
Merge branch 'main' into feat-import-sample-data-to-workspace
wanglam 9769622
Merge branch 'main' into feat-import-sample-data-to-workspace
wanglam 28d1f74
Address PR comments
wanglam 6162c2d
Merge branch 'main' into feat-import-sample-data-to-workspace
wanglam b82fcec
Merge branch 'main' into feat-import-sample-data-to-workspace
wanglam 5f8f9f4
Remove history listen in renderImportSampleDataApp
wanglam 3f27d71
Merge branch 'main' into feat-import-sample-data-to-workspace
wanglam 4d560c6
Remove Route for workspace import sample data entry point
wanglam 9a2bd3e
Merge branch 'main' into feat-import-sample-data-to-workspace
wanglam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ | ||
feat: | ||
- [Workspace]Import sample data to current workspace ([#6105](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6105)) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React, { useEffect, useRef } from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { coreMock } from '../../../../core/public/mocks'; | ||
import { renderImportSampleDataApp } from './application'; | ||
|
||
jest.mock('./components/home_app', () => ({ | ||
HomeApp: () => 'HomeApp', | ||
ImportSampleDataApp: () => 'ImportSampleDataApp', | ||
})); | ||
|
||
const coreStartMocks = coreMock.createStart(); | ||
|
||
const ComponentForRender = (props: { renderFn: typeof renderImportSampleDataApp }) => { | ||
const container = useRef<HTMLDivElement>(null); | ||
useEffect(() => { | ||
if (container.current) { | ||
const destroyFn = props.renderFn(container.current, coreStartMocks); | ||
return () => { | ||
destroyFn.then((res) => res()); | ||
}; | ||
} | ||
}, [props]); | ||
|
||
return <div ref={container} />; | ||
}; | ||
|
||
describe('renderImportSampleDataApp', () => { | ||
it('should render ImportSampleDataApp when calling renderImportSampleDataApp', async () => { | ||
const { container } = render(<ComponentForRender renderFn={renderImportSampleDataApp} />); | ||
expect(container).toMatchInlineSnapshot(` | ||
<div> | ||
<div> | ||
ImportSampleDataApp | ||
</div> | ||
</div> | ||
`); | ||
}); | ||
}); |
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
60 changes: 60 additions & 0 deletions
60
src/plugins/home/public/application/components/home_app.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,60 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { setServices } from '../opensearch_dashboards_services'; | ||
import { getMockedServices } from '../opensearch_dashboards_services.mock'; | ||
import { ImportSampleDataApp, HomeApp } from './home_app'; | ||
|
||
jest.mock('./legacy/home', () => ({ | ||
Home: () => <div>Home</div>, | ||
})); | ||
|
||
jest.mock('../load_tutorials', () => ({ | ||
getTutorial: () => {}, | ||
})); | ||
|
||
jest.mock('./tutorial_directory', () => ({ | ||
TutorialDirectory: (props: { withoutHomeBreadCrumb?: boolean }) => ( | ||
<div | ||
data-test-subj="tutorial_directory" | ||
data-without-home-bread-crumb={!!props.withoutHomeBreadCrumb} | ||
/> | ||
), | ||
})); | ||
|
||
describe('<HomeApp />', () => { | ||
let currentService: ReturnType<typeof getMockedServices>; | ||
beforeEach(() => { | ||
currentService = getMockedServices(); | ||
setServices(currentService); | ||
}); | ||
|
||
it('should not pass withoutHomeBreadCrumb to TutorialDirectory component', async () => { | ||
const originalHash = window.location.hash; | ||
const { findByTestId } = render(<HomeApp />); | ||
window.location.hash = '/tutorial_directory'; | ||
const tutorialRenderResult = await findByTestId('tutorial_directory'); | ||
expect(tutorialRenderResult.dataset.withoutHomeBreadCrumb).toEqual('false'); | ||
|
||
// revert to original hash | ||
window.location.hash = originalHash; | ||
}); | ||
}); | ||
|
||
describe('<ImportSampleDataApp />', () => { | ||
let currentService: ReturnType<typeof getMockedServices>; | ||
beforeEach(() => { | ||
currentService = getMockedServices(); | ||
setServices(currentService); | ||
}); | ||
|
||
it('should pass withoutHomeBreadCrumb to TutorialDirectory component', async () => { | ||
const { findByTestId } = render(<ImportSampleDataApp />); | ||
const tutorialRenderResult = await findByTestId('tutorial_directory'); | ||
expect(tutorialRenderResult.dataset.withoutHomeBreadCrumb).toEqual('true'); | ||
}); | ||
}); |
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
65 changes: 65 additions & 0 deletions
65
src/plugins/home/public/application/components/tutorial_directory.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,65 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { IntlProvider } from 'react-intl'; | ||
import { coreMock } from '../../../../../core/public/mocks'; | ||
import { setServices } from '../opensearch_dashboards_services'; | ||
import { getMockedServices } from '../opensearch_dashboards_services.mock'; | ||
|
||
const makeProps = () => { | ||
const coreMocks = coreMock.createStart(); | ||
return { | ||
addBasePath: coreMocks.http.basePath.prepend, | ||
openTab: 'foo', | ||
isCloudEnabled: false, | ||
}; | ||
}; | ||
|
||
describe('<TutorialDirectory />', () => { | ||
let currentService: ReturnType<typeof getMockedServices>; | ||
beforeEach(() => { | ||
currentService = getMockedServices(); | ||
setServices(currentService); | ||
}); | ||
it('should render home breadcrumbs when withoutHomeBreadCrumb is undefined', async () => { | ||
const finalProps = makeProps(); | ||
currentService.http.get.mockResolvedValueOnce([]); | ||
// @ts-ignore | ||
const { TutorialDirectory } = await import('./tutorial_directory'); | ||
render( | ||
<IntlProvider locale="en"> | ||
<TutorialDirectory {...finalProps} /> | ||
</IntlProvider> | ||
); | ||
expect(currentService.chrome.setBreadcrumbs).toBeCalledWith([ | ||
{ | ||
href: '#/', | ||
text: 'Home', | ||
}, | ||
{ | ||
text: 'Add data', | ||
}, | ||
]); | ||
}); | ||
|
||
it('should not render home breadcrumbs when withoutHomeBreadCrumb is true', async () => { | ||
const finalProps = makeProps(); | ||
currentService.http.get.mockResolvedValueOnce([]); | ||
// @ts-ignore | ||
const { TutorialDirectory } = await import('./tutorial_directory'); | ||
render( | ||
<IntlProvider locale="en"> | ||
<TutorialDirectory {...finalProps} withoutHomeBreadCrumb /> | ||
</IntlProvider> | ||
); | ||
expect(currentService.chrome.setBreadcrumbs).toBeCalledWith([ | ||
{ | ||
text: 'Add data', | ||
}, | ||
]); | ||
}); | ||
}); |
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
47 changes: 47 additions & 0 deletions
47
src/plugins/home/public/application/opensearch_dashboards_services.mock.ts
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,47 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { coreMock } from '../../../../core/public/mocks'; | ||
import { urlForwardingPluginMock } from '../../../url_forwarding/public/mocks'; | ||
import { homePluginMock } from '../mocks'; | ||
import { | ||
EnvironmentService, | ||
FeatureCatalogueRegistry, | ||
SectionTypeService, | ||
TutorialService, | ||
} from '../services'; | ||
import { telemetryPluginMock } from '../../../telemetry/public/mocks'; | ||
|
||
export const getMockedServices = () => { | ||
const coreMocks = coreMock.createStart(); | ||
const urlForwarding = urlForwardingPluginMock.createStartContract(); | ||
const homePlugin = homePluginMock.createSetupContract(); | ||
return { | ||
...coreMocks, | ||
...homePlugin, | ||
telemetry: telemetryPluginMock.createStartContract(), | ||
indexPatternService: jest.fn(), | ||
dataSource: { | ||
dataSourceEnabled: false, | ||
hideLocalCluster: false, | ||
noAuthenticationTypeEnabled: false, | ||
usernamePasswordAuthEnabled: false, | ||
awsSigV4AuthEnabled: false, | ||
}, | ||
opensearchDashboardsVersion: '', | ||
urlForwarding, | ||
savedObjectsClient: coreMocks.savedObjects.client, | ||
toastNotifications: coreMocks.notifications.toasts, | ||
banners: coreMocks.overlays.banners, | ||
trackUiMetric: jest.fn(), | ||
getBasePath: jest.fn(), | ||
addBasePath: jest.fn(), | ||
environmentService: new EnvironmentService(), | ||
tutorialService: new TutorialService(), | ||
homeConfig: homePlugin.config, | ||
featureCatalogue: new FeatureCatalogueRegistry(), | ||
sectionTypes: new SectionTypeService(), | ||
}; | ||
}; |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: why does it need a Route with path
*
here? Seems we don't even needRouter
hereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
renderTutorialDirectory
needprops.match.params.tab
data and pass it to TutorialDirectory component. But all the tabs has been deleted in this PR. I think we can remove the Route here and pass a fixedSAMPLE_DATA_TAB_ID
here.