/* * 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 { EuiButton, EuiCodeBlock, EuiFieldText, EuiFlexGroup, EuiFlexItem, EuiPageTemplate_Deprecated as EuiPageTemplate, EuiPanel, EuiText, } from '@elastic/eui'; import React, { useEffect, useState } from 'react'; import type { HttpSetup, IHttpFetchError, ResponseErrorBody } from '@kbn/core-http-browser'; export const App = ({ http, token }: { http: HttpSetup; token?: string }) => { const onCompleteSetup = async ({ shouldReloadConfig }: { shouldReloadConfig: boolean }) => { await http .post('/api/preboot/complete_setup', { body: JSON.stringify({ shouldReloadConfig }), }) .then(() => { setTimeout(() => { window.location.href = '/'; }, 5000); }); }; const onWriteToken = async () => { await http.post('/api/preboot/write_config', { body: JSON.stringify(configKeyValue) }); }; const onConnect = async () => { await http .post('/api/preboot/connect_to_es', { body: JSON.stringify(elasticsearchConfig) }) .then( (response) => setConnectResponse(JSON.stringify(response)), (err: IHttpFetchError) => setConnectResponse(err?.body?.message || 'ERROR') ); }; const [configKeyValue, setConfigKeyValue] = useState<{ key: string; value: string }>({ key: '', value: '', }); const [elasticsearchConfig, setElasticsearchConfig] = useState<{ host: string; username: string; password: string; }>({ host: 'http://localhost:9200', username: 'kibana_system', password: '', }); const [connectResponse, setConnectResponse] = useState(null); const [isSetupModeActive, setIsSetupModeActive] = useState(false); useEffect(() => { http.get<{ isSetupModeActive: boolean }>('/api/preboot/state').then( (response) => setIsSetupModeActive(response.isSetupModeActive), (err: IHttpFetchError) => setIsSetupModeActive(false) ); }, [http]); if (!isSetupModeActive) { return ( Kibana server is not ready yet. ); } return ( { setConfigKeyValue({ ...configKeyValue, key: e.target.value }); }} /> { setConfigKeyValue({ ...configKeyValue, value: e.target.value }); }} /> Write config Token from config: {token} onCompleteSetup({ shouldReloadConfig: true })} > Reload config and proceed to `setup` onCompleteSetup({ shouldReloadConfig: false })} > DO NOT reload config and proceed to `setup` { setElasticsearchConfig({ ...elasticsearchConfig, host: e.target.value }); }} /> { setElasticsearchConfig({ ...elasticsearchConfig, username: e.target.value, }); }} /> { setElasticsearchConfig({ ...elasticsearchConfig, password: e.target.value, }); }} /> Connect {connectResponse ?? ''} ); };