Page MenuHomePhabricator

Consider having the TemplateField's "translate" method output a StepOutput
Closed, ResolvedPublic

Description

Right now, the TemplateField's translate method returns a TemplateFieldOutput with an output property that is an array of either string or null. This is because the TemplateField's validate method converts individual invalid outputs in the procedure's output to null.

This behavior was chosen to be able to identify individual invalid values in array fields. However, it complicates things in some consumers of TemplateField such as the template.ts's outputToCitation function, because a valid template field output should not have nulls.

Consider having the validate method always return an array of string (i.e., a StepOutput). If any of the procedure's output values under validation is invalid, return an empty array.

In addition, consider removing the valid property from TemplateFieldOutput as it is redundant (it may be inferred from the output value).

Event Timeline

Alternatively, have the TemplateField's template method simply output the combination of procedure outputs (joined if isArray = true), regardless of whether the individual values are valid or not. Instead, use the validate method to set the output's valid property.

Consumers of TemplateField would then check this valid flag to decide whether to use the output or not.

procedures output --> join if field has isArray = true --> field output --> set valid flag --> consumer

diegodlh claimed this task.

Fixed in 4593a6ad, using the approach mentioned in my last comment.