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

feat(editors): resize properties panel along with editor #1090

Merged
merged 1 commit into from
Jan 11, 2019
Merged
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
8 changes: 7 additions & 1 deletion client/src/app/tabs/bpmn/BpmnEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,14 @@ export class BpmnEditor extends CachedComponent {
propertiesPanel.detach();
}

componentDidUpdate() {
componentDidUpdate(prevProps) {
if (!this.state.importing) {
this.checkImport();
}

if (prevProps.layout.propertiesPanel !== this.props.layout.propertiesPanel) {
this.triggerAction('resize');
}
}

ifMounted = (fn) => {
Expand Down Expand Up @@ -493,8 +497,10 @@ export class BpmnEditor extends CachedComponent {
const modeler = this.getModeler();

const canvas = modeler.get('canvas');
const eventBus = modeler.get('eventBus');

canvas.resized();
eventBus.fire('propertiesPanel.resized');
}

render() {
Expand Down
52 changes: 52 additions & 0 deletions client/src/app/tabs/bpmn/__tests__/BpmnEditorSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,58 @@ describe('<BpmnEditor>', function() {

});


describe('editor resize', function() {

afterEach(sinon.restore);


it('should resize editor and properties panel on layout change', async function() {

// given
const eventBusStub = sinon.stub({ fire() {} }),
canvasStub = sinon.stub({ resized() {} });

const cache = new Cache();

cache.add('editor', {
cached: {
modeler: new BpmnModeler({
eventBus: eventBusStub,
canvas: canvasStub
})
}
});

const {
instance
} = await renderEditor(diagramXML, {
cache
});

const mockLayout = {
propertiesPanel: {
open: true,
width: 500
}
};

eventBusStub.fire.resetHistory();
canvasStub.resized.resetHistory();

// when
const prevProps = instance.props;

instance.props = { ...prevProps, layout: mockLayout };
instance.componentDidUpdate(prevProps);

// expect
expect(canvasStub.resized).to.be.called;
expect(eventBusStub.fire).to.be.calledOnceWith('propertiesPanel.resized');
});

});

});


Expand Down
16 changes: 11 additions & 5 deletions client/src/app/tabs/cmmn/CmmnEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,14 @@ export class CmmnEditor extends CachedComponent {
modeler[fn]('error', 1500, this.handleError);
}

componentDidUpdate() {
componentDidUpdate(prevProps) {
if (!this.state.importing) {
this.checkImport();
}

if (prevProps.layout.propertiesPanel !== this.props.layout.propertiesPanel) {
this.triggerAction('resize');
}
}

undo = () => {
Expand Down Expand Up @@ -299,14 +303,14 @@ export class CmmnEditor extends CachedComponent {
}

triggerAction = (action, context) => {
const {
modeler
} = this.getCached();

if (action === 'resize') {
return this.resize();
}

const {
modeler
} = this.getCached();

// TODO(nikku): handle all editor actions
modeler.get('editorActions').trigger(action, context);
}
Expand Down Expand Up @@ -335,8 +339,10 @@ export class CmmnEditor extends CachedComponent {
} = this.getCached();

const canvas = modeler.get('canvas');
const eventBus = modeler.get('eventBus');

canvas.resized();
eventBus.fire('propertiesPanel.resized');
}

render() {
Expand Down
52 changes: 52 additions & 0 deletions client/src/app/tabs/cmmn/__tests__/CmmnEditorSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,58 @@ describe('<CmmnEditor>', function() {

});


describe('editor resize', function() {

afterEach(sinon.restore);


it('should resize editor and properties panel on layout change', async function() {

// given
const eventBusStub = sinon.stub({ fire() {} }),
canvasStub = sinon.stub({ resized() {} });

const cache = new Cache();

cache.add('editor', {
cached: {
modeler: new CmmnModeler({
eventBus: eventBusStub,
canvas: canvasStub
})
}
});

const {
instance
} = await renderEditor(diagramXML, {
cache
});

const mockLayout = {
propertiesPanel: {
open: true,
width: 500
}
};

eventBusStub.fire.resetHistory();
canvasStub.resized.resetHistory();

// when
const prevProps = instance.props;

instance.props = { ...prevProps, layout: mockLayout };
instance.componentDidUpdate(prevProps);

// expect
expect(canvasStub.resized).to.be.called;
expect(eventBusStub.fire).to.be.calledOnceWith('propertiesPanel.resized');
});

});

});


Expand Down
30 changes: 29 additions & 1 deletion client/src/app/tabs/dmn/DmnEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,14 @@ export class DmnEditor extends CachedComponent {
modeler.detach();
}

componentDidUpdate() {
componentDidUpdate(prevProps) {
if (!this.state.importing) {
this.checkImport();
}

if (prevProps.layout.propertiesPanel !== this.props.layout.propertiesPanel) {
this.triggerAction('resize');
}
}

ifMounted = (fn) => {
Expand Down Expand Up @@ -384,6 +388,10 @@ export class DmnEditor extends CachedComponent {
}

triggerAction = (action, options) => {
if (action === 'resize') {
return this.resize();
}

const {
modeler
} = this.getCached();
Expand All @@ -393,6 +401,26 @@ export class DmnEditor extends CachedComponent {
.trigger(action);
}

resize = () => {
const {
modeler
} = this.getCached();

const view = modeler.getActiveView();

if (view.type !== 'drd') {
return;
}

const viewer = modeler.getActiveViewer();

const canvas = viewer.get('canvas');
const eventBus = viewer.get('eventBus');

canvas.resized();
eventBus.fire('propertiesPanel.resized');
}

getXML() {
const {
modeler
Expand Down
53 changes: 53 additions & 0 deletions client/src/app/tabs/dmn/__tests__/DmnEditorSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,59 @@ describe('<DmnEditor>', function() {

});


describe('editor resize', function() {

afterEach(sinon.restore);


it('should resize editor and properties panel on layout change', async function() {

// given
const eventBusStub = sinon.stub({ fire() {} }),
canvasStub = sinon.stub({ resized() {} });

const cache = new Cache();

cache.add('editor', {
cached: {
modeler: new DmnModeler({
eventBus: eventBusStub,
canvas: canvasStub
})
}
});

const {
instance
} = await renderEditor(diagramXML, {
cache
});

const mockLayout = {
propertiesPanel: {
open: true,
width: 500
}
};

eventBusStub.fire.resetHistory();
canvasStub.resized.resetHistory();

// when
const prevProps = instance.props;

instance.props = { ...prevProps, layout: mockLayout };
instance.componentDidUpdate(prevProps);

// expect
expect(canvasStub.resized).to.be.called;
expect(eventBusStub.fire).to.be.calledOnceWith('propertiesPanel.resized');
});

});


});


Expand Down
3 changes: 3 additions & 0 deletions client/test/mocks/bpmn-js/Modeler.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export default class Modeler {

_getDefaultModules() {
return {
eventBus: {
fire() {}
},
canvas: {
resized() {}
},
Expand Down
3 changes: 3 additions & 0 deletions client/test/mocks/cmmn-js/Modeler.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export default class Modeler {

_getDefaultModules() {
return {
eventBus: {
fire() {}
},
canvas: {
resized() {}
},
Expand Down
3 changes: 3 additions & 0 deletions client/test/mocks/dmn-js/Modeler.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class Viewer {

_getDefaultModules() {
return {
eventBus: {
fire() {}
},
canvas: {
resized() {}
},
Expand Down