feat: add config for kanban columns
This commit is contained in:
@@ -6,11 +6,31 @@ import {
|
||||
normalizeTag,
|
||||
type ProjectConfig,
|
||||
} from "@/model/projectConfig";
|
||||
import { isTaskStatus } from "@/model/taskStatus";
|
||||
|
||||
function parseShownHiddenColumns(
|
||||
value: unknown,
|
||||
): Result<string[], AppError> {
|
||||
if (value === undefined) return ok([]);
|
||||
if (!Array.isArray(value)) {
|
||||
return err(
|
||||
appError(AppErrorVariant.INVALID_PROJECT_CONFIG, {
|
||||
detail: "shownHiddenColumns must be an array of strings",
|
||||
}),
|
||||
);
|
||||
}
|
||||
for (const item of value) {
|
||||
if (typeof item !== "string" || !isTaskStatus(item)) {
|
||||
return err(
|
||||
appError(AppErrorVariant.INVALID_PROJECT_CONFIG, {
|
||||
detail: `invalid status in shownHiddenColumns: ${item}`,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
return ok(value as string[]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse task-folder config.yml content.
|
||||
* Accepts missing/empty tags → [].
|
||||
*/
|
||||
export function parseProjectConfig(
|
||||
content: string,
|
||||
): Result<ProjectConfig, AppError> {
|
||||
@@ -39,33 +59,44 @@ export function parseProjectConfig(
|
||||
}
|
||||
|
||||
const record = data as Record<string, unknown>;
|
||||
|
||||
let tags: string[];
|
||||
if (record.tags === undefined) {
|
||||
return ok({ tags: [] });
|
||||
}
|
||||
|
||||
if (!Array.isArray(record.tags)) {
|
||||
return err(
|
||||
appError(AppErrorVariant.INVALID_PROJECT_CONFIG, {
|
||||
detail: "tags must be an array of strings",
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
const tags: string[] = [];
|
||||
const seen = new Set<string>();
|
||||
for (const item of record.tags) {
|
||||
if (typeof item !== "string") {
|
||||
tags = [];
|
||||
} else {
|
||||
if (!Array.isArray(record.tags)) {
|
||||
return err(
|
||||
appError(AppErrorVariant.INVALID_PROJECT_CONFIG, {
|
||||
detail: "tags must be an array of strings",
|
||||
}),
|
||||
);
|
||||
}
|
||||
const tag = normalizeTag(item);
|
||||
if (!tag || seen.has(tag)) continue;
|
||||
seen.add(tag);
|
||||
tags.push(tag);
|
||||
|
||||
tags = [];
|
||||
const seen = new Set<string>();
|
||||
for (const item of record.tags) {
|
||||
if (typeof item !== "string") {
|
||||
return err(
|
||||
appError(AppErrorVariant.INVALID_PROJECT_CONFIG, {
|
||||
detail: "tags must be an array of strings",
|
||||
}),
|
||||
);
|
||||
}
|
||||
const tag = normalizeTag(item);
|
||||
if (!tag || seen.has(tag)) continue;
|
||||
seen.add(tag);
|
||||
tags.push(tag);
|
||||
}
|
||||
}
|
||||
|
||||
return ok({ tags });
|
||||
const shownHiddenColumnsResult = parseShownHiddenColumns(
|
||||
record.shownHiddenColumns,
|
||||
);
|
||||
if (shownHiddenColumnsResult.isErr())
|
||||
return err(shownHiddenColumnsResult.error);
|
||||
|
||||
return ok({
|
||||
tags,
|
||||
shownHiddenColumns: shownHiddenColumnsResult.value,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user