mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-26 18:31:34 +01:00
PAP-10829 filter pipeline intake variables
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
a236029aeb
commit
5dbe72164a
2 files changed
+19
-12
No files matched your search
@@ -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),
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user