mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-01 15:35:12 +01:00
feat(control-plane): add annotation and workspace controls
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
1b89a8e3b8
commit
5794bc90f7
41 files changed
+3488
-435
No files matched your search
@@ -11,27 +11,50 @@ import { api } from "./client";
|
||||
|
||||
export type DocumentAnnotationListFilter = "open" | "resolved" | "all";
|
||||
|
||||
export type DocumentAnnotationTarget =
|
||||
| { kind: "issue"; issueId: string; documentKey: string }
|
||||
| { kind: "routine"; routineId: string; documentKey: "description" };
|
||||
|
||||
function issueTarget(issueId: string, documentKey: string): DocumentAnnotationTarget {
|
||||
return { kind: "issue", issueId, documentKey };
|
||||
}
|
||||
|
||||
function targetBasePath(target: DocumentAnnotationTarget) {
|
||||
if (target.kind === "routine") {
|
||||
return `/routines/${target.routineId}/description/annotations`;
|
||||
}
|
||||
return `/issues/${target.issueId}/documents/${encodeURIComponent(target.documentKey)}/annotations`;
|
||||
}
|
||||
|
||||
export const documentAnnotationsApi = {
|
||||
list: (
|
||||
issueId: string,
|
||||
key: string,
|
||||
options: { status?: DocumentAnnotationListFilter; includeComments?: boolean } = {},
|
||||
) => documentAnnotationsApi.listForTarget(issueTarget(issueId, key), options),
|
||||
listForTarget: (
|
||||
target: DocumentAnnotationTarget,
|
||||
options: { status?: DocumentAnnotationListFilter; includeComments?: boolean } = {},
|
||||
) => {
|
||||
const params = new URLSearchParams();
|
||||
if (options.status) params.set("status", options.status);
|
||||
if (options.includeComments) params.set("includeComments", "true");
|
||||
const qs = params.toString();
|
||||
return api.get<DocumentAnnotationThreadWithComments[]>(
|
||||
`/issues/${issueId}/documents/${encodeURIComponent(key)}/annotations${qs ? `?${qs}` : ""}`,
|
||||
`${targetBasePath(target)}${qs ? `?${qs}` : ""}`,
|
||||
);
|
||||
},
|
||||
get: (issueId: string, key: string, threadId: string) =>
|
||||
documentAnnotationsApi.getForTarget(issueTarget(issueId, key), threadId),
|
||||
getForTarget: (target: DocumentAnnotationTarget, threadId: string) =>
|
||||
api.get<DocumentAnnotationThreadWithComments>(
|
||||
`/issues/${issueId}/documents/${encodeURIComponent(key)}/annotations/${threadId}`,
|
||||
`${targetBasePath(target)}/${threadId}`,
|
||||
),
|
||||
create: (issueId: string, key: string, data: CreateDocumentAnnotationThreadRequest) =>
|
||||
documentAnnotationsApi.createForTarget(issueTarget(issueId, key), data),
|
||||
createForTarget: (target: DocumentAnnotationTarget, data: CreateDocumentAnnotationThreadRequest) =>
|
||||
api.post<DocumentAnnotationThreadWithComments>(
|
||||
`/issues/${issueId}/documents/${encodeURIComponent(key)}/annotations`,
|
||||
targetBasePath(target),
|
||||
data,
|
||||
),
|
||||
addComment: (
|
||||
@@ -39,9 +62,14 @@ export const documentAnnotationsApi = {
|
||||
key: string,
|
||||
threadId: string,
|
||||
data: CreateDocumentAnnotationCommentRequest,
|
||||
) => documentAnnotationsApi.addCommentForTarget(issueTarget(issueId, key), threadId, data),
|
||||
addCommentForTarget: (
|
||||
target: DocumentAnnotationTarget,
|
||||
threadId: string,
|
||||
data: CreateDocumentAnnotationCommentRequest,
|
||||
) =>
|
||||
api.post<DocumentAnnotationComment>(
|
||||
`/issues/${issueId}/documents/${encodeURIComponent(key)}/annotations/${threadId}/comments`,
|
||||
`${targetBasePath(target)}/${threadId}/comments`,
|
||||
data,
|
||||
),
|
||||
updateStatus: (
|
||||
@@ -49,10 +77,15 @@ export const documentAnnotationsApi = {
|
||||
key: string,
|
||||
threadId: string,
|
||||
status: DocumentAnnotationThreadStatus,
|
||||
) => documentAnnotationsApi.updateStatusForTarget(issueTarget(issueId, key), threadId, status),
|
||||
updateStatusForTarget: (
|
||||
target: DocumentAnnotationTarget,
|
||||
threadId: string,
|
||||
status: DocumentAnnotationThreadStatus,
|
||||
) => {
|
||||
const payload: UpdateDocumentAnnotationThreadRequest = { status };
|
||||
return api.patch<DocumentAnnotationThread>(
|
||||
`/issues/${issueId}/documents/${encodeURIComponent(key)}/annotations/${threadId}`,
|
||||
`${targetBasePath(target)}/${threadId}`,
|
||||
payload,
|
||||
);
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user