Skip to content

Commit 99a2a3b

Browse files
authored
DM-8598: Dispatch TBL_RESULTS_ACTIVE when table is removed. Merge PR #261.
DM-8598: Dispatch TBL_RESULTS_ACTIVE when table is removed
2 parents 3aee25f + bf2df1a commit 99a2a3b

File tree

4 files changed

+26
-19
lines changed

4 files changed

+26
-19
lines changed

src/firefly/js/tables/TablesCntlr.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* License information at https://github.com/Caltech-IPAC/firefly/blob/master/License.txt
33
*/
44
import {take} from 'redux-saga/effects';
5-
import {get, set, omitBy, pickBy, isNil, cloneDeep} from 'lodash';
5+
import {get, set, omitBy, pickBy, isNil, cloneDeep, findKey} from 'lodash';
66

77
import {flux} from '../Firefly.js';
88
import * as TblUtil from './TableUtil.js';
@@ -127,7 +127,8 @@ function actionCreators() {
127127
[TABLE_SORT]: tableFetch,
128128
[TABLE_FILTER]: tableFetch,
129129
[TABLE_FILTER_SELROW]: tableFilterSelrow,
130-
[TBL_RESULTS_ADDED]: tblResultsAdded
130+
[TBL_RESULTS_ADDED]: tblResultsAdded,
131+
[TABLE_REMOVE]: tblRemove
131132
};
132133
}
133134

@@ -346,6 +347,19 @@ function tblResultsAdded(action) {
346347
};
347348
}
348349

350+
function tblRemove(action) {
351+
return (dispatch) => {
352+
dispatch(action);
353+
const {tbl_id} = action.payload;
354+
const results = get(flux.getState(), [TABLE_SPACE_PATH, 'results'], {});
355+
Object.keys(results).forEach( (tbl_group) => {
356+
if (get(results, [tbl_group, 'active']) === tbl_id) {
357+
dispatchActiveTableChanged(findKey(results[tbl_group].tables), tbl_group);
358+
}
359+
});
360+
};
361+
}
362+
349363
function highlightRow(action) {
350364
return (dispatch) => {
351365
const {tbl_id, highlightedRow} = action.payload;

src/firefly/js/tables/reducer/TableResultsReducer.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44

55
import {updateSet, updateDelete} from '../../util/WebUtil.js';
6-
import {set, get, has, findKey} from 'lodash';
6+
import {set, get, has} from 'lodash';
77

88
import * as Cntlr from '../TablesCntlr.js';
99
import * as TblUtil from '../TableUtil.js';
@@ -44,12 +44,6 @@ function removeTable(root, action) {
4444
Object.keys(root).forEach( (tbl_group) => {
4545
if (has(root, [tbl_group, 'tables', tbl_id])) {
4646
root = updateDelete(root, [tbl_group, 'tables'], tbl_id);
47-
48-
if (tbl_id === get(root, [tbl_group,'active'])) {
49-
// active table have been remove. set it to the first available table
50-
const newActiveId = findKey(root[tbl_group].tables);
51-
root = updateSet(root, [tbl_group,'active'], newActiveId);
52-
}
5347
}
5448
});
5549

src/firefly/js/ui/panel/TabPanel.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,18 +194,18 @@ export class Tab extends Component {
194194
const textStyle = maxTitleWidth ? {float: 'left', width: maxTitleWidth-(removable?14:0)} : {};
195195

196196
return (
197-
<li className={tabClassName} onClick={() => !this.removed && onSelect(id,name)}>
197+
<li className={tabClassName} onClick={() => onSelect(id,name)}>
198198
<div>
199199
<div style={textStyle} className='text-ellipsis' title={name}>
200200
{name}
201201
</div>
202202
{removable &&
203203
<div style={{right: -4, top: -2}} className='btn-close'
204204
title='Remove Tab'
205-
onClick={() => {
205+
onClick={(e) => {
206206
onTabRemove && onTabRemove(name);
207-
this.removed = true;
208-
}}/>
207+
e.stopPropagation && e.stopPropagation();
208+
}}/>
209209
}
210210
</div>
211211
</li>);

src/firefly/js/visualize/saga/ChartsSync.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,12 @@ export function* syncCharts() {
6060
*/
6161
export function* syncChartViewer() {
6262
while (true) {
63-
const action = yield take([ChartsCntlr.CHART_ADD, TablesCntlr.TBL_RESULTS_ACTIVE, TablesCntlr.TABLE_REMOVE]);
63+
const action = yield take([ChartsCntlr.CHART_ADD, TablesCntlr.TBL_RESULTS_ACTIVE]);
6464
switch (action.type) {
6565
case ChartsCntlr.CHART_ADD:
66-
case TablesCntlr.TABLE_REMOVE:
6766
case TablesCntlr.TBL_RESULTS_ACTIVE:
68-
const {chartId} = action.payload;
69-
updateDefaultViewer(chartId);
67+
const {chartId, tbl_id} = action.payload;
68+
updateDefaultViewer(chartId, tbl_id);
7069
break;
7170
}
7271
}
@@ -100,8 +99,8 @@ export function* addDefaultScatter() {
10099
}
101100

102101

103-
function updateDefaultViewer(chartId) {
104-
const tblId = TableUtil.getActiveTableId();
102+
function updateDefaultViewer(chartId, active_tbl_id) {
103+
const tblId = active_tbl_id || TableUtil.getActiveTableId();
105104
const chartIds = [];
106105
chartIds.push(...ChartsCntlr.getChartIdsInGroup(tblId), ...ChartsCntlr.getChartIdsInGroup('default'));
107106
const currentIds = getViewerItemIds(getMultiViewRoot(),DEFAULT_PLOT2D_VIEWER_ID);

0 commit comments

Comments
 (0)