Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: optimize instance form ui

ecmadaoa0715ccb0079
diff --git a/frontend/src/components/instance/DataSourceForm.test.ts b/frontend/src/components/instance/DataSourceForm.test.ts
index 64ad12e0d0..9b02fb554f 100644
--- a/frontend/src/components/instance/DataSourceForm.test.ts
+++ b/frontend/src/components/instance/DataSourceForm.test.ts
@@ -38,11 +38,51 @@ describe("DataSourceForm password sources", () => {
const form = source();
const sourceIndex = form.indexOf("{passwordSourceControl}");
const inputIndex = form.indexOf('type="password"', sourceIndex);
- const storedHintIndex = form.indexOf("stored-in-bytebase");
expect(sourceIndex).toBeGreaterThan(0);
expect(inputIndex).toBeGreaterThan(sourceIndex);
- expect(storedHintIndex).toBeGreaterThan(sourceIndex);
+ });
+
+ test("places the Bytebase password storage hint below the password title", () => {
+ const form = source();
+ const plainPasswordIndex = form.indexOf("/* Plain password */");
+ const storedHintIndex = form.indexOf(
+ "instance.password-source.stored-in-bytebase",
+ plainPasswordIndex
+ );
+ const passwordInputIndex = form.indexOf(
+ 'type="password"',
+ plainPasswordIndex
+ );
+
+ expect(plainPasswordIndex).toBeGreaterThan(0);
+ expect(storedHintIndex).toBeGreaterThan(plainPasswordIndex);
+ expect(storedHintIndex).toBeLessThan(passwordInputIndex);
+ expect(form.slice(storedHintIndex - 100, storedHintIndex)).toContain(
+ "description={"
+ );
+ });
+
+ test("places external secret documentation below the source title", () => {
+ const form = source();
+ const externalSecretFieldIndex = form.indexOf(
+ "/* External secret fields */"
+ );
+ const passwordSourceControlIndex = form.indexOf(
+ "{passwordSourceControl}",
+ externalSecretFieldIndex
+ );
+ const learnMoreIndex = form.indexOf(
+ "<LearnMoreLink",
+ externalSecretFieldIndex
+ );
+
+ expect(externalSecretFieldIndex).toBeGreaterThan(0);
+ expect(learnMoreIndex).toBeGreaterThan(externalSecretFieldIndex);
+ expect(learnMoreIndex).toBeLessThan(passwordSourceControlIndex);
+ expect(form.slice(learnMoreIndex - 100, learnMoreIndex)).toContain(
+ "description={"
+ );
});
});
@@ -61,3 +101,21 @@ describe("DataSourceForm connection information buttons", () => {
expect(form).toContain('onOpenInfoPanel("ssh")');
});
});
+
+describe("DataSourceForm extra parameters", () => {
+ test("uses the same action width for add and remove rows", () => {
+ const extraParameters = source().slice(
+ source().indexOf("/* Extra connection parameters */")
+ );
+
+ expect(extraParameters.match(/className="w-24 shrink-0"/g)).toHaveLength(2);
+ });
+});
+
+describe("DataSourceForm layout", () => {
+ test("uses a 24px rhythm between connection fields", () => {
+ expect(source()).toContain(
+ 'className="grid grid-cols-1 gap-y-6 gap-x-4 border-none sm:grid-cols-3"'
+ );
+ });
+});
diff --git a/frontend/src/components/instance/DataSourceForm.tsx b/frontend/src/components/instance/DataSourceForm.tsx
index 88d1f3509a..52da263cf5 100644
--- a/frontend/src/components/instance/DataSourceForm.tsx
+++ b/frontend/src/components/instance/DataSourceForm.tsx
@@ -858,7 +858,7 @@ export function DataSourceForm({
return (
<ValidationProvider
- className="grid grid-cols-1 gap-y-4 gap-x-4 border-none sm:grid-cols-3"
+ className="grid grid-cols-1 gap-y-6 gap-x-4 border-none sm:grid-cols-3"
errors={ctx.getDataSourceErrors(dataSource)}
>
{authOnly
@@ -1169,7 +1169,7 @@ export function DataSourceForm({
type="button"
appearance="link"
size="xs"
- className="w-6 shrink-0 p-0"
+ className="h-auto shrink-0 p-0"
aria-label={t("instance.authentication")}
onClick={() =>
onOpenInfoPanel("authentication")
@@ -1239,7 +1239,12 @@ export function DataSourceForm({
{/* Plain password */}
{passwordType ===
DataSourceExternalSecret_SecretType.SECRET_TYPE_UNSPECIFIED && (
- <FormField title={<>{t("common.password")}</>}>
+ <FormField
+ title={<>{t("common.password")}</>}
+ description={t(
+ "instance.password-source.stored-in-bytebase"
+ )}
+ >
<div>
{!isCreating && allowUsingEmptyPassword && (
<label className="flex items-center gap-x-1.5 mb-2 text-sm cursor-pointer">
@@ -1281,11 +1286,6 @@ export function DataSourceForm({
}
/>
</div>
- <p className="text-xs leading-4 text-control-light">
- {t(
- "instance.password-source.stored-in-bytebase"
- )}
- </p>
</div>
</FormField>
)}
@@ -1301,14 +1301,14 @@ export function DataSourceForm({
(item) => item.value === passwordType
)?.label
}
- >
- <div className="flex flex-wrap items-center gap-2">
- {passwordSourceControl}
+ description={
<LearnMoreLink
href="https://docs.bytebase.com/get-started/connect/overview#secret-manager-integration"
className="text-sm text-accent"
/>
- </div>
+ }
+ >
+ {passwordSourceControl}
<ResponsiveFormLayout className="mt-2">
<fieldset
className="flex flex-col gap-4 rounded-xs border border-control-border px-3 py-2"
@@ -2171,14 +2171,14 @@ export function DataSourceForm({
<FormField
className="sm:col-span-3 sm:col-start-1"
title={
- <span className="flex items-center justify-start gap-x-2">
+ <span className="flex items-center justify-start gap-x-1">
{t("data-source.ssl.connection-security")}
{onOpenInfoPanel && hasSslInfo && (
<Button
type="button"
appearance="link"
size="xs"
- className="w-6 shrink-0 p-0"
+ className="h-auto shrink-0 p-0"
aria-label={t("data-source.ssl.connection-security")}
onClick={() => onOpenInfoPanel("ssl")}
>
@@ -2307,7 +2307,7 @@ export function DataSourceForm({
type="button"
appearance="link"
size="xs"
- className="w-6 shrink-0 p-0"
+ className="h-auto shrink-0 p-0"
aria-label={t("data-source.ssh-connection")}
onClick={() => onOpenInfoPanel("ssh")}
>
@@ -2325,105 +2325,120 @@ export function DataSourceForm({
)}
{/* Extra connection parameters */}
- {hasExtraParameters &&
- (showExtraParameters || extraConnectionParamsList.length > 0 ? (
- <FormField
- className="sm:col-span-3 sm:col-start-1"
- title={t("data-source.extra-params.self")}
- description={t("data-source.extra-params.description")}
- >
- <FormControlGroup className="mt-2">
- {allowEdit && (
- <FormControlRow>
- <Input
- value={newParamKey}
- className="min-w-0 flex-1"
- aria-label={t("instance.parameter-name-placeholder")}
- placeholder={t("instance.parameter-name-placeholder")}
- onChange={(e) => setNewParamKey(e.target.value)}
- />
- <Input
- value={newParamValue}
- className="min-w-0 flex-1"
- aria-label={t("instance.parameter-value-placeholder")}
- placeholder={t("instance.parameter-value-placeholder")}
- onChange={(e) => setNewParamValue(e.target.value)}
- />
- <Button
- appearance="outline"
- className="shrink-0"
- disabled={!newParamKey.trim()}
- onClick={addNewParameter}
- >
- {t("common.add")}
- </Button>
- </FormControlRow>
- )}
-
- {extraConnectionParamsList.map((param, index) => (
- <FormField
- key={param.key}
- validationField={`extraConnectionParameters.${param.key}`}
- showErrors
- >
+ {hasExtraParameters && (
+ <FormField
+ className="sm:col-span-3 sm:col-start-1"
+ title={t("data-source.extra-params.self")}
+ description={t("data-source.extra-params.description")}
+ >
+ {showExtraParameters || extraConnectionParamsList.length > 0 ? (
+ <>
+ <FormControlGroup className="mt-2">
+ {allowEdit && (
<FormControlRow>
<Input
+ value={newParamKey}
className="min-w-0 flex-1"
- value={param.key}
- disabled={!allowEdit}
aria-label={t("instance.parameter-name-placeholder")}
placeholder={t("instance.parameter-name-placeholder")}
- onChange={(e) =>
- updateExtraConnectionParamKey(index, e.target.value)
- }
+ onChange={(e) => setNewParamKey(e.target.value)}
/>
<Input
+ value={newParamValue}
className="min-w-0 flex-1"
- value={param.value}
- disabled={!allowEdit}
aria-label={t("instance.parameter-value-placeholder")}
placeholder={t(
"instance.parameter-value-placeholder"
)}
- onChange={(e) =>
- updateExtraConnectionParamValue(
- index,
- e.target.value
- )
- }
+ onChange={(e) => setNewParamValue(e.target.value)}
/>
- {allowEdit && (
- <Button
- variant="destructive"
- className="shrink-0"
- onClick={() => removeExtraConnectionParam(index)}
- >
- {t("common.remove")}
- </Button>
- )}
+ <Button
+ appearance="outline"
+ className="w-24 shrink-0"
+ disabled={!newParamKey.trim()}
+ onClick={addNewParameter}
+ >
+ {t("common.add")}
+ </Button>
</FormControlRow>
- </FormField>
- ))}
- </FormControlGroup>
-
- {extraConnectionParamsList.length === 0 && (
- <div className="textinfolabel text-sm italic mt-2">
- {allowEdit
- ? t("instance.no-params-yet-add-above")
- : t("instance.no-extra-params-configured")}
- </div>
- )}
- </FormField>
- ) : (
- <Button
- appearance="link"
- className="justify-start sm:col-span-3"
- onClick={() => setShowExtraParameters(true)}
- disabled={!allowEdit}
- >
- {t("instance.add-parameter")}
- </Button>
- ))}
+ )}
+
+ {extraConnectionParamsList.map((param, index) => (
+ <FormField
+ key={param.key}
+ validationField={`extraConnectionParameters.${param.key}`}
+ showErrors
+ >
+ <FormControlRow>
+ <Input
+ className="min-w-0 flex-1"
+ value={param.key}
+ disabled={!allowEdit}
+ aria-label={t(
+ "instance.parameter-name-placeholder"
+ )}
+ placeholder={t(
+ "instance.parameter-name-placeholder"
+ )}
+ onChange={(e) =>
+ updateExtraConnectionParamKey(
+ index,
+ e.target.value
+ )
+ }
+ />
+ <Input
+ className="min-w-0 flex-1"
+ value={param.value}
+ disabled={!allowEdit}
+ aria-label={t(
+ "instance.parameter-value-placeholder"
+ )}
+ placeholder={t(
+ "instance.parameter-value-placeholder"
+ )}
+ onChange={(e) =>
+ updateExtraConnectionParamValue(
+ index,
+ e.target.value
+ )
+ }
+ />
+ {allowEdit && (
+ <Button
+ variant="destructive"
+ className="w-24 shrink-0"
+ onClick={() => removeExtraConnectionParam(index)}
+ >
+ {t("common.remove")}
+ </Button>
+ )}
+ </FormControlRow>
+ </FormField>
+ ))}
+ </FormControlGroup>
+
+ {extraConnectionParamsList.length === 0 && (
+ <div className="textinfolabel text-sm italic mt-2">
+ {allowEdit
+ ? t("instance.no-params-yet-add-above")
+ : t("instance.no-extra-params-configured")}
+ </div>
+ )}
+ </>
+ ) : (
+ <Button
+ appearance="link"
+ size="sm"
+ className="self-start"
+ onClick={() => setShowExtraParameters(true)}
+ disabled={!allowEdit}
+ >
+ {t("instance.add-parameter")}
+ </Button>
+ )}
+ </FormField>
+ )}
</>
)}
</ValidationProvider>
diff --git a/frontend/src/components/instance/InstanceFormBody.test.ts b/frontend/src/components/instance/InstanceFormBody.test.ts
index ff83155ff7..19533258e3 100644
--- a/frontend/src/components/instance/InstanceFormBody.test.ts
+++ b/frontend/src/components/instance/InstanceFormBody.test.ts
@@ -199,6 +199,16 @@ describe("InstanceFormBody", () => {
expect(source).toContain(
'href="https://docs.bytebase.com/get-started/cloud#prerequisites"'
);
+
+ const firewallAlert = source.slice(
+ firewallAlertIndex,
+ source.indexOf("</Alert>", firewallAlertIndex)
+ );
+ expect(firewallAlert).toContain(
+ '<span>{t("instance.sentence.firewall-info")}</span>'
+ );
+ expect(firewallAlert).toContain("<LearnMoreLink");
+ expect(firewallAlert).not.toContain("<a");
});
test("keeps Docker-only host suggestions out of Bytebase Cloud", () => {
diff --git a/frontend/src/components/instance/InstanceFormBody.tsx b/frontend/src/components/instance/InstanceFormBody.tsx
index f04fe47c63..a6bc282470 100644
--- a/frontend/src/components/instance/InstanceFormBody.tsx
+++ b/frontend/src/components/instance/InstanceFormBody.tsx
@@ -628,7 +628,7 @@ export function SyncDatabases({
type="button"
appearance="link"
size="xs"
- className="w-6 shrink-0 p-0"
+ className="h-auto shrink-0 p-0"
aria-label={t("instance.sync-databases.self")}
onClick={() => onOpenInfoPanel("sync-databases")}
>
@@ -1453,14 +1453,10 @@ export function InstanceFormBody({ onOpenInfoPanel }: InstanceFormBodyProps) {
<div className="flex flex-col gap-4">
{isSaaSMode && (
<Alert variant="info">
- <a
- href="https://docs.bytebase.com/get-started/cloud#prerequisites"
- target="_blank"
- rel="noopener noreferrer"
- className="normal-link"
- >
- {t("instance.sentence.firewall-info")}
- </a>
+ <div className="flex flex-wrap items-center gap-x-2">
+ <span>{t("instance.sentence.firewall-info")}</span>
+ <LearnMoreLink href="https://docs.bytebase.com/get-started/cloud#prerequisites" />
+ </div>
</Alert>
)}
{editingDataSource?.id === adminDataSource.id && (
diff --git a/frontend/src/components/instance/InstanceFormContext.test.tsx b/frontend/src/components/instance/InstanceFormContext.test.tsx
index 49f547369a..940d5736a7 100644
--- a/frontend/src/components/instance/InstanceFormContext.test.tsx
+++ b/frontend/src/components/instance/InstanceFormContext.test.tsx
@@ -956,6 +956,85 @@ describe("InstanceFormProvider", () => {
}
);
+ test("places add parameter in the extra parameters form field", async () => {
+ mocks.hasExtraParameters = true;
+ const { DataSourceForm } = await vi.importActual<
+ typeof import("./DataSourceForm")
+ >("./DataSourceForm");
+ const Editor = () => {
+ const context = useInstanceFormContext();
+ return (
+ <DataSourceForm
+ dataSource={context.adminDataSource}
+ onDataSourceChange={() => undefined}
+ optionsOnly
+ />
+ );
+ };
+ const harness = renderIntoContainer();
+
+ try {
+ await harness.render(
+ <InstanceFormProvider>
+ <Editor />
+ </InstanceFormProvider>
+ );
+
+ const addParameter = Array.from(
+ harness.container.querySelectorAll("button")
+ ).find((element) => element.textContent === "instance.add-parameter");
+ const field = addParameter?.closest('[data-slot="form-field"]');
+
+ expect(field).not.toBeNull();
+ expect(
+ field?.querySelector('[data-slot="form-field-title"]')?.textContent
+ ).toBe("data-source.extra-params.self");
+ expect(addParameter?.className).toContain("h-7");
+ expect(addParameter?.className).toContain("self-start");
+ } finally {
+ harness.unmount();
+ }
+ });
+
+ test("keeps the optional username info icon close to its title", async () => {
+ const { DataSourceForm } = await vi.importActual<
+ typeof import("./DataSourceForm")
+ >("./DataSourceForm");
+ const Editor = () => {
+ const context = useInstanceFormContext();
+ return (
+ <DataSourceForm
+ dataSource={context.adminDataSource}
+ onDataSourceChange={() => undefined}
+ onOpenInfoPanel={() => undefined}
+ />
+ );
+ };
+ const harness = renderIntoContainer();
+
+ try {
+ await harness.render(
+ <InstanceFormProvider>
+ <Editor />
+ </InstanceFormProvider>
+ );
+
+ const usernameTitle = Array.from(
+ harness.container.querySelectorAll('[data-slot="form-field-title"]')
+ ).find((title) => title.textContent?.includes("common.username"));
+ const infoButton = usernameTitle?.querySelector<HTMLButtonElement>(
+ 'button[aria-label="instance.authentication"]'
+ );
+
+ expect(infoButton).not.toBeNull();
+ expect(infoButton?.className).toContain("h-auto");
+ expect(infoButton?.className).not.toContain("w-6");
+ expect(infoButton?.parentElement?.className).toContain("gap-x-1");
+ } finally {
+ harness.unmount();
+ }
+ });
+
test("clears errors when deleting the final invalid label unmounts its editor", async () => {
const { LabelListEditor } = await vi.importActual<
typeof import("@/components/LabelListEditor")
diff --git a/frontend/src/components/ui/segmented-control.test.tsx b/frontend/src/components/ui/segmented-control.test.tsx
index cdc9c929a1..5166b09ea4 100644
--- a/frontend/src/components/ui/segmented-control.test.tsx
+++ b/frontend/src/components/ui/segmented-control.test.tsx
@@ -113,4 +113,23 @@ describe("SegmentedControl", () => {
unmount();
});
+
+ test("does not replace a selected disabled segment background on hover", () => {
+ const { container, unmount } = renderIntoContainer(
+ createElement(SegmentedControl, {
+ ariaLabel: "Database sync",
+ value: "azure",
+ onValueChange: () => undefined,
+ options: providerOptions,
+ })
+ );
+
+ const selectedDisabledSegment = container.querySelectorAll("label")[4];
+ expect(selectedDisabledSegment?.className).toContain("bg-accent");
+ expect(selectedDisabledSegment?.className).not.toContain(
+ "hover:bg-background"
+ );
+
+ unmount();
+ });
});
diff --git a/frontend/src/components/ui/segmented-control.tsx b/frontend/src/components/ui/segmented-control.tsx
index 37bb3e8f07..4c25ab56fe 100644
--- a/frontend/src/components/ui/segmented-control.tsx
+++ b/frontend/src/components/ui/segmented-control.tsx
@@ -65,9 +65,12 @@ export function SegmentedControl<T extends string>({
? appearance === "soft"
? "bg-accent/10 text-accent"
: "bg-accent text-accent-text"
- : "bg-background text-control hover:bg-control-bg",
+ : cn(
+ "bg-background text-control",
+ !optionDisabled && "hover:bg-control-bg"
+ ),
optionDisabled
- ? "cursor-not-allowed opacity-50 hover:bg-background"
+ ? "cursor-not-allowed opacity-50"
: "cursor-pointer"
)}
style={stylexProps.style}