mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-08-04 14:57:42 +00:00
fix: Count downloadable file outputs
This commit is contained in:
parent
87f3a61f04
commit
d0f6881544
2 changed files with 31 additions and 3 deletions
|
|
@ -589,14 +589,18 @@ export function AttachmentGroup({ attachments }: { attachments?: TAttachment[] }
|
|||
mermaidArtifacts.sort(bySalience);
|
||||
imageAttachments.sort(bySalience);
|
||||
|
||||
const downloadableFileAttachments = fileAttachments.filter((attachment) =>
|
||||
Boolean(attachment.filepath),
|
||||
);
|
||||
const downloadableTextAttachments = textAttachments.filter((attachment) =>
|
||||
Boolean(attachment.filepath),
|
||||
);
|
||||
const textOnlyAttachments = textAttachments.filter((attachment) => !attachment.filepath);
|
||||
const groupDownloadableFiles = fileAttachments.length + downloadableTextAttachments.length > 1;
|
||||
const groupDownloadableFiles =
|
||||
downloadableFileAttachments.length + downloadableTextAttachments.length > 1;
|
||||
const groupedFileAttachments = groupDownloadableFiles
|
||||
? [...fileAttachments, ...downloadableTextAttachments].sort(bySalience)
|
||||
: fileAttachments;
|
||||
? [...downloadableFileAttachments, ...downloadableTextAttachments].sort(bySalience)
|
||||
: downloadableFileAttachments;
|
||||
const visibleTextAttachments = groupDownloadableFiles ? textOnlyAttachments : textAttachments;
|
||||
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -198,4 +198,28 @@ describe('AttachmentGroup', () => {
|
|||
expect(container.querySelector('pre')).toBeNull();
|
||||
expect(screen.getAllByTestId('file-container').length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('does not collapse a single downloadable text preview with a non-downloadable placeholder', () => {
|
||||
const attachments = [
|
||||
textAttachment({
|
||||
file_id: 'placeholder',
|
||||
filename: 'placeholder.zip',
|
||||
filepath: '',
|
||||
type: 'application/zip',
|
||||
text: undefined as unknown as string,
|
||||
}),
|
||||
textAttachment({
|
||||
file_id: 'json',
|
||||
filename: 'output.json',
|
||||
filepath: '/files/output.json',
|
||||
text: '{"ok":true}',
|
||||
}),
|
||||
] as TAttachment[];
|
||||
|
||||
const { container } = render(<AttachmentGroup attachments={attachments} />);
|
||||
|
||||
expect(screen.queryByRole('button', { name: 'com_ui_show_n_files' })).not.toBeInTheDocument();
|
||||
expect(container.querySelector('pre')?.textContent).toBe('{"ok":true}');
|
||||
expect(screen.getByTestId('file-container')).toHaveTextContent('output.json');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue