github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/ui/dashboard/src/components/SaveSnapshotButton/index.tsx (about) 1 import Icon from "../Icon"; 2 import NeutralButton from "../forms/NeutralButton"; 3 import { DashboardDataModeCLISnapshot } from "../../types"; 4 import { saveAs } from "file-saver"; 5 import { stripSnapshotDataForExport } from "../../utils/snapshot"; 6 import { timestampForFilename } from "../../utils/date"; 7 import { useDashboard } from "../../hooks/useDashboard"; 8 9 const SaveSnapshotButton = () => { 10 const { dashboard, dataMode, selectedDashboard, snapshot } = useDashboard(); 11 12 const saveSnapshot = () => { 13 if (!dashboard || !snapshot) { 14 return; 15 } 16 const streamlinedSnapshot = stripSnapshotDataForExport(snapshot); 17 const blob = new Blob([JSON.stringify(streamlinedSnapshot)], { 18 type: "application/json", 19 }); 20 saveAs(blob, `${dashboard.name}.${timestampForFilename(Date.now())}.sps`); 21 }; 22 23 if ( 24 dataMode === DashboardDataModeCLISnapshot || 25 (!selectedDashboard && !snapshot) 26 ) { 27 return null; 28 } 29 30 return ( 31 <NeutralButton 32 className="inline-flex items-center space-x-1" 33 disabled={!dashboard || !snapshot} 34 onClick={saveSnapshot} 35 > 36 <> 37 <Icon 38 className="inline-block text-foreground-lighter w-5 -mt-0.5" 39 icon="heroicons-outline:camera" 40 /> 41 <span className="hidden lg:block">Snap</span> 42 </> 43 </NeutralButton> 44 ); 45 }; 46 47 export default SaveSnapshotButton;