mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-17 11:20:37 +09:00
Mix approvals into inbox activity feed
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
parent
c121f4d4a7
commit
22ae70649b
3 changed files with 260 additions and 120 deletions
|
|
@ -13,6 +13,17 @@ 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;
|
||||
|
|
@ -126,6 +137,45 @@ export function getApprovalsForTab(
|
|||
});
|
||||
}
|
||||
|
||||
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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue