-
Couldn't load subscription status.
- Fork 0
Filter by uniqueness after filtering by scope #56
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6537b64
test: assert variables with different scopes not filtered by uniqueness
philippfromme 02e9c98
fix: filter by uniqueness after filtering by scope
philippfromme 3d95fd7
chore: fix type
philippfromme d198183
docs: improve jsdoc
nikku d6af0a6
chore: improve performance of check
philippfromme File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,6 @@ | ||
| import { getBusinessObject, is } from 'bpmn-js/lib/util/ModelUtil'; | ||
| import CachedValue from './util/CachedValue'; | ||
| import { getParents, getScope } from './util/scopeUtil'; | ||
| import { uniqueBy } from 'min-dash'; | ||
|
|
||
| /** | ||
| * @typedef {Object} AdditionalVariable | ||
|
|
@@ -17,6 +16,7 @@ import { uniqueBy } from 'min-dash'; | |
| * @typedef {AdditionalVariable} ProcessVariable | ||
| * @property {Array<ModdleElement>} origin | ||
| * @property {ModdleElement} scope | ||
| * @property {Array<Object>} provider | ||
| */ | ||
|
|
||
| /** | ||
|
|
@@ -49,7 +49,7 @@ export class BaseVariableResolver { | |
| } | ||
|
|
||
| /** | ||
| * To be implemented by super class. This should be an instance of `getProcessVariables` from `@bpmn-io/extract-process-variables`, | ||
| * To be implemented by a subclass. This should be an instance of `getProcessVariables` from `@bpmn-io/extract-process-variables`, | ||
| * either C7 or C8. | ||
| * | ||
| * @returns {Promise<Array<ProcessVariable>>} | ||
|
|
@@ -258,24 +258,40 @@ export class BaseVariableResolver { | |
| const root = getRootElement(bo); | ||
| const allVariables = await this.getProcessVariables(root); | ||
|
|
||
| // keep only unique variables based on name property | ||
| const uniqueVariables = uniqueBy('name', allVariables.reverse()); | ||
|
|
||
| // (1) get variables for given scope | ||
| var scopeVariables = uniqueVariables.filter(function(variable) { | ||
| var scopeVariables = allVariables.filter(function(variable) { | ||
| return variable.scope.id === bo.id; | ||
| }); | ||
|
|
||
| // (2) get variables for parent scopes | ||
| var parents = getParents(bo); | ||
|
|
||
| var parentsScopeVariables = uniqueVariables.filter(function(variable) { | ||
| var parentsScopeVariables = allVariables.filter(function(variable) { | ||
| return parents.find(function(parent) { | ||
| return parent.id === variable.scope.id; | ||
| }); | ||
| }); | ||
|
|
||
| return [ ...scopeVariables, ...parentsScopeVariables ]; | ||
| const reversedVariables = [ ...scopeVariables, ...parentsScopeVariables ].reverse(); | ||
|
|
||
| const seenNames = new Set(); | ||
|
|
||
| return reversedVariables.filter(variable => { | ||
|
|
||
| // if external variable, keep | ||
| if (variable.provider.find(extractor => extractor !== this._baseExtractor)) { | ||
philippfromme marked this conversation as resolved.
Show resolved
Hide resolved
philippfromme marked this conversation as resolved.
Show resolved
Hide resolved
philippfromme marked this conversation as resolved.
Show resolved
Hide resolved
philippfromme marked this conversation as resolved.
Show resolved
Hide resolved
philippfromme marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return true; | ||
| } | ||
|
|
||
| // if not external, keep only the first occurrence of each name | ||
| if (!seenNames.has(variable.name)) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Powered by Flip + 🤖 ❤️ |
||
| seenNames.add(variable.name); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| }); | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.