fix(recent-projects): show active projects during provisioning
This commit is contained in:
parent
4f97e9d2d8
commit
9675f9b331
3 changed files with 152 additions and 31 deletions
|
|
@ -3,7 +3,8 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||||
import { type DashboardRecentProject } from '@features/recent-projects/contracts';
|
import { type DashboardRecentProject } from '@features/recent-projects/contracts';
|
||||||
import { api, isElectronMode } from '@renderer/api';
|
import { api, isElectronMode } from '@renderer/api';
|
||||||
import { useStore } from '@renderer/store';
|
import { useStore } from '@renderer/store';
|
||||||
import { buildTaskCountsByProject, normalizePath } from '@renderer/utils/pathNormalize';
|
import { isTeamProvisioningActive } from '@renderer/store/slices/teamSlice';
|
||||||
|
import { buildTaskCountsByProject } from '@renderer/utils/pathNormalize';
|
||||||
import { useShallow } from 'zustand/react/shallow';
|
import { useShallow } from 'zustand/react/shallow';
|
||||||
|
|
||||||
import { adaptRecentProjectsSection } from '../adapters/RecentProjectsSectionAdapter';
|
import { adaptRecentProjectsSection } from '../adapters/RecentProjectsSectionAdapter';
|
||||||
|
|
@ -11,6 +12,7 @@ import {
|
||||||
sortRecentProjectsByDisplayPriority,
|
sortRecentProjectsByDisplayPriority,
|
||||||
subscribeRecentProjectOpenHistory,
|
subscribeRecentProjectOpenHistory,
|
||||||
} from '../utils/recentProjectOpenHistory';
|
} from '../utils/recentProjectOpenHistory';
|
||||||
|
import { buildActiveTeamsByProject } from '../utils/activeProjectTeams';
|
||||||
import {
|
import {
|
||||||
getRecentProjectsClientSnapshot,
|
getRecentProjectsClientSnapshot,
|
||||||
loadRecentProjectsWithClientCache,
|
loadRecentProjectsWithClientCache,
|
||||||
|
|
@ -62,16 +64,27 @@ export function useRecentProjectsSection(
|
||||||
openProjectPath: (projectPath: string) => Promise<void>;
|
openProjectPath: (projectPath: string) => Promise<void>;
|
||||||
selectProjectFolder: () => Promise<void>;
|
selectProjectFolder: () => Promise<void>;
|
||||||
} {
|
} {
|
||||||
const { globalTasks, globalTasksInitialized, globalTasksLoading, fetchAllTasks, teams } =
|
const {
|
||||||
useStore(
|
globalTasks,
|
||||||
useShallow((state) => ({
|
globalTasksInitialized,
|
||||||
globalTasks: state.globalTasks,
|
globalTasksLoading,
|
||||||
globalTasksInitialized: state.globalTasksInitialized,
|
fetchAllTasks,
|
||||||
globalTasksLoading: state.globalTasksLoading,
|
teams,
|
||||||
fetchAllTasks: state.fetchAllTasks,
|
provisioningRuns,
|
||||||
teams: state.teams,
|
currentProvisioningRunIdByTeam,
|
||||||
}))
|
provisioningSnapshotByTeam,
|
||||||
);
|
} = useStore(
|
||||||
|
useShallow((state) => ({
|
||||||
|
globalTasks: state.globalTasks,
|
||||||
|
globalTasksInitialized: state.globalTasksInitialized,
|
||||||
|
globalTasksLoading: state.globalTasksLoading,
|
||||||
|
fetchAllTasks: state.fetchAllTasks,
|
||||||
|
teams: state.teams,
|
||||||
|
provisioningRuns: state.provisioningRuns,
|
||||||
|
currentProvisioningRunIdByTeam: state.currentProvisioningRunIdByTeam,
|
||||||
|
provisioningSnapshotByTeam: state.provisioningSnapshotByTeam,
|
||||||
|
}))
|
||||||
|
);
|
||||||
const initialSnapshot = useMemo(() => getRecentProjectsClientSnapshot(), []);
|
const initialSnapshot = useMemo(() => getRecentProjectsClientSnapshot(), []);
|
||||||
const { openRecentProject, openProjectPath, selectProjectFolder } = useOpenRecentProject();
|
const { openRecentProject, openProjectPath, selectProjectFolder } = useOpenRecentProject();
|
||||||
const [recentProjects, setRecentProjects] = useState<DashboardRecentProject[]>(
|
const [recentProjects, setRecentProjects] = useState<DashboardRecentProject[]>(
|
||||||
|
|
@ -92,6 +105,21 @@ export function useRecentProjectsSection(
|
||||||
const recentProjectsRef = useRef<DashboardRecentProject[]>(
|
const recentProjectsRef = useRef<DashboardRecentProject[]>(
|
||||||
initialSnapshot?.payload.projects ?? []
|
initialSnapshot?.payload.projects ?? []
|
||||||
);
|
);
|
||||||
|
const provisioningState = useMemo(
|
||||||
|
() => ({ currentProvisioningRunIdByTeam, provisioningRuns }),
|
||||||
|
[currentProvisioningRunIdByTeam, provisioningRuns]
|
||||||
|
);
|
||||||
|
const provisioningTeamNames = useMemo(
|
||||||
|
() =>
|
||||||
|
Object.keys(currentProvisioningRunIdByTeam).filter((teamName) =>
|
||||||
|
isTeamProvisioningActive(provisioningState, teamName)
|
||||||
|
),
|
||||||
|
[currentProvisioningRunIdByTeam, provisioningState]
|
||||||
|
);
|
||||||
|
const provisioningTeamNamesKey = useMemo(
|
||||||
|
() => [...provisioningTeamNames].sort().join('\u0000'),
|
||||||
|
[provisioningTeamNames]
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
recentProjectsRef.current = recentProjects;
|
recentProjectsRef.current = recentProjects;
|
||||||
|
|
@ -173,7 +201,7 @@ export function useRecentProjectsSection(
|
||||||
return () => {
|
return () => {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
};
|
};
|
||||||
}, [teams]);
|
}, [provisioningTeamNamesKey, teams]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!searchQuery.trim()) {
|
if (!searchQuery.trim()) {
|
||||||
|
|
@ -189,25 +217,13 @@ export function useRecentProjectsSection(
|
||||||
const taskCountsByProject = useMemo(() => buildTaskCountsByProject(globalTasks), [globalTasks]);
|
const taskCountsByProject = useMemo(() => buildTaskCountsByProject(globalTasks), [globalTasks]);
|
||||||
|
|
||||||
const activeTeamsByProject = useMemo(() => {
|
const activeTeamsByProject = useMemo(() => {
|
||||||
const aliveSet = new Set(aliveTeams);
|
return buildActiveTeamsByProject({
|
||||||
const teamsByProject = new Map<string, TeamSummary[]>();
|
teams,
|
||||||
|
aliveTeamNames: aliveTeams,
|
||||||
for (const team of teams) {
|
provisioningTeamNames,
|
||||||
if (!team.projectPath || !aliveSet.has(team.teamName)) {
|
provisioningSnapshotByTeam,
|
||||||
continue;
|
});
|
||||||
}
|
}, [aliveTeams, provisioningSnapshotByTeam, provisioningTeamNames, teams]);
|
||||||
|
|
||||||
const key = normalizePath(team.projectPath);
|
|
||||||
const existing = teamsByProject.get(key);
|
|
||||||
if (existing) {
|
|
||||||
existing.push(team);
|
|
||||||
} else {
|
|
||||||
teamsByProject.set(key, [team]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return teamsByProject;
|
|
||||||
}, [aliveTeams, teams]);
|
|
||||||
|
|
||||||
const decoratedCards = useMemo(
|
const decoratedCards = useMemo(
|
||||||
() =>
|
() =>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
import { normalizePath } from '@renderer/utils/pathNormalize';
|
||||||
|
|
||||||
|
import type { TeamSummary } from '@shared/types';
|
||||||
|
|
||||||
|
interface BuildActiveTeamsByProjectInput {
|
||||||
|
teams: TeamSummary[];
|
||||||
|
aliveTeamNames: readonly string[];
|
||||||
|
provisioningTeamNames: readonly string[];
|
||||||
|
provisioningSnapshotByTeam: Record<string, TeamSummary>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function buildActiveTeamsByProject({
|
||||||
|
teams,
|
||||||
|
aliveTeamNames,
|
||||||
|
provisioningTeamNames,
|
||||||
|
provisioningSnapshotByTeam,
|
||||||
|
}: BuildActiveTeamsByProjectInput): Map<string, TeamSummary[]> {
|
||||||
|
const activeTeamNames = new Set<string>([...aliveTeamNames, ...provisioningTeamNames]);
|
||||||
|
if (activeTeamNames.size === 0) {
|
||||||
|
return new Map();
|
||||||
|
}
|
||||||
|
|
||||||
|
const existingTeamNames = new Set(teams.map((team) => team.teamName));
|
||||||
|
const syntheticProvisioningTeams = provisioningTeamNames
|
||||||
|
.filter((teamName) => !existingTeamNames.has(teamName))
|
||||||
|
.map((teamName) => provisioningSnapshotByTeam[teamName])
|
||||||
|
.filter((team): team is TeamSummary => Boolean(team));
|
||||||
|
|
||||||
|
const teamsByProject = new Map<string, TeamSummary[]>();
|
||||||
|
const visibleTeams =
|
||||||
|
syntheticProvisioningTeams.length > 0 ? [...teams, ...syntheticProvisioningTeams] : teams;
|
||||||
|
|
||||||
|
for (const team of visibleTeams) {
|
||||||
|
if (!team.projectPath || !activeTeamNames.has(team.teamName)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const key = normalizePath(team.projectPath);
|
||||||
|
const existing = teamsByProject.get(key);
|
||||||
|
if (existing) {
|
||||||
|
existing.push(team);
|
||||||
|
} else {
|
||||||
|
teamsByProject.set(key, [team]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return teamsByProject;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,57 @@
|
||||||
|
import { describe, expect, it } from 'vitest';
|
||||||
|
|
||||||
|
import { buildActiveTeamsByProject } from '@features/recent-projects/renderer/utils/activeProjectTeams';
|
||||||
|
|
||||||
|
import type { TeamSummary } from '@shared/types';
|
||||||
|
|
||||||
|
function makeTeamSummary(
|
||||||
|
overrides: Partial<TeamSummary> & Pick<TeamSummary, 'teamName' | 'displayName'>
|
||||||
|
): TeamSummary {
|
||||||
|
return {
|
||||||
|
...overrides,
|
||||||
|
description: overrides.description ?? '',
|
||||||
|
memberCount: overrides.memberCount ?? 0,
|
||||||
|
taskCount: overrides.taskCount ?? 0,
|
||||||
|
lastActivity: overrides.lastActivity ?? null,
|
||||||
|
teamName: overrides.teamName,
|
||||||
|
displayName: overrides.displayName,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('buildActiveTeamsByProject', () => {
|
||||||
|
it('treats provisioning-active existing teams as active before aliveList catches up', () => {
|
||||||
|
const lintai = makeTeamSummary({
|
||||||
|
teamName: 'signal-ops-3',
|
||||||
|
displayName: 'signal-ops-3',
|
||||||
|
projectPath: '/Users/test/lintai',
|
||||||
|
});
|
||||||
|
|
||||||
|
const teamsByProject = buildActiveTeamsByProject({
|
||||||
|
teams: [lintai],
|
||||||
|
aliveTeamNames: [],
|
||||||
|
provisioningTeamNames: ['signal-ops-3'],
|
||||||
|
provisioningSnapshotByTeam: {},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(teamsByProject.get('/users/test/lintai')).toEqual([lintai]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('includes synthetic provisioning snapshots for teams not yet present in team summaries', () => {
|
||||||
|
const provisioningSnapshot = makeTeamSummary({
|
||||||
|
teamName: 'northstar-team',
|
||||||
|
displayName: 'Northstar Team',
|
||||||
|
projectPath: '/Users/test/northstar',
|
||||||
|
});
|
||||||
|
|
||||||
|
const teamsByProject = buildActiveTeamsByProject({
|
||||||
|
teams: [],
|
||||||
|
aliveTeamNames: [],
|
||||||
|
provisioningTeamNames: ['northstar-team'],
|
||||||
|
provisioningSnapshotByTeam: {
|
||||||
|
'northstar-team': provisioningSnapshot,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(teamsByProject.get('/users/test/northstar')).toEqual([provisioningSnapshot]);
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Reference in a new issue