mirror of
https://github.com/multica-ai/multica.git
synced 2026-07-23 10:08:38 +02:00
* feat(labels): add scoped label management * fix(labels): address review feedback * fix(migrations): use unique label migration prefix
46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
import { queryOptions } from "@tanstack/react-query";
|
|
import { api } from "../api";
|
|
import type { LabelResourceType } from "../types";
|
|
|
|
export const labelKeys = {
|
|
all: (wsId: string) => ["labels", wsId] as const,
|
|
list: (wsId: string, resourceType: LabelResourceType = "issue") =>
|
|
[...labelKeys.all(wsId), "list", resourceType] as const,
|
|
detail: (wsId: string, id: string) =>
|
|
[...labelKeys.all(wsId), "detail", id] as const,
|
|
byIssue: (wsId: string, issueId: string) =>
|
|
[...labelKeys.all(wsId), "issue", issueId] as const,
|
|
byResource: (wsId: string, resourceType: "agent" | "skill", resourceId: string) =>
|
|
[...labelKeys.all(wsId), resourceType, resourceId] as const,
|
|
};
|
|
|
|
export function labelListOptions(wsId: string, resourceType: LabelResourceType = "issue") {
|
|
return queryOptions({
|
|
queryKey: labelKeys.list(wsId, resourceType),
|
|
queryFn: () => api.listLabels(resourceType),
|
|
select: (data) => data.labels,
|
|
});
|
|
}
|
|
|
|
export function resourceLabelsOptions(
|
|
wsId: string,
|
|
resourceType: "agent" | "skill",
|
|
resourceId: string,
|
|
) {
|
|
return queryOptions({
|
|
queryKey: labelKeys.byResource(wsId, resourceType, resourceId),
|
|
queryFn: () => api.listLabelsForResource(resourceType, resourceId),
|
|
select: (data) => data.labels,
|
|
enabled: Boolean(resourceId),
|
|
});
|
|
}
|
|
|
|
export function issueLabelsOptions(wsId: string, issueId: string) {
|
|
return queryOptions({
|
|
queryKey: labelKeys.byIssue(wsId, issueId),
|
|
queryFn: () => api.listLabelsForIssue(issueId),
|
|
select: (data) => data.labels,
|
|
enabled: Boolean(issueId),
|
|
});
|
|
}
|