-
Notifications
You must be signed in to change notification settings - Fork 889
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'opensearch-project:main' into Issue-1857
- Loading branch information
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.