forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
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 (opensearch-project#…
…1200) * Add DocView links pluggable injection capability * Add proper e2e + bugfix * set prop as lower case * Better name * Delete prop after usage * Camel case + avoid mutating * Added right data-test-subj in order to fix tests * update snapshot * Add hide prop in order to mimic ng-if condition * Add i18n translation support * Fix tests * Made text smaller + used eui components instead of custom css * Snapshots Signed-off-by: sitbubu <[email protected]>
- Loading branch information
1 parent
aec4d83
commit 5c5f01f
Showing
22 changed files
with
461 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
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
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: '=?', | ||
}, | ||
} | ||
); | ||
} |
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
34 changes: 34 additions & 0 deletions
34
...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.
68 changes: 68 additions & 0 deletions
68
...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,68 @@ | ||
/* | ||
* 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: 'generateCb link', | ||
generateCb: () => ({ | ||
url: 'aaa', | ||
}), | ||
}); | ||
registry.addDocViewLink({ order: 20, label: 'href link', href: 'bbb' }); | ||
|
||
const renderProps = { hit: {} } as DocViewLinkRenderProps; | ||
|
||
const wrapper = shallow(<DocViewerLinks {...renderProps} />); | ||
|
||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
|
||
test('Dont Render <DocViewerLink/> if generateCb.hide', () => { | ||
const registry = getDocViewsLinksRegistry(); | ||
registry.addDocViewLink({ | ||
order: 10, | ||
label: 'generateCb link', | ||
generateCb: () => ({ | ||
url: 'aaa', | ||
hide: true, | ||
}), | ||
}); | ||
|
||
const renderProps = { hit: {} } as DocViewLinkRenderProps; | ||
|
||
const wrapper = shallow(<DocViewerLinks {...renderProps} />); | ||
|
||
expect(wrapper).toMatchSnapshot(); | ||
}); |
35 changes: 35 additions & 0 deletions
35
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,35 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { EuiFlexGroup, EuiFlexItem, EuiListGroupItem, EuiListGroupItemProps } 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() | ||
.filter((item) => !(item.generateCb && item.generateCb(renderProps)?.hide)) | ||
.map((item) => { | ||
const { generateCb, href, ...props } = item; | ||
const listItem: EuiListGroupItemProps = { | ||
'data-test-subj': 'docTableRowAction', | ||
...props, | ||
href: generateCb ? generateCb(renderProps).url : href, | ||
}; | ||
|
||
return listItem; | ||
}); | ||
|
||
return ( | ||
<EuiFlexGroup gutterSize="xs"> | ||
{listItems.map((item, index) => ( | ||
<EuiFlexItem key={index}> | ||
<EuiListGroupItem {...item} /> | ||
</EuiFlexItem> | ||
))} | ||
</EuiFlexGroup> | ||
); | ||
} |
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)); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
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,25 @@ | ||
/* | ||
* 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; | ||
generateCb?( | ||
renderProps: any | ||
): { | ||
url: string; | ||
hide?: boolean; | ||
}; | ||
} | ||
|
||
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
Oops, something went wrong.