Palantir车间给出的验证表格参数



我们在Palantir workshop中有一个表单,它接受值并将它们添加到本体对象中。我的任务是根据表单中给出的输入验证组合(userId、startdate、states(,无论它们是否已经存在。我们有一个typescript函数,当我们提交表单时会调用它。我对typescript完全陌生。你能帮我怎么做到这一点吗。

import {
@OntologyEditFunction,
LocalDate,
Integer, 
Users,
Double,
FunctionsMap, 
Function,
} from "@foundry/functions-api";
import {
Objects, 
ObjectSet,
ObjectWeUse,
} from "@foundry/ontology-api";
@OntologyEditFunction()
public async createSkus(
userId: string,
is_Sku_Pending?: string,
partition?: string,
startdate?: LocalDate,
all_states?: string,
states?: string[], //selects multiples values
): Promise<void> {
let final_states;

if (all_states && all_states === "All") {
final_states = U.all_usa_states; // A pre defined const string array
} else if (all_states && all_states === "All but UT") {
final_states = U.all_usa_states_without_utah; // A pre defined const string array
} else {
final_states = states;
}
for (let i = 0; i < packages.length; i++) {
let sku= Objects.create().ObjectWeUse(U.uuidv4());
sku.userId= U.uuidv4();
sku.states= final_states;
sku.strs = startdate;
sku.partition = partition
sku.isSkuPending = is_Sku_Pending;

有两种方法可以验证Foundry中的操作:

  1. 操作提交标准,适用于所有操作类型,允许您使用自定义用户反馈消息配置复杂的、面向用户的提交验证。这些是验证标准并向用户提供反馈的首选方式。在配置中,您可以引用用户提供的任何输入参数,也可以引用对象参数的任何属性。这应该足够有表现力来实现您想要进行的检查。

  2. 函数支持的操作(以及任何函数(中,您可以抛出面向用户的错误,这将阻止函数执行并向用户提供错误消息。这可用于检查可能只有在函数执行时才能访问的条件,但这是一种更糟糕的用户体验,因为用户填写表格并单击按钮,只有才会收到错误消息。

我建议使用第一种方法。

最新更新