mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 10:48:20 +01:00
fix(projects): surface dirPath + agentPref on bare project cards
aec0ef8dropped the dashed "Add context →" placeholder, leaving bare tiles with just a title. Honest, but the user still had to click in to see anything concrete. user_projects already stores the SSOT for project runtime metadata (dirPath, agentPref) — surfacing it on the card removes the need for that click. DB: add fetchRuntimeMetaByEntityIds() that joins user_projects by entityProjectId. Use in both getProjects and getOrgEntityProjects so the returned ProjectRow gains dirPath + agentPref fields. Single parallel query per page-load alongside fetchAttributesByEntityIds — no N+1. UI: extend the Project type with optional dirPath/agentPref. Render them as small mono chips on truly bare tiles (no description, no status, no maturity, no health signals, no next_step, no extra attrs) — the same gapaec0ef8left visually empty. dirPath is truncated to the last two path segments (e.g. ".local/share/foo") with the full path in title-tooltip. agentPref renders as a micro- badge. Drops out cleanly when both fields are null. No behavior change on tiles that already render status/maturity/etc.
This commit is contained in:
2 files changed
+80
-12
No files matched your search
@@ -40,6 +40,11 @@ type Project = {
|
||||
description: string | null;
|
||||
attrs: Record<string, string>;
|
||||
readonly?: boolean;
|
||||
// Surfaced from user_projects via getProjects join so bare-attr tiles can
|
||||
// show concrete project context (dir path + preferred agent) instead of
|
||||
// just a clickable title.
|
||||
dirPath?: string | null;
|
||||
agentPref?: string | null;
|
||||
};
|
||||
|
||||
function ProjectCard({
|
||||
@@ -151,11 +156,26 @@ function ProjectCard({
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{/* No empty-state placeholder: a card with only a title is less ugly
|
||||
than a card with a dashed-bordered "Add context →" prompt that
|
||||
dominates the visual when the user is scanning 20+ tiles. The whole
|
||||
card is already clickable (onClick on the wrapper) so the affordance
|
||||
to open the project is preserved. */}
|
||||
{/* Bare-attr tiles (no description/status/maturity/health/next_step/
|
||||
custom attrs) get the dirPath + agentPref from the user_projects
|
||||
join. Same affordance as the dropped "Add context →" placeholder —
|
||||
the whole card is clickable — but the user can now see WHERE the
|
||||
project lives and WHICH agent runs it at a glance. Drops out when
|
||||
neither field is set (truly unconfigured project). */}
|
||||
{!description && !status && !maturity && !hasIssues && !nextStep && extraAttrs.length === 0 && (project.dirPath || project.agentPref) && (
|
||||
<div className="flex flex-wrap items-center gap-1.5 text-xs text-text-tertiary">
|
||||
{project.dirPath && (
|
||||
<code className="truncate rounded bg-surface-overlay px-1.5 py-0.5 font-mono text-[10px]" title={project.dirPath}>
|
||||
{project.dirPath.replace(/^.*\/([^/]+\/[^/]+)$/, "$1")}
|
||||
</code>
|
||||
)}
|
||||
{project.agentPref && (
|
||||
<span className="ui-micro-badge rounded-full border-border-default bg-surface-overlay">
|
||||
{project.agentPref}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -57,6 +57,32 @@ export async function deleteProject(userId: string, id: string) {
|
||||
return deleted ?? null;
|
||||
}
|
||||
|
||||
// Fetch the user_projects runtime metadata (dirPath + agentPref) for a list
|
||||
// of entity ids. Returned map is keyed by entityProjectId — entities without
|
||||
// a linked user_projects row are absent (caller treats as null).
|
||||
//
|
||||
// user_projects is the SSOT for where the project lives on disk and which
|
||||
// agent it prefers; the Projects page card needs both so bare-attr tiles show
|
||||
// concrete context instead of just a clickable title.
|
||||
async function fetchRuntimeMetaByEntityIds(
|
||||
entityIds: string[],
|
||||
): Promise<Map<string, { dirPath: string | null; agentPref: string | null }>> {
|
||||
const out = new Map<string, { dirPath: string | null; agentPref: string | null }>();
|
||||
if (entityIds.length === 0) return out;
|
||||
const rows = await db
|
||||
.select({
|
||||
entityProjectId: userProjects.entityProjectId,
|
||||
dirPath: userProjects.dirPath,
|
||||
agentPref: userProjects.agentPref,
|
||||
})
|
||||
.from(userProjects)
|
||||
.where(inArray(userProjects.entityProjectId, entityIds));
|
||||
for (const r of rows) {
|
||||
if (r.entityProjectId) out.set(r.entityProjectId, { dirPath: r.dirPath, agentPref: r.agentPref });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
export async function getProjects(userId: string) {
|
||||
const projects = await db
|
||||
.select()
|
||||
@@ -69,12 +95,21 @@ export async function getProjects(userId: string) {
|
||||
)
|
||||
.orderBy(entities.name);
|
||||
|
||||
const attrsByEntity = await fetchAttributesByEntityIds(projects.map((p) => p.id));
|
||||
const ids = projects.map((p) => p.id);
|
||||
const [attrsByEntity, runtimeByEntity] = await Promise.all([
|
||||
fetchAttributesByEntityIds(ids),
|
||||
fetchRuntimeMetaByEntityIds(ids),
|
||||
]);
|
||||
|
||||
return projects.map((p) => ({
|
||||
...p,
|
||||
attrs: attrsByEntity.get(p.id) ?? {},
|
||||
}));
|
||||
return projects.map((p) => {
|
||||
const runtime = runtimeByEntity.get(p.id) ?? { dirPath: null, agentPref: null };
|
||||
return {
|
||||
...p,
|
||||
attrs: attrsByEntity.get(p.id) ?? {},
|
||||
dirPath: runtime.dirPath,
|
||||
agentPref: runtime.agentPref,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export type ProjectRow = Awaited<ReturnType<typeof getProjects>>[number];
|
||||
@@ -88,8 +123,21 @@ export async function getOrgEntityProjects(userId: string): Promise<(ProjectRow
|
||||
.from(entities)
|
||||
.where(and(inArray(entities.userId, peerIds), eq(entities.type, ENTITY_TYPE.PROJECT)))
|
||||
.orderBy(entities.name);
|
||||
const attrsByEntity = await fetchAttributesByEntityIds(projects.map((p) => p.id));
|
||||
return projects.map((p) => ({ ...p, attrs: attrsByEntity.get(p.id) ?? {}, readonly: true as const }));
|
||||
const ids = projects.map((p) => p.id);
|
||||
const [attrsByEntity, runtimeByEntity] = await Promise.all([
|
||||
fetchAttributesByEntityIds(ids),
|
||||
fetchRuntimeMetaByEntityIds(ids),
|
||||
]);
|
||||
return projects.map((p) => {
|
||||
const runtime = runtimeByEntity.get(p.id) ?? { dirPath: null, agentPref: null };
|
||||
return {
|
||||
...p,
|
||||
attrs: attrsByEntity.get(p.id) ?? {},
|
||||
dirPath: runtime.dirPath,
|
||||
agentPref: runtime.agentPref,
|
||||
readonly: true as const,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user