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

Added support to different diagrams per XML file #967

Closed

Conversation

snakebyte85
Copy link

Different diagrams (processes or collaborations) can be saved inside a single XML file, following BPMN 2.0 standard, but bpmn-js renders only the first diagram.

This commit allows a developer to select a specific diagram to be rendered, using the ID of the process or collaboration in this simply way:

bpmnViewer.importXML(bpmnXML, done, processId);

The first diagram (like before) will be rendered if processId is null

bpmn-js internally already supported the selection of a specific diagram to render, but the interfaces did not allow this

This is useful for #87

@philippfromme
Copy link
Contributor

Thanks for filing this pull request. Being able to specify which diagram you want to import would definitely be an improvement. We'll look into this. In the meantime, a few thoughts:

  • the specified ID should always reference a bpmndi:BPMNDiagram
  • importXML could support specifying a model instance when opening a diagram so you can switch between different diagrams in an XML file without reimporting the XML every single time - alternatively we could use importDefinitions

@snakebyte85
Copy link
Author

  • select diagram only for diagramId
  • Created method to switch diagram for an already imported XML in this way
    switchDiagram("<diagramId>")

Let me know if something else is needed

@barmac barmac self-requested a review April 9, 2019 13:18
@nikku
Copy link
Member

nikku commented Apr 9, 2019

Thanks for your follow up @snakebyte85. Could you add some test cases that bring the code coverage to a decent amount?

@snakebyte85
Copy link
Author

I added the needed test cases. I added two bpmns to be tested:

Sorry if I didn't that before but I am not practical of the used test enviroment and used patterns.

Let me know if tests needed to be modified

lib/Viewer.js Outdated Show resolved Hide resolved
lib/Viewer.js Outdated Show resolved Hide resolved
lib/Viewer.js Outdated Show resolved Hide resolved
lib/Viewer.js Outdated Show resolved Hide resolved
lib/Viewer.js Outdated Show resolved Hide resolved
@barmac
Copy link
Member

barmac commented Apr 10, 2019

Thank you for your further commits. I left a few comments that will need to be resolved before we merge the PR.

Can you please make sure your commits adhere to our contributing rules?

Can we also have a test case for a situation when the selected diagram is not present?

Copy link
Member

@barmac barmac left a comment

Choose a reason for hiding this comment

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

Please read the comments in the code and in the issue for feedback.

@snakebyte85 snakebyte85 force-pushed the feature/select-diagram branch from 393e763 to 2363327 Compare April 11, 2019 08:34
@snakebyte85
Copy link
Author

All done

Let me know for something else

This introduces a new parameter to `Viewer#importXML`
which enables to choose the diagram to display.

```
var viewer = new Viewer({ container: container });
viewer.importXML(xml, diagramId, done);
```

Closes bpmn-io#87
@barmac barmac force-pushed the feature/select-diagram branch from 2363327 to 36a7713 Compare April 11, 2019 12:09
@ghost ghost assigned barmac Apr 11, 2019
@ghost ghost added the needs review Review pending label Apr 11, 2019
@barmac barmac force-pushed the feature/select-diagram branch 5 times, most recently from b16ffb5 to f99dcbc Compare April 12, 2019 09:08
This adds a method to switch displayed diagram without reimporting
xml via

```
var viewer = new Viewer({ container: container });
viewer.importXML(xml, diagramId, done);

var diagrams = viewer.getDefinitions().diagrams;
viewer.open(diagrams[1], done);
```
@barmac barmac force-pushed the feature/select-diagram branch from f99dcbc to ed6fa0a Compare April 12, 2019 09:09
@barmac
Copy link
Member

barmac commented Apr 12, 2019

I slightly changed the API so that instead of #switchDiagram we have #open. Also, callback will be invoked with real errors instead of objects with message property. Furthermore, I added documentation.

@nikku Can you please have a look at this?

@barmac barmac requested a review from nikku April 12, 2019 09:11
@nikku
Copy link
Member

nikku commented Apr 12, 2019

@snakebyte85 Thanks again for your contribution.

@barmac I discovered an issue with re-opens if elements are shown in multiple BPMNDiagram instances. Cf. 95c1895 for a test case that fails. We'd need to sort out this issue before merging this feature. Could you have a look into it?

@barmac
Copy link
Member

barmac commented Apr 15, 2019

Current state is on https://github.com/bpmn-io/bpmn-js/tree/select-diagram

I pushed a bugfix for BpmnTreeWalker when context wasn't passed. This revealed that the current implementation renders more elements than enough, as a result of this.

There is also a problem of unnecessary warnings when an element is included in more than one DI.

@barmac
Copy link
Member

barmac commented Apr 15, 2019

I rebased the branch on top of master. There are still two failing test cases.

  1. We never deregister elements DI once it's registered, which for some diagrams results in unnecessary rendering here during diagram switch. See this test case for details.

  2. At the moment, we send a warning if an element's DI prop has already been registered. This is noticeable during a render of second diagram which uses the same elements, as in this test case. I think if we fix the first issue, the second one might be resolved, too.

Please feel free to update your branch with bpmn-js/select-diagram and add solution for the abovementioned issues :).

@nikku
Copy link
Member

nikku commented Apr 16, 2019

Merged via #983.

Thanks for your contribution 🎉

@nikku nikku closed this Apr 16, 2019
@bpmn-io-tasks bpmn-io-tasks bot removed the needs review Review pending label Apr 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants