Skip to content

Commit

Permalink
feat(client): add global layout
Browse files Browse the repository at this point in the history
Related to #866
Related to #911
  • Loading branch information
philippfromme authored and nikku committed Dec 1, 2018
1 parent 7abb394 commit b0f4db0
Show file tree
Hide file tree
Showing 10 changed files with 352 additions and 127 deletions.
35 changes: 33 additions & 2 deletions client/src/app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ import History from './History';

import css from './App.less';

import {
merge
} from 'min-dash';

const log = debug('App');

const tabLoaded = {
Expand All @@ -51,7 +55,17 @@ export class App extends Component {
tabs: [],
activeTab: EMPTY_TAB,
dirtyTabs: {},
tabState: {}
tabState: {},
layout: {

// TODO get layout from workspace
minimap: {
open: true
},
propertiesPanel: {
open: true
}
}
};

// TODO(nikku): make state
Expand Down Expand Up @@ -317,6 +331,20 @@ export class App extends Component {
this.props.onContextMenu(type);
}

handleLayoutChanged = (newLayout) => {
const {
layout
} = this.state;

this.setState({
layout: merge(layout, newLayout)
});

console.log('App#onLayoutChanged', merge(layout, newLayout));

// TODO persist to workspace
}

/**
* Mark the active tab as shown.
*/
Expand Down Expand Up @@ -697,7 +725,8 @@ export class App extends Component {

const {
tabs,
tabState
tabState,
layout
} = this.state;

const Tab = this.state.Tab || EmptyTab;
Expand Down Expand Up @@ -804,9 +833,11 @@ export class App extends Component {
<Tab
key={ activeTab.id }
tab={ activeTab }
layout={ layout }
onChanged={ this.handleTabChanged }
onError={ this.handleTabError }
onShown={ this.handleTabShown }
onLayoutChanged={ this.handleLayoutChanged }
onContextMenu={ this.openTabMenu }
ref={ this.tabRef }
/>
Expand Down
2 changes: 1 addition & 1 deletion client/src/app/cached/WithCachedState.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default function(Comp) {

const initialCachedState =
'createCachedState' in Comp
? Comp.createCachedState()
? Comp.createCachedState(this.props)
: {};

const {
Expand Down
22 changes: 18 additions & 4 deletions client/src/app/tabs/MultiSheetTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,12 @@ class MultiSheetTab extends CachedComponent {
}

handleError = (error) => {
const { tab } = this.props;
const {
onError,
tab
} = this.props;

this.props.onError(tab, error);
onError(tab, error);
}

handleContextMenu = (event, context) => {
Expand All @@ -102,6 +105,14 @@ class MultiSheetTab extends CachedComponent {

}

handleLayoutChanged = (newLayout) => {
const {
onLayoutChanged
} = this.props;

onLayoutChanged(newLayout);
}

triggerAction = async (action, options) => {

const editor = this.editorRef.current;
Expand Down Expand Up @@ -199,7 +210,8 @@ class MultiSheetTab extends CachedComponent {

let {
id,
xml
xml,
layout
} = this.props;

if (!sheets) {
Expand All @@ -219,11 +231,13 @@ class MultiSheetTab extends CachedComponent {
ref={ this.editorRef }
id={ `${id}-${activeSheet.id}` }
xml={ lastXML || xml }
layout={ layout }
activeSheet={ activeSheet }
onSheetsChanged={ this.sheetsChanged }
onContextMenu={ this.handleContextMenu }
onChanged={ this.handleChanged }
onError={ this.handleError } />
onError={ this.handleError }
onLayoutChanged={ this.handleLayoutChanged } />
</TabContainer>

<TabLinks
Expand Down
69 changes: 60 additions & 9 deletions client/src/app/tabs/bpmn/BpmnEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ import css from './BpmnEditor.less';

import generateImage from '../../util/generateImage';

import classNames from 'classnames';

import { merge } from 'min-dash';

const COLORS = [{
title: 'White',
fill: 'white',
Expand Down Expand Up @@ -57,7 +61,13 @@ export class BpmnEditor extends CachedComponent {
constructor(props) {
super(props);

this.state = {};
const {
layout
} = this.props;

this.state = {
layout
};

this.ref = React.createRef();
this.propertiesPanelRef = React.createRef();
Expand Down Expand Up @@ -148,9 +158,11 @@ export class BpmnEditor extends CachedComponent {
}

handleMinimapToggle = (event) => {
console.warn('minimap toggle', event.open);

// TODO(nikku): persist minimap toggle state
this.handleLayoutChange({
minimap: {
open: event.open
}
});
}

handleElementTemplateErrors = (event) => {
Expand Down Expand Up @@ -353,6 +365,36 @@ export class BpmnEditor extends CachedComponent {
}
}

handlePropertiesPanelToggle = () => {
const {
layout
} = this.state;

this.handleLayoutChange({
propertiesPanel: {
open: !layout.propertiesPanel.open
}
});
}

handleLayoutChange(newLayout) {
const {
onLayoutChanged
} = this.props;

const {
layout
} = this.state;

newLayout = merge(layout, newLayout);

this.setState({
layout: newLayout
});

onLayoutChanged(newLayout);
}

resize = () => {
const {
modeler
Expand All @@ -364,11 +406,13 @@ export class BpmnEditor extends CachedComponent {
}

render() {

const {
layout,
loading
} = this.state;

const propertiesPanelOpen = layout.propertiesPanel && layout.propertiesPanel.open;

return (
<div className={ css.BpmnEditor }>

Expand Down Expand Up @@ -477,20 +521,27 @@ export class BpmnEditor extends CachedComponent {
onContextMenu={ this.handleContextMenu }
></div>

<div className="properties">
<div className="toggle">Properties Panel</div>
<div className={ classNames('properties', { 'open': propertiesPanelOpen }) }>
<div className="toggle" onClick={ this.handlePropertiesPanelToggle }>Properties Panel</div>
<div className="resize-handle"></div>
<div className="properties-container" ref={ this.propertiesPanelRef }></div>
</div>
</div>
);
}

static createCachedState() {
static createCachedState(props) {

const {
layout
} = props;

// TODO(nikku): wire element template loading
const modeler = new CamundaBpmnModeler({
position: 'absolute'
position: 'absolute',
minimap: {
open: layout.minimap.open
}
});

return {
Expand Down
4 changes: 4 additions & 0 deletions client/src/app/tabs/bpmn/BpmnEditor.less
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
border-left: solid 1px #CCC;
box-shadow: 0 0 2px rgba(0, 0, 0, 0.3);

&:not(.open) .properties-container {
width: 0px;
}

.toggle {
position: absolute;
left: -30px;
Expand Down
Loading

0 comments on commit b0f4db0

Please sign in to comment.