forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Typescriptify ui/embeddable folder (#19648)
* Typescriptify ui/embeddable folder * Allow ts modules from ui/public folders to be imported * Address review comments from Tim * Address code review from Oleg * remove lodash usage * remove mappng to non public folder
- Loading branch information
1 parent
1617da9
commit 16fc1cf
Showing
11 changed files
with
187 additions
and
117 deletions.
There are no files selected for viewing
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
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* 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 * as PropTypes from 'prop-types'; | ||
import { ContainerState } from './types'; | ||
|
||
// TODO: we'll be able to get rid of this shape once all of dashboard is typescriptified too. | ||
export const embeddableShape = PropTypes.shape({ | ||
destroy: PropTypes.func.isRequired, | ||
metadata: PropTypes.object.isRequired, | ||
onContainerStateChanged: PropTypes.func.isRequired, | ||
render: PropTypes.func.isRequired, | ||
}); | ||
|
||
interface EmbeddableMetadata { | ||
// TODO: change to an array, embeddables should be able to specify multiple index patterns they use. Also | ||
// see https://github.com/elastic/kibana/issues/19408 - this needs to be generalized to support embeddables that | ||
// use dynamic index patterns (vega, TSVB) instead of saved object index patterns (most other visualizations). | ||
/** | ||
* Should specify any index pattern the embeddable uses. This will be used by the container to list out | ||
* available fields to filter on. | ||
*/ | ||
indexPattern?: object; | ||
|
||
/** | ||
* The title, or name, of the embeddable. | ||
*/ | ||
title?: string; | ||
|
||
/** | ||
* A url to direct the user for managing the embeddable instance. We may want to eventually make this optional | ||
* for non-instanced panels that can only be created and deleted but not edited. We also wish to eventually support | ||
* in-place editing on the dashboard itself, so another option could be to supply an element, or fly out panel, to | ||
* offer for editing directly on the dashboard. | ||
*/ | ||
editUrl?: string; | ||
} | ||
|
||
interface EmbeddableOptions { | ||
metadata?: EmbeddableMetadata; | ||
render?: (domNode: HTMLElement, containerState: ContainerState) => void; | ||
destroy?: () => void; | ||
onContainerStateChanged?: (containerState: ContainerState) => void; | ||
} | ||
|
||
export abstract class Embeddable { | ||
public readonly metadata: EmbeddableMetadata = {}; | ||
|
||
// TODO: Make title and editUrl required and move out of options parameter. | ||
constructor(options: EmbeddableOptions = {}) { | ||
this.metadata = options.metadata || {}; | ||
|
||
if (options.render) { | ||
this.render = options.render; | ||
} | ||
|
||
if (options.destroy) { | ||
this.destroy = options.destroy; | ||
} | ||
|
||
if (options.onContainerStateChanged) { | ||
this.onContainerStateChanged = options.onContainerStateChanged; | ||
} | ||
} | ||
|
||
public abstract onContainerStateChanged(containerState: ContainerState): void; | ||
|
||
/** | ||
* Embeddable should render itself at the given domNode. | ||
*/ | ||
public abstract render( | ||
domNode: HTMLElement, | ||
containerState: ContainerState | ||
): void; | ||
|
||
public destroy(): void { | ||
return; | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export interface ContainerState { | ||
// 'view' or 'edit'. Should probably be an enum but I'm undecided where to define it, here or in dashboard code. | ||
viewMode: string; | ||
|
||
timeRange: { | ||
// To and From should be either an absolute time range in utc format or a relative one (e.g. now-15m) | ||
to: string; | ||
from: string; | ||
}; | ||
|
||
// The shape will be up to the embeddable type. | ||
embeddableCustomization?: object; | ||
|
||
/** | ||
* Whether or not panel titles are hidden. It is not the embeddable's responsibility to hide the title (the container | ||
* handles that). This information is currently only used to determine the title for reporting (data-sharing-title | ||
* attribute). If we move that out of the embeddables and push it to the container (as we probably should), then | ||
* we shouldn't need to expose this information. | ||
*/ | ||
hidePanelTitles: boolean; | ||
|
||
/** | ||
* Is the current panel in expanded mode | ||
*/ | ||
isPanelExpanded: boolean; | ||
} | ||
|
||
export interface EmbeddableState { | ||
/** | ||
* Any customization data that should be stored at the panel level. For | ||
* example, pie slice colors, or custom per panel sort order or columns. | ||
*/ | ||
customization: object; | ||
/** | ||
* A possible filter the embeddable wishes dashboard to apply. | ||
*/ | ||
stagedFilter: object; | ||
} |
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