mirror of
https://github.com/elastic/kibana.git
synced 2025-06-27 10:40:07 -04:00
[UnifiedDocViewer] Move Discover doc viewer into plugin/package (#162847)
## Summary Replaces https://github.com/elastic/kibana/pull/154012. Moves the Discover doc viewer component into a new plugin/package, `@kbn/unified-doc-viewer` and `@kbn/unified-doc-viewer-plugin`. ### Checklist - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/)) - [ ] Any UI touched in this PR does not create any new axe failures (run axe in browser: [FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/), [Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US)) - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server)) - [ ] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers) ### Risk Matrix Before closing this PR, invite QA, stakeholders, and other developers to identify risks that should be tested prior to the change/feature release. When forming the risk matrix, consider some of the following examples and how they may potentially impact the change: | Risk | Probability | Severity | Mitigation/Notes | |---------------------------|-------------|----------|-------------------------| | Multiple Spaces—unexpected behavior in non-default Kibana Space. | Low | High | Integration tests will verify that all features are still supported in non-default Kibana Space and when user switches between spaces. | | Multiple nodes—Elasticsearch polling might have race conditions when multiple Kibana nodes are polling for the same tasks. | High | Low | Tasks are idempotent, so executing them multiple times will not result in logical error, but will degrade performance. To test for this case we add plenty of unit tests around this logic and document manual testing procedure. | | Code should gracefully handle cases when feature X or plugin Y are disabled. | Medium | High | Unit tests will verify that any feature flag or plugin combination still results in our service operational. | | [See more potential risk examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) | ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Shahzad <shahzad31comp@gmail.com>
This commit is contained in:
parent
59231988c7
commit
09cd69d386
137 changed files with 1325 additions and 760 deletions
3
examples/unified_doc_viewer/README.md
Normal file
3
examples/unified_doc_viewer/README.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
## Unified Doc Viewer
|
||||
|
||||
An example plugin showing usage of the unified doc viewer plugin (plugins/unified_doc_viewer) and package (@kbn/unified-doc-viewer).
|
16
examples/unified_doc_viewer/kibana.jsonc
Normal file
16
examples/unified_doc_viewer/kibana.jsonc
Normal file
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"type": "plugin",
|
||||
"id": "@kbn/unified-doc-viewer-examples",
|
||||
"owner": "@elastic/kibana-core",
|
||||
"description": "Examples showing usage of the unified doc viewer.",
|
||||
"plugin": {
|
||||
"id": "unifiedDocViewerExamples",
|
||||
"server": false,
|
||||
"browser": true,
|
||||
"requiredPlugins": [
|
||||
"data",
|
||||
"developerExamples",
|
||||
"unifiedDocViewer"
|
||||
]
|
||||
}
|
||||
}
|
72
examples/unified_doc_viewer/public/application.tsx
Normal file
72
examples/unified_doc_viewer/public/application.tsx
Normal file
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* 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, { useEffect, useState } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import type { AppMountParameters, CoreStart } from '@kbn/core/public';
|
||||
import { buildDataTableRecord } from '@kbn/discover-utils';
|
||||
import type { DataTableRecord } from '@kbn/discover-utils/types';
|
||||
import type { DataView } from '@kbn/data-views-plugin/common';
|
||||
import { UnifiedDocViewer } from '@kbn/unified-doc-viewer-plugin/public';
|
||||
import { DataPublicPluginStart } from '@kbn/data-plugin/public';
|
||||
import type { StartDeps } from './plugin';
|
||||
|
||||
export const renderApp = (
|
||||
core: CoreStart,
|
||||
{ data }: StartDeps,
|
||||
{ element }: AppMountParameters
|
||||
) => {
|
||||
ReactDOM.render(<UnifiedDocViewerExamplesApp data={data} />, element);
|
||||
|
||||
return () => {
|
||||
ReactDOM.unmountComponentAtNode(element);
|
||||
};
|
||||
};
|
||||
|
||||
function UnifiedDocViewerExamplesApp({ data }: { data: DataPublicPluginStart }) {
|
||||
const [dataView, setDataView] = useState<DataView | null>();
|
||||
const [hit, setHit] = useState<DataTableRecord | null>();
|
||||
|
||||
useEffect(() => {
|
||||
data.dataViews.getDefault().then((defaultDataView) => setDataView(defaultDataView));
|
||||
}, [data]);
|
||||
|
||||
useEffect(() => {
|
||||
const setDefaultHit = async () => {
|
||||
if (!dataView?.id) return;
|
||||
const response = await data.search
|
||||
.search({
|
||||
params: {
|
||||
index: dataView?.getIndexPattern(),
|
||||
body: {
|
||||
fields: ['*'],
|
||||
_source: false,
|
||||
},
|
||||
},
|
||||
})
|
||||
.toPromise();
|
||||
const docs = response?.rawResponse?.hits?.hits ?? [];
|
||||
if (docs.length > 0) {
|
||||
const record = buildDataTableRecord(docs[0], dataView);
|
||||
setHit(record);
|
||||
}
|
||||
};
|
||||
|
||||
setDefaultHit();
|
||||
}, [data, dataView]);
|
||||
|
||||
return (
|
||||
<>
|
||||
{dataView?.id && hit ? (
|
||||
<UnifiedDocViewer hit={hit} dataView={dataView} />
|
||||
) : (
|
||||
'Loading... (make sure you have a default data view and at least one matching document)'
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
12
examples/unified_doc_viewer/public/index.ts
Normal file
12
examples/unified_doc_viewer/public/index.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
* 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 { UnifiedDocViewerExamplesPlugin } from './plugin';
|
||||
|
||||
export function plugin() {
|
||||
return new UnifiedDocViewerExamplesPlugin();
|
||||
}
|
49
examples/unified_doc_viewer/public/plugin.tsx
Normal file
49
examples/unified_doc_viewer/public/plugin.tsx
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* 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 { AppMountParameters, CoreSetup, CoreStart, Plugin } from '@kbn/core/public';
|
||||
import { DeveloperExamplesSetup } from '@kbn/developer-examples-plugin/public';
|
||||
import type { DataPublicPluginStart } from '@kbn/data-plugin/public';
|
||||
|
||||
export interface SetupDeps {
|
||||
developerExamples: DeveloperExamplesSetup;
|
||||
}
|
||||
|
||||
export interface StartDeps {
|
||||
data: DataPublicPluginStart;
|
||||
}
|
||||
|
||||
export class UnifiedDocViewerExamplesPlugin implements Plugin<void, void, SetupDeps, StartDeps> {
|
||||
public setup(core: CoreSetup<StartDeps>, deps: SetupDeps) {
|
||||
// Register an application into the side navigation menu
|
||||
core.application.register({
|
||||
id: 'unifiedDocViewer',
|
||||
title: 'Unified Doc Viewer Examples',
|
||||
async mount(params: AppMountParameters) {
|
||||
// Load application bundle
|
||||
const { renderApp } = await import('./application');
|
||||
// Get start services as specified in kibana.json
|
||||
const [coreStart, depsStart] = await core.getStartServices();
|
||||
// Render the application
|
||||
return renderApp(coreStart, depsStart, params);
|
||||
},
|
||||
});
|
||||
|
||||
// This section is only needed to get this example plugin to show up in our Developer Examples.
|
||||
deps.developerExamples.register({
|
||||
appId: 'unifiedDocViewer',
|
||||
title: 'Unified Doc Viewer Examples',
|
||||
description: 'Examples showcasing the unified doc viewer.',
|
||||
});
|
||||
}
|
||||
|
||||
public start(core: CoreStart) {
|
||||
return {};
|
||||
}
|
||||
|
||||
public stop() {}
|
||||
}
|
24
examples/unified_doc_viewer/tsconfig.json
Normal file
24
examples/unified_doc_viewer/tsconfig.json
Normal file
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "target/types"
|
||||
},
|
||||
"include": [
|
||||
"index.ts",
|
||||
"common/**/*.ts",
|
||||
"public/**/*.ts",
|
||||
"public/**/*.tsx",
|
||||
"../../typings/**/*"
|
||||
],
|
||||
"exclude": [
|
||||
"target/**/*",
|
||||
],
|
||||
"kbn_references": [
|
||||
"@kbn/core",
|
||||
"@kbn/data-plugin",
|
||||
"@kbn/data-views-plugin",
|
||||
"@kbn/developer-examples-plugin",
|
||||
"@kbn/discover-utils",
|
||||
"@kbn/unified-doc-viewer-plugin",
|
||||
]
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue