Skip to content

Commit

Permalink
clean doc views component
Browse files Browse the repository at this point in the history
* remove the function which helps to convert angular directive to
react render function
* clean types

Issue Resolved:
opensearch-project#1717

Signed-off-by: Anan Zhuang <[email protected]>
  • Loading branch information
ananzh committed Aug 5, 2022
1 parent 5fb4143 commit 7368b39
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 132 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,16 @@
* under the License.
*/

import { auto } from 'angular';
import { convertDirectiveToRenderFn } from './doc_views_helpers';
import { DocView, DocViewInput, OpenSearchSearchHit, DocViewInputFn } from './doc_views_types';

export class DocViewsRegistry {
private docViews: DocView[] = [];
private angularInjectorGetter: (() => Promise<auto.IInjectorService>) | null = null;

setAngularInjectorGetter = (injectorGetter: () => Promise<auto.IInjectorService>) => {
this.angularInjectorGetter = injectorGetter;
};

/**
* Extends and adds the given doc view to the registry array
*/
addDocView(docViewRaw: DocViewInput | DocViewInputFn) {
const docView = typeof docViewRaw === 'function' ? docViewRaw() : docViewRaw;
if (docView.directive) {
// convert angular directive to render function for backwards compatibility
docView.render = convertDirectiveToRenderFn(docView.directive, () => {
if (!this.angularInjectorGetter) {
throw new Error('Angular was not initialized');
}
return this.angularInjectorGetter();
});
}
if (typeof docView.shouldShow !== 'function') {
docView.shouldShow = () => true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,9 @@
*/

import { ComponentType } from 'react';
import { IScope } from 'angular';
import { SearchResponse } from 'elasticsearch';
import { IndexPattern } from '../../../../data/public';

export interface AngularDirective {
controller: (...injectedServices: any[]) => void;
template: string;
}

export type AngularScope = IScope;

export type OpenSearchSearchHit<T = unknown> = SearchResponse<T>['hits']['hits'][number];

export interface FieldMapping {
Expand All @@ -64,15 +56,16 @@ export interface DocViewRenderProps {
onAddColumn?: (columnName: string) => void;
onRemoveColumn?: (columnName: string) => void;
}

export type DocViewerComponent = ComponentType<DocViewRenderProps>;

export type DocViewRenderFn = (
domeNode: HTMLDivElement,
renderProps: DocViewRenderProps
) => () => void;

export interface DocViewInput {
component?: DocViewerComponent;
directive?: AngularDirective;
order: number;
render?: DocViewRenderFn;
shouldShow?: (hit: OpenSearchSearchHit) => boolean;
Expand Down
1 change: 0 additions & 1 deletion src/plugins/discover/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ export class DiscoverPlugin
stopUrlTracker();
};

this.docViewsRegistry.setAngularInjectorGetter(this.getEmbeddableInjector);
core.application.register({
id: 'discover',
title: 'Discover',
Expand Down

0 comments on commit 7368b39

Please sign in to comment.