mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-19 04:00:38 +09:00
Merge public-gh/master into paperclip-company-import-export
This commit is contained in:
commit
9e19f1d005
49 changed files with 3997 additions and 2501 deletions
|
|
@ -4,11 +4,14 @@ import { beforeEach, describe, expect, it } from "vitest";
|
|||
import type { Approval, DashboardSummary, HeartbeatRun, Issue, JoinRequest } from "@paperclipai/shared";
|
||||
import {
|
||||
computeInboxBadgeData,
|
||||
getApprovalsForTab,
|
||||
getInboxWorkItems,
|
||||
getRecentTouchedIssues,
|
||||
getUnreadTouchedIssues,
|
||||
loadLastInboxTab,
|
||||
RECENT_ISSUES_LIMIT,
|
||||
saveLastInboxTab,
|
||||
shouldShowInboxSection,
|
||||
} from "./inbox";
|
||||
|
||||
const storage = new Map<string, string>();
|
||||
|
|
@ -46,6 +49,19 @@ function makeApproval(status: Approval["status"]): Approval {
|
|||
};
|
||||
}
|
||||
|
||||
function makeApprovalWithTimestamps(
|
||||
id: string,
|
||||
status: Approval["status"],
|
||||
updatedAt: string,
|
||||
): Approval {
|
||||
return {
|
||||
...makeApproval(status),
|
||||
id,
|
||||
createdAt: new Date(updatedAt),
|
||||
updatedAt: new Date(updatedAt),
|
||||
};
|
||||
}
|
||||
|
||||
function makeJoinRequest(id: string): JoinRequest {
|
||||
return {
|
||||
id,
|
||||
|
|
@ -231,6 +247,77 @@ describe("inbox helpers", () => {
|
|||
expect(issues).toHaveLength(2);
|
||||
});
|
||||
|
||||
it("shows recent approvals in updated order and unread approvals as actionable only", () => {
|
||||
const approvals = [
|
||||
makeApprovalWithTimestamps("approval-approved", "approved", "2026-03-11T02:00:00.000Z"),
|
||||
makeApprovalWithTimestamps("approval-pending", "pending", "2026-03-11T01:00:00.000Z"),
|
||||
makeApprovalWithTimestamps(
|
||||
"approval-revision",
|
||||
"revision_requested",
|
||||
"2026-03-11T03:00:00.000Z",
|
||||
),
|
||||
];
|
||||
|
||||
expect(getApprovalsForTab(approvals, "recent", "all").map((approval) => approval.id)).toEqual([
|
||||
"approval-revision",
|
||||
"approval-approved",
|
||||
"approval-pending",
|
||||
]);
|
||||
expect(getApprovalsForTab(approvals, "unread", "all").map((approval) => approval.id)).toEqual([
|
||||
"approval-revision",
|
||||
"approval-pending",
|
||||
]);
|
||||
expect(getApprovalsForTab(approvals, "all", "resolved").map((approval) => approval.id)).toEqual([
|
||||
"approval-approved",
|
||||
]);
|
||||
});
|
||||
|
||||
it("mixes approvals into the inbox feed by most recent activity", () => {
|
||||
const newerIssue = makeIssue("1", true);
|
||||
newerIssue.lastExternalCommentAt = new Date("2026-03-11T04:00:00.000Z");
|
||||
|
||||
const olderIssue = makeIssue("2", false);
|
||||
olderIssue.lastExternalCommentAt = new Date("2026-03-11T02:00:00.000Z");
|
||||
|
||||
const approval = makeApprovalWithTimestamps(
|
||||
"approval-between",
|
||||
"pending",
|
||||
"2026-03-11T03:00:00.000Z",
|
||||
);
|
||||
|
||||
expect(
|
||||
getInboxWorkItems({
|
||||
issues: [olderIssue, newerIssue],
|
||||
approvals: [approval],
|
||||
}).map((item) => item.kind === "issue" ? `issue:${item.issue.id}` : `approval:${item.approval.id}`),
|
||||
).toEqual([
|
||||
"issue:1",
|
||||
"approval:approval-between",
|
||||
"issue:2",
|
||||
]);
|
||||
});
|
||||
|
||||
it("can include sections on recent without forcing them to be unread", () => {
|
||||
expect(
|
||||
shouldShowInboxSection({
|
||||
tab: "recent",
|
||||
hasItems: true,
|
||||
showOnRecent: true,
|
||||
showOnUnread: false,
|
||||
showOnAll: false,
|
||||
}),
|
||||
).toBe(true);
|
||||
expect(
|
||||
shouldShowInboxSection({
|
||||
tab: "unread",
|
||||
hasItems: true,
|
||||
showOnRecent: true,
|
||||
showOnUnread: false,
|
||||
showOnAll: false,
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("limits recent touched issues before unread badge counting", () => {
|
||||
const issues = Array.from({ length: RECENT_ISSUES_LIMIT + 5 }, (_, index) => {
|
||||
const issue = makeIssue(String(index + 1), index < 3);
|
||||
|
|
|
|||
|
|
@ -12,6 +12,18 @@ export const ACTIONABLE_APPROVAL_STATUSES = new Set(["pending", "revision_reques
|
|||
export const DISMISSED_KEY = "paperclip:inbox:dismissed";
|
||||
export const INBOX_LAST_TAB_KEY = "paperclip:inbox:last-tab";
|
||||
export type InboxTab = "recent" | "unread" | "all";
|
||||
export type InboxApprovalFilter = "all" | "actionable" | "resolved";
|
||||
export type InboxWorkItem =
|
||||
| {
|
||||
kind: "issue";
|
||||
timestamp: number;
|
||||
issue: Issue;
|
||||
}
|
||||
| {
|
||||
kind: "approval";
|
||||
timestamp: number;
|
||||
approval: Approval;
|
||||
};
|
||||
|
||||
export interface InboxBadgeData {
|
||||
inbox: number;
|
||||
|
|
@ -104,6 +116,85 @@ export function getUnreadTouchedIssues(issues: Issue[]): Issue[] {
|
|||
return issues.filter((issue) => issue.isUnreadForMe);
|
||||
}
|
||||
|
||||
export function getApprovalsForTab(
|
||||
approvals: Approval[],
|
||||
tab: InboxTab,
|
||||
filter: InboxApprovalFilter,
|
||||
): Approval[] {
|
||||
const sortedApprovals = [...approvals].sort(
|
||||
(a, b) => normalizeTimestamp(b.updatedAt) - normalizeTimestamp(a.updatedAt),
|
||||
);
|
||||
|
||||
if (tab === "recent") return sortedApprovals;
|
||||
if (tab === "unread") {
|
||||
return sortedApprovals.filter((approval) => ACTIONABLE_APPROVAL_STATUSES.has(approval.status));
|
||||
}
|
||||
if (filter === "all") return sortedApprovals;
|
||||
|
||||
return sortedApprovals.filter((approval) => {
|
||||
const isActionable = ACTIONABLE_APPROVAL_STATUSES.has(approval.status);
|
||||
return filter === "actionable" ? isActionable : !isActionable;
|
||||
});
|
||||
}
|
||||
|
||||
export function approvalActivityTimestamp(approval: Approval): number {
|
||||
const updatedAt = normalizeTimestamp(approval.updatedAt);
|
||||
if (updatedAt > 0) return updatedAt;
|
||||
return normalizeTimestamp(approval.createdAt);
|
||||
}
|
||||
|
||||
export function getInboxWorkItems({
|
||||
issues,
|
||||
approvals,
|
||||
}: {
|
||||
issues: Issue[];
|
||||
approvals: Approval[];
|
||||
}): InboxWorkItem[] {
|
||||
return [
|
||||
...issues.map((issue) => ({
|
||||
kind: "issue" as const,
|
||||
timestamp: issueLastActivityTimestamp(issue),
|
||||
issue,
|
||||
})),
|
||||
...approvals.map((approval) => ({
|
||||
kind: "approval" as const,
|
||||
timestamp: approvalActivityTimestamp(approval),
|
||||
approval,
|
||||
})),
|
||||
].sort((a, b) => {
|
||||
const timestampDiff = b.timestamp - a.timestamp;
|
||||
if (timestampDiff !== 0) return timestampDiff;
|
||||
|
||||
if (a.kind === "issue" && b.kind === "issue") {
|
||||
return sortIssuesByMostRecentActivity(a.issue, b.issue);
|
||||
}
|
||||
if (a.kind === "approval" && b.kind === "approval") {
|
||||
return approvalActivityTimestamp(b.approval) - approvalActivityTimestamp(a.approval);
|
||||
}
|
||||
|
||||
return a.kind === "approval" ? -1 : 1;
|
||||
});
|
||||
}
|
||||
|
||||
export function shouldShowInboxSection({
|
||||
tab,
|
||||
hasItems,
|
||||
showOnRecent,
|
||||
showOnUnread,
|
||||
showOnAll,
|
||||
}: {
|
||||
tab: InboxTab;
|
||||
hasItems: boolean;
|
||||
showOnRecent: boolean;
|
||||
showOnUnread: boolean;
|
||||
showOnAll: boolean;
|
||||
}): boolean {
|
||||
if (!hasItems) return false;
|
||||
if (tab === "recent") return showOnRecent;
|
||||
if (tab === "unread") return showOnUnread;
|
||||
return showOnAll;
|
||||
}
|
||||
|
||||
export function computeInboxBadgeData({
|
||||
approvals,
|
||||
joinRequests,
|
||||
|
|
|
|||
80
ui/src/lib/onboarding-route.test.ts
Normal file
80
ui/src/lib/onboarding-route.test.ts
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
isOnboardingPath,
|
||||
resolveRouteOnboardingOptions,
|
||||
shouldRedirectCompanylessRouteToOnboarding,
|
||||
} from "./onboarding-route";
|
||||
|
||||
describe("isOnboardingPath", () => {
|
||||
it("matches the global onboarding route", () => {
|
||||
expect(isOnboardingPath("/onboarding")).toBe(true);
|
||||
});
|
||||
|
||||
it("matches a company-prefixed onboarding route", () => {
|
||||
expect(isOnboardingPath("/pap/onboarding")).toBe(true);
|
||||
});
|
||||
|
||||
it("ignores non-onboarding routes", () => {
|
||||
expect(isOnboardingPath("/pap/dashboard")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveRouteOnboardingOptions", () => {
|
||||
it("opens company creation for the global onboarding route", () => {
|
||||
expect(
|
||||
resolveRouteOnboardingOptions({
|
||||
pathname: "/onboarding",
|
||||
companies: [],
|
||||
}),
|
||||
).toEqual({ initialStep: 1 });
|
||||
});
|
||||
|
||||
it("opens agent creation when the prefixed company exists", () => {
|
||||
expect(
|
||||
resolveRouteOnboardingOptions({
|
||||
pathname: "/pap/onboarding",
|
||||
companyPrefix: "pap",
|
||||
companies: [{ id: "company-1", issuePrefix: "PAP" }],
|
||||
}),
|
||||
).toEqual({ initialStep: 2, companyId: "company-1" });
|
||||
});
|
||||
|
||||
it("falls back to company creation when the prefixed company is missing", () => {
|
||||
expect(
|
||||
resolveRouteOnboardingOptions({
|
||||
pathname: "/pap/onboarding",
|
||||
companyPrefix: "pap",
|
||||
companies: [],
|
||||
}),
|
||||
).toEqual({ initialStep: 1 });
|
||||
});
|
||||
});
|
||||
|
||||
describe("shouldRedirectCompanylessRouteToOnboarding", () => {
|
||||
it("redirects companyless entry routes into onboarding", () => {
|
||||
expect(
|
||||
shouldRedirectCompanylessRouteToOnboarding({
|
||||
pathname: "/",
|
||||
hasCompanies: false,
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("does not redirect when already on onboarding", () => {
|
||||
expect(
|
||||
shouldRedirectCompanylessRouteToOnboarding({
|
||||
pathname: "/onboarding",
|
||||
hasCompanies: false,
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("does not redirect when companies exist", () => {
|
||||
expect(
|
||||
shouldRedirectCompanylessRouteToOnboarding({
|
||||
pathname: "/issues",
|
||||
hasCompanies: true,
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
51
ui/src/lib/onboarding-route.ts
Normal file
51
ui/src/lib/onboarding-route.ts
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
type OnboardingRouteCompany = {
|
||||
id: string;
|
||||
issuePrefix: string;
|
||||
};
|
||||
|
||||
export function isOnboardingPath(pathname: string): boolean {
|
||||
const segments = pathname.split("/").filter(Boolean);
|
||||
|
||||
if (segments.length === 1) {
|
||||
return segments[0]?.toLowerCase() === "onboarding";
|
||||
}
|
||||
|
||||
if (segments.length === 2) {
|
||||
return segments[1]?.toLowerCase() === "onboarding";
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export function resolveRouteOnboardingOptions(params: {
|
||||
pathname: string;
|
||||
companyPrefix?: string;
|
||||
companies: OnboardingRouteCompany[];
|
||||
}): { initialStep: 1 | 2; companyId?: string } | null {
|
||||
const { pathname, companyPrefix, companies } = params;
|
||||
|
||||
if (!isOnboardingPath(pathname)) return null;
|
||||
|
||||
if (!companyPrefix) {
|
||||
return { initialStep: 1 };
|
||||
}
|
||||
|
||||
const matchedCompany =
|
||||
companies.find(
|
||||
(company) =>
|
||||
company.issuePrefix.toUpperCase() === companyPrefix.toUpperCase(),
|
||||
) ?? null;
|
||||
|
||||
if (!matchedCompany) {
|
||||
return { initialStep: 1 };
|
||||
}
|
||||
|
||||
return { initialStep: 2, companyId: matchedCompany.id };
|
||||
}
|
||||
|
||||
export function shouldRedirectCompanylessRouteToOnboarding(params: {
|
||||
pathname: string;
|
||||
hasCompanies: boolean;
|
||||
}): boolean {
|
||||
return !params.hasCompanies && !isOnboardingPath(params.pathname);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue