forked from geosolutions-it/MapStore2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes geosolutions-it#3534 switch content tab when 0 results (maps/d…
…ashboards) (geosolutions-it#3733) (cherry picked from commit 5c8f7e9)
- Loading branch information
Showing
9 changed files
with
227 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright 2018, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
const expect = require('expect'); | ||
|
||
const { | ||
onTabSelected, | ||
ON_TAB_SELECTED | ||
} = require('../contenttabs'); | ||
|
||
describe('Test contenttabs actions', () => { | ||
|
||
it('Test onTabSelected action creator', () => { | ||
const id = 'layer_001'; | ||
const retval = onTabSelected(id); | ||
expect(retval).toExist(); | ||
expect(retval.id).toBe(id); | ||
expect(retval.type).toBe(ON_TAB_SELECTED); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright 2019, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
const ON_TAB_SELECTED = 'CONTENT_TABS:ON_TAB_SELECTED'; | ||
|
||
/** | ||
* Select Tab | ||
* @memberof actions.contenttabs | ||
* @param {string} id tab id | ||
* | ||
* @return {object} of type `ON_TAB_SELECTED` with tab id | ||
*/ | ||
|
||
const onTabSelected = (id) => { | ||
return { | ||
type: ON_TAB_SELECTED, | ||
id | ||
}; | ||
}; | ||
|
||
module.exports = {onTabSelected, ON_TAB_SELECTED}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright 2019, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
var expect = require('expect'); | ||
const {testEpic} = require('./epicTestUtils'); | ||
|
||
const {MAPS_LOAD_MAP, MAPS_LIST_LOADED} = require("../../actions/maps"); | ||
const {DASHBOARDS_LIST_LOADED} = require("../../actions/dashboards"); | ||
const {updateMapsDashboardTabs} = require("../contenttabs"); | ||
|
||
describe('Test Maps Dashboard Content Tabs', () => { | ||
it('test updateMapsDashboardTabs flow ', done => { | ||
const act = [ | ||
{type: MAPS_LOAD_MAP}, | ||
{type: MAPS_LIST_LOADED, maps: {totalCount: 0}}, | ||
{type: DASHBOARDS_LIST_LOADED, totalCount: 1} | ||
]; | ||
testEpic(updateMapsDashboardTabs, 1, act, (res) => { | ||
const action = res[0]; | ||
expect(action).toExist(); | ||
expect(action.id).toBe("dashboards"); | ||
done(); | ||
}, {contenttabs: {selected: "maps"}}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2019, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
const Rx = require('rxjs'); | ||
const {findKey} = require('lodash'); | ||
const {MAPS_LOAD_MAP, MAPS_LIST_LOADED} = require("../actions/maps"); | ||
const { | ||
DASHBOARDS_LIST_LOADED | ||
} = require('../actions/dashboards'); | ||
const {onTabSelected} = require("../actions/contenttabs"); | ||
/** | ||
* Update Maps and Dashboards counts to select contenttabs each tab has to have a key in its ContentTab configuration | ||
* @param {object} action | ||
*/ | ||
const updateMapsDashboardTabs = (action$, {getState = () => {}}) => | ||
action$.ofType(MAPS_LOAD_MAP) | ||
.switchMap(() => { | ||
return Rx.Observable.forkJoin(action$.ofType(MAPS_LIST_LOADED).take(1), action$.ofType(DASHBOARDS_LIST_LOADED).take(1)) | ||
.switchMap((r) => { | ||
const results = {maps: r[0].maps, dashboards: r[1] }; | ||
const {contenttabs = {}} = getState() || {}; | ||
const {selected} = contenttabs; | ||
if (results[selected] && results[selected].totalCount === 0) { | ||
const id = findKey(results, ({totalCount}) => totalCount > 0); | ||
if (id) { | ||
return Rx.Observable.of(onTabSelected(id)); | ||
} | ||
} | ||
return Rx.Observable.empty(); | ||
}); | ||
}); | ||
|
||
|
||
module.exports = {updateMapsDashboardTabs}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2019, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
const expect = require('expect'); | ||
|
||
const { | ||
onTabSelected | ||
} = require('../../actions/contenttabs'); | ||
|
||
const contenttabs = require('../contenttabs'); | ||
|
||
describe('Test contenttabs reducer', () => { | ||
|
||
it('select correct tab', () => { | ||
const id = 'dashboard'; | ||
const state = contenttabs({selected: "maps"}, onTabSelected(id)); | ||
expect(state).toEqual( | ||
{ | ||
selected: id | ||
} | ||
); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright 2019, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
const { | ||
ON_TAB_SELECTED | ||
} = require('../actions/contenttabs'); | ||
|
||
function contenttabs(state = {selected: "maps"}, action) { | ||
switch (action.type) { | ||
case ON_TAB_SELECTED: { | ||
return {selected: action.id || "maps"}; | ||
} | ||
default: | ||
return state; | ||
} | ||
} | ||
|
||
module.exports = contenttabs; |