Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Niklas Kiefer committed Nov 29, 2018
1 parent 79cd80f commit e36dde4
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 36 deletions.
28 changes: 18 additions & 10 deletions client/src/app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,21 +509,21 @@ export class App extends Component {

const response = await dialog.showEmptyFileDialog({
file,
fileType
type: fileType
});

if (response == 'create') {
assign(file, {
contents: tabsProvider.getInitialFileContents(fileType)
});

// TODO(philippfromme): fix dirty state
let tab = this.addTab(
tabsProvider.createTabForFile(file)
);

this.handleTabChanged(tab)({
dirty: true
tab = await this.updateTab(tab, {
file: {
...file,
contents: tabsProvider.getInitialFileContents(fileType)
}
});

await this.selectTab(tab);
Expand Down Expand Up @@ -697,10 +697,6 @@ export class App extends Component {
});
}

if ('contents' in properties) {
tab.file.contents = properties.contents;
}

tabState = {
...tabState,
...properties
Expand All @@ -710,6 +706,18 @@ export class App extends Component {
tabState
});

// todo: discuss - allow to call with all kind of tab properties?
if (typeof properties.newContents !== 'undefined') {
const file = tab.file;

this.updateTab(tab, {
file: {
...file,
contents: properties.newContents
}
});
}

this.updateMenu(tabState);
}

Expand Down
42 changes: 29 additions & 13 deletions client/src/app/__tests__/AppSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -731,30 +731,46 @@ describe('<App>', function() {
});


describe('tab changing', function() {
describe.only('tab changing', function() {

it('should update contents on tab changed', async function() {
let app, tab;

// given
const {
app
} = createApp();
beforeEach(async function() {

app = createApp().app;

await app.createDiagram('bpmn');

const {
activeTab
} = app.state;
tab = app.state.activeTab;

});

const newContents = 'foo';
it('should call #updateTab when attributes given', async function() {

// given
const updateSpy = spy(app, 'updateTab');

const NEW_FILE_CONTENTS = '< bar/>';

// when
app.handleTabChanged(activeTab)({
contents: newContents
app.handleTabChanged(tab)({
newContents: NEW_FILE_CONTENTS
});

// then
expect(activeTab.file.contents).to.equal(newContents);
expect(updateSpy).to.have.been.called;
});

it('should NOT call #updateTab when NO attributes given', async function() {

// given
const updateSpy = spy(app, 'updateTab');

// when
app.handleTabChanged(tab)();

// then
expect(updateSpy).to.not.have.been.called;
});

});
Expand Down
20 changes: 7 additions & 13 deletions client/src/app/tabs/bpmn/BpmnEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ import {
replaceNamespace
} from './util/namespace';

import {
assign
} from 'min-dash';

const NAMESPACE_URL_ACTIVITI = 'http://activiti.org/bpmn',
NAMESPACE_URL_CAMUNDA = 'http://camunda.org/schema/1.0/bpmn',
NAMESPACE_PREFIX_ACTIVITI = 'activiti',
Expand Down Expand Up @@ -237,8 +233,9 @@ export class BpmnEditor extends CachedComponent {
});

this.handleChanged({
xml
newContents: xml
});

}

return xml;
Expand Down Expand Up @@ -267,10 +264,6 @@ export class BpmnEditor extends CachedComponent {


handleChanged = (event = {}) => {
const {
xml
} = event;

const {
modeler
} = this.getCached();
Expand All @@ -279,6 +272,10 @@ export class BpmnEditor extends CachedComponent {
onChanged
} = this.props;

const {
newContents
} = event;

const commandStack = modeler.get('commandStack');
const selection = modeler.get('selection');

Expand All @@ -299,6 +296,7 @@ export class BpmnEditor extends CachedComponent {
lassoTool: !inputActive,
moveCanvas: !inputActive,
moveToOrigin: !inputActive,
newContents,
paste: !modeler.get('clipboard').isEmpty(),
propertiesPanel: true,
redo: commandStack.canRedo(),
Expand All @@ -310,10 +308,6 @@ export class BpmnEditor extends CachedComponent {
zoom: true
};

if (xml) {
assign(newState, { contents : xml });
}

const contextMenu = getBpmnContextMenu(newState);

const editMenu = getBpmnEditMenu(newState);
Expand Down

0 comments on commit e36dde4

Please sign in to comment.