kibana/examples/preboot_example/public/app.tsx
Constance 98f73d674a
Upgrade EUI to v63.0.6 - updates to new EuiPageTemplate and deprecates old page components (#139524)
* Update all usages of EuiPageTemplate to EuiPageTemplate_Deprecated

* EuiPageContent_Deprecated as EuiPageContent

* EuiPageContentBody_Deprecated as EuiPageContentBody

* EuiPageContentHeader_Deprecated as EuiPageContentHeader

* EuiPageContentHeaderSection_Deprecated as EuiPageContentHeaderSection

* EuiPageSideBar_Deprecated as EuiPageSideBar

* EuiPageContent__Deprecated to EuiPageContent_Deprecated

* Fix rogue semi-colons

* WIP: NoDataConfigPage & NoDataPage converted to new template

- `withSolutionNav` not yet handled

* WIP: KibanaPageTemplateInner converted to use new template

- Pushes existing `pageHeader` prompts onto created EuiPageTemplate.PageHeader
- Uses `isEmptyState` to push `pageHeader` props to EuiPageTemplate.EmptyPrompt instead (if `children` are not supplied)

* WIP: `withSolutionNav` now renders the sidebar content properly

- Collapsing isn’t working (minWidth isn’t updating)

* Fixing stickiness of sidebar

* [Security] Fixed SecuritySolutionTemplateWrapper’s usage

- Moved `bottomBar` to EuiPageTemplate.BottomBar (now contained in just the page contents)
- Change EuiPanel children wrapper with EuiPageTemplate.Section

* [O11y] Wrap `children` with EuiPageTemplate.Section

* Fix getting_started usage

* WIP: Fixing types

* Removing `template` pass through

* Set EUI to 63.0.0

* [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix'

* More import fixes

* Sidebar component update

* Expand `KibanaPageTemplate` to all namespaced EUI counterparts

- Updated `docs/tutorials` mdx page
- Fixed SolutionNav prop types

* Updated the tutorial mdx page

* [Stack Management] Updated app layout to new template

- Some temporary props applied for BWC until all other pages can be converted
- Converted `API Keys` page’s layout (and especially prompt usags) to new paradigm

* Fix circular dep

* Fix new circular dependency

- copying and pasting types from KibanaPageTemplateProps, but ah well

* [Security Solution] Remove `template` prop - no longer a prop on Kibana/EuiPageTemplate

* [O11y] Allow customizing EuiPageTemplate.Section wrapper

- converts pageBodyProps
- fixes non-centered loading template

* [Enterprise Search] Update page templates

- fix layouts by auto-wrapping an EuiPageSection for padding, while adding a `customPageSections` prop for more custom sections/layouts

- re-center 404 errors

- update tests

* Update KibanaPageTemplate tests

* Update snapshots

* Fix FTR test with removed EUI classNames

* Fix FTR tests with changed kbn classNames

* Update failing dashboard snapshots

- drop shadow changed slightly in EUI

* Fix failing Security Cypress test

* [O11y] Fix Inventory page using deprecated CSS hooks

* [O11y][Uptime] Fix missing bottom bars

- Modifies ObservabilityPageTemplate to accept a `bottomBar` prop (a la the old EuiPageTemplate behavior)

NOTE: This opinionated page layout structure is starting to feel like it could be potentially limiting / have all the same pitfalls the previous EuiPageTemplate did. If so, consider something closer to the Enterprise Search page template conversion (`customPageSections`).

- Misc cleanup: Use `KibanaPageTemplate` over `EuiPageTemplate`

* [O11y] Fix route template typing

- Since theObservabilityPageTemplate is using the new Eui/KibanaPageTemplate, its child templates and types need to be updated accordingly

* Fix broken minWidth behavior

- was an EUI issue that required a patch release
+ update snapshots

* [Security Solution] Type fixes, restore empty state

- Fix empty state logic removed in a previous commit
- bogarts KibanaPageTemplate's `isEmptyState` prop instead of using `template="noData"`

- extend template wrappers to past ...rest to underlying Kibana/EuiPageTemplate

+ replace EuiPageTemplate with KibanaPageTemplate for consistency

* Fix failing synthetics selector

* Grab EUI v63.0.6

- for deprecation tags and section tag support

* Fix Kibana Overview plugin layout

- needs to use KibanaPageTemplate.Section to get padding back

- use `bottomBorder` prop over horizontal rules

- restore previous page color via panelled=false

* Convert Home plugin to new KibanaPageTemplate

- use KibanaPageTemplate.Section instead to preserve page width/paddings

- use `bottomBorder` instead of `EuiHorizontalRule`

- NOTE: This causes margins to decrease slightly from xxl to xl (largest padding available for EuiPageSection) - this can be restored by CSS overrides if desired

- update CSS to preserve previous looks, + convert to logical properties

* [O11y] Fix non-centered empty/loading states

* [O11y] Restore subdued background on various empty state prompts

* [O11y] Fix all instances of views that require a scrollable full-height child

+ restore comment for inventory view

* [O11y][ux] Fix broken sidebar

- The entire app was missing a wrapping EuiProvider, and as such breakpoint utils were not working, and the sidebar was missing

+ misc cleanup
  - remove unnecessary fragment
  - remove role="main" attr - now that EuiPageTemplate sets a `main` tag, they'll conflict
  - add isEmptyState to center loading component

* [APM Cypress tests] harden flaky test

* [APM Cypress tests] Fix failing Cypress test, again

Co-authored-by: cchaos <caroline.horn@elastic.co>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2022-09-07 15:35:23 -05:00

219 lines
6.9 KiB
TypeScript

/*
* 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<ResponseErrorBody>) =>
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<string | null>(null);
const [isSetupModeActive, setIsSetupModeActive] = useState<boolean>(false);
useEffect(() => {
http.get<{ isSetupModeActive: boolean }>('/api/preboot/state').then(
(response) => setIsSetupModeActive(response.isSetupModeActive),
(err: IHttpFetchError) => setIsSetupModeActive(false)
);
}, [http]);
if (!isSetupModeActive) {
return (
<EuiPageTemplate
restrictWidth={false}
template="empty"
pageHeader={{
iconType: 'logoElastic',
pageTitle: 'Welcome to Elastic',
}}
>
<EuiPanel>
<EuiText>Kibana server is not ready yet.</EuiText>
</EuiPanel>
</EuiPageTemplate>
);
}
return (
<EuiPageTemplate
restrictWidth={false}
template="empty"
pageHeader={{
iconType: 'logoElastic',
pageTitle: 'Welcome to Elastic',
}}
>
<EuiPanel>
<EuiFlexGroup>
<EuiFlexItem grow={false}>
<EuiFlexGroup direction={'column'}>
<EuiFlexItem>
<EuiFieldText
placeholder="Config key"
value={configKeyValue.key}
onChange={(e) => {
setConfigKeyValue({ ...configKeyValue, key: e.target.value });
}}
/>
</EuiFlexItem>
<EuiFlexItem>
<EuiFieldText
placeholder="Config value"
value={configKeyValue.value}
onChange={(e) => {
setConfigKeyValue({ ...configKeyValue, value: e.target.value });
}}
/>
</EuiFlexItem>
<EuiFlexItem>
<EuiButton
size="m"
color={'danger'}
onClick={onWriteToken}
disabled={!configKeyValue.key || !configKeyValue.value}
>
Write config
</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiFlexGroup direction={'column'}>
<EuiFlexItem>
<EuiText>Token from config: {token}</EuiText>
</EuiFlexItem>
<EuiFlexItem>
<EuiButton
size="m"
color={'danger'}
onClick={() => onCompleteSetup({ shouldReloadConfig: true })}
>
Reload config and proceed to `setup`
</EuiButton>
</EuiFlexItem>
<EuiFlexItem>
<EuiButton
size="m"
color={'primary'}
onClick={() => onCompleteSetup({ shouldReloadConfig: false })}
>
DO NOT reload config and proceed to `setup`
</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiFlexGroup direction={'column'}>
<EuiFlexItem>
<EuiFieldText
placeholder="elasticsearch.hosts"
value={elasticsearchConfig.host}
onChange={(e) => {
setElasticsearchConfig({ ...elasticsearchConfig, host: e.target.value });
}}
/>
</EuiFlexItem>
<EuiFlexItem>
<EuiFieldText
placeholder="elasticsearch.username"
value={elasticsearchConfig.username}
onChange={(e) => {
setElasticsearchConfig({
...elasticsearchConfig,
username: e.target.value,
});
}}
/>
</EuiFlexItem>
<EuiFlexItem>
<EuiFieldText
placeholder="elasticsearch.password"
value={elasticsearchConfig.password}
onChange={(e) => {
setElasticsearchConfig({
...elasticsearchConfig,
password: e.target.value,
});
}}
/>
</EuiFlexItem>
<EuiFlexItem>
<EuiButton
size="m"
color={'danger'}
onClick={onConnect}
disabled={
!elasticsearchConfig.host ||
!elasticsearchConfig.username ||
!elasticsearchConfig.password
}
>
Connect
</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
<EuiFlexItem>
<EuiCodeBlock language="json" paddingSize="s" isCopyable>
{connectResponse ?? ''}
</EuiCodeBlock>
</EuiFlexItem>
</EuiFlexGroup>
</EuiPanel>
</EuiPageTemplate>
);
};