-
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.
Merge branch 'master' into ml-api-histograms
- Loading branch information
Showing
291 changed files
with
1,134 additions
and
190 deletions.
There are no files selected for viewing
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
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
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
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
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
28 changes: 28 additions & 0 deletions
28
examples/embeddable_examples/common/book_saved_object_attributes.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,28 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { SavedObjectAttributes } from '../../../src/core/types'; | ||
|
||
export const BOOK_SAVED_OBJECT = 'book'; | ||
|
||
export interface BookSavedObjectAttributes extends SavedObjectAttributes { | ||
title: string; | ||
author?: string; | ||
readIt?: boolean; | ||
} |
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
90 changes: 90 additions & 0 deletions
90
examples/embeddable_examples/public/book/book_component.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,90 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import React from 'react'; | ||
import { EuiFlexItem, EuiFlexGroup, EuiIcon } from '@elastic/eui'; | ||
|
||
import { EuiText } from '@elastic/eui'; | ||
import { EuiFlexGrid } from '@elastic/eui'; | ||
import { withEmbeddableSubscription } from '../../../../src/plugins/embeddable/public'; | ||
import { BookEmbeddableInput, BookEmbeddableOutput, BookEmbeddable } from './book_embeddable'; | ||
|
||
interface Props { | ||
input: BookEmbeddableInput; | ||
output: BookEmbeddableOutput; | ||
embeddable: BookEmbeddable; | ||
} | ||
|
||
function wrapSearchTerms(task?: string, search?: string) { | ||
if (!search || !task) return task; | ||
const parts = task.split(new RegExp(`(${search})`, 'g')); | ||
return parts.map((part, i) => | ||
part === search ? ( | ||
<span key={i} style={{ backgroundColor: 'yellow' }}> | ||
{part} | ||
</span> | ||
) : ( | ||
part | ||
) | ||
); | ||
} | ||
|
||
export function BookEmbeddableComponentInner({ input: { search }, output: { attributes } }: Props) { | ||
const title = attributes?.title; | ||
const author = attributes?.author; | ||
const readIt = attributes?.readIt; | ||
|
||
return ( | ||
<EuiFlexGroup gutterSize="s"> | ||
<EuiFlexItem> | ||
<EuiFlexGrid columns={1} gutterSize="none"> | ||
{title ? ( | ||
<EuiFlexItem> | ||
<EuiText data-test-subj="bookEmbeddableTitle"> | ||
<h3>{wrapSearchTerms(title, search)},</h3> | ||
</EuiText> | ||
</EuiFlexItem> | ||
) : null} | ||
{author ? ( | ||
<EuiFlexItem> | ||
<EuiText data-test-subj="bookEmbeddableAuthor"> | ||
<h5>-{wrapSearchTerms(author, search)}</h5> | ||
</EuiText> | ||
</EuiFlexItem> | ||
) : null} | ||
{readIt ? ( | ||
<EuiFlexItem> | ||
<EuiIcon type="check" /> | ||
</EuiFlexItem> | ||
) : ( | ||
<EuiFlexItem> | ||
<EuiIcon type="cross" /> | ||
</EuiFlexItem> | ||
)} | ||
</EuiFlexGrid> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); | ||
} | ||
|
||
export const BookEmbeddableComponent = withEmbeddableSubscription< | ||
BookEmbeddableInput, | ||
BookEmbeddableOutput, | ||
BookEmbeddable, | ||
{} | ||
>(BookEmbeddableComponentInner); |
123 changes: 123 additions & 0 deletions
123
examples/embeddable_examples/public/book/book_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,123 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { Subscription } from 'rxjs'; | ||
import { | ||
Embeddable, | ||
EmbeddableInput, | ||
IContainer, | ||
EmbeddableOutput, | ||
SavedObjectEmbeddableInput, | ||
AttributeService, | ||
} from '../../../../src/plugins/embeddable/public'; | ||
import { BookSavedObjectAttributes } from '../../common'; | ||
import { BookEmbeddableComponent } from './book_component'; | ||
|
||
export const BOOK_EMBEDDABLE = 'book'; | ||
export type BookEmbeddableInput = BookByValueInput | BookByReferenceInput; | ||
export interface BookEmbeddableOutput extends EmbeddableOutput { | ||
hasMatch: boolean; | ||
attributes: BookSavedObjectAttributes; | ||
} | ||
|
||
interface BookInheritedInput extends EmbeddableInput { | ||
search?: string; | ||
} | ||
|
||
export type BookByValueInput = { attributes: BookSavedObjectAttributes } & BookInheritedInput; | ||
export type BookByReferenceInput = SavedObjectEmbeddableInput & BookInheritedInput; | ||
|
||
/** | ||
* Returns whether any attributes contain the search string. If search is empty, true is returned. If | ||
* there are no savedAttributes, false is returned. | ||
* @param search - the search string | ||
* @param savedAttributes - the saved object attributes for the saved object with id `input.savedObjectId` | ||
*/ | ||
function getHasMatch(search?: string, savedAttributes?: BookSavedObjectAttributes): boolean { | ||
if (!search) return true; | ||
if (!savedAttributes) return false; | ||
return Boolean( | ||
(savedAttributes.author && savedAttributes.author.match(search)) || | ||
(savedAttributes.title && savedAttributes.title.match(search)) | ||
); | ||
} | ||
|
||
export class BookEmbeddable extends Embeddable<BookEmbeddableInput, BookEmbeddableOutput> { | ||
public readonly type = BOOK_EMBEDDABLE; | ||
private subscription: Subscription; | ||
private node?: HTMLElement; | ||
private savedObjectId?: string; | ||
private attributes?: BookSavedObjectAttributes; | ||
|
||
constructor( | ||
initialInput: BookEmbeddableInput, | ||
private attributeService: AttributeService< | ||
BookSavedObjectAttributes, | ||
BookByValueInput, | ||
BookByReferenceInput | ||
>, | ||
{ | ||
parent, | ||
}: { | ||
parent?: IContainer; | ||
} | ||
) { | ||
super(initialInput, {} as BookEmbeddableOutput, parent); | ||
|
||
this.subscription = this.getInput$().subscribe(async () => { | ||
const savedObjectId = (this.getInput() as BookByReferenceInput).savedObjectId; | ||
const attributes = (this.getInput() as BookByValueInput).attributes; | ||
if (this.attributes !== attributes || this.savedObjectId !== savedObjectId) { | ||
this.savedObjectId = savedObjectId; | ||
this.reload(); | ||
} else { | ||
this.updateOutput({ | ||
attributes: this.attributes, | ||
hasMatch: getHasMatch(this.input.search, this.attributes), | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
public render(node: HTMLElement) { | ||
if (this.node) { | ||
ReactDOM.unmountComponentAtNode(this.node); | ||
} | ||
this.node = node; | ||
ReactDOM.render(<BookEmbeddableComponent embeddable={this} />, node); | ||
} | ||
|
||
public async reload() { | ||
this.attributes = await this.attributeService.unwrapAttributes(this.input); | ||
|
||
this.updateOutput({ | ||
attributes: this.attributes, | ||
hasMatch: getHasMatch(this.input.search, this.attributes), | ||
}); | ||
} | ||
|
||
public destroy() { | ||
super.destroy(); | ||
this.subscription.unsubscribe(); | ||
if (this.node) { | ||
ReactDOM.unmountComponentAtNode(this.node); | ||
} | ||
} | ||
} |
Oops, something went wrong.