@@ -4,10 +4,21 @@ import {
44 getCodeCrumbsMapForCurrentCcFlow
55} from 'utils/treeLayout' ;
66import { fetchFile } from 'utils/connection' ;
7+ import { ACTIONS as VIEW_SWITCHES_ACTIONS } from 'components/controls/ViewSwitches/store/constants' ;
8+ import {
9+ getCheckedState ,
10+ getValuesState ,
11+ getDisabledState
12+ } from 'components/controls/ViewSwitches/store/selectors' ;
713
814import { getFoldersForPaths , downloadObjectAsJsonFile , uploadFileAsObject } from './utils' ;
9- import { ACTIONS } from '../constants' ;
10- import { ACTIONS as VIEW_SWITCHES_ACTIONS } from 'components/controls/ViewSwitches/store/constants' ;
15+ import { ACTIONS , DEFAULT_NAMESPACE } from '../constants' ;
16+ import {
17+ getSource ,
18+ getSourceUserChoice ,
19+ getCodeCrumbsUserChoice ,
20+ getDependenciesUserChoice
21+ } from '../selectors' ;
1122
1223export const setInitialSourceData = payload => ( {
1324 type : ACTIONS . SET_INITIAL_SOURCE_DATA ,
@@ -48,7 +59,7 @@ export const selectCodeCrumb = (fileNode, codeCrumb) => ({
4859
4960export const setDependenciesEntryPoint = fileNode => ( dispatch , getState ) => {
5061 const state = getState ( ) ;
51- const { dependenciesShowDirectOnly } = state . viewSwitches . checkedState ;
62+ const { dependenciesShowDirectOnly } = getCheckedState ( state ) ;
5263
5364 return dispatch ( {
5465 type : ACTIONS . SET_DEPENDENCIES_ENTRY_POINT ,
@@ -78,7 +89,7 @@ export const selectDependencyEdge = (target, sources, groupName) => dispatch =>
7889export const selectCodeCrumbedFlow = flow => ( dispatch , getState ) => {
7990 const state = getState ( ) ;
8091
81- const { selectedCrumbedFlowKey, codeCrumbedFlowsMap } = state . dataBus ;
92+ const { selectedCrumbedFlowKey, codeCrumbedFlowsMap } = getCodeCrumbsUserChoice ( state ) ;
8293 const firstFlow = Object . keys ( codeCrumbedFlowsMap || { } ) [ 0 ] ;
8394
8495 dispatch ( {
@@ -89,20 +100,17 @@ export const selectCodeCrumbedFlow = flow => (dispatch, getState) => {
89100
90101export const calcFilesTreeLayoutNodes = ( ) => ( dispatch , getState ) => {
91102 const state = getState ( ) ;
92- const {
93- sourceTree,
94- openedFolders,
95- activeItemsMap,
96- codeCrumbedFlowsMap,
97- selectedCrumbedFlowKey,
98- filesMap
99- } = state . dataBus ;
100- const { checkedState } = state . viewSwitches ;
103+
104+ const { sourceTree, filesMap } = getSource ( state ) ;
105+ const { openedFolders, activeItemsMap } = getSourceUserChoice ( state ) ;
106+ const { codeCrumbedFlowsMap, selectedCrumbedFlowKey } = getCodeCrumbsUserChoice ( state ) ;
107+
108+ const { codeCrumbsDiagramOn, codeCrumbsMinimize, codeCrumbsFilterFlow } = getCheckedState ( state ) ;
101109
102110 if ( ! sourceTree ) return ;
103111
104112 let activeCodeCrumbs = undefined ;
105- if ( checkedState . codeCrumbsKeepOnlySelectedFlow && codeCrumbedFlowsMap [ selectedCrumbedFlowKey ] ) {
113+ if ( codeCrumbsFilterFlow && codeCrumbedFlowsMap [ selectedCrumbedFlowKey ] ) {
106114 activeCodeCrumbs = getCodeCrumbsMapForCurrentCcFlow ( {
107115 codeCrumbedFlowsMap,
108116 selectedCrumbedFlowKey,
@@ -113,7 +121,7 @@ export const calcFilesTreeLayoutNodes = () => (dispatch, getState) => {
113121 return dispatch ( {
114122 type : ACTIONS . UPDATE_FILES_TREE_LAYOUT_NODES ,
115123 payload : getTreeLayout ( sourceTree , {
116- includeFileChildren : checkedState . codeCrumbs && ! checkedState . codeCrumbsMinimize ,
124+ includeFileChildren : codeCrumbsDiagramOn && ! codeCrumbsMinimize ,
117125 openedFolders,
118126 activeItemsMap,
119127 activeCodeCrumbs
@@ -123,13 +131,13 @@ export const calcFilesTreeLayoutNodes = () => (dispatch, getState) => {
123131
124132export const setActiveItems = ( filesList , foldersMap = { } ) => ( dispatch , getState ) => {
125133 const state = getState ( ) ;
134+ const { activeItemsMap } = getSourceUserChoice ( state ) ;
135+ const { sourceKeepOnlyActiveItems } = getCheckedState ( state ) ;
126136
127137 return dispatch ( {
128138 type : ACTIONS . SET_ACTIVE_ITEMS ,
129139 payload : {
130- ...( ! state . viewSwitches . checkedState . sourceKeepOnlyActiveItems
131- ? state . dataBus . activeItemsMap
132- : { } ) ,
140+ ...( ! sourceKeepOnlyActiveItems ? activeItemsMap : { } ) ,
133141 ...filesList . reduce ( ( acc , item ) => {
134142 //TODO:move this to util!
135143 acc [ item ] = true ;
@@ -144,27 +152,23 @@ export const setActiveItems = (filesList, foldersMap = {}) => (dispatch, getStat
144152export const updateFoldersByActiveChildren = ( ) => ( dispatch , getState ) => {
145153 const state = getState ( ) ;
146154
147- const {
148- filesMap,
149- openedFolders,
150- selectedNode,
151- codeCrumbedFlowsMap,
152- selectedCrumbedFlowKey
153- } = state . dataBus ;
155+ const { filesMap } = getSource ( state ) ;
156+ const { openedFolders, selectedNode } = getSourceUserChoice ( state ) ;
157+ const { codeCrumbedFlowsMap, selectedCrumbedFlowKey } = getCodeCrumbsUserChoice ( state ) ;
154158
155159 const {
156- dependencies ,
157- codeCrumbs ,
160+ dependenciesDiagramOn ,
161+ codeCrumbsDiagramOn ,
158162 sourceKeepOnlyActiveItems,
159- codeCrumbsKeepOnlySelectedFlow
160- } = state . viewSwitches . checkedState ;
163+ codeCrumbsFilterFlow
164+ } = getCheckedState ( state ) ;
161165
162- const depFilePaths = dependencies ? Object . keys ( selectedNode . dependencies || { } ) : [ ] ;
163- let ccFilePaths = codeCrumbs
166+ const depFilePaths = dependenciesDiagramOn ? Object . keys ( selectedNode . dependencies || { } ) : [ ] ;
167+ let ccFilePaths = codeCrumbsDiagramOn
164168 ? Object . keys ( filesMap ) . filter ( path => filesMap [ path ] . hasCodecrumbs )
165169 : [ ] ;
166170
167- if ( codeCrumbsKeepOnlySelectedFlow && codeCrumbedFlowsMap [ selectedCrumbedFlowKey ] ) {
171+ if ( codeCrumbsFilterFlow && codeCrumbedFlowsMap [ selectedCrumbedFlowKey ] ) {
168172 const currentFlowFiles = getFilesForCurrentCcFlow ( {
169173 codeCrumbedFlowsMap,
170174 selectedCrumbedFlowKey,
@@ -191,20 +195,26 @@ export const updateFoldersByActiveChildren = () => (dispatch, getState) => {
191195
192196// TODO: group and move actions to different files
193197export const downloadStore = ( ) => ( dispatch , getState ) => {
194- const { viewSwitches, dataBus } = getState ( ) ;
198+ const state = getState ( ) ;
199+
200+ const { sourceTree, filesMap, foldersMap } = getSource ( state ) ;
201+ const { dependenciesRootEntryName } = getDependenciesUserChoice ( state ) ;
202+ const { codeCrumbedFlowsMap } = getCodeCrumbsUserChoice ( state ) ;
195203
196204 const partialStateToSave = {
197205 viewSwitches : {
198- checkedState : viewSwitches . checkedState ,
199- disabledState : viewSwitches . disabledState ,
200- valuesState : viewSwitches . valuesState
206+ checkedState : getCheckedState ( state ) ,
207+ valuesState : getValuesState ( state ) ,
208+ disabledState : getDisabledState ( state )
201209 } ,
202210 dataBus : {
203- sourceTree : dataBus . sourceTree ,
204- filesMap : dataBus . filesMap ,
205- foldersMap : dataBus . foldersMap ,
206- codeCrumbedFlowsMap : dataBus . codeCrumbedFlowsMap ,
207- dependenciesRootEntryName : dataBus . dependenciesRootEntryName
211+ [ DEFAULT_NAMESPACE ] : {
212+ sourceTree,
213+ filesMap,
214+ foldersMap,
215+ codeCrumbedFlowsMap,
216+ dependenciesRootEntryName
217+ }
208218 }
209219 } ;
210220
@@ -214,6 +224,6 @@ export const downloadStore = () => (dispatch, getState) => {
214224export const uploadStore = file => dispatch => {
215225 uploadFileAsObject ( file ) . then ( object => {
216226 dispatch ( { type : VIEW_SWITCHES_ACTIONS . SET_FULL_STATE , payload : object . data . viewSwitches } ) ;
217- dispatch ( setInitialSourceData ( object . data . dataBus ) ) ;
227+ dispatch ( setInitialSourceData ( object . data . dataBus [ DEFAULT_NAMESPACE ] ) ) ;
218228 } ) ;
219- } ;
229+ } ;
0 commit comments