mirror of
https://github.com/anomalyco/opencode.git
synced 2026-07-10 04:48:32 +00:00
refactor(core): inline form info construction
This commit is contained in:
parent
d9742d5ede
commit
228db3dd9a
1 changed files with 6 additions and 12 deletions
|
|
@ -136,7 +136,12 @@ export const layer = Layer.effect(
|
|||
title: input.title,
|
||||
...(input.metadata === undefined ? {} : { metadata: input.metadata }),
|
||||
}
|
||||
const form = makeInfo(input, base)
|
||||
const form: Info =
|
||||
input.mode === "form"
|
||||
? { ...base, mode: "form", fields: input.fields }
|
||||
: input.mode === "url"
|
||||
? { ...base, mode: "url", url: input.url }
|
||||
: { ...base, mode: "integration", integrationID: input.integrationID }
|
||||
const entry: Entry = {
|
||||
form,
|
||||
state: { status: "pending" },
|
||||
|
|
@ -247,17 +252,6 @@ function validateAnswer(form: Info, answer: Answer) {
|
|||
}
|
||||
}
|
||||
|
||||
function makeInfo(input: CreateInput, base: Omit<Info, "mode" | "fields" | "url" | "integrationID">): Info {
|
||||
switch (input.mode) {
|
||||
case "form":
|
||||
return { ...base, mode: "form", fields: input.fields }
|
||||
case "url":
|
||||
return { ...base, mode: "url", url: input.url }
|
||||
case "integration":
|
||||
return { ...base, mode: "integration", integrationID: input.integrationID }
|
||||
}
|
||||
}
|
||||
|
||||
function isActive(field: Form.Field, answer: Answer) {
|
||||
if (!field.when) return true
|
||||
return field.when.every((when) => matches(when, answer[when.key]))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue