Skip to content

Commit

Permalink
feat: add restoresize to download button
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon committed Nov 19, 2023
1 parent 2342d84 commit 81818e3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/components/Backups/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const backupsData = [
restore: {
status: 'completed',
restoreLocation: 'https://example.com/backup',
restoreSize: 300
},
},
{
Expand Down
1 change: 1 addition & 0 deletions src/components/Backups/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface BackupsProps {
restore: {
status: 'completed' | 'pending' | 'failed';
restoreLocation?: string;
restoreSize?: number;
};
}[];
}
Expand Down
8 changes: 7 additions & 1 deletion src/components/RestoreButton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import React from 'react';
import Button from 'components/Button';
import Prepare from 'components/RestoreButton/Prepare';


function humanFileSize(size) {
var i = size == 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024));
return (size / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i];
}

/**
* A button to restore a backup.
*/
Expand All @@ -13,7 +19,7 @@ const RestoreButton = ({ backup: { backupId, restore } }) => {

if (restore.status === 'failed') return <Button disabled>Retrieve failed</Button>;

return <Button href={restore.restoreLocation}>Download</Button>;
return <Button href={restore.restoreLocation}>Download ({humanFileSize(restore.restoreSize)})</Button>;
};

export default RestoreButton;
1 change: 1 addition & 0 deletions src/lib/query/EnvironmentWithBackups.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default gql`
id
status
restoreLocation
restoreSize
}
}
}
Expand Down

0 comments on commit 81818e3

Please sign in to comment.