You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polaris.apache.org by jb...@apache.org on 2026/03/20 12:52:36 UTC
(polaris-tools) branch main updated: refactor(console): extract reusable FormField component to reduce form boilerplate (#182)
This is an automated email from the ASF dual-hosted git repository.
jbonofre pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/polaris-tools.git
The following commit(s) were added to refs/heads/main by this push:
new 8a6e532 refactor(console): extract reusable FormField component to reduce form boilerplate (#182)
8a6e532 is described below
commit 8a6e532ab45bb57f242ade5feabd93aaf3184f17
Author: hyonun <11...@users.noreply.github.com>
AuthorDate: Fri Mar 20 21:52:32 2026 +0900
refactor(console): extract reusable FormField component to reduce form boilerplate (#182)
* feat(console): add reusable FormField component to reduce form boilerplate
* refactor(console): replace repeated Label+Input+Error form pattern with FormField component
* style(console): change text-red-600 -> text-destructive
- due to darkmode
---
.../components/forms/ConfigureConnectionModal.tsx | 37 +++++------
.../src/components/forms/CreateCatalogModal.tsx | 50 +++++++--------
.../components/forms/CreateCatalogRoleModal.tsx | 58 ++++++++---------
.../src/components/forms/CreateNamespaceModal.tsx | 35 +++++-----
.../components/forms/CreatePrincipalRoleModal.tsx | 36 +++++------
console/src/components/forms/CreateViewModal.tsx | 34 +++++-----
console/src/components/forms/EditCatalogModal.tsx | 61 ++++++++----------
.../src/components/forms/EditPrincipalModal.tsx | 32 +++++-----
.../src/components/forms/GrantPrivilegeModal.tsx | 74 ++++++++++------------
.../src/components/forms/ResetCredentialsModal.tsx | 49 +++++++-------
console/src/components/ui/form-field.tsx | 43 +++++++++++++
11 files changed, 261 insertions(+), 248 deletions(-)
diff --git a/console/src/components/forms/ConfigureConnectionModal.tsx b/console/src/components/forms/ConfigureConnectionModal.tsx
index 328fa2e..2d8d3d2 100644
--- a/console/src/components/forms/ConfigureConnectionModal.tsx
+++ b/console/src/components/forms/ConfigureConnectionModal.tsx
@@ -34,6 +34,7 @@ import {
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
+import { FormField } from "@/components/ui/form-field"
import {
Select,
SelectContent,
@@ -152,8 +153,7 @@ export function ConfigureConnectionModal({
</DialogDescription>
</DialogHeader>
<form onSubmit={handleSubmit(onSubmit)} className="space-y-4">
- <div className="space-y-2">
- <Label htmlFor="queryEngine">Query Engine</Label>
+ <FormField label="Query Engine" htmlFor="queryEngine" error={errors.queryEngine?.message}>
<Select
onValueChange={(value) => {
setValue("queryEngine", value)
@@ -170,23 +170,20 @@ export function ConfigureConnectionModal({
))}
</SelectContent>
</Select>
- {errors.queryEngine && (
- <p className="text-sm text-red-600">{errors.queryEngine.message}</p>
- )}
- </div>
-
- <div className="space-y-2">
- <Label htmlFor="principalName">Principal Name</Label>
+ </FormField>
+
+ <FormField
+ label="Principal Name"
+ htmlFor="principalName"
+ error={errors.principalName?.message}
+ hint="A new principal will be created."
+ >
<Input
id="principalName"
{...register("principalName")}
placeholder="polaris_demo_connection_spark"
/>
- <p className="text-xs text-gray-500">A new principal will be created.</p>
- {errors.principalName && (
- <p className="text-sm text-red-600">{errors.principalName.message}</p>
- )}
- </div>
+ </FormField>
<div className="flex items-center justify-between">
<Label htmlFor="createRole">Create new principal role</Label>
@@ -201,17 +198,17 @@ export function ConfigureConnectionModal({
</div>
{createNewRole ? (
- <div className="space-y-2">
- <Label htmlFor="principalRoleName">Principal Role Name</Label>
+ <FormField
+ label="Principal Role Name"
+ htmlFor="principalRoleName"
+ error={errors.principalRoleName?.message}
+ >
<Input
id="principalRoleName"
{...register("principalRoleName")}
placeholder="Enter role name"
/>
- {errors.principalRoleName && (
- <p className="text-sm text-red-600">{errors.principalRoleName.message}</p>
- )}
- </div>
+ </FormField>
) : (
<div className="space-y-2">
<Label htmlFor="principalRole">Principal Role</Label>
diff --git a/console/src/components/forms/CreateCatalogModal.tsx b/console/src/components/forms/CreateCatalogModal.tsx
index a60ac5c..dbf220b 100644
--- a/console/src/components/forms/CreateCatalogModal.tsx
+++ b/console/src/components/forms/CreateCatalogModal.tsx
@@ -33,6 +33,7 @@ import type {
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
+import { FormField } from "@/components/ui/form-field"
import {
Select,
SelectContent,
@@ -280,14 +281,11 @@ export function CreateCatalogModal({ open, onOpenChange, onCreated }: CreateCata
onSubmit={handleSubmit((values) => createMutation.mutate(values))}
className="space-y-4"
>
- <div className="space-y-2">
- <Label htmlFor="name">Name</Label>
+ <FormField label="Name" htmlFor="name" error={errors.name?.message}>
<Input id="name" placeholder="e.g. prod" {...register("name")} />
- {errors.name && <p className="text-sm text-red-600">{errors.name.message}</p>}
- </div>
+ </FormField>
- <div className="space-y-2">
- <Label>Type</Label>
+ <FormField label="Type" error={errors.type?.message}>
<Select
onValueChange={(v) =>
setValue("type", v as FormValues["type"], { shouldValidate: true })
@@ -302,23 +300,24 @@ export function CreateCatalogModal({ open, onOpenChange, onCreated }: CreateCata
<SelectItem value="EXTERNAL">EXTERNAL</SelectItem>
</SelectContent>
</Select>
- {errors.type && <p className="text-sm text-red-600">{errors.type.message}</p>}
- </div>
+ </FormField>
- <div className="space-y-2">
- <Label htmlFor="defaultBaseLocation">Default base location</Label>
+ <FormField
+ label="Default base location"
+ htmlFor="defaultBaseLocation"
+ error={errors.defaultBaseLocation?.message}
+ >
<Input
id="defaultBaseLocation"
placeholder="e.g. s3://bucket/prefix or file:///path"
{...register("defaultBaseLocation")}
/>
- {errors.defaultBaseLocation && (
- <p className="text-sm text-red-600">{errors.defaultBaseLocation.message}</p>
- )}
- </div>
+ </FormField>
- <div className="space-y-2">
- <Label>Storage provider</Label>
+ <FormField
+ label="Storage provider"
+ hint="Select the cloud/storage provider used by this catalog."
+ >
<Controller
name="storageType"
control={control}
@@ -336,22 +335,19 @@ export function CreateCatalogModal({ open, onOpenChange, onCreated }: CreateCata
</Select>
)}
/>
- <p className="text-xs text-muted-foreground">
- Select the cloud/storage provider used by this catalog.
- </p>
- </div>
- <div className="space-y-2">
- <Label htmlFor="allowedLocations">Allowed locations (comma-separated)</Label>
+ </FormField>
+
+ <FormField
+ label="Allowed locations (comma-separated)"
+ htmlFor="allowedLocations"
+ hint="Optional list of storage locations allowed for this catalog. Example: s3://bucket/prefix/"
+ >
<Input
id="allowedLocations"
placeholder="s3://bucket1/, s3://bucket2/"
{...register("allowedLocations")}
/>
- <p className="text-xs text-muted-foreground">
- Optional list of storage locations allowed for this catalog. Example:
- s3://bucket/prefix/
- </p>
- </div>
+ </FormField>
{/* Provider-specific fields */}
{storageType === "S3" && (
diff --git a/console/src/components/forms/CreateCatalogRoleModal.tsx b/console/src/components/forms/CreateCatalogRoleModal.tsx
index 717baaa..104a61e 100644
--- a/console/src/components/forms/CreateCatalogRoleModal.tsx
+++ b/console/src/components/forms/CreateCatalogRoleModal.tsx
@@ -33,8 +33,8 @@ import {
} from "@/components/ui/dialog"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
-import { Label } from "@/components/ui/label"
import { Textarea } from "@/components/ui/textarea"
+import { FormField } from "@/components/ui/form-field"
import {
Select,
SelectContent,
@@ -178,8 +178,16 @@ export function CreateCatalogRoleModal({
</DialogDescription>
</DialogHeader>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
- <div className="space-y-2">
- <Label htmlFor="catalogName">Catalog</Label>
+ <FormField
+ label="Catalog"
+ htmlFor="catalogName"
+ error={form.formState.errors.catalogName?.message}
+ hint={
+ isNew
+ ? "Select the catalog where this role will be created."
+ : "Catalog cannot be changed."
+ }
+ >
<Select
value={form.watch("catalogName")}
onValueChange={(value) => form.setValue("catalogName", value)}
@@ -206,31 +214,26 @@ export function CreateCatalogRoleModal({
)}
</SelectContent>
</Select>
- {form.formState.errors.catalogName && (
- <p className="text-sm text-red-600">{form.formState.errors.catalogName.message}</p>
- )}
- <p className="text-xs text-muted-foreground">
- {isNew
- ? "Select the catalog where this role will be created."
- : "Catalog cannot be changed."}
- </p>
- </div>
+ </FormField>
- <div className="space-y-2">
- <Label htmlFor="name">Name</Label>
- <Input id="name" {...form.register("name")} placeholder="role-name" disabled={!isNew} />
- {form.formState.errors.name && (
- <p className="text-sm text-red-600">{form.formState.errors.name.message}</p>
- )}
- <p className="text-xs text-muted-foreground">
- {isNew
+ <FormField
+ label="Name"
+ htmlFor="name"
+ error={form.formState.errors.name?.message}
+ hint={
+ isNew
? "The unique name for this catalog role."
- : "Catalog role name cannot be changed."}
- </p>
- </div>
+ : "Catalog role name cannot be changed."
+ }
+ >
+ <Input id="name" {...form.register("name")} placeholder="role-name" disabled={!isNew} />
+ </FormField>
- <div className="space-y-2">
- <Label htmlFor="properties">Properties</Label>
+ <FormField
+ label="Properties"
+ htmlFor="properties"
+ hint="Enter properties as key=value pairs, one per line."
+ >
<Textarea
id="properties"
value={propertiesText}
@@ -239,10 +242,7 @@ export function CreateCatalogRoleModal({
className="font-mono text-sm"
rows={6}
/>
- <p className="text-xs text-muted-foreground">
- Enter properties as key=value pairs, one per line.
- </p>
- </div>
+ </FormField>
<DialogFooter>
<Button
diff --git a/console/src/components/forms/CreateNamespaceModal.tsx b/console/src/components/forms/CreateNamespaceModal.tsx
index c9eefbf..13c8d22 100644
--- a/console/src/components/forms/CreateNamespaceModal.tsx
+++ b/console/src/components/forms/CreateNamespaceModal.tsx
@@ -27,6 +27,7 @@ import { namespacesApi } from "@/api/catalog/namespaces"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
+import { FormField } from "@/components/ui/form-field"
import {
Dialog,
DialogContent,
@@ -216,37 +217,31 @@ export function CreateNamespaceModal({
onSubmit={handleSubmit((values) => createMutation.mutate(values))}
className="space-y-4"
>
- <div className="space-y-2">
- <Label htmlFor="namespacePath">
- Namespace path {parentNamespace && "(relative to parent)"}
- </Label>
+ <FormField
+ label={<>Namespace path {parentNamespace && "(relative to parent)"}</>}
+ htmlFor="namespacePath"
+ error={errors.namespacePath?.message}
+ hint='Use dots to create nested namespaces (e.g., "outer.inner"). Each part must contain only alphanumeric characters, underscores, or hyphens.'
+ >
<Input
id="namespacePath"
placeholder={parentNamespace ? "e.g. inner" : "e.g. accounting or accounting.tax"}
{...register("namespacePath")}
/>
- {errors.namespacePath && (
- <p className="text-sm text-red-600">{errors.namespacePath.message}</p>
- )}
- <p className="text-xs text-muted-foreground">
- Use dots to create nested namespaces (e.g., "outer.inner"). Each part must contain
- only alphanumeric characters, underscores, or hyphens.
- </p>
- </div>
+ </FormField>
- <div className="space-y-2">
- <Label htmlFor="location">Location (optional)</Label>
+ <FormField
+ label="Location (optional)"
+ htmlFor="location"
+ error={errors.location?.message}
+ hint="Storage location for this namespace. Must be within the catalog's base location and allowed locations."
+ >
<Input
id="location"
placeholder="e.g. s3://bucket/prefix/ or file:///path/to/namespace"
{...register("location")}
/>
- {errors.location && <p className="text-sm text-red-600">{errors.location.message}</p>}
- <p className="text-xs text-muted-foreground">
- Storage location for this namespace. Must be within the catalog's base location and
- allowed locations.
- </p>
- </div>
+ </FormField>
<div className="space-y-2">
<div className="flex items-center justify-between">
diff --git a/console/src/components/forms/CreatePrincipalRoleModal.tsx b/console/src/components/forms/CreatePrincipalRoleModal.tsx
index 8e261d5..6b4bcae 100644
--- a/console/src/components/forms/CreatePrincipalRoleModal.tsx
+++ b/console/src/components/forms/CreatePrincipalRoleModal.tsx
@@ -33,8 +33,8 @@ import {
} from "@/components/ui/dialog"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
-import { Label } from "@/components/ui/label"
import { Textarea } from "@/components/ui/textarea"
+import { FormField } from "@/components/ui/form-field"
import { principalRolesApi } from "@/api/management/principal-roles"
import type { PrincipalRole } from "@/types/api"
@@ -155,21 +155,24 @@ export function CreatePrincipalRoleModal({
</DialogDescription>
</DialogHeader>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
- <div className="space-y-2">
- <Label htmlFor="name">Name</Label>
- <Input id="name" {...form.register("name")} placeholder="role-name" disabled={!isNew} />
- {form.formState.errors.name && (
- <p className="text-sm text-red-600">{form.formState.errors.name.message}</p>
- )}
- <p className="text-xs text-muted-foreground">
- {isNew
+ <FormField
+ label="Name"
+ htmlFor="name"
+ error={form.formState.errors.name?.message}
+ hint={
+ isNew
? "The unique name for this principal role."
- : "Principal role name cannot be changed."}
- </p>
- </div>
+ : "Principal role name cannot be changed."
+ }
+ >
+ <Input id="name" {...form.register("name")} placeholder="role-name" disabled={!isNew} />
+ </FormField>
- <div className="space-y-2">
- <Label htmlFor="properties">Properties</Label>
+ <FormField
+ label="Properties"
+ htmlFor="properties"
+ hint="Enter properties as key=value pairs, one per line."
+ >
<Textarea
id="properties"
value={propertiesText}
@@ -178,10 +181,7 @@ export function CreatePrincipalRoleModal({
className="font-mono text-sm"
rows={6}
/>
- <p className="text-xs text-muted-foreground">
- Enter properties as key=value pairs, one per line.
- </p>
- </div>
+ </FormField>
<DialogFooter>
<Button
diff --git a/console/src/components/forms/CreateViewModal.tsx b/console/src/components/forms/CreateViewModal.tsx
index 1649d14..61848bc 100644
--- a/console/src/components/forms/CreateViewModal.tsx
+++ b/console/src/components/forms/CreateViewModal.tsx
@@ -25,8 +25,8 @@ import { toast } from "sonner"
import { viewsApi } from "@/api/catalog/views"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
-import { Label } from "@/components/ui/label"
import { Textarea } from "@/components/ui/textarea"
+import { FormField } from "@/components/ui/form-field"
import {
Dialog,
DialogContent,
@@ -136,32 +136,32 @@ export function CreateViewModal({
</DialogDescription>
</DialogHeader>
<form onSubmit={handleSubmit(onSubmit)} className="space-y-4">
- <div className="space-y-2">
- <Label htmlFor="name">View Name</Label>
+ <FormField label="View Name" htmlFor="name" error={errors.name?.message}>
<Input id="name" placeholder="my_view" {...register("name")} />
- {errors.name && <p className="text-sm text-red-600">{errors.name.message}</p>}
- </div>
+ </FormField>
- <div className="space-y-2">
- <Label htmlFor="dialect">SQL Dialect</Label>
+ <FormField
+ label="SQL Dialect"
+ htmlFor="dialect"
+ error={errors.dialect?.message}
+ hint="The SQL dialect used for the view (e.g., spark, trino, presto)"
+ >
<Input id="dialect" placeholder="spark" {...register("dialect")} />
- {errors.dialect && <p className="text-sm text-red-600">{errors.dialect.message}</p>}
- <p className="text-xs text-muted-foreground">
- The SQL dialect used for the view (e.g., spark, trino, presto)
- </p>
- </div>
+ </FormField>
- <div className="space-y-2">
- <Label htmlFor="sql">SQL Query</Label>
+ <FormField
+ label="SQL Query"
+ htmlFor="sql"
+ error={errors.sql?.message}
+ hint="The SQL query that defines this view"
+ >
<Textarea
id="sql"
placeholder="SELECT * FROM my_table WHERE ..."
className="min-h-[150px] font-mono text-sm"
{...register("sql")}
/>
- {errors.sql && <p className="text-sm text-red-600">{errors.sql.message}</p>}
- <p className="text-xs text-muted-foreground">The SQL query that defines this view</p>
- </div>
+ </FormField>
<DialogFooter>
<Button type="button" variant="outline" onClick={() => onOpenChange(false)}>
diff --git a/console/src/components/forms/EditCatalogModal.tsx b/console/src/components/forms/EditCatalogModal.tsx
index cb864a8..4a357e0 100644
--- a/console/src/components/forms/EditCatalogModal.tsx
+++ b/console/src/components/forms/EditCatalogModal.tsx
@@ -29,6 +29,7 @@ import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import { Textarea } from "@/components/ui/textarea"
+import { FormField } from "@/components/ui/form-field"
import {
Select,
SelectContent,
@@ -243,32 +244,30 @@ export function EditCatalogModal({
onSubmit={handleSubmit((values) => updateMutation.mutate(values))}
className="space-y-4"
>
- <div className="space-y-2">
- <Label htmlFor="name">Name</Label>
+ <FormField label="Name" htmlFor="name" hint="Catalog name cannot be changed">
<Input id="name" value={catalog.name} disabled />
- <p className="text-xs text-muted-foreground">Catalog name cannot be changed</p>
- </div>
+ </FormField>
- <div className="space-y-2">
- <Label>Type</Label>
+ <FormField label="Type" hint="Catalog type cannot be changed">
<Input value={catalog.type} disabled />
- <p className="text-xs text-muted-foreground">Catalog type cannot be changed</p>
- </div>
+ </FormField>
- <div className="space-y-2">
- <Label htmlFor="defaultBaseLocation">Default base location</Label>
+ <FormField
+ label="Default base location"
+ htmlFor="defaultBaseLocation"
+ error={errors.defaultBaseLocation?.message}
+ >
<Input
id="defaultBaseLocation"
placeholder="e.g. s3://bucket/prefix or file:///path"
{...register("defaultBaseLocation")}
/>
- {errors.defaultBaseLocation && (
- <p className="text-sm text-red-600">{errors.defaultBaseLocation.message}</p>
- )}
- </div>
+ </FormField>
- <div className="space-y-2">
- <Label>Storage provider</Label>
+ <FormField
+ label="Storage provider"
+ hint="Select the cloud/storage provider used by this catalog."
+ >
<Controller
name="storageType"
control={control}
@@ -286,23 +285,19 @@ export function EditCatalogModal({
</Select>
)}
/>
- <p className="text-xs text-muted-foreground">
- Select the cloud/storage provider used by this catalog.
- </p>
- </div>
+ </FormField>
- <div className="space-y-2">
- <Label htmlFor="allowedLocations">Allowed locations (comma-separated)</Label>
+ <FormField
+ label="Allowed locations (comma-separated)"
+ htmlFor="allowedLocations"
+ hint="Optional list of storage locations allowed for this catalog. Example: s3://bucket/prefix/"
+ >
<Input
id="allowedLocations"
placeholder="s3://bucket1/, s3://bucket2/"
{...register("allowedLocations")}
/>
- <p className="text-xs text-muted-foreground">
- Optional list of storage locations allowed for this catalog. Example:
- s3://bucket/prefix/
- </p>
- </div>
+ </FormField>
{/* Provider-specific fields */}
{storageType === "S3" && (
@@ -389,18 +384,18 @@ export function EditCatalogModal({
</div>
)}
- <div className="space-y-2">
- <Label htmlFor="propertiesJson">Properties (JSON format)</Label>
+ <FormField
+ label="Properties (JSON format)"
+ htmlFor="propertiesJson"
+ hint="Catalog properties as JSON. You can also use key=value format, one per line."
+ >
<Textarea
id="propertiesJson"
placeholder='{"key": "value"}'
rows={6}
{...register("propertiesJson")}
/>
- <p className="text-xs text-muted-foreground">
- Catalog properties as JSON. You can also use key=value format, one per line.
- </p>
- </div>
+ </FormField>
<DialogFooter>
<Button
diff --git a/console/src/components/forms/EditPrincipalModal.tsx b/console/src/components/forms/EditPrincipalModal.tsx
index 087b71f..5424e05 100644
--- a/console/src/components/forms/EditPrincipalModal.tsx
+++ b/console/src/components/forms/EditPrincipalModal.tsx
@@ -33,8 +33,8 @@ import {
} from "@/components/ui/dialog"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
-import { Label } from "@/components/ui/label"
import { Textarea } from "@/components/ui/textarea"
+import { FormField } from "@/components/ui/form-field"
import { principalsApi } from "@/api/management/principals"
import type { Principal, PrincipalWithCredentials } from "@/types/api"
@@ -153,24 +153,27 @@ export function EditPrincipalModal({
</DialogDescription>
</DialogHeader>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
- <div className="space-y-2">
- <Label htmlFor="name">Name</Label>
+ <FormField
+ label="Name"
+ htmlFor="name"
+ error={form.formState.errors.name?.message}
+ hint={
+ isNew ? "The unique name for this principal." : "Principal name cannot be changed."
+ }
+ >
<Input
id="name"
{...form.register("name")}
placeholder="principal-name"
disabled={!isNew}
/>
- {form.formState.errors.name && (
- <p className="text-sm text-red-600">{form.formState.errors.name.message}</p>
- )}
- <p className="text-xs text-muted-foreground">
- {isNew ? "The unique name for this principal." : "Principal name cannot be changed."}
- </p>
- </div>
+ </FormField>
- <div className="space-y-2">
- <Label htmlFor="properties">Properties</Label>
+ <FormField
+ label="Properties"
+ htmlFor="properties"
+ hint="Enter properties as key=value pairs, one per line."
+ >
<Textarea
id="properties"
value={propertiesText}
@@ -179,10 +182,7 @@ export function EditPrincipalModal({
className="font-mono text-sm"
rows={6}
/>
- <p className="text-xs text-muted-foreground">
- Enter properties as key=value pairs, one per line.
- </p>
- </div>
+ </FormField>
<DialogFooter>
<Button
diff --git a/console/src/components/forms/GrantPrivilegeModal.tsx b/console/src/components/forms/GrantPrivilegeModal.tsx
index d3dd671..86b011f 100644
--- a/console/src/components/forms/GrantPrivilegeModal.tsx
+++ b/console/src/components/forms/GrantPrivilegeModal.tsx
@@ -34,6 +34,7 @@ import {
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
+import { FormField } from "@/components/ui/form-field"
import {
Select,
SelectContent,
@@ -772,8 +773,11 @@ export function GrantPrivilegeModal({ open, onOpenChange, onSuccess }: GrantPriv
</DialogHeader>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
{/* Catalog Selection */}
- <div className="space-y-2">
- <Label htmlFor="catalogName">Catalog *</Label>
+ <FormField
+ label="Catalog *"
+ htmlFor="catalogName"
+ error={form.formState.errors.catalogName?.message}
+ >
<Select
value={form.watch("catalogName")}
onValueChange={(value) => {
@@ -802,14 +806,14 @@ export function GrantPrivilegeModal({ open, onOpenChange, onSuccess }: GrantPriv
)}
</SelectContent>
</Select>
- {form.formState.errors.catalogName && (
- <p className="text-sm text-red-600">{form.formState.errors.catalogName.message}</p>
- )}
- </div>
+ </FormField>
{/* Catalog Role Selection */}
- <div className="space-y-2">
- <Label htmlFor="catalogRoleName">Catalog Role *</Label>
+ <FormField
+ label="Catalog Role *"
+ htmlFor="catalogRoleName"
+ error={form.formState.errors.catalogRoleName?.message}
+ >
<Select
value={form.watch("catalogRoleName")}
onValueChange={(value) => form.setValue("catalogRoleName", value)}
@@ -840,16 +844,14 @@ export function GrantPrivilegeModal({ open, onOpenChange, onSuccess }: GrantPriv
)}
</SelectContent>
</Select>
- {form.formState.errors.catalogRoleName && (
- <p className="text-sm text-red-600">
- {form.formState.errors.catalogRoleName.message}
- </p>
- )}
- </div>
+ </FormField>
{/* Entity Type Selection */}
- <div className="space-y-2">
- <Label htmlFor="entityType">Entity Type *</Label>
+ <FormField
+ label="Entity Type *"
+ htmlFor="entityType"
+ error={form.formState.errors.entityType?.message}
+ >
<Select
value={form.watch("entityType")}
onValueChange={(value) => {
@@ -873,49 +875,37 @@ export function GrantPrivilegeModal({ open, onOpenChange, onSuccess }: GrantPriv
<SelectItem value="policy">Policy</SelectItem>
</SelectContent>
</Select>
- {form.formState.errors.entityType && (
- <p className="text-sm text-red-600">{form.formState.errors.entityType.message}</p>
- )}
- </div>
+ </FormField>
{/* Namespace Path (conditional) */}
{entityType !== "catalog" && (
- <div className="space-y-2">
- <Label htmlFor="namespacePath">
- Namespace Path {entityType === "namespace" ? "(optional)" : "*"}
- </Label>
+ <FormField
+ label={`Namespace Path ${entityType === "namespace" ? "(optional)" : "*"}`}
+ htmlFor="namespacePath"
+ error={form.formState.errors.namespacePath?.message}
+ hint='Enter namespace path as period-delimited segments (e.g., "sales.2024"). Leave empty for root namespace.'
+ >
<Input
id="namespacePath"
{...form.register("namespacePath")}
placeholder="ns1.ns2 (period-delimited, leave empty for root)"
/>
- {form.formState.errors.namespacePath && (
- <p className="text-sm text-red-600">
- {form.formState.errors.namespacePath.message}
- </p>
- )}
- <p className="text-xs text-muted-foreground">
- Enter namespace path as period-delimited segments (e.g., "sales.2024"). Leave
- empty for root namespace.
- </p>
- </div>
+ </FormField>
)}
{/* Entity Name (conditional) */}
{["table", "view", "policy"].includes(entityType) && (
- <div className="space-y-2">
- <Label htmlFor="entityName">
- {entityType.charAt(0).toUpperCase() + entityType.slice(1)} Name *
- </Label>
+ <FormField
+ label={`${entityType.charAt(0).toUpperCase() + entityType.slice(1)} Name *`}
+ htmlFor="entityName"
+ error={form.formState.errors.entityName?.message}
+ >
<Input
id="entityName"
{...form.register("entityName")}
placeholder={`Enter ${entityType} name`}
/>
- {form.formState.errors.entityName && (
- <p className="text-sm text-red-600">{form.formState.errors.entityName.message}</p>
- )}
- </div>
+ </FormField>
)}
{/* Privilege Selection */}
diff --git a/console/src/components/forms/ResetCredentialsModal.tsx b/console/src/components/forms/ResetCredentialsModal.tsx
index 2ea3ef7..1eeea44 100644
--- a/console/src/components/forms/ResetCredentialsModal.tsx
+++ b/console/src/components/forms/ResetCredentialsModal.tsx
@@ -34,6 +34,7 @@ import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import { Switch } from "@/components/ui/switch"
+import { FormField } from "@/components/ui/form-field"
import { principalsApi } from "@/api/management/principals"
import { getErrorMessage } from "@/lib/errorHandler"
import type { PrincipalWithCredentials } from "@/types/api"
@@ -161,30 +162,34 @@ export function ResetCredentialsModal({
{useCustomCredentials && (
<div className="space-y-4 rounded-lg border p-4">
- <div className="space-y-2">
- <Label htmlFor="clientId">
- Client ID <span className="text-destructive">*</span>
- </Label>
+ <FormField
+ label={
+ <>
+ Client ID <span className="text-destructive">*</span>
+ </>
+ }
+ htmlFor="clientId"
+ error={form.formState.errors.clientId?.message}
+ hint="Must be a valid client ID previously generated by this service."
+ >
<Input
id="clientId"
{...form.register("clientId")}
placeholder="Enter client ID"
disabled={resetMutation.isPending}
/>
- {form.formState.errors.clientId && (
- <p className="text-sm text-destructive">
- {form.formState.errors.clientId.message}
- </p>
- )}
- <p className="text-xs text-muted-foreground">
- Must be a valid client ID previously generated by this service.
- </p>
- </div>
+ </FormField>
- <div className="space-y-2">
- <Label htmlFor="clientSecret">
- Client Secret <span className="text-destructive">*</span>
- </Label>
+ <FormField
+ label={
+ <>
+ Client Secret <span className="text-destructive">*</span>
+ </>
+ }
+ htmlFor="clientSecret"
+ error={form.formState.errors.clientSecret?.message}
+ hint="Must meet the service's requirements for secret format."
+ >
<Input
id="clientSecret"
type="password"
@@ -192,15 +197,7 @@ export function ResetCredentialsModal({
placeholder="Enter client secret"
disabled={resetMutation.isPending}
/>
- {form.formState.errors.clientSecret && (
- <p className="text-sm text-destructive">
- {form.formState.errors.clientSecret.message}
- </p>
- )}
- <p className="text-xs text-muted-foreground">
- Must meet the service's requirements for secret format.
- </p>
- </div>
+ </FormField>
</div>
)}
diff --git a/console/src/components/ui/form-field.tsx b/console/src/components/ui/form-field.tsx
new file mode 100644
index 0000000..65e393a
--- /dev/null
+++ b/console/src/components/ui/form-field.tsx
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import * as React from "react"
+import { Label } from "@/components/ui/label"
+
+interface FormFieldProps {
+ label: React.ReactNode
+ htmlFor?: string
+ error?: string
+ hint?: React.ReactNode
+ children: React.ReactNode
+ className?: string
+}
+
+function FormField({ label, htmlFor, error, hint, children, className }: FormFieldProps) {
+ return (
+ <div className={className ?? "space-y-2"}>
+ <Label htmlFor={htmlFor}>{label}</Label>
+ {children}
+ {error && <p className="text-sm text-destructive">{error}</p>}
+ {hint && <p className="text-xs text-muted-foreground">{hint}</p>}
+ </div>
+ )
+}
+
+export { FormField }