Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions web/src/pages/Library.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { api, type Doc, type ExtractionDrop, type SourceView } from "../api";
import { S } from "../i18n";
import {
CREATABLE_SOURCE_KINDS,
hasSyncFields,
type CreatableSourceKind,
} from "../sourceKinds";
import { useKb, useKbId } from "../kb";
Expand Down Expand Up @@ -1477,7 +1478,7 @@ function SourceModal({
? davUrl.trim()
: kind === "s3" || kind === "azure_blob" || kind === "gcs"
? s3Bucket.trim()
: true);
: hasSyncFields(kind, { repo, jiraUrl, jiraProject }));

// 注意用 div 而非 label:label 会把 :hover/click 转发给内部第一个可标记控件
//(button 也算),导致图标网格/日程选择器悬停时第一个按钮常亮
Expand Down Expand Up @@ -1961,7 +1962,8 @@ function SourceEditModal({
? feedUrl.trim()
: kind === "custom"
? endpoint.trim()
: true);
: // Jira 的配置这里改不了:挡住它只会让人连名字都改不成
kind === "jira_issues" || hasSyncFields(kind, { repo }));

// div 而非 label:label 会把 :hover/click 转发给第一个可标记控件
const field = (label: string, node: React.ReactNode) => (
Expand Down
14 changes: 14 additions & 0 deletions web/src/sourceKinds.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { expect, it } from "vitest";
import { hasSyncFields } from "./sourceKinds";

it.each([
["github_issues", { repo: " " }, false],
["github_repo", { repo: "" }, false],
["github_repo", { repo: "https://github.com/o/r" }, false],
["github_repo", { repo: " o/r " }, true],
["jira_issues", { jiraUrl: "https://j.test", jiraProject: "" }, false],
["jira_issues", { jiraUrl: "https://j.test", jiraProject: "P" }, true],
["folder", {}, true],
])("a %s source with %j can sync: %s", (kind, fields, expected) => {
expect(hasSyncFields(kind, fields)).toBe(expected);
});
15 changes: 15 additions & 0 deletions web/src/sourceKinds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,18 @@ export type CreatableSourceKind = (typeof CREATABLE_SOURCE_KINDS)[number];

/** 库里还会有两种人建不出来的:每个库自带的 `memory`,与老数据的 `upload` */
export type SourceKind = CreatableSourceKind | "memory" | "upload";

/**
* GitHub、Jira 来源同步缺不得的几项填了没有。缺了照样建得出来、存得下,之后每一轮同步
* 都只会报错。仓库要是 `owner/name`:粘一整条 GitHub 链接进来,后端同样每轮拒收
*/
export function hasSyncFields(
kind: string,
f: { repo?: string; jiraUrl?: string; jiraProject?: string },
): boolean {
if (kind === "github_issues" || kind === "github_repo") {
return /^[^/\s]+\/[^/\s]+$/.test(f.repo?.trim() ?? "");
}
if (kind === "jira_issues") return Boolean(f.jiraUrl?.trim() && f.jiraProject?.trim());
return true;
}
Loading