-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
707 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# NoDataExamples | ||
|
||
A Kibana plugin to demonstrate the stateful capabilities of integrated NoDataPage services: | ||
|
||
- getAnalyticsNoDataPageFlavor | ||
- useHasApiKeys |
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,10 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export const PLUGIN_ID = 'noDataExamples'; | ||
export const PLUGIN_NAME = 'NoDataExamples'; |
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,15 @@ | ||
{ | ||
"type": "plugin", | ||
"id": "@kbn/no-data-page-example-plugin", | ||
"owner": "@elastic/appex-sharedux", | ||
"description": "A Kibana plugin to demonstrate the stateful capabilities of integrated NoDataPage services", | ||
"plugin": { | ||
"id": "no_data_page_example", | ||
"server": false, | ||
"browser": true, | ||
"requiredPlugins": [ | ||
"developerExamples", | ||
"noDataPage" | ||
] | ||
} | ||
} |
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,12 @@ | ||
{ | ||
"name": "noDataExamples", | ||
"version": "0.0.0", | ||
"private": true, | ||
"scripts": { | ||
"bootstrap": "yarn kbn bootstrap && yarn install", | ||
"build": "yarn plugin-helpers build", | ||
"dev": "yarn plugin-helpers dev", | ||
"plugin-helpers": "node ../../scripts/plugin_helpers", | ||
"kbn": "node ../../scripts/kbn" | ||
} | ||
} |
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,23 @@ | ||
/* | ||
* 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 from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { AppMountParameters, CoreStart } from '@kbn/core/public'; | ||
import { NoDataExamplesApp } from './components/app'; | ||
import { NoDataExamplesPluginSetupDeps } from '.'; | ||
|
||
export const renderApp = ( | ||
_: CoreStart, | ||
{ element }: AppMountParameters, | ||
{ noDataPage }: Pick<NoDataExamplesPluginSetupDeps, 'noDataPage'> | ||
) => { | ||
ReactDOM.render(<NoDataExamplesApp noDataPage={noDataPage} />, element); | ||
|
||
return () => ReactDOM.unmountComponentAtNode(element); | ||
}; |
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 @@ | ||
/* | ||
* 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, { useState } from 'react'; | ||
|
||
import { EuiButton, EuiCode, EuiHorizontalRule, EuiLoadingSpinner, EuiText } from '@elastic/eui'; | ||
import { NoDataPagePluginSetup } from '@kbn/no-data-page-plugin/public'; | ||
import { KibanaErrorBoundary, KibanaErrorBoundaryProvider } from '@kbn/shared-ux-error-boundary'; | ||
import { KibanaPageTemplate } from '@kbn/shared-ux-page-kibana-template'; | ||
import { PLUGIN_NAME } from '../../common'; | ||
|
||
interface NoDataExamplesAppDeps { | ||
noDataPage: NoDataPagePluginSetup; | ||
} | ||
|
||
export const NoDataExamplesApp: React.FC<NoDataExamplesAppDeps> = ({ noDataPage }) => { | ||
// Use React hooks to manage state. | ||
const [showHasApiKeys, setShowHasApiKeys] = useState<boolean | null>(null); | ||
|
||
const onClickHandler = () => { | ||
setShowHasApiKeys(true); | ||
}; | ||
|
||
const ShowHasApiKeys = () => { | ||
const hasApiKeysResponse = noDataPage.useHasApiKeys(); | ||
if (hasApiKeysResponse == null) { | ||
return <>undetermined</>; | ||
} | ||
const { hasApiKeys, loading, error } = hasApiKeysResponse; | ||
|
||
if (error) { | ||
throw error; | ||
} | ||
|
||
if (loading) { | ||
return <EuiLoadingSpinner size="s" />; | ||
} | ||
|
||
return <>{hasApiKeys ? 'yes' : 'no'}</>; | ||
}; | ||
|
||
// Render the application DOM. | ||
// Note that `navigation.ui.TopNavMenu` is a stateful component exported on the `navigation` plugin's start contract. | ||
return ( | ||
<KibanaErrorBoundaryProvider analytics={undefined}> | ||
<KibanaErrorBoundary> | ||
<KibanaPageTemplate> | ||
<KibanaPageTemplate.Header | ||
pageTitle={PLUGIN_NAME} | ||
data-test-subj="noDataPageExampleHeader" | ||
/> | ||
<KibanaPageTemplate.Section grow={false}> | ||
<EuiText> | ||
<p> | ||
Service: <EuiCode>hasApiKeys</EuiCode> | ||
<br /> | ||
<span data-test-subj="noDataPageExampleHasApiKeysResult"> | ||
Current user has API keys:{' '} | ||
<strong>{showHasApiKeys ? <ShowHasApiKeys /> : 'unknown'}</strong> | ||
</span> | ||
</p> | ||
<p>Click to determine whether the user has created active API keys.</p> | ||
<EuiButton | ||
type="primary" | ||
size="s" | ||
onClick={onClickHandler} | ||
data-test-subj="noDataPageExampleHasApiKeysClick" | ||
> | ||
Click | ||
</EuiButton> | ||
</EuiText> | ||
</KibanaPageTemplate.Section> | ||
<KibanaPageTemplate.Section> | ||
<EuiHorizontalRule /> | ||
<EuiText> | ||
<p> | ||
Service: <EuiCode>getAnalyticsNoDataPageFlavor</EuiCode> | ||
<br /> | ||
Analytics NoDataPage Flavor:{' '} | ||
<strong data-test-subj="noDataPageExampleNoDataPageFlavorResult"> | ||
{noDataPage.getAnalyticsNoDataPageFlavor() ?? 'undefined'} | ||
</strong> | ||
</p> | ||
</EuiText> | ||
</KibanaPageTemplate.Section> | ||
</KibanaPageTemplate> | ||
</KibanaErrorBoundary> | ||
</KibanaErrorBoundaryProvider> | ||
); | ||
}; |
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,23 @@ | ||
/* | ||
* 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 { DeveloperExamplesSetup } from '@kbn/developer-examples-plugin/public'; | ||
import { NoDataPagePluginSetup } from '@kbn/no-data-page-plugin/public'; | ||
import { NoDataExamplesPlugin } from './plugin'; | ||
|
||
// This exports static code and TypeScript types, | ||
// as well as, Kibana Platform `plugin()` initializer. | ||
export function plugin() { | ||
return new NoDataExamplesPlugin(); | ||
} | ||
export type { NoDataExamplesPluginSetup, NoDataExamplesPluginStart } from './types'; | ||
|
||
export interface NoDataExamplesPluginSetupDeps { | ||
developerExamples: DeveloperExamplesSetup; | ||
noDataPage: NoDataPagePluginSetup; | ||
} |
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,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 { NoDataExamplesPluginSetup, NoDataExamplesPluginStart } from './types'; | ||
import { PLUGIN_ID, PLUGIN_NAME } from '../common'; | ||
import { NoDataExamplesPluginSetupDeps } from '.'; | ||
|
||
export class NoDataExamplesPlugin | ||
implements Plugin<NoDataExamplesPluginSetup, NoDataExamplesPluginStart> | ||
{ | ||
public setup(core: CoreSetup, deps: NoDataExamplesPluginSetupDeps) { | ||
const { developerExamples, noDataPage } = deps; | ||
|
||
// Register an application into the side navigation menu | ||
core.application.register({ | ||
id: PLUGIN_ID, | ||
title: PLUGIN_NAME, | ||
async mount(params: AppMountParameters) { | ||
// Load application bundle | ||
const { renderApp } = await import('./application'); | ||
// Get start services as specified in kibana.json | ||
const [coreStart] = await core.getStartServices(); | ||
// Render the application | ||
return renderApp(coreStart, params, { noDataPage }); | ||
}, | ||
}); | ||
|
||
// This section is only needed to get this example plugin to show up in our Developer Examples. | ||
developerExamples.register({ | ||
appId: PLUGIN_ID, | ||
title: PLUGIN_NAME, | ||
description: `Demonstrates the stateful capabilities of integrated NoDataPage services`, | ||
}); | ||
|
||
return {}; | ||
} | ||
|
||
public start(_: CoreStart): NoDataExamplesPluginStart { | ||
return {}; | ||
} | ||
|
||
public stop() {} | ||
} |
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,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. | ||
*/ | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface NoDataExamplesPluginSetup {} | ||
|
||
export type NoDataExamplesPluginStart = NoDataExamplesPluginSetup; |
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,81 @@ | ||
{ | ||
"formats": { | ||
"number": { | ||
"currency": { | ||
"style": "currency" | ||
}, | ||
"percent": { | ||
"style": "percent" | ||
} | ||
}, | ||
"date": { | ||
"short": { | ||
"month": "numeric", | ||
"day": "numeric", | ||
"year": "2-digit" | ||
}, | ||
"medium": { | ||
"month": "short", | ||
"day": "numeric", | ||
"year": "numeric" | ||
}, | ||
"long": { | ||
"month": "long", | ||
"day": "numeric", | ||
"year": "numeric" | ||
}, | ||
"full": { | ||
"weekday": "long", | ||
"month": "long", | ||
"day": "numeric", | ||
"year": "numeric" | ||
} | ||
}, | ||
"time": { | ||
"short": { | ||
"hour": "numeric", | ||
"minute": "numeric" | ||
}, | ||
"medium": { | ||
"hour": "numeric", | ||
"minute": "numeric", | ||
"second": "numeric" | ||
}, | ||
"long": { | ||
"hour": "numeric", | ||
"minute": "numeric", | ||
"second": "numeric", | ||
"timeZoneName": "short" | ||
}, | ||
"full": { | ||
"hour": "numeric", | ||
"minute": "numeric", | ||
"second": "numeric", | ||
"timeZoneName": "short" | ||
} | ||
}, | ||
"relative": { | ||
"years": { | ||
"units": "year" | ||
}, | ||
"months": { | ||
"units": "month" | ||
}, | ||
"days": { | ||
"units": "day" | ||
}, | ||
"hours": { | ||
"units": "hour" | ||
}, | ||
"minutes": { | ||
"units": "minute" | ||
}, | ||
"seconds": { | ||
"units": "second" | ||
} | ||
} | ||
}, | ||
"messages": { | ||
"noDataExamples.buttonText": "Translate me to Japanese" | ||
} | ||
} |
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,13 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "./target/types" | ||
}, | ||
"include": [ | ||
"index.ts", | ||
"public/**/*.ts", | ||
"public/**/*.tsx", | ||
"../../typings/**/*" | ||
], | ||
"exclude": [] | ||
} |
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,13 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export const NO_DATA_API_PATHS: Record<string, Record<string, string>> = { | ||
internal: { | ||
hasApiKeys: '/internal/no_data/has_api_keys', | ||
}, | ||
}; |
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,11 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export interface HasApiKeysApiResponse { | ||
has_api_keys: 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
Oops, something went wrong.