-
Notifications
You must be signed in to change notification settings - Fork 939
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
Add DocView links pluggable injection capability #1200
Changes from all commits
cea96a3
0eeac1d
9410612
09ba5ce
7ffec20
353c2db
7dde376
3298b42
983241c
76d6dd4
38934ef
ab2b1b3
5ec302b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,28 +15,12 @@ | |
</div> | ||
</div> | ||
</div> | ||
<div class="euiFlexItem euiFlexItem--flexGrowZero euiText euiText--small"> | ||
<div class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--directionRow"> | ||
<div class="euiFlexItem euiFlexItem--flexGrowZero euiText euiText--small"> | ||
<a | ||
class="euiLink" | ||
data-test-subj="docTableRowAction" | ||
ng-href="{{ getContextAppHref() }}" | ||
ng-if="indexPattern.isTimeBased()" | ||
i18n-id="discover.docTable.tableRow.viewSurroundingDocumentsLinkText" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a way to utilize i18n within the updated component once we have i18n translations? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure, added. |
||
i18n-default-message="View surrounding documents" | ||
></a> | ||
</div> | ||
<div class="euiFlexItem euiFlexItem--flexGrowZero euiText euiText--small"> | ||
<a | ||
class="euiLink" | ||
data-test-subj="docTableRowAction" | ||
ng-href="#/doc/{{indexPattern.id}}/{{row._index}}?id={{uriEncodedId}}" | ||
i18n-id="discover.docTable.tableRow.viewSingleDocumentLinkText" | ||
i18n-default-message="View single document" | ||
></a> | ||
</div> | ||
</div> | ||
<div data-test-subj="docViewerLinks"> | ||
<doc-viewer-links | ||
columns="columns" | ||
hit="hit" | ||
index-pattern="indexPattern" | ||
></doc-viewer-links> | ||
</div> | ||
</div> | ||
<div data-test-subj="docViewer"> | ||
|
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: '=?', | ||
}, | ||
} | ||
); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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(); | ||
}); |
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> | ||
); | ||
} |
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)); | ||
} | ||
} |
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; | ||
} |
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.
I'm not seeing this logic in the src/plugins/discover/public/plugin.ts, could we include that?
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.
done