Skip to content

Commit

Permalink
Merge branch 'master' of github.com:elastic/kibana into obs-applink
Browse files Browse the repository at this point in the history
  • Loading branch information
cauemarcondes committed Jul 9, 2020
2 parents 7e5b9ae + 1b4804b commit 5538000
Show file tree
Hide file tree
Showing 562 changed files with 7,418 additions and 4,213 deletions.
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
4 changes: 2 additions & 2 deletions docs/developer/testing/interpreting-ci-failures.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Clicking the link next to the check in the conversation tab of a pull request wi

To view the results of a job execution in Jenkins, either click the link in the comment left by `@elasticmachine` or search for the `kibana-ci` check in the list at the bottom of the PR. This link will take you to the top-level page for the specific job execution that failed.

image::images/jenkins/job_view.png[]
image::images/job_view.png[]

1. *Git Changes:* the list of commits that were in this build which weren't in the previous build. For Pull Requests this list is calculated by comparing against the most recent Pull Request which was tested, it is not limited to build for this specific Pull Request, so it's not very useful.
2. *Test Results:* A link to the test results screen, and shortcuts to the failed tests. Functional tests capture and store the log output from each specific test, and make it visible at these links. For other test runners only the error message is visible and log output must be tracked down in the *Pipeline Steps*.
Expand All @@ -29,6 +29,6 @@ image::images/jenkins/job_view.png[]

To view the logs for a failed specific ciGroup, jest, mocha, type checkers, linters, etc., click on the *Pipeline Steps* link in from the Job page.

image::images/jenkins/pipeline_steps_view.png[]
image::images/pipeline_steps_view.png[]

Scroll down the page until you find a failed step *(1)*, and then look up a few lines for the `Branch:` step to see which specific job this is. If this is the job you're looking for click the little terminal icon next to the failed step *(1)* to view the logs for that specific step in the Pipeline.
2 changes: 1 addition & 1 deletion docs/development/core/server/kibana-plugin-core-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [SavedObjectsBulkUpdateResponse](./kibana-plugin-core-server.savedobjectsbulkupdateresponse.md) | |
| [SavedObjectsClientProviderOptions](./kibana-plugin-core-server.savedobjectsclientprovideroptions.md) | Options to control the creation of the Saved Objects Client. |
| [SavedObjectsClientWrapperOptions](./kibana-plugin-core-server.savedobjectsclientwrapperoptions.md) | Options passed to each SavedObjectsClientWrapperFactory to aid in creating the wrapper instance. |
| [SavedObjectsComplexFieldMapping](./kibana-plugin-core-server.savedobjectscomplexfieldmapping.md) | See [SavedObjectsFieldMapping](./kibana-plugin-core-server.savedobjectsfieldmapping.md) for documentation.<!-- -->Note: this type intentially doesn't include a type definition for defining the <code>dynamic</code> mapping parameter. Saved Object fields should always inherit the <code>dynamic: 'strict'</code> paramater. If you are unsure of the shape of your data use <code>type: 'object', enabled: false</code> instead. |
| [SavedObjectsComplexFieldMapping](./kibana-plugin-core-server.savedobjectscomplexfieldmapping.md) | See [SavedObjectsFieldMapping](./kibana-plugin-core-server.savedobjectsfieldmapping.md) for documentation. |
| [SavedObjectsCoreFieldMapping](./kibana-plugin-core-server.savedobjectscorefieldmapping.md) | See [SavedObjectsFieldMapping](./kibana-plugin-core-server.savedobjectsfieldmapping.md) for documentation. |
| [SavedObjectsCreateOptions](./kibana-plugin-core-server.savedobjectscreateoptions.md) | |
| [SavedObjectsDeleteByNamespaceOptions](./kibana-plugin-core-server.savedobjectsdeletebynamespaceoptions.md) | |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [SavedObjectsComplexFieldMapping](./kibana-plugin-core-server.savedobjectscomplexfieldmapping.md) &gt; [dynamic](./kibana-plugin-core-server.savedobjectscomplexfieldmapping.dynamic.md)

## SavedObjectsComplexFieldMapping.dynamic property

The dynamic property of the mapping, either `false` or `'strict'`<!-- -->. If unspecified `dynamic: 'strict'` will be inherited from the top-level index mappings.

Note: To limit the number of mapping fields Saved Object types should \*never\* use `dynamic: true`<!-- -->.

<b>Signature:</b>

```typescript
dynamic?: false | 'strict';
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [SavedObjectsComplexFieldMapping](./kibana-plugin-core-server.savedobjectscomplexfieldmapping.md) &gt; [enabled](./kibana-plugin-core-server.savedobjectscomplexfieldmapping.enabled.md)

## SavedObjectsComplexFieldMapping.enabled property

<b>Signature:</b>

```typescript
enabled?: boolean;
```
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

See [SavedObjectsFieldMapping](./kibana-plugin-core-server.savedobjectsfieldmapping.md) for documentation.

Note: this type intentially doesn't include a type definition for defining the `dynamic` mapping parameter. Saved Object fields should always inherit the `dynamic: 'strict'` paramater. If you are unsure of the shape of your data use `type: 'object', enabled: false` instead.

<b>Signature:</b>

```typescript
Expand All @@ -19,6 +17,8 @@ export interface SavedObjectsComplexFieldMapping
| Property | Type | Description |
| --- | --- | --- |
| [doc\_values](./kibana-plugin-core-server.savedobjectscomplexfieldmapping.doc_values.md) | <code>boolean</code> | |
| [dynamic](./kibana-plugin-core-server.savedobjectscomplexfieldmapping.dynamic.md) | <code>false &#124; 'strict'</code> | The dynamic property of the mapping, either <code>false</code> or <code>'strict'</code>. If unspecified <code>dynamic: 'strict'</code> will be inherited from the top-level index mappings.<!-- -->Note: To limit the number of mapping fields Saved Object types should \*never\* use <code>dynamic: true</code>. |
| [enabled](./kibana-plugin-core-server.savedobjectscomplexfieldmapping.enabled.md) | <code>boolean</code> | |
| [properties](./kibana-plugin-core-server.savedobjectscomplexfieldmapping.properties.md) | <code>SavedObjectsMappingProperties</code> | |
| [type](./kibana-plugin-core-server.savedobjectscomplexfieldmapping.type.md) | <code>string</code> | |

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export interface SavedObjectsCoreFieldMapping
| Property | Type | Description |
| --- | --- | --- |
| [doc\_values](./kibana-plugin-core-server.savedobjectscorefieldmapping.doc_values.md) | <code>boolean</code> | |
| [enabled](./kibana-plugin-core-server.savedobjectscorefieldmapping.enabled.md) | <code>boolean</code> | |
| [fields](./kibana-plugin-core-server.savedobjectscorefieldmapping.fields.md) | <code>{</code><br/><code> [subfield: string]: {</code><br/><code> type: string;</code><br/><code> ignore_above?: number;</code><br/><code> };</code><br/><code> }</code> | |
| [index](./kibana-plugin-core-server.savedobjectscorefieldmapping.index.md) | <code>boolean</code> | |
| [null\_value](./kibana-plugin-core-server.savedobjectscorefieldmapping.null_value.md) | <code>number &#124; boolean &#124; string</code> | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## SavedObjectsTypeMappingDefinition.dynamic property

The dynamic property of the mapping. either `false` or 'strict'. Defaults to `false`
The dynamic property of the mapping, either `false` or `'strict'`<!-- -->. If unspecified `dynamic: 'strict'` will be inherited from the top-level index mappings.

<b>Signature:</b>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ const typeDefinition: SavedObjectsTypeMappingDefinition = {

| Property | Type | Description |
| --- | --- | --- |
| [dynamic](./kibana-plugin-core-server.savedobjectstypemappingdefinition.dynamic.md) | <code>false &#124; 'strict'</code> | The dynamic property of the mapping. either <code>false</code> or 'strict'. Defaults to <code>false</code> |
| [dynamic](./kibana-plugin-core-server.savedobjectstypemappingdefinition.dynamic.md) | <code>false &#124; 'strict'</code> | The dynamic property of the mapping, either <code>false</code> or <code>'strict'</code>. If unspecified <code>dynamic: 'strict'</code> will be inherited from the top-level index mappings. |
| [properties](./kibana-plugin-core-server.savedobjectstypemappingdefinition.properties.md) | <code>SavedObjectsMappingProperties</code> | The underlying properties of the type mapping |

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
Binary file removed docs/images/AddFieldButton.jpg
Diff not rendered.
Binary file removed docs/images/CollapseButton.jpg
Diff not rendered.
Binary file removed docs/images/Dashboard_Resize_Menu.png
Diff not rendered.
Binary file removed docs/images/Dashboard_visualization_data.png
Diff not rendered.
Binary file removed docs/images/Discover-ContextView-FilterMontage.png
Diff not rendered.
Binary file removed docs/images/Discover-FieldStats.jpg
Diff not rendered.
Binary file removed docs/images/Discover-MoveColumn.jpg
Diff not rendered.
Binary file removed docs/images/EditVis.png
Diff not rendered.
Binary file removed docs/images/ExistsButton.jpg
Diff not rendered.
Binary file removed docs/images/ExpandButton.jpg
Diff not rendered.
Binary file removed docs/images/NYCTA-Table.jpg
Diff not rendered.
Binary file removed docs/images/NewDashboard.png
Diff not rendered.
Binary file removed docs/images/RemoveFieldButton.jpg
Diff not rendered.
Binary file removed docs/images/Start-Page.png
Diff not rendered.
Binary file removed docs/images/TimeFilter.jpg
Diff not rendered.
Binary file removed docs/images/VizEditor.jpg
Diff not rendered.
Binary file removed docs/images/add-column-button.png
Diff not rendered.
Binary file removed docs/images/add_filter_field.png
Diff not rendered.
Binary file removed docs/images/add_filter_operator.png
Diff not rendered.
Binary file removed docs/images/add_filter_value.png
Diff not rendered.
Binary file removed docs/images/auto_format_after.png
Diff not rendered.
Binary file removed docs/images/auto_format_before.png
Diff not rendered.
Binary file removed docs/images/auto_format_bulk.png
Diff not rendered.
Binary file removed docs/images/autorefresh-intervals.png
Diff not rendered.
Binary file removed docs/images/autorefresh-pause.png
Diff not rendered.
Binary file removed docs/images/autorefresh.png
Diff not rendered.
Binary file removed docs/images/bar-terms-agg.png
Diff not rendered.
Binary file removed docs/images/bar-terms-subagg.png
Diff not rendered.
Binary file removed docs/images/canvas-align-elements.gif
Diff not rendered.
Binary file removed docs/images/canvas-background-color-picker.gif
Diff not rendered.
Binary file removed docs/images/canvas-click-drag-element.gif
Diff not rendered.
Binary file removed docs/images/canvas-distribute-elements.gif
Diff not rendered.
Binary file removed docs/images/canvas-download-json.gif
Diff not rendered.
Binary file removed docs/images/canvas-ecommerce.png
Diff not rendered.
Binary file removed docs/images/canvas-element-order.gif
Diff not rendered.
Binary file removed docs/images/canvas-embed_workpad.gif
Diff not rendered.
Binary file removed docs/images/canvas-fullscreen.gif
Diff not rendered.
Binary file removed docs/images/canvas-move-pixel.gif
Diff not rendered.
Binary file removed docs/images/canvas-resize-element.gif
Diff not rendered.
Binary file removed docs/images/canvas-zoom.gif
Diff not rendered.
Binary file removed docs/images/canvas_create_image.png
Diff not rendered.
Binary file removed docs/images/canvas_map-time-filter.gif
Diff not rendered.
Binary file removed docs/images/canvas_share_autoplay_480.gif
Diff not rendered.
Binary file removed docs/images/canvas_share_hidetoolbar_480.gif
Diff not rendered.
Binary file removed docs/images/canvas_workpad_3_page.png
Diff not rendered.
Binary file removed docs/images/canvas_workpad_edit_style.png
Diff not rendered.
Binary file removed docs/images/canvas_workpad_weblog.png
Diff not rendered.
Binary file removed docs/images/controls/controls_options.png
Diff not rendered.
Binary file removed docs/images/controls/dropdown_control_editor.png
Diff not rendered.
Binary file removed docs/images/controls/range_slider_editor.png
Diff not rendered.
Binary file removed docs/images/discover-compass.png
Diff not rendered.
Binary file removed docs/images/edit_filter_query.png
Diff not rendered.
Binary file removed docs/images/filter-actions.png
Diff not rendered.
Binary file removed docs/images/filter-allbuttons.png
Diff not rendered.
Binary file removed docs/images/filter-sample.png
Diff not rendered.
Binary file removed docs/images/goal.png
Diff not rendered.
Binary file removed docs/images/history.png
Diff not rendered.
Binary file removed docs/images/labelbutton.png
Diff not rendered.
Binary file removed docs/images/lens_remove_layer.png
Diff not rendered.
Binary file removed docs/images/management-index-management.png
Diff not rendered.
Binary file removed docs/images/management-upgrade-assistant-8.0.png
Diff not rendered.
Binary file removed docs/images/management-watcher-buttons.png
Diff not rendered.
Binary file removed docs/images/management_rolled_dashboard.png
Diff not rendered.
Binary file removed docs/images/management_rollups_visualization.png
Diff not rendered.
Binary file removed docs/images/markdown-example.png
Diff not rendered.
Binary file removed docs/images/multiple_requests.png
Diff not rendered.
Binary file removed docs/images/regionmap.png
Diff not rendered.
Binary file removed docs/images/search-button.jpg
Diff not rendered.
Binary file removed docs/images/security_base_all.png
Diff not rendered.
Binary file removed docs/images/share-short-link.png
Diff not rendered.
Binary file removed docs/images/time-filter-absolute.jpg
Diff not rendered.
Binary file removed docs/images/time-filter-relative.jpg
Diff not rendered.
Binary file removed docs/images/time-filter.jpg
Diff not rendered.
Binary file removed docs/images/time-picker-step.jpg
Diff not rendered.
Binary file removed docs/images/time-picker.jpg
Diff not rendered.
Binary file removed docs/images/timelion-arg-help.jpg
Diff not rendered.
Binary file removed docs/images/timelion-read-only-badge.png
Diff not rendered.
Binary file removed docs/images/timelion-save01.png
Diff not rendered.
Binary file removed docs/images/timelion-save02.png
Diff not rendered.
Binary file removed docs/images/tsvb-annotations.png
Diff not rendered.
Binary file removed docs/images/tsvb-data-tab-derivative-example.png
Diff not rendered.
Binary file removed docs/images/tsvb-data-tab-label.png
Diff not rendered.
Diff not rendered.
Binary file removed docs/images/tsvb-data-tab-series-options.png
Diff not rendered.
Binary file removed docs/images/tutorial-full-inspect2.png
Diff not rendered.
Binary file removed docs/images/tutorial-sample-discover-2.png
Diff not rendered.
Binary file removed docs/images/tutorial-sample-inspect2.png
Diff not rendered.
Binary file removed docs/images/tutorial-visualize-pie-1.png
Diff not rendered.
Binary file removed docs/images/visualize-flow.png
Diff not rendered.
Binary file removed docs/images/visualize-icon.png
Diff not rendered.
Binary file removed docs/images/visualize_coordinate_map_example.png
Diff not rendered.
Binary file removed docs/images/visualize_region_map_example.png
Diff not rendered.
Binary file removed docs/images/viz-fit-bounds.png
Diff not rendered.
Binary file removed docs/images/viz-lat-long-filter.png
Diff not rendered.
Binary file removed docs/images/viz-zoom.png
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
4 changes: 2 additions & 2 deletions docs/user/alerting/action-types/pagerduty.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ Then, select the *Integrations* tab and click the *New Integration* button.
* If you are creating a new service for your integration,
go to
https://support.pagerduty.com/docs/services-and-integrations#section-configuring-services-and-integrations[Configuring Services and Integrations]
and follow the steps outlined in the *Create a New Service* section, selecting *Elastic* as the *Integration Type* in step 4.
and follow the steps outlined in the *Create a New Service* section, selecting *Elastic Alerts* as the *Integration Type* in step 4.
Continue with the <<pagerduty-in-elastic, In Elastic>> section once you have finished these steps.

. Enter an *Integration Name* in the format Elastic-service-name (for example, Elastic-Alerting or Kibana-APM-Alerting)
and select Elastic from the *Integration Type* menu.
and select *Elastic Alerts* from the *Integration Type* menu.
. Click *Add Integration* to save your new integration.
+
You will be redirected to the *Integrations* tab for your service. An Integration Key is generated on this screen.
Expand Down
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
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;
}
1 change: 1 addition & 0 deletions examples/embeddable_examples/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
*/

export { TodoSavedObjectAttributes } from './todo_saved_object_attributes';
export { BookSavedObjectAttributes, BOOK_SAVED_OBJECT } from './book_saved_object_attributes';
2 changes: 1 addition & 1 deletion examples/embeddable_examples/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"kibanaVersion": "kibana",
"server": true,
"ui": true,
"requiredPlugins": ["embeddable"],
"requiredPlugins": ["embeddable", "uiActions"],
"optionalPlugins": [],
"extraPublicDirs": ["public/todo", "public/hello_world", "public/todo/todo_ref_embeddable"]
}
90 changes: 90 additions & 0 deletions examples/embeddable_examples/public/book/book_component.tsx
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 examples/embeddable_examples/public/book/book_embeddable.tsx
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);
}
}
}
Loading

0 comments on commit 5538000

Please sign in to comment.