PAP-10829 filter pipeline intake variables

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip committed 2026-06-10 20:45:15 +00:00
1 parent a236029aeb
commit 5dbe72164a
2 files changed
+19 -12

No files matched your search

+6 -4
View File
@@ -8,8 +8,9 @@ describe("pipeline service helpers", () => {
pipelineId: "pipeline-1",
config: {
variables: [
{ key: "customer", label: "Customer", type: "text", required: true, options: [], showInAddForm: false },
{ key: "urgency", label: "Urgency", type: "select", options: ["low", "high"], required: false, showInAddForm: false },
{ key: "customer", label: "Customer", type: "text", required: true, options: [], showInAddForm: true },
{ key: "urgency", label: "Urgency", type: "select", options: ["low", "high"], required: false, showInAddForm: true },
{ key: "internal_notes", label: "Internal notes", type: "multiline", required: true, options: [], showInAddForm: false },
],
},
},
@@ -49,8 +50,9 @@ describe("pipeline service helpers", () => {
it("validates required intake fields for pipeline stage variables", () => {
const variables = [
{ key: "customer", label: "Customer", type: "text" as const, required: true, options: [], showInAddForm: false },
{ key: "notes", label: "Notes", type: "multiline" as const, required: false, options: [], showInAddForm: false },
{ key: "customer", label: "Customer", type: "text" as const, required: true, options: [], showInAddForm: true },
{ key: "notes", label: "Notes", type: "multiline" as const, required: false, options: [], showInAddForm: true },
{ key: "internal_code", label: "Internal code", type: "text" as const, required: true, options: [], showInAddForm: false },
];
expect(() =>
validateStageRequiredFields({ customer: "Acme" }, variables),
+13 -8
View File
@@ -101,13 +101,15 @@ export function extractPipelineIntakeFormFields(stages: PipelineStageRow[]): Pip
const first = stages[0];
if (!first) return [];
const stageConfig = normalizeStageConfig(first.config);
return stageConfig.variables.map((variable) => ({
key: variable.key,
label: variable.label,
type: variable.type,
required: variable.required,
options: variable.options,
}));
return stageConfig.variables
.filter((variable) => variable.showInAddForm)
.map((variable) => ({
key: variable.key,
label: variable.label,
type: variable.type,
required: variable.required,
options: variable.options,
}));
}
export function validateStageRequiredFields(
@@ -115,6 +117,7 @@ export function validateStageRequiredFields(
stageVariables: PipelineStageVariable[],
) {
const missing = stageVariables
.filter((variable) => variable.showInAddForm)
.filter((variable) => variable.required)
.filter((variable) => {
const value = fields[variable.key];
@@ -246,7 +249,9 @@ async function resolvePipelineIntakeStage(db: PipelineDb, pipelineId: string, st
function validateStageRequiredFieldsForIngest(stage: PipelineStageRow, fields: Record<string, unknown>) {
const config = normalizeStageConfig(stage.config);
const requiredVariables = Array.isArray(config.variables) ? config.variables : [];
const requiredVariables = Array.isArray(config.variables)
? config.variables.filter((variable) => variable.showInAddForm)
: [];
validateStageRequiredFields(fields, requiredVariables);
}