Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve variables tab integration #4638

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions client/src/app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -1945,6 +1945,11 @@ export class App extends PureComponent {
return this.emitWithTab(type, activeTab, payload);
}

if (action === 'open-bottom-panel') {
const { panel } = this.state.layout;
return panel.open ? this.closePanel() : this.openPanel();
}

const tab = this.tabRef.current;

return tab.triggerAction(action, options);
Expand Down
54 changes: 54 additions & 0 deletions client/src/app/__tests__/AppSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2085,6 +2085,60 @@ describe('<App>', function() {

});

describe('bottom-panel', function() {

describe('#triggerAction', function() {

it('should open', function() {

// given
const { app } = createApp();

app.setLayout({
panel: {
open: false,
}
});

// when
app.triggerAction('open-bottom-panel');

// then
expect(app.state.layout).to.eql({
panel: {
open: true,
tab: 'log'
}
});
});


it('should close', function() {

// given
const { app } = createApp();

app.setLayout({
panel: {
open: true,
}
});

// when
app.triggerAction('open-bottom-panel');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
app.triggerAction('open-bottom-panel');
app.triggerAction('toggle-bottom-panel');

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename to toggle, as toggle is what it is.


// then
expect(app.state.layout).to.eql({
panel: {
open: false
}
});
});

});

});

});


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership.
*
* Camunda licenses this file to you under the MIT; you may not use this file
* except in compliance with the MIT License.
*/

import React from 'react';

import classnames from 'classnames';

import { Fill } from '../../../slot-fill';

export default function VariableOutlineStatusBarItem(props) {
const {
onToggle,
layout
} = props;

const { panel = {} } = layout;

return <Fill slot="status-bar__file" group="9_variables">
<button
className={ classnames(
'btn',
{ 'btn--active': panel.open && panel.tab === 'variable-outline' }
) }
onClick={ onToggle }
> Variables </button>
</Fill>;
}
18 changes: 17 additions & 1 deletion client/src/app/panel/tabs/variable-outline/VariableOutlineTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,26 @@

import { Fill } from '../../../slot-fill';

import VariableOutlineStatusBarItem from './VariableOutlineStatusBarItem';

export default function VariableTab(props) {
const {
layout = {},
injector,
id
id,
onAction
} = props;

const onToggle = () => {
const { panel = {} } = layout;

Check warning on line 30 in client/src/app/panel/tabs/variable-outline/VariableOutlineTab.js

View check run for this annotation

Codecov / codecov/patch

client/src/app/panel/tabs/variable-outline/VariableOutlineTab.js#L30

Added line #L30 was not covered by tests

if (!panel.open || panel.tab !== 'variable-outline') {
onAction('open-panel', { tab: 'variable-outline' });
} else if (panel.tab === 'variable-outline') {
onAction('close-panel');

Check warning on line 35 in client/src/app/panel/tabs/variable-outline/VariableOutlineTab.js

View check run for this annotation

Codecov / codecov/patch

client/src/app/panel/tabs/variable-outline/VariableOutlineTab.js#L32-L35

Added lines #L32 - L35 were not covered by tests
}
};

return <>
<Fill slot="bottom-panel"
id="variable-outline"
Expand All @@ -34,5 +46,9 @@
<VariableOutline injector={ injector } key={ id } />
</div>
</Fill>

<VariableOutlineStatusBarItem
layout={ layout }
onToggle={ onToggle } />
</>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/**
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership.
*
* Camunda licenses this file to you under the MIT; you may not use this file
* except in compliance with the MIT License.
*/

/* global sinon */

import React from 'react';

import { mount } from 'enzyme';

import {
SlotFillRoot,
Slot
} from '../../../../slot-fill';

import VariableOutlineStatusBarItem from '../VariableOutlineStatusBarItem';

const spy = sinon.spy;


describe('VariableOutlineStatusBarItem', function() {

it('should render', function() {

// when
const wrapper = renderVariableOutlineStatusBarItem();

// then
expect(wrapper.find(VariableOutlineStatusBarItem).exists()).to.be.true;
});


describe('toggle', function() {

it('should be active (open)', function() {

// when
const wrapper = renderVariableOutlineStatusBarItem({
layout: {
panel: {
open: true,
tab: 'variable-outline'
}
}
});

// then
expect(wrapper.find('.btn').hasClass('btn--active')).to.be.true;
});


it('should not be active (closed)', function() {

// when
const wrapper = renderVariableOutlineStatusBarItem();

// then
expect(wrapper.find('.btn').hasClass('btn--active')).to.be.false;
});


it('should call callback on toggle', function() {

// given
const onToggleSpy = spy();

const wrapper = renderVariableOutlineStatusBarItem({
onToggle: onToggleSpy
});

// when
wrapper.find('.btn').simulate('click');

// then
expect(onToggleSpy).to.have.been.calledOnce;
});

});

});


// helpers //////////

const defaultLayout = {
panel: {
open: false,
tab: 'variable-outline'
}
};


function renderVariableOutlineStatusBarItem(options = {}) {
const {
layout = defaultLayout,
onToggle
} = options;

return mount(
<SlotFillRoot>
<Slot name="status-bar__file" />
<VariableOutlineStatusBarItem
layout={ layout }
onToggle={ onToggle } />
</SlotFillRoot>
);
}
3 changes: 2 additions & 1 deletion client/src/app/tabs/bpmn/BpmnEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,8 @@ export class BpmnEditor extends CachedComponent {
setColor: !!selectionLength,
spaceTool: !inputActive,
undo: commandStack.canUndo(),
zoom: true
zoom: true,
bottomPanel: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this variable? Why do we explicitly need to configure it? I assume that the bottom panel is always available, one way or the other.

};

// ensure backwards compatibility
Expand Down
12 changes: 11 additions & 1 deletion client/src/app/tabs/bpmn/getBpmnWindowMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
export default function getBpmnWindowMenu(state) {
return [
...getZoomEntries(state),
...getPropertiesPanelEntries(state)
...getPropertiesPanelEntries(state),
...getBottomPanelEntries(state)
];
}

Expand Down Expand Up @@ -51,3 +52,12 @@ function getPropertiesPanelEntries({ propertiesPanel }) {
action: 'resetProperties'
} ] : [];
}

function getBottomPanelEntries({ bottomPanel }) {
return bottomPanel ? [ {
label: 'Toggle Bottom Panel',
accelerator: 'CommandOrControl+B',
action: 'open-bottom-panel'
}
] : [];
}
8 changes: 5 additions & 3 deletions client/src/app/tabs/cloud-bpmn/BpmnEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,8 @@ export class BpmnEditor extends CachedComponent {
setColor: !!selectionLength,
spaceTool: !inputActive,
undo: commandStack.canUndo(),
zoom: true
zoom: true,
bottomPanel: true
};

// ensure backwards compatibility
Expand Down Expand Up @@ -758,7 +759,7 @@ export class BpmnEditor extends CachedComponent {
render() {
const engineProfile = this.engineProfile.getCached();

const { layout } = this.props;
const { layout, onAction } = this.props;

const modeler = this.getModeler();
const imported = modeler.getDefinitions();
Expand Down Expand Up @@ -796,7 +797,8 @@ export class BpmnEditor extends CachedComponent {
<VariableTab
id={ this.props.id }
layout={ layout }
injector={ injector } />
injector={ injector }
onAction={ onAction } />
</div>
);
}
Expand Down