/* * 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public * License v3.0 only", or the "Server Side Public License, v 1". */ import React, { useState } from 'react'; import ReactDOM from 'react-dom'; import { EuiText, EuiPageTemplate, EuiCard, EuiPageHeader, EuiFlexGroup, EuiFlexItem, EuiFieldSearch, EuiListGroup, EuiHighlight, EuiLink, EuiButtonIcon, } from '@elastic/eui'; import { AnalyticsServiceStart, AppMountParameters, I18nStart, ThemeServiceStart, UserProfileService, } from '@kbn/core/public'; import { KibanaRenderContextProvider } from '@kbn/react-kibana-context-render'; import { ExampleDefinition } from './types'; interface StartServices { analytics: Pick; i18n: I18nStart; theme: Pick; userProfile: UserProfileService; } interface Props { startServices: StartServices; examples: ExampleDefinition[]; navigateToApp: (appId: string) => void; getUrlForApp: (appId: string) => string; } function DeveloperExamples({ startServices, examples, navigateToApp, getUrlForApp }: Props) { const [search, setSearch] = useState(''); const lcSearch = search.toLowerCase(); const filteredExamples = !lcSearch ? examples : examples.filter((def) => { if (def.description.toLowerCase().indexOf(lcSearch) >= 0) return true; if (def.title.toLowerCase().indexOf(lcSearch) >= 0) return true; return false; }); return ( The following examples showcase services and APIs that are available to developers. setSearch(e.target.value)} isClearable={true} aria-label="Search developer examples" /> {filteredExamples.map((def) => ( {def.description} } title={ { navigateToApp(def.appId); }} > {def.title} window.open(getUrlForApp(def.appId), '_blank', 'noopener, noreferrer') } > Open in new tab } image={def.image} footer={def.links ? : undefined} /> ))} ); } export const renderApp = (props: Props, element: AppMountParameters['element']) => { ReactDOM.render(, element); return () => ReactDOM.unmountComponentAtNode(element); };