-
Notifications
You must be signed in to change notification settings - Fork 553
feat: clickhouse warehouse setup UI #8028
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
92ae9bf
feat: ClickHouse warehouse connection types in frontend API layer
Zaimwa9 323e01e
feat: ClickHouse warehouse config form
Zaimwa9 592773c
feat: ClickHouse warehouse setup flow behind clickhouse_warehouse flag
Zaimwa9 438e82e
feat: surface warehouse connection status detail in the frontend
Zaimwa9 3153113
fix: address review feedback on warehouse frontend
Zaimwa9 1f9edaa
feat: test ClickHouse connection before saving warehouse config
Zaimwa9 42149a9
feat: allow saving warehouse config after failed connection test
Zaimwa9 8f27c08
fix: address warehouse form review feedback
Zaimwa9 0a8a2d3
fix: toast warehouse test results and align inline messages under but…
Zaimwa9 78816ff
fix: always show test connection button on warehouse form
Zaimwa9 5594d21
fix: discard stale warehouse test results and terminal punctuation edge
Zaimwa9 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 hidden or 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 hidden or 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 hidden or 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
280 changes: 280 additions & 0 deletions
280
...end/web/components/pages/environment-settings/tabs/warehouse-tab/ClickHouseConfigForm.tsx
This file contains hidden or 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,280 @@ | ||
| import React, { FC, useRef, useState } from 'react' | ||
| import Button from 'components/base/forms/Button' | ||
| import Input from 'components/base/forms/Input' | ||
| import Switch from 'components/Switch' | ||
| import ErrorMessage from 'components/ErrorMessage' | ||
| import WarningMessage from 'components/WarningMessage' | ||
| import { ClickHouseConfig } from 'common/types/responses' | ||
| import { useTestWarehouseConnectionConfigMutation } from 'common/services/useWarehouseConnection' | ||
| import { | ||
| buildClickHousePayload, | ||
| canTestClickHouseConnection, | ||
| CLICKHOUSE_DEFAULTS, | ||
| ClickHouseFormData, | ||
| ClickHouseFormState, | ||
| isClickHouseConfigDirty, | ||
| isClickHouseFormValid, | ||
| } from './clickhouseConfig' | ||
| import { | ||
| getButtonLabel, | ||
| getTestFailureWarning, | ||
| getWarehouseErrorMessage, | ||
| } from './warehouseFormUtils' | ||
| import './ConfigForm.scss' | ||
|
|
||
| type ClickHouseConfigFormProps = { | ||
| environmentId: string | ||
| onSave: (data: ClickHouseFormData) => Promise<unknown> | ||
| onCancel?: () => void | ||
| isEdit?: boolean | ||
| initialConfig?: ClickHouseConfig | ||
| initialName?: string | ||
| } | ||
|
|
||
| type TestState = 'idle' | 'connected' | 'errored' | ||
|
|
||
| const ClickHouseConfigForm: FC<ClickHouseConfigFormProps> = ({ | ||
| environmentId, | ||
| initialConfig, | ||
| initialName = '', | ||
| isEdit = false, | ||
| onCancel, | ||
| onSave, | ||
| }) => { | ||
| const defaults = { ...CLICKHOUSE_DEFAULTS, ...initialConfig } | ||
| const [name, setName] = useState(initialName) | ||
| const [host, setHost] = useState(defaults.host) | ||
| const [port, setPort] = useState(String(defaults.port)) | ||
| const [database, setDatabase] = useState(defaults.database) | ||
| const [username, setUsername] = useState(defaults.username) | ||
| const [password, setPassword] = useState('') | ||
| const [secure, setSecure] = useState(defaults.secure) | ||
| const [isSaving, setIsSaving] = useState(false) | ||
| const [error, setError] = useState(false) | ||
| const [testState, setTestState] = useState<TestState>('idle') | ||
| const [testDetail, setTestDetail] = useState<string | null>(null) | ||
| const testRevision = useRef(0) | ||
|
|
||
| const [testConnectionConfig, { isLoading: isTesting }] = | ||
| useTestWarehouseConnectionConfigMutation() | ||
|
|
||
| const form: ClickHouseFormState = { | ||
| database, | ||
| host, | ||
| name, | ||
| password, | ||
| port, | ||
| secure, | ||
| username, | ||
| } | ||
| const isValid = isClickHouseFormValid(form, isEdit) | ||
| const requiresTest = !isEdit || isClickHouseConfigDirty(form, initialConfig) | ||
| const canTest = canTestClickHouseConnection(form) | ||
| const canSave = isValid && (!requiresTest || testState !== 'idle') | ||
|
|
||
| const setField = | ||
| <T,>(setter: (value: T) => void) => | ||
| (value: T) => { | ||
| setter(value) | ||
| testRevision.current += 1 | ||
| setTestState('idle') | ||
| setTestDetail(null) | ||
| } | ||
|
|
||
| const handleTest = async () => { | ||
| if (!canTest || isTesting) return | ||
| setError(false) | ||
| const revision = testRevision.current | ||
| try { | ||
| const { config, credentials } = buildClickHousePayload(form) | ||
| const result = await testConnectionConfig({ | ||
| config, | ||
| credentials, | ||
| environmentId, | ||
| warehouse_type: 'clickhouse', | ||
| }).unwrap() | ||
| if (revision !== testRevision.current) return | ||
| if (result.status === 'connected') { | ||
| setTestState('connected') | ||
| setTestDetail(null) | ||
| toast('Connection verified') | ||
| } else { | ||
| setTestState('errored') | ||
| setTestDetail(result.status_detail) | ||
| toast( | ||
| result.status_detail || 'Connection failed — check your credentials', | ||
| 'danger', | ||
| ) | ||
| } | ||
| } catch { | ||
| if (revision !== testRevision.current) return | ||
| setTestState('errored') | ||
| setTestDetail(null) | ||
| toast('Failed to test connection', 'danger') | ||
| } | ||
| } | ||
|
|
||
| const handleSubmit = async (e: React.FormEvent) => { | ||
| e.preventDefault() | ||
| if (!canSave || isSaving) return | ||
|
|
||
| setIsSaving(true) | ||
| setError(false) | ||
| try { | ||
| await onSave(buildClickHousePayload(form)) | ||
| } catch { | ||
| setError(true) | ||
| setIsSaving(false) | ||
| } | ||
| } | ||
|
|
||
| return ( | ||
| <form onSubmit={handleSubmit} className='wh-config-form'> | ||
| <div className='wh-config-form__card'> | ||
| <div className='wh-config-form__field'> | ||
| <label className='wh-config-form__label'>Host</label> | ||
| <Input | ||
| value={host} | ||
| onChange={(e: React.ChangeEvent<HTMLInputElement>) => | ||
| setField(setHost)(e.target.value) | ||
| } | ||
| placeholder='your-instance.clickhouse.cloud' | ||
| disabled={isEdit} | ||
| /> | ||
| <span className='wh-config-form__hint'> | ||
| {isEdit | ||
| ? "Host can't be changed. To use a different ClickHouse instance, disconnect and create a new connection." | ||
| : 'The hostname of your ClickHouse instance, without protocol or port.'} | ||
| </span> | ||
| </div> | ||
|
|
||
| <div className='wh-config-form__field'> | ||
| <label className='wh-config-form__label'>Name</label> | ||
| <Input | ||
| value={name} | ||
| onChange={(e: React.ChangeEvent<HTMLInputElement>) => | ||
| setName(e.target.value) | ||
| } | ||
| placeholder='e.g. Production ClickHouse' | ||
| /> | ||
| </div> | ||
|
|
||
| <div className='wh-config-form__row'> | ||
| <div className='wh-config-form__field'> | ||
| <label className='wh-config-form__label'>Port</label> | ||
| <Input | ||
| value={port} | ||
| onChange={(e: React.ChangeEvent<HTMLInputElement>) => | ||
| setField(setPort)(e.target.value) | ||
| } | ||
| placeholder='9440' | ||
| /> | ||
| </div> | ||
| <div className='wh-config-form__field'> | ||
| <label className='wh-config-form__label'>Database</label> | ||
| <Input | ||
| value={database} | ||
| onChange={(e: React.ChangeEvent<HTMLInputElement>) => | ||
| setField(setDatabase)(e.target.value) | ||
| } | ||
| placeholder='flagsmith' | ||
| /> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div className='wh-config-form__field'> | ||
| <label className='wh-config-form__label'>Username</label> | ||
| <Input | ||
| value={username} | ||
| onChange={(e: React.ChangeEvent<HTMLInputElement>) => | ||
| setField(setUsername)(e.target.value) | ||
| } | ||
| placeholder='default' | ||
| /> | ||
| </div> | ||
|
|
||
| <div className='wh-config-form__field'> | ||
| <label className='wh-config-form__label'>Password</label> | ||
| <Input | ||
| value={password} | ||
| onChange={(e: React.ChangeEvent<HTMLInputElement>) => | ||
| setField(setPassword)(e.target.value) | ||
| } | ||
| type='password' | ||
| placeholder={isEdit ? '••••••••' : 'Password'} | ||
| /> | ||
| {isEdit && ( | ||
| <span className='wh-config-form__hint'> | ||
| {requiresTest && !password | ||
| ? 'Enter your password to test the connection before saving.' | ||
| : 'Leave blank to keep the current password.'} | ||
| </span> | ||
| )} | ||
| </div> | ||
|
|
||
| <div className='wh-config-form__field'> | ||
| <div className='d-flex flex-row align-items-center gap-2'> | ||
| <Switch checked={secure} onChange={setField(setSecure)} /> | ||
| <label className='wh-config-form__label mb-0'> | ||
| Secure connection (TLS) | ||
| </label> | ||
| </div> | ||
| </div> | ||
|
|
||
| {error && <ErrorMessage error={getWarehouseErrorMessage(isEdit)} />} | ||
|
|
||
| <div className='wh-config-form__actions'> | ||
| {isEdit && onCancel && ( | ||
| <Button | ||
| id='warehouse-config-cancel' | ||
| theme='outline' | ||
| size='small' | ||
| onClick={onCancel} | ||
| type='button' | ||
| > | ||
| Cancel | ||
| </Button> | ||
| )} | ||
| <Button | ||
| id='warehouse-config-test' | ||
| theme='outline' | ||
| size='small' | ||
| type='button' | ||
| onClick={handleTest} | ||
| disabled={!requiresTest || !canTest || isTesting} | ||
| > | ||
| {isTesting ? 'Testing...' : 'Test connection'} | ||
| </Button> | ||
| <Button | ||
| id='warehouse-config-save' | ||
| theme='primary' | ||
| size='small' | ||
| type='submit' | ||
| disabled={isSaving || !canSave} | ||
| > | ||
| {getButtonLabel(isEdit, isSaving)} | ||
| </Button> | ||
| </div> | ||
|
|
||
| {testState === 'connected' && ( | ||
| <div className='d-flex justify-content-end'> | ||
| <span className='wh-config-form__hint text-success'> | ||
| Connection verified. You can now save. | ||
| </span> | ||
| </div> | ||
| )} | ||
| {testState === 'errored' && ( | ||
| <div className='d-flex justify-content-end'> | ||
| <WarningMessage | ||
| warningMessage={getTestFailureWarning(testDetail)} | ||
| warningMessageClass='mb-0' | ||
| /> | ||
| </div> | ||
| )} | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| </div> | ||
| </form> | ||
| ) | ||
| } | ||
|
|
||
| ClickHouseConfigForm.displayName = 'ClickHouseConfigForm' | ||
| export default ClickHouseConfigForm | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.