feat(task-023): bind workflow templates into demo flow
This commit is contained in:
@@ -1,13 +1,25 @@
|
||||
import type { TargetSiteConfig } from "@pipeline/shared";
|
||||
import type {
|
||||
ArticleCreateRequest,
|
||||
TargetSiteConfig,
|
||||
WorkflowTemplateSummary,
|
||||
} from "@pipeline/shared";
|
||||
|
||||
export type NewArticleDraft = {
|
||||
targetSiteId: string;
|
||||
workflowTemplateId: string;
|
||||
briefDescription: string;
|
||||
workingTitle: string;
|
||||
contentType: string;
|
||||
primaryKeyword: string;
|
||||
};
|
||||
|
||||
export type WorkflowTemplateOption = {
|
||||
id: string;
|
||||
label: string;
|
||||
version: number;
|
||||
stageCount: number;
|
||||
};
|
||||
|
||||
export type FieldErrors = Record<string, string>;
|
||||
|
||||
export type NewArticleFormState = {
|
||||
@@ -16,9 +28,14 @@ export type NewArticleFormState = {
|
||||
formError?: string;
|
||||
};
|
||||
|
||||
export function initialDraft(sites: readonly TargetSiteConfig[]): NewArticleDraft {
|
||||
export function initialDraft(
|
||||
sites: readonly TargetSiteConfig[],
|
||||
workflows: readonly WorkflowTemplateSummary[] = [],
|
||||
): NewArticleDraft {
|
||||
const workflowOptions = buildWorkflowTemplateOptions(workflows);
|
||||
return {
|
||||
targetSiteId: sites.length > 0 ? sites[0].id : "",
|
||||
workflowTemplateId: workflowOptions.length > 0 ? workflowOptions[0].id : "",
|
||||
briefDescription: "",
|
||||
workingTitle: "",
|
||||
contentType: "longform_guide",
|
||||
@@ -26,6 +43,33 @@ export function initialDraft(sites: readonly TargetSiteConfig[]): NewArticleDraf
|
||||
};
|
||||
}
|
||||
|
||||
export function buildWorkflowTemplateOptions(
|
||||
workflows: readonly WorkflowTemplateSummary[],
|
||||
): WorkflowTemplateOption[] {
|
||||
return workflows
|
||||
.filter((workflow) => workflow.status === "ACTIVE")
|
||||
.map((workflow) => ({
|
||||
id: workflow.id,
|
||||
label: `${workflow.name} v${workflow.version}`,
|
||||
version: workflow.version,
|
||||
stageCount: workflow.stages?.length ?? 0,
|
||||
}));
|
||||
}
|
||||
|
||||
export function buildCreateArticlePayload(
|
||||
values: NewArticleDraft,
|
||||
): ArticleCreateRequest {
|
||||
return {
|
||||
target_site_id: values.targetSiteId,
|
||||
workflow_template_id: values.workflowTemplateId || null,
|
||||
brief_description: values.briefDescription,
|
||||
working_title: values.workingTitle || null,
|
||||
language: "en",
|
||||
content_type: values.contentType,
|
||||
primary_keyword: values.primaryKeyword || null,
|
||||
};
|
||||
}
|
||||
|
||||
export function validateArticleDraft(values: NewArticleDraft): FieldErrors {
|
||||
const errors: FieldErrors = {};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user