|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the "Elastic License |
| 4 | + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side |
| 5 | + * Public License v 1"; you may not use this file except in compliance with, at |
| 6 | + * your election, the "Elastic License 2.0", the "GNU Affero General Public |
| 7 | + * License v3.0 only", or the "Server Side Public License, v 1". |
| 8 | + */ |
| 9 | + |
| 10 | +import React, { useMemo } from 'react'; |
| 11 | +import { EuiPageTemplate, EuiTitle } from '@elastic/eui'; |
| 12 | +import type { CoreStart } from '@kbn/core/public'; |
| 13 | + |
| 14 | +import useObservable from 'react-use/lib/useObservable'; |
| 15 | +import { defer } from 'rxjs'; |
| 16 | +import { httpResponseIntoObservable } from '@kbn/sse-utils-client'; |
| 17 | +import { PLUGIN_NAME } from '../../common'; |
| 18 | + |
| 19 | +interface FeatureFlagsExampleAppDeps { |
| 20 | + http: CoreStart['http']; |
| 21 | +} |
| 22 | + |
| 23 | +export const SseExampleApp = ({ http }: FeatureFlagsExampleAppDeps) => { |
| 24 | + const sseResponse$ = useMemo(() => { |
| 25 | + return defer(() => |
| 26 | + http.get('/internal/sse_examples/clock', { |
| 27 | + asResponse: true, |
| 28 | + rawResponse: true, |
| 29 | + version: '1', |
| 30 | + }) |
| 31 | + ).pipe(httpResponseIntoObservable<{ message: string; type: 'clock' }>()); |
| 32 | + }, [http]); |
| 33 | + |
| 34 | + const sseResponse = useObservable(sseResponse$, { message: 'Initial value', type: 'clock' }); |
| 35 | + |
| 36 | + return ( |
| 37 | + <> |
| 38 | + <EuiPageTemplate> |
| 39 | + <EuiPageTemplate.Header> |
| 40 | + <EuiTitle size="l"> |
| 41 | + <h1>{PLUGIN_NAME}</h1> |
| 42 | + </EuiTitle> |
| 43 | + </EuiPageTemplate.Header> |
| 44 | + <EuiPageTemplate.Section> |
| 45 | + <h2>{sseResponse.message}</h2> |
| 46 | + </EuiPageTemplate.Section> |
| 47 | + </EuiPageTemplate> |
| 48 | + </> |
| 49 | + ); |
| 50 | +}; |
0 commit comments