fix(documents): surface signedFromDocumentId + hub cleanup
Three follow-ups from Task 15 code review: 1. (Important) The aggregated files API now LEFT JOINs against documents to surface signedFromDocumentId per file row. The "view signing details" button on EntityFolderView's Files section now passes the workflow id to SigningDetailsDialog instead of the file id. Previously the button always 404'd and the dialog hung in the loading state. Drops the v1 filename-prefix heuristic. 2. (Minor) Drop dead initialTab prop + DocumentsHubTab import — leftover from the pre-refactor tab strip. 3. (Minor) FlatFolderListing remounts on folder switch via a key prop, restoring the pre-refactor typeFilter reset behaviour. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -283,7 +283,7 @@ export async function getFileById(id: string, portId: string) {
|
||||
export interface AggregatedFileGroup {
|
||||
label: string;
|
||||
source: 'direct' | 'client' | 'company' | 'yacht';
|
||||
files: Array<typeof files.$inferSelect>;
|
||||
files: Array<typeof files.$inferSelect & { signedFromDocumentId: string | null }>;
|
||||
total: number;
|
||||
}
|
||||
|
||||
@@ -415,9 +415,7 @@ export async function collectRelatedEntities(
|
||||
companies,
|
||||
and(eq(companies.id, companyMemberships.companyId), eq(companies.portId, portId)),
|
||||
)
|
||||
.where(
|
||||
and(eq(companyMemberships.clientId, entityId), isNull(companyMemberships.endDate)),
|
||||
);
|
||||
.where(and(eq(companyMemberships.clientId, entityId), isNull(companyMemberships.endDate)));
|
||||
|
||||
const directYachts = await db
|
||||
.select({ id: yachts.id, name: yachts.name })
|
||||
@@ -463,9 +461,7 @@ export async function collectRelatedEntities(
|
||||
clients,
|
||||
and(eq(clients.id, companyMemberships.clientId), eq(clients.portId, portId)),
|
||||
)
|
||||
.where(
|
||||
and(eq(companyMemberships.companyId, entityId), isNull(companyMemberships.endDate)),
|
||||
);
|
||||
.where(and(eq(companyMemberships.companyId, entityId), isNull(companyMemberships.endDate)));
|
||||
|
||||
const ownedYachts = await db
|
||||
.select({ id: yachts.id, name: yachts.name })
|
||||
@@ -518,10 +514,37 @@ async function fetchGroupRows(
|
||||
portId: string,
|
||||
predicate: ReturnType<typeof eq>,
|
||||
limit: number,
|
||||
): Promise<{ rows: Array<typeof files.$inferSelect>; total: number }> {
|
||||
): Promise<{
|
||||
rows: Array<typeof files.$inferSelect & { signedFromDocumentId: string | null }>;
|
||||
total: number;
|
||||
}> {
|
||||
const rows = await db
|
||||
.select()
|
||||
.select({
|
||||
id: files.id,
|
||||
portId: files.portId,
|
||||
clientId: files.clientId,
|
||||
yachtId: files.yachtId,
|
||||
companyId: files.companyId,
|
||||
folderId: files.folderId,
|
||||
filename: files.filename,
|
||||
originalName: files.originalName,
|
||||
mimeType: files.mimeType,
|
||||
sizeBytes: files.sizeBytes,
|
||||
storagePath: files.storagePath,
|
||||
storageBucket: files.storageBucket,
|
||||
category: files.category,
|
||||
uploadedBy: files.uploadedBy,
|
||||
createdAt: files.createdAt,
|
||||
// Reverse-link: if any document row has this file as its signed_file_id,
|
||||
// surface that document's id. LEFT JOIN preserves files with no workflow link.
|
||||
// Defense-in-depth: portId filter on both the join condition and the outer where.
|
||||
signedFromDocumentId: documents.id,
|
||||
})
|
||||
.from(files)
|
||||
.leftJoin(
|
||||
documents,
|
||||
and(eq(documents.signedFileId, files.id), eq(documents.portId, portId)),
|
||||
)
|
||||
.where(and(eq(files.portId, portId), predicate))
|
||||
.orderBy(desc(files.createdAt))
|
||||
.limit(limit);
|
||||
|
||||
Reference in New Issue
Block a user