Skip to content

Commit

Permalink
Merge pull request #1758 from dakotablair/collapsed-cell-status
Browse files Browse the repository at this point in the history
Fix SCT-2664: Show status when cells are collapsed
  • Loading branch information
briehl authored Jul 14, 2020
2 parents 1531c4d + 3807e22 commit 950194f
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,20 @@ define([
}

function render(cell) {
/*
The cell metadata 'kbase.cellState.toggleMinMax' is the
canonical indicator of whether a cell is collapsed or not.
*/
const cellCollapsed = utils.getCellMeta(
cell, 'kbase.cellState.toggleMinMax', 'maximized'
) !== 'maximized';
const execMessage = cell.element[0].querySelectorAll(
'[data-element="execMessage"]'
)[0];
const collapsedCellStatus = cellCollapsed ? (
execMessage && execMessage.innerHTML
) : '';

var events = Events.make({ node: container }),
buttons = [
div({ class: 'buttons pull-right' }, [
Expand Down Expand Up @@ -470,7 +484,11 @@ define([
overflow: 'hidden'
}
}, [getCellSubtitle(cell)])
])
]),
div(
{ style: { margin: '0px 0px 0px auto' } },
[collapsedCellStatus]
)
])
]),
div({ class: 'col-sm-3 buttons-container' }, [
Expand Down
44 changes: 44 additions & 0 deletions test/unit/spec/narrative_core/kbaseCellToolbarMenu-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,53 @@
define([
'kbaseCellToolbarMenu'
], function(Widget) {
'use strict';
describe('Test the kbaseCellToolbarMenu widget', function() {
const mockParentCell = (message, collapsedState) => {
const messageContainer = document.createElement('div');
const execMessage = document.createElement('div');
execMessage.setAttribute('data-element', 'execMessage');
execMessage.innerHTML = message;
messageContainer.appendChild(execMessage);
return {
element: [messageContainer],
metadata: {
kbase: {
cellState: {
toggleMinMax: collapsedState
},
type: 'app'
}
}
};
};
const message = 'When in the course of human events...';

it('Should do things', function() {
});

it('Should show the status message when collapsed', function() {
const instance = Widget.make();
const parentCell = mockParentCell(message, 'minimized');
const toolbarDiv = document.createElement('div');
instance.register_callback([toolbarDiv], parentCell);
expect(
toolbarDiv.querySelectorAll(
'div.title div:nth-child(3)'
)[0].innerHTML
).toBe(message);
});

it('Should suppress the status message if not collapsed', function() {
const instance = Widget.make();
const parentCell = mockParentCell(message, 'maximized');
const toolbarDiv = document.createElement('div');
instance.register_callback([toolbarDiv], parentCell);
expect(
toolbarDiv.querySelectorAll(
'div.title div:nth-child(3)'
)[0].innerHTML
).toBe('');
});
});
});

0 comments on commit 950194f

Please sign in to comment.