picklist 2
This commit is contained in:
@@ -25,7 +25,7 @@ export function formatFieldHint(field: FieldDescription): string {
|
||||
|
||||
if (isPickListField(field)) {
|
||||
lines.push("Tipo: PickList (lista de opções)");
|
||||
lines.push("Escolha um valor na lista — não digite o nome exibido manualmente.");
|
||||
lines.push("Escolha um valor na lista — a API recebe o ID como string (ex: /C_GenericTaskSetor/Edição).");
|
||||
const refType = (field as { referencedEntities?: string[] }).referencedEntities?.[0];
|
||||
if (refType) {
|
||||
lines.push(`Opções carregadas de: ${refType}`);
|
||||
|
||||
@@ -64,7 +64,7 @@ async function promptPickListSelection(
|
||||
|
||||
const match = pickListOptions.find((o) => o.id === selectedId);
|
||||
return {
|
||||
value: { id: selectedId },
|
||||
value: selectedId,
|
||||
displayLabel: match
|
||||
? `${match.label} (${match.id})`
|
||||
: String(selectedId),
|
||||
@@ -95,6 +95,7 @@ async function promptManualEntityValue(
|
||||
}
|
||||
|
||||
function formatEntityDisplayLabel(value: JsonValue): string | undefined {
|
||||
if (typeof value === "string") return value;
|
||||
if (value && typeof value === "object" && "id" in value) {
|
||||
const id = (value as { id?: unknown }).id;
|
||||
if (typeof id === "string") return id;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { FieldDescription, FieldType, JsonValue } from "@arco/clarizen-lib";
|
||||
import { getFieldTypeExample } from "../metadata/field-hints.js";
|
||||
import { isPickListField } from "../metadata/picklist.js";
|
||||
|
||||
export class ValueParseError extends Error {
|
||||
constructor(message: string) {
|
||||
@@ -54,6 +55,29 @@ function parseEntity(raw: string): JsonValue {
|
||||
);
|
||||
}
|
||||
|
||||
/** PickList fields accept the entity ID as a plain string, not `{ id }`. */
|
||||
function parsePickListEntityId(raw: string): string {
|
||||
const trimmed = raw.trim();
|
||||
if (trimmed.startsWith("{")) {
|
||||
try {
|
||||
const parsed = JSON.parse(trimmed) as Record<string, unknown>;
|
||||
if (typeof parsed.id === "string") {
|
||||
return parsed.id;
|
||||
}
|
||||
throw new ValueParseError('JSON de PickList deve conter "id".');
|
||||
} catch (err) {
|
||||
if (err instanceof ValueParseError) throw err;
|
||||
throw new ValueParseError(`JSON inválido para PickList: "${raw}"`);
|
||||
}
|
||||
}
|
||||
if (trimmed.startsWith("/")) {
|
||||
return trimmed;
|
||||
}
|
||||
throw new ValueParseError(
|
||||
`ID de PickList inválido: "${raw}". Use /Tipo/id ou {"id":"/Tipo/id"}`,
|
||||
);
|
||||
}
|
||||
|
||||
function parseJsonObject(raw: string, typeName: string): JsonValue {
|
||||
try {
|
||||
return JSON.parse(raw.trim()) as JsonValue;
|
||||
@@ -108,6 +132,10 @@ export function parseFieldValue(
|
||||
throw new ValueParseError("Valor não pode ser vazio.");
|
||||
}
|
||||
|
||||
if (isPickListField(field)) {
|
||||
return parsePickListEntityId(raw);
|
||||
}
|
||||
|
||||
return parseByType(raw, field.type);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user