mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-22 11:54:35 +01:00
fix(dashboard): scope areas and responsibilities to each user (#22513)
This commit is contained in:
1 parent
558dbb0132
commit
856f14e507
68 files changed
+2708
-559
No files matched your search
@@ -21,17 +21,19 @@ import {
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog";
|
||||
import { useResolvedViewerId } from "@/hooks/useResolvedViewerId";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { queryKeys } from "@/lib/queryKeys";
|
||||
|
||||
type AreaRef = Pick<ResponsibilityArea, "id" | "title" | "status">;
|
||||
|
||||
/** The company's areas that can take a responsibility (active and proposed). */
|
||||
/** The viewer's areas that can take a responsibility (active and proposed). */
|
||||
export function useResponsibilityAreas(companyId: string | null | undefined, enabled = true) {
|
||||
const { userId } = useResolvedViewerId({ enabled });
|
||||
return useQuery({
|
||||
queryKey: queryKeys.responsibilities.areas(companyId ?? "__none__"),
|
||||
queryKey: [...queryKeys.responsibilities.areas(companyId ?? "__none__"), userId],
|
||||
queryFn: () => responsibilityAreasApi.list(companyId!),
|
||||
enabled: enabled && !!companyId,
|
||||
enabled: enabled && !!companyId && !!userId,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -458,7 +458,7 @@ function AgentStatusBody({
|
||||
mutationFn: (row: AgentStatusRow) => responsibilitiesApi.requestStatusUpdate(row.responsibility.id),
|
||||
onSuccess: async (_state, row) => {
|
||||
await Promise.all([
|
||||
queryClient.invalidateQueries({ queryKey: queryKeys.responsibilities.statusReports(companyId) }),
|
||||
queryClient.invalidateQueries({ queryKey: ["responsibilities", "status-reports", companyId] }),
|
||||
queryClient.invalidateQueries({ queryKey: queryKeys.responsibilities.statusReport(row.responsibility.id) }),
|
||||
]);
|
||||
},
|
||||
@@ -577,7 +577,7 @@ export function DashboardAgentStatus(props: DashboardViewProps) {
|
||||
const active = useMemo(() => activeResponsibilities(overview.responsibilities), [overview.responsibilities]);
|
||||
const { data: session } = useQuery({ queryKey: queryKeys.auth.session, queryFn: () => authApi.getSession() });
|
||||
const query = useQuery({
|
||||
queryKey: queryKeys.responsibilities.statusReports(companyId),
|
||||
queryKey: queryKeys.responsibilities.statusReports(companyId, props.overview.ownerUserId),
|
||||
queryFn: () => responsibilitiesApi.statusReports(companyId),
|
||||
enabled: active.length > 0,
|
||||
});
|
||||
|
||||
@@ -671,7 +671,7 @@ function AutomationSkeleton() {
|
||||
export function DashboardAutomation({ companyId, overview, agents, agentsById, now, onAddResponsibility, onReviewProposals }: DashboardViewProps) {
|
||||
const active = useMemo(() => activeResponsibilities(overview.responsibilities), [overview.responsibilities]);
|
||||
const query = useQuery({
|
||||
queryKey: queryKeys.responsibilities.automation(companyId),
|
||||
queryKey: queryKeys.responsibilities.automation(companyId, overview.ownerUserId),
|
||||
queryFn: () => responsibilitiesApi.automation(companyId),
|
||||
enabled: active.length > 0,
|
||||
});
|
||||
|
||||
@@ -20,17 +20,17 @@ import { ProposalsNotice } from "./ResponsibilityViewParts";
|
||||
import type { DashboardViewProps } from "./view-props";
|
||||
|
||||
/** Which areas are folded, remembered in the browser; works without storage. */
|
||||
function useCollapsedAreas(): [ReadonlySet<string>, (key: string) => void] {
|
||||
const [collapsed, setCollapsed] = useState<ReadonlySet<string>>(() => readCollapsedAreas());
|
||||
function useCollapsedAreas(scope: string): [ReadonlySet<string>, (key: string) => void] {
|
||||
const [collapsed, setCollapsed] = useState<ReadonlySet<string>>(() => readCollapsedAreas(scope));
|
||||
const toggle = useCallback((key: string) => {
|
||||
setCollapsed((current) => {
|
||||
const next = new Set(current);
|
||||
if (next.has(key)) next.delete(key);
|
||||
else next.add(key);
|
||||
writeCollapsedAreas(next);
|
||||
writeCollapsedAreas(next, scope);
|
||||
return next;
|
||||
});
|
||||
}, []);
|
||||
}, [scope]);
|
||||
return [collapsed, toggle];
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ export function DashboardOutlineV2({
|
||||
() => outlineV2Groups(overview.areas, overview.responsibilities, keepEmptyAreas),
|
||||
[overview.areas, overview.responsibilities, keepEmptyAreas],
|
||||
);
|
||||
const [collapsed, toggle] = useCollapsedAreas();
|
||||
const [collapsed, toggle] = useCollapsedAreas(JSON.stringify([companyId, overview.ownerUserId]));
|
||||
const query = search.trim();
|
||||
const shown = useMemo(() => searchOutlineV2Groups(groups, query), [groups, query]);
|
||||
|
||||
@@ -161,7 +161,7 @@ export function DashboardOutlineV2({
|
||||
);
|
||||
|
||||
// Nothing owned and nothing proposed: only the module, and any area just added by hand.
|
||||
if (active.length === 0 && overview.proposed.length === 0) {
|
||||
if (groups.length === 0 && active.length === 0 && overview.proposed.length === 0) {
|
||||
return (
|
||||
<div className="flex flex-col gap-4" data-dashboard-view="outline_v2" data-dashboard-empty="">
|
||||
<DashboardEditModule
|
||||
@@ -171,7 +171,6 @@ export function DashboardOutlineV2({
|
||||
agentsById={agentsById}
|
||||
onAddArea={onAddArea}
|
||||
/>
|
||||
{groups.filter((group) => keepEmptyAreas.has(group.key)).map(renderArea)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ function useUpdateResponsibility(id: string) {
|
||||
return useMutation({
|
||||
mutationFn: (patch: UpdateResponsibility) => responsibilitiesApi.update(id, patch),
|
||||
onSuccess: (updated) => {
|
||||
queryClient.setQueryData<ResponsibilityDetail>(queryKeys.responsibilities.detail(id), (old) =>
|
||||
queryClient.setQueriesData<ResponsibilityDetail>({ queryKey: queryKeys.responsibilities.detail(id) }, (old) =>
|
||||
old ? { ...old, ...updated } : old);
|
||||
void queryClient.invalidateQueries({ queryKey: queryKeys.responsibilities.all });
|
||||
},
|
||||
|
||||
@@ -4,6 +4,7 @@ import type { ResponsibilitySummary as Narrative } from "@paperclipai/shared";
|
||||
import { responsibilitiesApi } from "@/api/responsibilities";
|
||||
import { queryKeys } from "@/lib/queryKeys";
|
||||
import { summaryAttribution, summaryRefetchDelay } from "@/lib/responsibility-summary";
|
||||
import { useResolvedViewerId } from "@/hooks/useResolvedViewerId";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
/**
|
||||
@@ -28,10 +29,11 @@ function useNarrative(queryKey: readonly unknown[], queryFn: () => Promise<Narra
|
||||
|
||||
/** The Dashboard's paragraph of where everything stands. */
|
||||
export function useDashboardNarrative(companyId: string | null | undefined) {
|
||||
const { userId } = useResolvedViewerId();
|
||||
return useNarrative(
|
||||
queryKeys.responsibilities.summary(companyId ?? "__none__"),
|
||||
queryKeys.responsibilities.summary(companyId ?? "__none__", userId),
|
||||
() => responsibilitiesApi.companySummary(companyId!),
|
||||
!!companyId,
|
||||
!!companyId && !!userId,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import { responsibilitiesApi } from "@/api/responsibilities";
|
||||
import { secretsApi } from "@/api/secrets";
|
||||
import type { MentionOption } from "@/components/MarkdownEditor";
|
||||
import { useQueryView } from "@/components/QueryView";
|
||||
import { useResolvedViewerId } from "@/hooks/useResolvedViewerId";
|
||||
import { useResponsibilitiesEnabled } from "@/hooks/useResponsibilitiesEnabled";
|
||||
import { companyProjectsQuery } from "@/lib/company-projects-query";
|
||||
import { buildCompanyUserProfileMap, buildMarkdownMentionOptions } from "@/lib/company-members";
|
||||
@@ -34,6 +35,7 @@ export function useRoutineFormOptions(
|
||||
const enabled = Boolean(companyId) && active;
|
||||
const { enabled: responsibilitiesOn } = useResponsibilitiesEnabled();
|
||||
|
||||
const { userId } = useResolvedViewerId({ enabled: enabled && responsibilitiesOn });
|
||||
const agentsQuery = useQuery({
|
||||
queryKey: queryKeys.agents.list(companyId ?? ""),
|
||||
queryFn: () => agentsApi.list(companyId!),
|
||||
@@ -51,9 +53,9 @@ export function useRoutineFormOptions(
|
||||
enabled,
|
||||
});
|
||||
const responsibilitiesQuery = useQuery({
|
||||
queryKey: queryKeys.responsibilities.overview(companyId ?? ""),
|
||||
queryKey: queryKeys.responsibilities.overview(companyId ?? "", { ownerUserId: userId }),
|
||||
queryFn: () => responsibilitiesApi.overview(companyId!),
|
||||
enabled: enabled && responsibilitiesOn,
|
||||
enabled: enabled && responsibilitiesOn && !!userId,
|
||||
});
|
||||
|
||||
// Failed reads are reported, never shown as empty choices.
|
||||
|
||||
Reference in new issue
Block a user