-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Discover] Deangularization of search embeddable (#100552)
* [Discover] Render empty embeddable * First version of grid embeddable * More search embeddable * Almost stable version * Fixing typescript errors * Fixing filtering and sorting * Add data-shared-item to DiscoverGridEmbeddable * Trigger rerender when title changes * Fixing incorrectly touched files * Remove search_embeddable * Remove lodash * Fixing imports * Minor fixes * Removing unnecessary files * Minor fix * Remove unused import * Applying PR comments * Applying PR comments * Removing search embeddable * Fix missing import * Addressing PR comments * Do not memoize saved search component * Applying Matthias's suggestion Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
012bb44
commit 80b109f
Showing
10 changed files
with
418 additions
and
327 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
85 changes: 85 additions & 0 deletions
85
src/plugins/discover/public/application/angular/doc_table/create_doc_table_embeddable.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,85 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React, { useRef, useEffect } from 'react'; | ||
import { I18nProvider } from '@kbn/i18n/react'; | ||
import { IScope } from 'angular'; | ||
import { getServices } from '../../../kibana_services'; | ||
import { DocTableLegacyProps, injectAngularElement } from './create_doc_table_react'; | ||
|
||
type AngularEmbeddableScope = IScope & { renderProps?: DocTableEmbeddableProps }; | ||
|
||
export interface DocTableEmbeddableProps extends Partial<DocTableLegacyProps> { | ||
refs: HTMLElement; | ||
} | ||
|
||
function getRenderFn(domNode: Element, props: DocTableEmbeddableProps) { | ||
const directive = { | ||
template: `<doc-table | ||
class="panel-content" | ||
columns="renderProps.columns" | ||
data-description="{{renderProps.searchDescription}}" | ||
data-shared-item | ||
data-test-subj="embeddedSavedSearchDocTable" | ||
data-title="{{renderProps.sharedItemTitle}}" | ||
filter="renderProps.onFilter" | ||
hits="renderProps.rows" | ||
index-pattern="renderProps.indexPattern" | ||
is-loading="renderProps.isLoading" | ||
on-add-column="renderProps.onAddColumn" | ||
on-change-sort-order="renderProps.onSort" | ||
on-move-column="renderProps.onMoveColumn" | ||
on-remove-column="renderProps.onRemoveColumn" | ||
render-complete | ||
sorting="renderProps.sort" | ||
total-hit-count="renderProps.totalHitCount" | ||
use-new-fields-api="renderProps.useNewFieldsApi"></doc-table>`, | ||
}; | ||
|
||
return async () => { | ||
try { | ||
const injector = await getServices().getEmbeddableInjector(); | ||
return await injectAngularElement(domNode, directive.template, props, injector); | ||
} catch (e) { | ||
// eslint-disable-next-line no-console | ||
console.error(e); | ||
throw e; | ||
} | ||
}; | ||
} | ||
|
||
export function DiscoverDocTableEmbeddable(props: DocTableEmbeddableProps) { | ||
return ( | ||
<I18nProvider> | ||
<DocTableLegacyInner {...props} /> | ||
</I18nProvider> | ||
); | ||
} | ||
|
||
function DocTableLegacyInner(renderProps: DocTableEmbeddableProps) { | ||
const scope = useRef<AngularEmbeddableScope | undefined>(); | ||
|
||
useEffect(() => { | ||
if (renderProps.refs && !scope.current) { | ||
const fn = getRenderFn(renderProps.refs, renderProps); | ||
fn().then((newScope) => { | ||
scope.current = newScope; | ||
}); | ||
} else if (scope?.current) { | ||
scope.current.renderProps = { ...renderProps }; | ||
scope.current.$applyAsync(); | ||
} | ||
}, [renderProps]); | ||
|
||
useEffect(() => { | ||
return () => { | ||
scope.current?.$destroy(); | ||
}; | ||
}, []); | ||
return <React.Fragment />; | ||
} |
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.