fix(renderer): use snapshot.currentCompanyId as single source of truth (D-03)
CompanySlice's standalone currentCompanyId field + setCurrentCompanyId action were never written by any caller, so useDesktopEvents.ts read null and fell through to full refresh for every entity event -- the granular patch machinery was dead code. - Remove currentCompanyId field + setCurrentCompanyId from CompanySlice - refreshBadges reads from snapshot.currentCompanyId - useDesktopEvents reads companyId from snapshot.currentCompanyId - Update store unit test to seed snapshot instead of calling removed action
This commit is contained in:
1 parent
a130dc29f5
commit
0119872db6
3 files changed
+4
-11
No files matched your search
@@ -13,7 +13,7 @@ export function useDesktopEvents(
|
|||||||
const store = useAppStore;
|
const store = useAppStore;
|
||||||
|
|
||||||
async function handleGranularBatch(events: GranularEventEntry[]) {
|
async function handleGranularBatch(events: GranularEventEntry[]) {
|
||||||
const companyId = store.getState().currentCompanyId;
|
const companyId = store.getState().snapshot?.currentCompanyId ?? null;
|
||||||
if (!companyId) {
|
if (!companyId) {
|
||||||
void refreshRef.current();
|
void refreshRef.current();
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -14,14 +14,12 @@ import type { SidebarBadges } from "@shared/contracts";
|
|||||||
|
|
||||||
export interface CompanySlice {
|
export interface CompanySlice {
|
||||||
snapshot: ProfileSnapshot | null;
|
snapshot: ProfileSnapshot | null;
|
||||||
currentCompanyId: string | null;
|
|
||||||
companyMetrics: CompanyMetrics | null;
|
companyMetrics: CompanyMetrics | null;
|
||||||
standupReport: StandupReport | null;
|
standupReport: StandupReport | null;
|
||||||
inboxItems: InboxItem[];
|
inboxItems: InboxItem[];
|
||||||
badges: SidebarBadges | null;
|
badges: SidebarBadges | null;
|
||||||
error: string | null;
|
error: string | null;
|
||||||
setSnapshot: (snapshot: ProfileSnapshot | null) => void;
|
setSnapshot: (snapshot: ProfileSnapshot | null) => void;
|
||||||
setCurrentCompanyId: (id: string | null) => void;
|
|
||||||
setCompanyMetrics: (metrics: CompanyMetrics | null) => void;
|
setCompanyMetrics: (metrics: CompanyMetrics | null) => void;
|
||||||
setStandupReport: (report: StandupReport | null) => void;
|
setStandupReport: (report: StandupReport | null) => void;
|
||||||
setInboxItems: (items: InboxItem[]) => void;
|
setInboxItems: (items: InboxItem[]) => void;
|
||||||
@@ -46,7 +44,6 @@ export const createCompanySlice: StateCreator<
|
|||||||
CompanySlice
|
CompanySlice
|
||||||
> = (set, get) => ({
|
> = (set, get) => ({
|
||||||
snapshot: null,
|
snapshot: null,
|
||||||
currentCompanyId: null,
|
|
||||||
companyMetrics: null,
|
companyMetrics: null,
|
||||||
standupReport: null,
|
standupReport: null,
|
||||||
inboxItems: [],
|
inboxItems: [],
|
||||||
@@ -56,10 +53,6 @@ export const createCompanySlice: StateCreator<
|
|||||||
set((state) => {
|
set((state) => {
|
||||||
state.snapshot = snapshot;
|
state.snapshot = snapshot;
|
||||||
}),
|
}),
|
||||||
setCurrentCompanyId: (id) =>
|
|
||||||
set((state) => {
|
|
||||||
state.currentCompanyId = id;
|
|
||||||
}),
|
|
||||||
setCompanyMetrics: (metrics) =>
|
setCompanyMetrics: (metrics) =>
|
||||||
set((state) => {
|
set((state) => {
|
||||||
state.companyMetrics = metrics;
|
state.companyMetrics = metrics;
|
||||||
@@ -166,7 +159,7 @@ export const createCompanySlice: StateCreator<
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
refreshBadges: async () => {
|
refreshBadges: async () => {
|
||||||
const companyId = get().currentCompanyId;
|
const companyId = get().snapshot?.currentCompanyId ?? null;
|
||||||
if (!companyId) return;
|
if (!companyId) return;
|
||||||
try {
|
try {
|
||||||
const result = await window.agentCompany.getSidebarBadges(companyId);
|
const result = await window.agentCompany.getSidebarBadges(companyId);
|
||||||
|
|||||||
@@ -495,8 +495,8 @@ describe("CompanySlice patch methods", () => {
|
|||||||
const mockBadges = { tasks: 5, approvals: 2, runs: 0, messages: 3 };
|
const mockBadges = { tasks: 5, approvals: 2, runs: 0, messages: 3 };
|
||||||
mockGetSidebarBadges.mockResolvedValue({ ok: true, data: mockBadges });
|
mockGetSidebarBadges.mockResolvedValue({ ok: true, data: mockBadges });
|
||||||
|
|
||||||
// Set current company ID first
|
// Seed snapshot with currentCompanyId -- refreshBadges reads from snapshot
|
||||||
useAppStore.getState().setCurrentCompanyId("company-1");
|
useAppStore.getState().setSnapshot(makeSnapshot());
|
||||||
|
|
||||||
await useAppStore.getState().refreshBadges();
|
await useAppStore.getState().refreshBadges();
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user