import { shell } from 'electron' ; import * as enums from '../enums' ; import App from '../components/App' ; import LoadingOverlay from '../containers/LoadingOverlay' ; import ModalPopup from '../containers/ModalPopup' ; import LogGroups from '../containers/LogGroups' ; import LogStreams from '../containers/LogStreams' ; import LogContent from '../containers/LogContent' ; import Filters from '../containers/Filters' ; import Settings from '../containers/Settings' ; import DownloadList from '../containers/DownloadList' ; import DownloadBadge from '../containers/DownloadBadge' ; import SettingsBalloon from '../containers/SettingsBalloon' ; import * as actions from '../actions/' ; import { StoreState } from '../types' ; import { connect , Dispatch } from 'react-redux' ; import { load , currentDate , connectCloudWatchLogs , getCloudWatchLogGroups , getCloudWatchLogStreams , getCloudWatchLogsEvents } from '../side-effect-functions' ; import * as types from '../common-interfaces' ; export function mapStateToProps ( { window , settings , logGroups , logStreams , logEvents } ) { return { LoadingOverlay : LoadingOverlay , ModalPopup : ModalPopup , LogGroups : LogGroups , LogStreams : LogStreams , LogContent : LogContent , Filters : Filters , Settings : Settings , DownloadList : DownloadList , DownloadBadge : DownloadBadge , SettingsBalloon : SettingsBalloon , windowContent : window . windowContent , settings : settings . settings , logGroupName : logGroups . selectedName , logStream : logStreams . logStreams . find ( s => s . logStreamName === logStreams . selectedName ) , runningJobs : logEvents . runningJobs , errorJobs : logEvents . errorJobs , } ; } export function mapDispatchToProps ( dispatch ) { return { ShowWindowContent : ( windowContent ) => dispatch ( actions . showWindowContent ( windowContent ) ) , LoadSettings : ( ) => dispatch ( actions . loadSettings ( load , currentDate ) ) , ReloadAll : ( settings , logGroupName ? , logStream ? ) => reloadAll ( dispatch , settings , logGroupName , logStream ) , OpenGithub : ( ) => shell . openExternal ( 'https://github.com/megmogmog1965/cloudwatchlogs-downloader' ) , } ; } function reloadAll ( dispatch , settings , logGroupName ? , logStream ? ) { dispatch ( actions . fetchLogGroups ( settings , ( callbackStart , callbackError , callbackEnd ) => getCloudWatchLogGroups ( connectCloudWatchLogs ( settings ) , callbackStart , callbackError , callbackEnd ) ) ) ; if ( ! logGroupName ) { return ; } dispatch ( actions . fetchLogStreams ( settings , logGroupName , ( callbackStart , callbackError , callbackEnd ) => getCloudWatchLogStreams ( connectCloudWatchLogs ( settings ) , logGroupName , callbackStart , callbackError , callbackEnd ) ) ) ; if ( ! logStream ) { return ; } const margin = 5 * 60 * 1000 ; const endDate = new Date ( logStream . lastEventTimestamp + margin ) ; const startDate = new Date ( logStream . firstEventTimestamp - margin ) ; const limit = 20 ; dispatch ( actions . fetchLogText ( settings , ( callbackData , callbackError , callbackEnd ) => getCloudWatchLogsEvents ( connectCloudWatchLogs ( settings ) , logGroupName , logStream . logStreamName , startDate , endDate , callbackData , callbackError , callbackEnd , false , limit ) ) ) ; } export default connect ( mapStateToProps , mapDispatchToProps ) ( App as any ) ;