Initial import of streamline
This commit is contained in:
@@ -0,0 +1,168 @@
|
||||
import { useState } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import "../styles.css";
|
||||
import { api, type MrSubmittersPreview, type SubmitMrResult } from "../lib/api";
|
||||
import type { BoardItem, Task } from "../types";
|
||||
import TaskCard from "../components/TaskCard";
|
||||
import TaskDetailDrawer from "../components/TaskDetailDrawer";
|
||||
import Toaster from "../components/Toaster";
|
||||
import DialogHost from "../components/DialogHost";
|
||||
|
||||
/**
|
||||
* 本地演示:Bug 抽屉里点「提交 MR」先弹「以谁的名义提交 MR」。抽屉是真组件,喂假数据;候选人和提交
|
||||
* 两个接口在这里打桩,按场景回不同结果。抽屉里其它接口都连不上,只看 MR 那一块。
|
||||
*
|
||||
* 打开方式:control-web 下 `API_TARGET=http://127.0.0.1:9 bun x vite --port 8092`,访问
|
||||
* /demo-mr-submit-as.html(API_TARGET 指向死端口,保证不会代理到任何真实服务)。
|
||||
*/
|
||||
|
||||
const now = Date.now();
|
||||
const mrUrl = (id: number) => `https://bits.bytedance.net/devops/1500037378/code/detail/${id}`;
|
||||
const base = {
|
||||
kind: "bug" as const, platform: "android", priorityKey: 1, pinned: 0, createdAt: now - 26 * 3_600_000,
|
||||
statusChangedAt: now - 40 * 60_000, clusters: [], tags: [], status: "manual_review", mrUrl: null,
|
||||
watcherLabels: {}, mrState: null, mergedIntoBaseAt: null, baseRef: null, repoKey: null,
|
||||
createdViaKeyId: null, createdViaSource: null, createdViaLabel: null, createdViaOwner: null, externalId: null,
|
||||
description: "Meego 导入。", executionPlan: null, reproSteps: null, remark: null, reviewHistory: [],
|
||||
attempts: 1, executorNodeId: "fei-android-01", branchName: "bugfix/streamline-demo",
|
||||
workspacePath: "/tmp/demo", beforeEvidencePath: null, afterEvidencePath: null, failureReason: null,
|
||||
};
|
||||
|
||||
interface Scenario {
|
||||
note: string;
|
||||
item: BoardItem;
|
||||
preview: MrSubmittersPreview;
|
||||
/** 提交结果按选中的人给;抛错用 string。 */
|
||||
result: (asUser: string | undefined) => SubmitMrResult | string;
|
||||
}
|
||||
|
||||
const mk = (over: Record<string, unknown>): BoardItem => ({ ...base, ...over } as unknown as BoardItem);
|
||||
const ok = (who: string, id: number): SubmitMrResult => ({ ok: true, mrUrl: mrUrl(id), bitsUser: who });
|
||||
|
||||
const SCENARIOS: Scenario[] = [
|
||||
{
|
||||
note: "① 就是 81c7b38b 那张单的形状:经办人 jinchaoshuai 不在关注人里,关注人三位(含我)。默认选经办人",
|
||||
item: mk({ id: "s1", title: "【Android】play_time 缺少PhotoParam部分key", meegoId: "7322667510",
|
||||
watchers: ["jingyuan.yi@bytedance.com", "yangqifan.harry@bytedance.com", "huayipeng@bytedance.com"] }),
|
||||
preview: { defaultUser: "jinchaoshuai", candidates: [
|
||||
{ user: "jinchaoshuai", roles: ["assignee"], hasToken: true },
|
||||
{ user: "jingyuan.yi", roles: ["watcher", "self"], hasToken: true },
|
||||
{ user: "yangqifan.harry", roles: ["watcher"], hasToken: true },
|
||||
{ user: "huayipeng", roles: ["watcher"], hasToken: false },
|
||||
] },
|
||||
result: (who) => ok(who || "jingyuan.yi", 8510001),
|
||||
},
|
||||
{
|
||||
note: "② 经办人没绑 Token:那一行置灰写原因,默认退到我自己",
|
||||
item: mk({ id: "s2", title: "【iOS】个人页头像预览缩放后无法关闭", platform: "ios", meegoId: "6931177420",
|
||||
watchers: ["jingyuan.yi@bytedance.com", "qa.zhang@bytedance.com"] }),
|
||||
preview: { defaultUser: "jingyuan.yi", candidates: [
|
||||
{ user: "rd.wang", roles: ["assignee"], hasToken: false },
|
||||
{ user: "jingyuan.yi", roles: ["watcher", "self"], hasToken: true },
|
||||
{ user: "qa.zhang", roles: ["watcher"], hasToken: true },
|
||||
] },
|
||||
result: (who) => ok(who || "jingyuan.yi", 8510002),
|
||||
},
|
||||
{
|
||||
note: "③ 选的人 Token 失效 / 没仓库权限:报错,单子不动(这里任何人都会失败)",
|
||||
item: mk({ id: "s3", title: "【Android】故事发布失败没有提示", meegoId: "6931196005",
|
||||
watchers: ["rd.li@bytedance.com", "jingyuan.yi@bytedance.com"] }),
|
||||
preview: { defaultUser: "rd.li", candidates: [
|
||||
{ user: "rd.li", roles: ["assignee", "watcher"], hasToken: true },
|
||||
{ user: "jingyuan.yi", roles: ["watcher", "self"], hasToken: true },
|
||||
] },
|
||||
result: (who) => `create_mr: as ${who}: 403 no permission on repo tiktok_android`,
|
||||
},
|
||||
{
|
||||
note: "④ 对照:单上只有我(没有经办人 / 其他关注人)—— 不弹窗,直接以我的名义提交",
|
||||
item: mk({ id: "s4", title: "【Android】草稿箱封面加载慢", meegoId: null, watchers: ["jingyuan.yi@bytedance.com"] }),
|
||||
preview: { defaultUser: "jingyuan.yi", candidates: [{ user: "jingyuan.yi", roles: ["watcher", "self"], hasToken: true }] },
|
||||
result: () => ok("jingyuan.yi", 8510004),
|
||||
},
|
||||
{
|
||||
note: "⑤ 单上谁都没绑 Token(包括我):提示先绑定,并打开我的绑定框",
|
||||
item: mk({ id: "s5", title: "【Android】直播间礼物面板偶现空白", meegoId: "6931200002",
|
||||
watchers: ["jingyuan.yi@bytedance.com"] }),
|
||||
preview: { defaultUser: null, candidates: [
|
||||
{ user: "rd.sun", roles: ["assignee"], hasToken: false },
|
||||
{ user: "jingyuan.yi", roles: ["watcher", "self"], hasToken: false },
|
||||
] },
|
||||
result: () => "unreachable",
|
||||
},
|
||||
{
|
||||
note: "⑥ Feature:没有 Meego 经办人,建单人排第一、默认选他;其余是关注人和我",
|
||||
item: mk({ id: "s6", kind: "feature", title: "【Android】评论区支持发送 GIF", meegoId: null,
|
||||
watchers: ["pm.wu@bytedance.com", "rd.li@bytedance.com", "jingyuan.yi@bytedance.com"] }),
|
||||
preview: { defaultUser: "pm.wu", candidates: [
|
||||
{ user: "pm.wu", roles: ["creator", "watcher"], hasToken: true },
|
||||
{ user: "rd.li", roles: ["watcher"], hasToken: true },
|
||||
{ user: "jingyuan.yi", roles: ["watcher", "self"], hasToken: true },
|
||||
] },
|
||||
result: (who) => ok(who || "jingyuan.yi", 8510006),
|
||||
},
|
||||
];
|
||||
|
||||
const byId = new Map(SCENARIOS.map((s) => [s.item.id, s]));
|
||||
let setItems: (fn: (m: Map<string, BoardItem>) => Map<string, BoardItem>) => void = () => {};
|
||||
const wait = (ms: number) => new Promise((r) => setTimeout(r, ms));
|
||||
|
||||
const submitters = async (id: string) => { await wait(400); return byId.get(id)!.preview; };
|
||||
const submit = async (id: string, _repoKey?: string, asUser?: string) => {
|
||||
await wait(1000);
|
||||
const r = byId.get(id)!.result(asUser);
|
||||
if (typeof r === "string") throw new Error(r);
|
||||
if (r.mrUrl) setItems((m) => new Map(m).set(id, { ...m.get(id)!, mrUrl: r.mrUrl } as BoardItem));
|
||||
lastAuthor.set(id, r.bitsUser || "?");
|
||||
return r;
|
||||
};
|
||||
Object.assign(api, {
|
||||
me: async () => ({ email: "jingyuan.yi@bytedance.com", hasBitsToken: true }),
|
||||
mrSubmitters: submitters, featureMrSubmitters: submitters,
|
||||
submitMr: submit, submitMrFeature: submit,
|
||||
});
|
||||
const lastAuthor = new Map<string, string>();
|
||||
|
||||
function Demo() {
|
||||
const [items, _setItems] = useState(() => new Map(SCENARIOS.map((s) => [s.item.id, s.item])));
|
||||
setItems = _setItems;
|
||||
const [openId, setOpenId] = useState<string | null>(null);
|
||||
const open = openId ? items.get(openId) ?? null : null;
|
||||
return (
|
||||
<div className="op-demo">
|
||||
<h1>以谁的名义提交 MR · 演示</h1>
|
||||
<p className="op-sub">点卡片打开抽屉,在「人工复核」那块点 MR 行的「提交 MR」(Bug 和 Feature 都有)。抽屉是真组件、数据是假的,其它接口连不上,只看 MR 那一块。当前登录人假定是 jingyuan.yi。刷新页面重置。</p>
|
||||
<div className="op-cards">
|
||||
{SCENARIOS.map((s) => {
|
||||
const it = items.get(s.item.id)!;
|
||||
const url = (it as Task).mrUrl;
|
||||
return (
|
||||
<div key={s.item.id} className="op-case">
|
||||
<div className="op-note">{s.note}</div>
|
||||
<TaskCard item={it} onOpen={() => setOpenId(it.id)} />
|
||||
<div className="op-mr">{url ? `MR ${url.replace(/.*\//, "")} · 作者 ${lastAuthor.get(it.id)}` : "还没有 MR"}</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<TaskDetailDrawer item={open} onClose={() => setOpenId(null)} />
|
||||
<Toaster />
|
||||
<DialogHost />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const style = document.createElement("style");
|
||||
style.textContent = `
|
||||
html, body, #root { height: auto !important; overflow: auto !important; }
|
||||
body { margin: 0; background: var(--bg, #f6f7f9); }
|
||||
.op-demo { padding: 24px 32px 64px; max-width: 1120px; color: var(--text); }
|
||||
.op-demo h1 { font-size: 20px; margin: 0 0 6px; }
|
||||
.op-sub { font-size: 13px; color: var(--muted); margin: 0 0 24px; }
|
||||
.op-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 20px; }
|
||||
.op-case { display: flex; flex-direction: column; gap: 8px; }
|
||||
.op-note { font-size: 12px; color: var(--muted); line-height: 1.5; min-height: 54px; }
|
||||
.op-mr { font-size: 12px; color: var(--muted); font-family: var(--mono, monospace); }
|
||||
`;
|
||||
document.head.appendChild(style);
|
||||
|
||||
createRoot(document.getElementById("root")!).render(<Demo />);
|
||||
Reference in New Issue
Block a user