Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions web/src/components/ConnectionStringFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ interface Props {
historyUrl?: string
/** Spark only: optional History Server platform token. */
historyPlatformToken?: string
/** Spark only: optional Worker UI publish link (the full `?_token=` link). */
workerUrl?: string
testState: ConnectionTestState
/** Error text of a failed test, shown verbatim unless it carries a translatable code. */
testError: string
Expand All @@ -38,6 +40,7 @@ interface Props {
onLivyPlatformTokenChange?: (token: string) => void
onHistoryUrlChange?: (url: string) => void
onHistoryPlatformTokenChange?: (token: string) => void
onWorkerUrlChange?: (url: string) => void
onTest: () => void
/**
* Editing a saved registration: the stored values never come back, so every field starts empty
Expand All @@ -56,6 +59,7 @@ type Field =
| 'livyPlatform'
| 'historyUrl'
| 'historyPlatform'
| 'workerUrl'

function RevealToggle({ revealed, label, onToggle }: { revealed: boolean; label: string; onToggle: () => void }) {
return (
Expand Down Expand Up @@ -88,6 +92,7 @@ export default function ConnectionStringFields({
livyPlatformToken = '',
historyUrl = '',
historyPlatformToken = '',
workerUrl = '',
testState,
testError,
testInfo,
Expand All @@ -100,6 +105,7 @@ export default function ConnectionStringFields({
onLivyPlatformTokenChange,
onHistoryUrlChange,
onHistoryPlatformTokenChange,
onWorkerUrlChange,
onTest,
editing = false,
}: Props) {
Expand All @@ -114,6 +120,7 @@ export default function ConnectionStringFields({
livyPlatform: false,
historyUrl: false,
historyPlatform: false,
workerUrl: false,
})
const toggle = (field: Field) => setRevealed((current) => ({ ...current, [field]: !current[field] }))
const testing = testState === 'testing'
Expand Down Expand Up @@ -395,6 +402,29 @@ export default function ConnectionStringFields({
{t('admin_db.history_pair_hint')}
</p>
)}

<div className="space-y-2 pt-1">
<label htmlFor="db-worker-url" className="label">
{t('admin_db.worker_url')}
</label>
<div className="relative">
<input
id="db-worker-url"
type={revealed.workerUrl ? 'text' : 'password'}
className="input pr-11 font-mono text-caption"
value={workerUrl}
onChange={(e) => onWorkerUrlChange?.(e.target.value)}
placeholder={t(editing ? 'admin_db.connection_unchanged' : 'admin_db.worker_url_placeholder')}
autoComplete="off"
spellCheck={false}
/>
<RevealToggle
revealed={revealed.workerUrl}
label={revealed.workerUrl ? t('admin_db.hide_connection_url') : t('admin_db.show_connection_url')}
onToggle={() => toggle('workerUrl')}
/>
</div>
</div>
</>
)}

Expand Down
9 changes: 9 additions & 0 deletions web/src/components/DatabaseForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export default function DatabaseForm({ mode, database, available, onSaved, onCan
const [livyPlatformToken, setLivyPlatformToken] = useState('')
const [historyUrl, setHistoryUrl] = useState('')
const [historyPlatformToken, setHistoryPlatformToken] = useState('')
const [workerUrl, setWorkerUrl] = useState('')
const [testState, setTestState] = useState<ConnectionTestState>('idle')
const [testedSignature, setTestedSignature] = useState<string | null>(null)
const [testError, setTestError] = useState('')
Expand Down Expand Up @@ -93,6 +94,7 @@ export default function DatabaseForm({ mode, database, available, onSaved, onCan
setLivyPlatformToken('')
setHistoryUrl('')
setHistoryPlatformToken('')
setWorkerUrl('')
invalidateTest()
setFormError('')
}
Expand Down Expand Up @@ -136,6 +138,10 @@ export default function DatabaseForm({ mode, database, available, onSaved, onCan
setHistoryPlatformToken(next)
}

function changeWorkerUrl(next: string) {
setWorkerUrl(next)
}

async function testConnection() {
if (testState === 'testing' || !isConnectionKind(activeKind)) return
const signature = connectionSignature({ kind: activeKind, url, platformToken, appToken })
Expand Down Expand Up @@ -174,6 +180,7 @@ export default function DatabaseForm({ mode, database, available, onSaved, onCan
livyPlatformToken,
historyUrl,
historyPlatformToken,
workerUrl,
}
const canSave = canSaveForm({
mode,
Expand Down Expand Up @@ -286,6 +293,7 @@ export default function DatabaseForm({ mode, database, available, onSaved, onCan
livyPlatformToken={livyPlatformToken}
historyUrl={historyUrl}
historyPlatformToken={historyPlatformToken}
workerUrl={workerUrl}
editing={editing}
testState={testState}
testError={testError}
Expand All @@ -299,6 +307,7 @@ export default function DatabaseForm({ mode, database, available, onSaved, onCan
onLivyPlatformTokenChange={changeLivyPlatformToken}
onHistoryUrlChange={changeHistoryUrl}
onHistoryPlatformTokenChange={changeHistoryPlatformToken}
onWorkerUrlChange={changeWorkerUrl}
onTest={testConnection}
/>
) : (
Expand Down
13 changes: 13 additions & 0 deletions web/src/lib/__tests__/connectionStringFields.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ describe('ConnectionStringFields', () => {
expect(html).toContain('id="db-history-platform-token" type="password"')
expect(html).toContain(t('admin_db.history_url'))
expect(html).toContain(t('admin_db.history_platform_token'))
// Worker UI publish link
expect(html).toContain('id="db-worker-url" type="password"')
expect(html).toContain(t('admin_db.worker_url'))
// No SQL connection-string copy leaks into the Spark form
expect(html).not.toContain(t('admin_db.connection_url_hint'))
expect(html).not.toContain('type="password" data-reveal')
Expand All @@ -79,12 +82,14 @@ describe('ConnectionStringFields', () => {
expect(pgHtml).not.toContain('id="db-spark-ui-platform-token"')
expect(pgHtml).not.toContain('id="db-history-url"')
expect(pgHtml).not.toContain('id="db-history-platform-token"')
expect(pgHtml).not.toContain('id="db-worker-url"')

const mysqlHtml = render({ kind: 'mysql', url: 'mysql://u:p@host/db' })
expect(mysqlHtml).not.toContain('id="db-spark-ui-url"')
expect(mysqlHtml).not.toContain('id="db-spark-ui-platform-token"')
expect(mysqlHtml).not.toContain('id="db-history-url"')
expect(mysqlHtml).not.toContain('id="db-history-platform-token"')
expect(mysqlHtml).not.toContain('id="db-worker-url"')
})

it('masks the Spark UI publish address in edit mode and offers a reveal toggle', () => {
Expand All @@ -93,6 +98,14 @@ describe('ConnectionStringFields', () => {
expect(html).toContain('id="db-spark-ui-platform-token" type="password"')
expect(html).toContain('id="db-history-url" type="password"')
expect(html).toContain('id="db-history-platform-token" type="password"')
expect(html).toContain('id="db-worker-url" type="password"')
})

it('masks the Worker UI publish link because it carries the token', () => {
const html = render({ kind: 'spark', workerUrl: 'https://worker-ui.example.com/?_token=secret' })
expect(html).toContain('id="db-worker-url" type="password"')
expect(html).toContain(t('admin_db.show_connection_url'))
expect(html).toContain(t('admin_db.worker_url'))
})

it('shows pair validation alert only when exactly one History Server field is filled', () => {
Expand Down
41 changes: 41 additions & 0 deletions web/src/lib/__tests__/databaseForm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
sparkLivyTouched,
sparkUiPairValid,
sparkUiTouched,
workerUrlTouched,
} from '../database-form'
import { connectionSignature } from '../connection-string'

Expand Down Expand Up @@ -63,6 +64,17 @@ describe('sparkHistoryTouched', () => {
})
})

describe('workerUrlTouched', () => {
it('is false while the publish link stays blank', () => {
expect(workerUrlTouched(untouched)).toBe(false)
expect(workerUrlTouched({ ...untouched, workerUrl: ' ' })).toBe(false)
})

it('is true once the publish link has text', () => {
expect(workerUrlTouched({ ...untouched, workerUrl: 'https://worker-ui.example.com/?_token=t' })).toBe(true)
})
})

describe('sparkUiPairValid', () => {
it('is true when both are empty or undefined', () => {
expect(sparkUiPairValid()).toBe(true)
Expand Down Expand Up @@ -484,6 +496,35 @@ describe('connectionPatch', () => {
})
).toBe(null)
})

it('includes the trimmed Worker UI publish link when present', () => {
expect(
connectionPatch('spark', {
url: 'https://spark.example.com',
platformToken: 'p',
appToken: 'a',
workerUrl: ' https://worker-ui.example.com/?_token=t ',
})
).toEqual({
connection_url: 'https://spark.example.com',
platform_token: 'p',
app_token: 'a',
worker_ui_url: 'https://worker-ui.example.com/?_token=t',
})
})

it('sends only the Worker UI publish link in edit mode when the connection is untouched', () => {
expect(
connectionPatch('spark', {
url: '',
platformToken: '',
appToken: '',
workerUrl: 'https://worker-ui.example.com/?_token=t',
})
).toEqual({
worker_ui_url: 'https://worker-ui.example.com/?_token=t',
})
})
})

describe('providerPrefill', () => {
Expand Down
2 changes: 2 additions & 0 deletions web/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ export const adminApi = {
livy_platform_token?: string
history_url?: string
history_platform_token?: string
worker_ui_url?: string
cf_database_id?: string
name?: string
description?: string
Expand All @@ -533,6 +534,7 @@ export const adminApi = {
livy_platform_token?: string
history_url?: string
history_platform_token?: string
worker_ui_url?: string
}
) => apiFetch<{ message: string }>(`/admin/databases/${id}`, { method: 'PATCH', body: JSON.stringify(body) }),
deleteDatabase: (id: string) => apiFetch<{ message: string }>(`/admin/databases/${id}`, { method: 'DELETE' }),
Expand Down
22 changes: 18 additions & 4 deletions web/src/lib/database-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export interface ConnectionValues {
historyUrl?: string
/** Spark only: optional History Server platform token. */
historyPlatformToken?: string
/** Spark only: optional Worker UI publish link (the full `?_token=` link; the worker splits it). */
workerUrl?: string
}

/**
Expand Down Expand Up @@ -63,6 +65,11 @@ export function sparkHistoryTouched(values: ConnectionValues): boolean {
return [values.historyUrl, values.historyPlatformToken].some((v) => (v?.trim() ?? '') !== '')
}

/** Whether the admin typed the Worker UI publish link. */
export function workerUrlTouched(values: ConnectionValues): boolean {
return (values.workerUrl?.trim() ?? '') !== ''
}

/**
* Spark UI publish address and platform token travel as a pair: both filled, or both left blank.
* Filling only one is an incomplete pair that the server refuses with 400.
Expand Down Expand Up @@ -141,21 +148,24 @@ export interface ConnectionPatch {
livy_platform_token?: string
history_url?: string
history_platform_token?: string
worker_ui_url?: string
}

/**
* The connection part of an edit's PATCH body, or null when every field was left blank (the stored
* registration stays as it is). Spark's three connection values travel as one group, and its two
* optional UI values travel as another group; a partial fill in either group yields null — the form's
* gate already refuses to save that.
* registration stays as it is). Spark's three connection values travel as one group, each optional
* UI endpoint (Spark UI, Livy, History Server) travels as its own URL/token pair, and the Worker UI
* travels as a single publish link; a partial fill yields null — the form's gate already refuses to
* save that.
*/
export function connectionPatch(kind: ConnectionKind, values: ConnectionValues): ConnectionPatch | null {
const touched = connectionTouched(values)
const uiTouched = kind === 'spark' && sparkUiTouched(values)
const livyTouched = kind === 'spark' && sparkLivyTouched(values)
const historyTouched = kind === 'spark' && sparkHistoryTouched(values)
const workerTouched = kind === 'spark' && workerUrlTouched(values)

if (!touched && !uiTouched && !livyTouched && !historyTouched) return null
if (!touched && !uiTouched && !livyTouched && !historyTouched && !workerTouched) return null
if (touched && connectionSignature({ kind, ...values }) === null) return null
if (uiTouched && !sparkUiPairValid(values.uiUrl, values.uiPlatformToken)) return null
if (livyTouched && !sparkLivyPairValid(values.livyUrl, values.livyPlatformToken)) return null
Expand Down Expand Up @@ -186,5 +196,9 @@ export function connectionPatch(kind: ConnectionKind, values: ConnectionValues):
result.history_platform_token = values.historyPlatformToken.trim()
}

if (workerTouched && values.workerUrl) {
result.worker_ui_url = values.workerUrl.trim()
}

return result
}
4 changes: 4 additions & 0 deletions web/src/lib/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ export const translations: Record<Locale, Record<string, string>> = {
'admin_db.history_url_placeholder': 'https://your-history-server.example.com',
'admin_db.history_platform_token': 'History Server platform token',
'admin_db.history_pair_hint': 'History Server publish address and platform token must both be provided.',
'admin_db.worker_url': 'Worker UI publish link',
'admin_db.worker_url_placeholder': 'https://your-worker-ui.example.com/?_token=…',
'admin_db.register_title_spark': 'Register a SparkSQL data source',
'admin_db.register_desc_spark':
'The whole SparkSQL service is one data source. Paste its publish address and the two tokens; it is tested live before it is stored, and a failed test saves nothing.',
Expand Down Expand Up @@ -920,6 +922,8 @@ export const translations: Record<Locale, Record<string, string>> = {
'admin_db.history_url_placeholder': 'https://你的-history-server-服务地址',
'admin_db.history_platform_token': 'History Server 平台令牌',
'admin_db.history_pair_hint': 'History Server 发布地址与平台令牌需同时填写。',
'admin_db.worker_url': 'Worker UI 发布链接',
'admin_db.worker_url_placeholder': 'https://你的-worker-ui-服务地址/?_token=…',
'admin_db.register_title_spark': '登记 SparkSQL 数据源',
'admin_db.register_desc_spark':
'整个 SparkSQL 服务就是一个数据源。粘贴发布地址与两枚令牌,保存前会实连测试一次,测试不通过不会落库。',
Expand Down
2 changes: 2 additions & 0 deletions web/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface Database {
has_spark_ui?: boolean
has_livy?: boolean
has_history_server?: boolean
has_worker_ui?: boolean
}

// A registered database as the admin API returns it
Expand All @@ -52,6 +53,7 @@ export interface AdminDatabase {
has_spark_ui?: boolean
has_livy?: boolean
has_history_server?: boolean
has_worker_ui?: boolean
}

export interface LivyBatch {
Expand Down