import { createPageModule } from 'redux-with-domain' ; import _ from 'lodash' ; import AttributesModule from '../../container/workbook/chartAttribute' ; import DatasetFieldsModule from '../../container/workbook/datasetField' ; import DatasetListModule , { kSelectedDatasetIdChangeEmitName } from '../../container/workbook/datasetList' ; import ReportCanvasModule , { kDatasetIdChangeEmitName } from '../../container/common/reportCanvas' ; import ReportListModule , { kSelectedReportIdChangeEmitName } from '../../container/workbook/reportList' ; import workbookDomain from '../../domain/workbook' ; import reportDomain , { ReportItem } from '../../domain/report' ; import loadWorkbook from '../../service/loadWorkbook' ; export default createPageModule ( 'workbook' , { initialState : { workbookId : '' , selectedReportId : '' } , selectors : { getWorkbookName : state => { const workbook = workbookDomain . entities . workbookList . get ( state . workbookId ) ; return workbook ? workbook . name : '' ; } , getSelectedDatasetId : state => { return DatasetListModule . selectors . getSelectedDatasetId ( state ) ; } , getSelectedReportId : state => { return state . selectedReportId ; } , getSelectedChartId : state => { return ReportCanvasModule . selectors . getSelectedChartId ( state ) ; } } , reducers : { saveWorkbookId : ( state , { payload } ) => { return { ... state , workbookId : payload } ; } , saveSelectedReportId : ( state , { payload } ) => { return { ... state , selectedReportId : payload } ; } } , injectModules : [ AttributesModule , DatasetFieldsModule , DatasetListModule , ReportCanvasModule , ReportListModule ] , effects : ( { actions , selectors , sagaEffects : { call , put } , enhancer : { syncPut } } ) => ( { * init ( { payload : workbookId } ) { yield syncPut ( actions . saveWorkbookId ( workbookId ) ) ; yield call ( loadWorkbook , workbookId ) ; yield syncPut ( ReportListModule . actions . init ( ) ) ; yield syncPut ( DatasetListModule . actions . init ( ) ) ; } , * setSelectedReport ( { payload : reportId } ) { yield syncPut ( actions . saveSelectedReportId ( reportId ) ) ; yield syncPut ( ReportCanvasModule . actions . saveSelectedChartId ( '' ) ) ; yield put ( ReportCanvasModule . actions . reloadChart ( reportId ) ) ; } } ) , watchers : ( { actions , sagaEffects : { put } , enhancer : { syncPut } } ) => { return { * [ DatasetListModule . event ( kSelectedDatasetIdChangeEmitName ) ] ( { } ) { yield put ( ReportCanvasModule . actions . saveSelectedChartId ( '' ) ) ; } , * [ ReportCanvasModule . event ( kDatasetIdChangeEmitName ) ] ( { payload } ) { yield put ( DatasetListModule . actions . saveSelectedDataset ( payload ) ) ; } , * [ ReportListModule . event ( kSelectedReportIdChangeEmitName ) ] ( { payload } ) { yield syncPut ( actions . setSelectedReport ( payload ) ) ; } } ; } } ) ;