-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interactive setup mode #106881
Merged
Merged
Interactive setup mode #106881
Changes from 29 commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
caa9ad3
Interactive setup mode
thomheymann 34672fc
remove first attempt
thomheymann 09d1f95
Added suggestions from code review
thomheymann 4177cef
Verify CA before writing config
thomheymann 185660d
fix i18n path
thomheymann 4e7b041
updated plugin list
thomheymann 5223dfa
Updated page bundle limits
thomheymann decec27
added manual configuration
thomheymann f2c42d4
Merge branch 'master' of github.com:elastic/kibana into interactive-s…
thomheymann 56b068b
fetch certificate chain
thomheymann 44d5432
Merge branch 'master' of github.com:elastic/kibana into interactive-s…
thomheymann 309dd38
Fix race condition when calling multiple form methods
thomheymann da3daf9
Fix i18n errors
thomheymann 44229d4
added types and refactored slightly
thomheymann 7a3c2d9
welcome page styling
thomheymann 21ffd73
Remove holdsetup config option
thomheymann 8837a12
typo
thomheymann 312c287
fix build errors
thomheymann b0d35b1
Merge branch 'master' into interactive-setup
thomheymann ba00e1e
Updated manual configuration form
thomheymann 3867ce6
Remove issuer link
thomheymann 9703fe0
Add tests for decode enrollment token
thomheymann a76873d
Removed unused class names
thomheymann 96a282d
fix issue where credentials got inherited from base config
thomheymann d0adcab
Added tooltips and text overflow
thomheymann dbc2cd1
styling fixes
thomheymann eabab62
refactored text truncate
thomheymann 180a0ab
Added unit tests
thomheymann 0ebb990
Merge branch 'master' of github.com:elastic/kibana into interactive-s…
thomheymann 6ee2096
added suggestions from code review
thomheymann 1fae7fc
Merge branch 'master' of github.com:elastic/kibana into interactive-s…
thomheymann a732fbb
Fixed typo and tests
thomheymann 1038b0c
Styling fixes
thomheymann 57d46be
Fix i18n errors
thomheymann bf97edc
Merge branch 'master' of github.com:elastic/kibana into interactive-s…
thomheymann b7b0837
Added suggestions from code review
thomheymann a67e2de
Added route tests
thomheymann f0f2aa2
Merge branch 'master' of github.com:elastic/kibana into interactive-s…
thomheymann a14c140
Explicit type exports
thomheymann d14ea4e
Fix server url
thomheymann 993c11c
Merge branch 'master' of github.com:elastic/kibana into interactive-s…
thomheymann bbb89d2
Added unit tests
thomheymann a45adb7
Merge branch 'master' of github.com:elastic/kibana into interactive-s…
thomheymann 0f25dc6
Added product not supported scenario
thomheymann 8e504ca
Merge branch 'master' of github.com:elastic/kibana into interactive-s…
thomheymann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,21 @@ | ||
.interactiveSetup { | ||
@include kibanaFullScreenGraphics; | ||
} | ||
|
||
.interactiveSetup__header { | ||
padding: $euiSizeXL; | ||
} | ||
|
||
.interactiveSetup__logo { | ||
@include kibanaCircleLogo; | ||
@include euiBottomShadowMedium; | ||
|
||
margin-bottom: $euiSizeXL; | ||
} | ||
|
||
.interactiveSetup__content { | ||
margin: auto; | ||
max-width: map-get($euiBreakpoints, 's') - $euiSizeXL; | ||
padding-left: $euiSizeXL; | ||
padding-right: $euiSizeXL; | ||
} | ||
thomheymann marked this conversation as resolved.
Show resolved
Hide resolved
|
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 |
---|---|---|
|
@@ -6,22 +6,78 @@ | |
* Side Public License, v 1. | ||
*/ | ||
|
||
import { EuiPageTemplate, EuiPanel, EuiText } from '@elastic/eui'; | ||
import React from 'react'; | ||
import './app.scss'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: not for this PR, just so that I don't forget about these two points we should do for alpha2:
|
||
|
||
import { EuiIcon, EuiPanel, EuiSpacer, EuiTitle } from '@elastic/eui'; | ||
import type { FunctionComponent } from 'react'; | ||
import React, { useState } from 'react'; | ||
|
||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
|
||
import { ClusterAddressForm } from './cluster_address_form'; | ||
import type { ClusterConfigurationFormProps } from './cluster_configuration_form'; | ||
import { ClusterConfigurationForm } from './cluster_configuration_form'; | ||
import { EnrollmentTokenForm } from './enrollment_token_form'; | ||
import { ProgressIndicator } from './progress_indicator'; | ||
|
||
export const App: FunctionComponent = () => { | ||
const [page, setPage] = useState<'token' | 'manual' | 'success'>('token'); | ||
const [cluster, setCluster] = useState< | ||
Omit<ClusterConfigurationFormProps, 'onCancel' | 'onSuccess'> | ||
>(); | ||
|
||
export const App = () => { | ||
return ( | ||
<EuiPageTemplate | ||
restrictWidth={false} | ||
template="empty" | ||
pageHeader={{ | ||
iconType: 'logoElastic', | ||
pageTitle: 'Welcome to Elastic', | ||
}} | ||
> | ||
<EuiPanel> | ||
<EuiText>Kibana server is not ready yet.</EuiText> | ||
</EuiPanel> | ||
</EuiPageTemplate> | ||
<div className="interactiveSetup"> | ||
<header className="interactiveSetup__header"> | ||
<div className="interactiveSetup__content eui-textCenter"> | ||
<EuiSpacer size="xxl" /> | ||
<span className="interactiveSetup__logo"> | ||
<EuiIcon type="logoElastic" size="xxl" /> | ||
</span> | ||
<EuiTitle size="m"> | ||
<h1> | ||
<FormattedMessage | ||
id="interactiveSetup.app.pageTitle" | ||
defaultMessage="Configure Elastic to get started" | ||
/> | ||
</h1> | ||
</EuiTitle> | ||
<EuiSpacer size="xl" /> | ||
</div> | ||
</header> | ||
<div className="interactiveSetup__content"> | ||
<EuiPanel paddingSize="l"> | ||
<div hidden={page !== 'token'}> | ||
thomheymann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<EnrollmentTokenForm | ||
onCancel={() => setPage('manual')} | ||
onSuccess={() => setPage('success')} | ||
/> | ||
</div> | ||
<div hidden={page !== 'manual'}> | ||
{cluster ? ( | ||
<ClusterConfigurationForm | ||
onCancel={() => setCluster(undefined)} | ||
onSuccess={() => setPage('success')} | ||
{...cluster} | ||
/> | ||
) : ( | ||
<ClusterAddressForm | ||
onCancel={() => setPage('token')} | ||
onSuccess={(result, values) => | ||
setCluster({ | ||
host: values.host, | ||
authRequired: result.statusCode === 401, | ||
certificateChain: result.certificateChain, | ||
}) | ||
} | ||
/> | ||
)} | ||
</div> | ||
{page === 'success' && ( | ||
<ProgressIndicator onSuccess={() => window.location.replace(window.location.href)} /> | ||
)} | ||
</EuiPanel> | ||
</div> | ||
</div> | ||
); | ||
}; |
68 changes: 68 additions & 0 deletions
68
src/plugins/interactive_setup/public/cluster_address_form.test.tsx
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,68 @@ | ||
/* | ||
* 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 { fireEvent, render, waitFor } from '@testing-library/react'; | ||
import React from 'react'; | ||
|
||
import { coreMock } from 'src/core/public/mocks'; | ||
|
||
import { ClusterAddressForm } from './cluster_address_form'; | ||
import { Providers } from './plugin'; | ||
|
||
jest.mock('@elastic/eui/lib/services/accessibility/html_id_generator', () => ({ | ||
htmlIdGenerator: () => () => `id-${Math.random()}`, | ||
})); | ||
azasypkin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
describe('ClusterAddressForm', () => { | ||
jest.setTimeout(20_000); | ||
|
||
it('calls enrollment API when submitting form', async () => { | ||
const coreStart = coreMock.createStart(); | ||
coreStart.http.post.mockResolvedValue({}); | ||
|
||
const onSuccess = jest.fn(); | ||
|
||
const { findByRole, findByLabelText } = render( | ||
<Providers http={coreStart.http}> | ||
<ClusterAddressForm onSuccess={onSuccess} /> | ||
</Providers> | ||
); | ||
fireEvent.change(await findByLabelText('Address'), { | ||
target: { value: 'https://localhost' }, | ||
}); | ||
fireEvent.click(await findByRole('button', { name: 'Check address', hidden: true })); | ||
|
||
await waitFor(() => { | ||
expect(coreStart.http.post).toHaveBeenLastCalledWith('/internal/interactive_setup/ping', { | ||
body: JSON.stringify({ | ||
hosts: ['https://localhost:9200'], | ||
}), | ||
}); | ||
expect(onSuccess).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
it('validates form', async () => { | ||
const coreStart = coreMock.createStart(); | ||
const onSuccess = jest.fn(); | ||
|
||
const { findAllByText, findByRole, findByLabelText } = render( | ||
<Providers http={coreStart.http}> | ||
<ClusterAddressForm onSuccess={onSuccess} /> | ||
</Providers> | ||
); | ||
|
||
fireEvent.change(await findByLabelText('Address'), { | ||
target: { value: 'localhost' }, | ||
}); | ||
|
||
fireEvent.click(await findByRole('button', { name: 'Check address', hidden: true })); | ||
|
||
await findAllByText(/Enter a valid address including protocol/i); | ||
thomheymann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
}); |
132 changes: 132 additions & 0 deletions
132
src/plugins/interactive_setup/public/cluster_address_form.tsx
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,132 @@ | ||
/* | ||
* 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, | ||
EuiButtonEmpty, | ||
EuiFieldText, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiForm, | ||
EuiFormRow, | ||
EuiSpacer, | ||
} from '@elastic/eui'; | ||
import type { FunctionComponent } from 'react'; | ||
import React from 'react'; | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
|
||
import type { PingResponse } from '../common'; | ||
import type { ValidationErrors } from './use_form'; | ||
import { useForm } from './use_form'; | ||
import { useHttp } from './use_http'; | ||
|
||
export interface ClusterAddressFormValues { | ||
host: string; | ||
} | ||
|
||
export interface ClusterAddressFormProps { | ||
defaultValues?: ClusterAddressFormValues; | ||
onCancel?(): void; | ||
onSuccess?(result: PingResponse, values: ClusterAddressFormValues): void; | ||
} | ||
|
||
export const ClusterAddressForm: FunctionComponent<ClusterAddressFormProps> = ({ | ||
defaultValues = { | ||
host: 'https://localhost:9200', | ||
}, | ||
onCancel, | ||
onSuccess, | ||
}) => { | ||
const http = useHttp(); | ||
|
||
const [form, eventHandlers] = useForm({ | ||
defaultValues, | ||
validate: async (values) => { | ||
const errors: ValidationErrors<typeof values> = {}; | ||
|
||
if (!values.host) { | ||
errors.host = i18n.translate('interactiveSetup.clusterAddressForm.hostRequiredError', { | ||
defaultMessage: 'Enter an address.', | ||
}); | ||
} else { | ||
try { | ||
const url = new URL(values.host); | ||
if (!url.protocol || !url.hostname) { | ||
throw new Error(); | ||
} | ||
} catch (error) { | ||
errors.host = i18n.translate('interactiveSetup.clusterAddressForm.hostInvalidError', { | ||
defaultMessage: 'Enter a valid address including protocol.', | ||
}); | ||
} | ||
} | ||
|
||
return errors; | ||
}, | ||
onSubmit: async (values) => { | ||
const url = new URL(values.host); | ||
const host = `${url.protocol}//${url.hostname}:${url.port || 9200}`; | ||
|
||
const result = await http.post<PingResponse>('/internal/interactive_setup/ping', { | ||
body: JSON.stringify({ | ||
hosts: [host], | ||
}), | ||
}); | ||
|
||
onSuccess?.(result, { host }); | ||
}, | ||
}); | ||
|
||
return ( | ||
<EuiForm component="form" noValidate {...eventHandlers}> | ||
<EuiFormRow | ||
label={i18n.translate('interactiveSetup.clusterAddressForm.hostLabel', { | ||
defaultMessage: 'Address', | ||
})} | ||
error={form.errors.host} | ||
isInvalid={form.touched.host && !!form.errors.host} | ||
fullWidth | ||
> | ||
<EuiFieldText | ||
name="host" | ||
value={form.values.host} | ||
isInvalid={form.touched.host && !!form.errors.host} | ||
fullWidth | ||
/> | ||
</EuiFormRow> | ||
<EuiSpacer /> | ||
|
||
<EuiFlexGroup responsive={false} justifyContent="flexEnd"> | ||
<EuiFlexItem grow={false}> | ||
<EuiButtonEmpty flush="right" iconType="arrowLeft" onClick={onCancel}> | ||
<FormattedMessage | ||
id="interactiveSetup.clusterAddressForm.cancelButton" | ||
defaultMessage="Back" | ||
/> | ||
</EuiButtonEmpty> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiButton | ||
type="submit" | ||
isLoading={form.isSubmitting} | ||
isDisabled={form.isSubmitted && form.isInvalid} | ||
fill | ||
> | ||
<FormattedMessage | ||
id="interactiveSetup.clusterAddressForm.validateButton" | ||
defaultMessage="{isSubmitting, select, true{Checking address…} other{Check address}}" | ||
values={{ isSubmitting: form.isSubmitting }} | ||
/> | ||
</EuiButton> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiForm> | ||
); | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bad merge:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need that there so that translations get picked up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thomheymann I meant that this is already defined below 🙂