import type { DdlParams } from "../../../lib/objectCrud"; import { FormRow, inputClass, controlClass } from "./formRow"; interface Props { params: DdlParams; schemas?: string[]; onChange: (p: DdlParams) => void; } type SequenceOp = "create" | "alter" | "restart"; const OP_LABELS: Record = { create: "Create", alter: "Alter", restart: "Restart", }; function getOp(params: DdlParams): SequenceOp { const action = (params.action ?? {}) as Record; const op = action.op; if (op === "alter" || op === "restart") return op; return "create"; } function patchAction( params: DdlParams, patch: Record, ): DdlParams { const action = (params.action ?? {}) as Record; return { ...params, action: { ...action, ...patch } }; } export function SequenceForm({ params, schemas, onChange }: Props) { const op = getOp(params); const action = (params.action ?? {}) as Record; return (
{schemas && schemas.length > 0 ? ( ) : ( onChange({ ...params, schema: e.target.value })} className={inputClass} /> )} onChange({ ...params, name: e.target.value })} className={inputClass} /> {(op === "create" || op === "alter") && ( <> onChange(patchAction(params, { increment: e.target.value })) } className={inputClass} /> onChange(patchAction(params, { min_value: e.target.value })) } className={inputClass} /> onChange(patchAction(params, { max_value: e.target.value })) } className={inputClass} /> {op === "create" && ( onChange(patchAction(params, { start: e.target.value })) } className={inputClass} /> )} )} {op === "restart" && ( onChange(patchAction(params, { with: e.target.value })) } className={inputClass} /> )}
); }