picklist 2
This commit is contained in:
BIN
Binary file not shown.
@@ -74,9 +74,9 @@ Campos **nullable** permitem limpar o valor escolhendo "Limpar campo (null)" ou
|
|||||||
|
|
||||||
## Campos PickList
|
## Campos PickList
|
||||||
|
|
||||||
Campos com `presentationType: PickList` (listas de opções customizadas ou do sistema) exibem uma **lista carregada da API** com nomes legíveis (ex: `Conteúdo`). O app envia automaticamente o ID correto (`/C_GenericTaskSetor/<guid>`), evitando erros ao digitar o nome manualmente.
|
Campos com `presentationType: PickList` (listas de opções customizadas ou do sistema) exibem uma **lista carregada da API** com nomes legíveis (ex: `Conteúdo`). O app envia o ID como **string** (`"/C_GenericTaskSetor/Edição"`), não como objeto `{"id":"..."}` — formato exigido pela API do Adaptive Work para PickList.
|
||||||
|
|
||||||
Campos de **referência** (`ReferenceToObject`, ex: User, Project) continuam exigindo o ID manual ou JSON `{"id":"/Tipo/guid"}`.
|
Campos de **referência** (`ReferenceToObject`, ex: User, Project) continuam exigindo objeto `{"id":"/Tipo/guid"}` ou `/Tipo/guid` convertido para `{ id }`.
|
||||||
|
|
||||||
## Variáveis de ambiente
|
## Variáveis de ambiente
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@ Exemplo resumido:
|
|||||||
"typeName": "Task",
|
"typeName": "Task",
|
||||||
"filter": "Todos",
|
"filter": "Todos",
|
||||||
"fieldName": "C_MeuCampo",
|
"fieldName": "C_MeuCampo",
|
||||||
"value": { "id": "/C_GenericTaskSetor/abc123" },
|
"value": "/C_GenericTaskSetor/Edição",
|
||||||
"valueLabel": "Conteúdo (/C_GenericTaskSetor/abc123)"
|
"valueLabel": "Conteúdo (/C_GenericTaskSetor/abc123)"
|
||||||
},
|
},
|
||||||
"summary": { "total": 10, "updated": 9, "errors": 1 },
|
"summary": { "total": 10, "updated": 9, "errors": 1 },
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ export function formatFieldHint(field: FieldDescription): string {
|
|||||||
|
|
||||||
if (isPickListField(field)) {
|
if (isPickListField(field)) {
|
||||||
lines.push("Tipo: PickList (lista de opções)");
|
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];
|
const refType = (field as { referencedEntities?: string[] }).referencedEntities?.[0];
|
||||||
if (refType) {
|
if (refType) {
|
||||||
lines.push(`Opções carregadas de: ${refType}`);
|
lines.push(`Opções carregadas de: ${refType}`);
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ async function promptPickListSelection(
|
|||||||
|
|
||||||
const match = pickListOptions.find((o) => o.id === selectedId);
|
const match = pickListOptions.find((o) => o.id === selectedId);
|
||||||
return {
|
return {
|
||||||
value: { id: selectedId },
|
value: selectedId,
|
||||||
displayLabel: match
|
displayLabel: match
|
||||||
? `${match.label} (${match.id})`
|
? `${match.label} (${match.id})`
|
||||||
: String(selectedId),
|
: String(selectedId),
|
||||||
@@ -95,6 +95,7 @@ async function promptManualEntityValue(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function formatEntityDisplayLabel(value: JsonValue): string | undefined {
|
function formatEntityDisplayLabel(value: JsonValue): string | undefined {
|
||||||
|
if (typeof value === "string") return value;
|
||||||
if (value && typeof value === "object" && "id" in value) {
|
if (value && typeof value === "object" && "id" in value) {
|
||||||
const id = (value as { id?: unknown }).id;
|
const id = (value as { id?: unknown }).id;
|
||||||
if (typeof id === "string") return id;
|
if (typeof id === "string") return id;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import type { FieldDescription, FieldType, JsonValue } from "@arco/clarizen-lib";
|
import type { FieldDescription, FieldType, JsonValue } from "@arco/clarizen-lib";
|
||||||
import { getFieldTypeExample } from "../metadata/field-hints.js";
|
import { getFieldTypeExample } from "../metadata/field-hints.js";
|
||||||
|
import { isPickListField } from "../metadata/picklist.js";
|
||||||
|
|
||||||
export class ValueParseError extends Error {
|
export class ValueParseError extends Error {
|
||||||
constructor(message: string) {
|
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 {
|
function parseJsonObject(raw: string, typeName: string): JsonValue {
|
||||||
try {
|
try {
|
||||||
return JSON.parse(raw.trim()) as JsonValue;
|
return JSON.parse(raw.trim()) as JsonValue;
|
||||||
@@ -108,6 +132,10 @@ export function parseFieldValue(
|
|||||||
throw new ValueParseError("Valor não pode ser vazio.");
|
throw new ValueParseError("Valor não pode ser vazio.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isPickListField(field)) {
|
||||||
|
return parsePickListEntityId(raw);
|
||||||
|
}
|
||||||
|
|
||||||
return parseByType(raw, field.type);
|
return parseByType(raw, field.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user