Skip to content

Commit

Permalink
Add real file name to file_output frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelsierant committed Oct 16, 2024
1 parent d4154f5 commit 06035c5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@ import { Download } from 'lucide-react';
import { ItemList } from '~/components/list/ItemList';

interface FileOutputProps {
files: Blob[];
files: {
content: Blob;
name: string;
}[];
}

export const FileOutput: React.FC<FileOutputProps> = ({ files }) => {
return (
<ItemList
className="flex flex-col items-center gap-1 overflow-y-auto"
itemClassName="w-full"
items={files.map((file, index) => ({ id: index, file }))}
items={files.map((file, index) => ({ id: index, file: file.content, name: file.name }))}
renderItem={(file) => <FileOutputListItem file={file} />}
/>
);
};

interface FileOutputListItemProps {
file: { id: number; file: Blob };
file: { id: number; file: Blob, name: string };
}
export function FileOutputListItem({ file }: FileOutputListItemProps) {
return (
Expand All @@ -29,21 +32,21 @@ export function FileOutputListItem({ file }: FileOutputListItemProps) {
<div className="flex gap-1 grow max-w-[90%]">
<div className="flex flex-col w-full max-w-[95%]">
<h6 className="whitespace-nowrap text-xs truncate">
{'foo file name'}
{file.name}
</h6>
</div>
</div>
<DownloadButton blob={file.file} />
<DownloadButton blob={file.file} name={file.name} />
</article>
);
}

function DownloadButton({ blob }: { blob: Blob }) {
function DownloadButton({ blob, name }: { blob: Blob, name: string }) {
const downloadFile = () => {
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'file.txt';
a.download = name;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ function checkIfStringPayloads(events: IEvent[]) {
// }

function getFileOutput(event: IEvent) {
return new Blob([event.payload], { type: 'file' });
return {
content: new Blob([event.payload], { type: event.metadata.file_type }),
name: event.metadata.file_name,
};
}

interface TextOutputProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface IEvent {
block: string;
output: string;
payload: any;
metadata: any;
}
interface IRunPipelineContext {
events: IEvent[];
Expand Down Expand Up @@ -65,8 +66,7 @@ export const RunPipelineProvider: React.FC<RunPipelineProviderProps> = ({
);

const onMessage = useCallback(
(block: string, output: string, payload: any) =>
setEvents((events) => [...events, { block, output, payload }]),
(block: string, output: string, payload: any, metadata: any) => setEvents((events) => [...events, { block, output, payload, metadata }]),
[],
);

Expand Down

0 comments on commit 06035c5

Please sign in to comment.