-
Notifications
You must be signed in to change notification settings - Fork 920
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DocView links pluggable injection capability
Signed-off-by: sitbubu <[email protected]>
- Loading branch information
1 parent
5b314d2
commit 944f7c3
Showing
16 changed files
with
334 additions
and
24 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
28 changes: 28 additions & 0 deletions
28
src/plugins/discover/public/application/angular/doc_viewer_links.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,28 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { DocViewerLinks } from '../components/doc_viewer_links/doc_viewer_links'; | ||
|
||
export function createDocViewerLinksDirective(reactDirective: any) { | ||
return reactDirective( | ||
(props: any) => { | ||
return <DocViewerLinks {...props} />; | ||
}, | ||
[ | ||
'hit', | ||
['indexPattern', { watchDepth: 'reference' }], | ||
['columns', { watchDepth: 'collection' }], | ||
], | ||
{ | ||
restrict: 'E', | ||
scope: { | ||
hit: '=', | ||
indexPattern: '=', | ||
columns: '=?', | ||
}, | ||
} | ||
); | ||
} |
25 changes: 25 additions & 0 deletions
25
...blic/application/components/doc_viewer_links/__snapshots__/doc_viewer_links.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
src/plugins/discover/public/application/components/doc_viewer_links/doc_viewer_links.scss
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,21 @@ | ||
.osdDocViewerLinks { | ||
.euiListGroup { | ||
list-style-type: none; | ||
margin: 0; | ||
padding: 0; | ||
overflow: hidden; | ||
display: inline; | ||
|
||
.euiListGroupItem { | ||
float: left; | ||
padding: 0; | ||
margin: 0 5px; | ||
display: inline-block; | ||
|
||
a { | ||
padding: 0; | ||
margin: 0; | ||
} | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...plugins/discover/public/application/components/doc_viewer_links/doc_viewer_links.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,44 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { DocViewerLinks } from './doc_viewer_links'; | ||
import { getDocViewsLinksRegistry } from '../../../opensearch_dashboards_services'; | ||
import { DocViewLinkRenderProps } from '../../doc_views_links/doc_views_links_types'; | ||
|
||
jest.mock('../../../opensearch_dashboards_services', () => { | ||
let registry: any[] = []; | ||
return { | ||
getDocViewsLinksRegistry: () => ({ | ||
addDocViewLink(view: any) { | ||
registry.push(view); | ||
}, | ||
getDocViewsLinksSorted() { | ||
return registry; | ||
}, | ||
resetRegistry: () => { | ||
registry = []; | ||
}, | ||
}), | ||
}; | ||
}); | ||
|
||
beforeEach(() => { | ||
(getDocViewsLinksRegistry() as any).resetRegistry(); | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test('Render <DocViewerLink/> with 2 different links', () => { | ||
const registry = getDocViewsLinksRegistry(); | ||
registry.addDocViewLink({ order: 10, label: 'generateUrlFn link', generateUrlFn: () => 'aaa' }); | ||
registry.addDocViewLink({ order: 20, label: 'href link', href: 'bbb' }); | ||
|
||
const renderProps = { hit: {} } as DocViewLinkRenderProps; | ||
|
||
const wrapper = shallow(<DocViewerLinks {...renderProps} />); | ||
|
||
expect(wrapper).toMatchSnapshot(); | ||
}); |
25 changes: 25 additions & 0 deletions
25
src/plugins/discover/public/application/components/doc_viewer_links/doc_viewer_links.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,25 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import './doc_viewer_links.scss'; | ||
import React from 'react'; | ||
import { EuiListGroup } from '@elastic/eui'; | ||
import { getDocViewsLinksRegistry } from '../../../opensearch_dashboards_services'; | ||
import { DocViewLinkRenderProps } from '../../doc_views_links/doc_views_links_types'; | ||
|
||
export function DocViewerLinks(renderProps: DocViewLinkRenderProps) { | ||
const listItems = getDocViewsLinksRegistry() | ||
.getDocViewsLinksSorted() | ||
.map((item) => { | ||
item.href = item.generateUrlFn ? item.generateUrlFn(renderProps) : item.href; | ||
return item; | ||
}); | ||
|
||
return ( | ||
<div className="osdDocViewerLinks"> | ||
<EuiListGroup listItems={listItems} /> | ||
</div> | ||
); | ||
} |
18 changes: 18 additions & 0 deletions
18
src/plugins/discover/public/application/doc_views_links/doc_views_links_registry.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,18 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { DocViewLink } from './doc_views_links_types'; | ||
|
||
export class DocViewsLinksRegistry { | ||
private docViewsLinks: DocViewLink[] = []; | ||
|
||
addDocViewLink(docViewLink: DocViewLink) { | ||
this.docViewsLinks.push(docViewLink); | ||
} | ||
|
||
getDocViewsLinksSorted() { | ||
return this.docViewsLinks.sort((a, b) => (Number(a.order) > Number(b.order) ? 1 : -1)); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/plugins/discover/public/application/doc_views_links/doc_views_links_types.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,20 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { EuiListGroupItemProps } from '@elastic/eui'; | ||
import { OpenSearchSearchHit } from '../doc_views/doc_views_types'; | ||
import { IndexPattern } from '../../../../data/public'; | ||
|
||
export interface DocViewLink extends EuiListGroupItemProps { | ||
href?: string; | ||
order: number; | ||
generateUrlFn?(renderProps: any): string; | ||
} | ||
|
||
export interface DocViewLinkRenderProps { | ||
columns?: string[]; | ||
hit: OpenSearchSearchHit; | ||
indexPattern: IndexPattern; | ||
} |
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
8 changes: 8 additions & 0 deletions
8
test/plugin_functional/plugins/doc_views_links_plugin/opensearch_dashboards.json
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,8 @@ | ||
{ | ||
"id": "docViewLinksPlugin", | ||
"version": "0.0.1", | ||
"opensearchDashboardsVersion": "opensearchDashboards", | ||
"server": false, | ||
"ui": true, | ||
"requiredPlugins": ["discover"] | ||
} |
17 changes: 17 additions & 0 deletions
17
test/plugin_functional/plugins/doc_views_links_plugin/package.json
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,17 @@ | ||
{ | ||
"name": "docViewLinksPlugin", | ||
"version": "1.0.0", | ||
"main": "target/test/plugin_functional/plugins/doc_views_links_plugin", | ||
"opensearchDashboards": { | ||
"version": "opensearchDashboards", | ||
"templateVersion": "1.0.0" | ||
}, | ||
"license": "Apache-2.0", | ||
"scripts": { | ||
"osd": "node ../../../../scripts/osd.js", | ||
"build": "rm -rf './target' && tsc" | ||
}, | ||
"devDependencies": { | ||
"typescript": "4.0.2" | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
test/plugin_functional/plugins/doc_views_links_plugin/public/index.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,8 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { DocViewsLinksPlugin } from './plugin'; | ||
|
||
export const plugin = () => new DocViewsLinksPlugin(); |
Oops, something went wrong.