-
Notifications
You must be signed in to change notification settings - Fork 490
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9241f46
commit 3714f6a
Showing
4 changed files
with
211 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH | ||
* under one or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information regarding copyright | ||
* ownership. | ||
* | ||
* Camunda licenses this file to you under the MIT; you may not use this file | ||
* except in compliance with the MIT License. | ||
*/ | ||
|
||
/** | ||
* @typedef { import('./types').IndexItem } IndexItem | ||
* @typedef { import('./types').AutoCompletion } AutoCompletion | ||
*/ | ||
|
||
export default class AutoCompletions { | ||
constructor(processApplications) { | ||
this._processApplications = processApplications; | ||
} | ||
|
||
/** | ||
* | ||
* @param {string} value | ||
* @param {string} type | ||
* | ||
* @returns {Array<AutoCompletion>} | ||
*/ | ||
get(value, type) { | ||
const items = this._processApplications.getItems().filter(item => item.type !== 'processApplication'); | ||
|
||
return items | ||
.filter(item => item.metadata.type === type) | ||
.reduce((autoCompletions, item) => { | ||
const { metadata } = item; | ||
|
||
const { ids } = metadata; | ||
|
||
return [ | ||
...autoCompletions, | ||
...ids | ||
.filter(id => id.includes(value)) | ||
.map(id => createAutoCompletion(item, id)) | ||
]; | ||
}, []); | ||
} | ||
}; | ||
|
||
/** | ||
* @param {IndexItem} item | ||
* @param {string} value | ||
* | ||
* @returns {AutoCompletion} | ||
*/ | ||
function createAutoCompletion(item, value) { | ||
return { | ||
uri: item.file.uri, | ||
value | ||
}; | ||
} |
145 changes: 145 additions & 0 deletions
145
client/src/app/process-applications/__tests__/AutoCompletionsSpec.js
This file contains 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 |
---|---|---|
@@ -0,0 +1,145 @@ | ||
/** | ||
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH | ||
* under one or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information regarding copyright | ||
* ownership. | ||
* | ||
* Camunda licenses this file to you under the MIT; you may not use this file | ||
* except in compliance with the MIT License. | ||
*/ | ||
|
||
import ProcessApplications from '../ProcessApplications'; | ||
import AutoCompletions from '../AutoCompletions'; | ||
|
||
describe('AutoCompletions', function() { | ||
|
||
let processApplications, autoCompletions; | ||
|
||
beforeEach(function() { | ||
processApplications = new ProcessApplications(); | ||
|
||
processApplications.emit('activeTab-changed', DEFAULT_ACTIVE_TAB); | ||
|
||
processApplications.emit('items-changed', DEFAULT_ITEMS_PROCESS_APPLICATION); | ||
|
||
autoCompletions = new AutoCompletions(processApplications); | ||
}); | ||
|
||
|
||
describe('#get', function() { | ||
|
||
it('should get autocompletion', function() { | ||
|
||
// given | ||
const value = 'BarDec'; | ||
|
||
// when | ||
const autocompletions = autoCompletions.get(value, 'dmn'); | ||
|
||
// then | ||
console.log(autocompletions); | ||
expect(autocompletions).to.have.length(1); | ||
expect(autocompletions).to.eql([ | ||
{ | ||
uri: 'file:///C:/process-application/bar/bar.dmn', | ||
value: 'BarDecision' | ||
} | ||
]); | ||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
const DEFAULT_ITEMS = [ | ||
{ | ||
file: { | ||
uri: 'file:///C:/process-application/foo.bpmn', | ||
path: 'C://process-application/foo.bpmn', | ||
dirname: 'C://process-application', | ||
contents: '<?xml version="1.0" encoding="UTF-8"?>' | ||
}, | ||
metadata: { | ||
type: 'bpmn', | ||
ids: [ 'FooProcess' ], | ||
linkedIds: [ | ||
{ linkedId: 'BarProcess', elementId: 'CallActivity_1', type: 'bpmn' }, | ||
{ linkedId: 'BarDecision', elementId: 'BusinessRuleTask_1', type: 'dmn' }, | ||
{ linkedId: 'BarForm', elementId: 'UserTask_1', type: 'form' } | ||
] | ||
} | ||
}, | ||
{ | ||
file: { | ||
uri: 'file:///C:/process-application/bar/bar.bpmn', | ||
path: 'C://process-application/bar/bar.bpmn', | ||
dirname: 'C://process-application/bar', | ||
contents: '<?xml version="1.0" encoding="UTF-8"?>' | ||
}, | ||
metadata: { | ||
type: 'bpmn', | ||
ids: [ 'BarProcess' ], | ||
linkedIds: [ | ||
{ linkedId: 'BazDecision', elementId: 'BusinessRuleTask_1', type: 'dmn' } | ||
] | ||
} | ||
}, | ||
{ | ||
file: { | ||
uri: 'file:///C:/process-application/bar/bar.dmn', | ||
path: 'C://process-application/bar/bar.dmn', | ||
dirname: 'C://process-application/bar', | ||
contents: '<?xml version="1.0" encoding="UTF-8"?>' | ||
}, | ||
metadata: { | ||
type: 'dmn', | ||
ids: [ 'BarDecision', 'BazDecision' ], | ||
linkedIds: [] | ||
} | ||
}, | ||
{ | ||
file: { | ||
uri: 'file:///C:/process-application/bar/bar.form', | ||
path: 'C://process-application/bar/bar.form', | ||
dirname: 'C://process-application/bar', | ||
contents: '{}' | ||
}, | ||
metadata: { | ||
type: 'form', | ||
ids: [ 'BarForm' ], | ||
linkedIds: [] | ||
} | ||
}, | ||
{ | ||
file: { | ||
uri: 'file:///C:/bar.bpmn', | ||
path: 'C://bar.bpmn', | ||
dirname: 'C://', | ||
contents: '<?xml version="1.0" encoding="UTF-8"?>' | ||
}, | ||
metadata: { | ||
type: 'bpmn' | ||
} | ||
} | ||
]; | ||
|
||
const DEFAULT_ITEMS_PROCESS_APPLICATION = [ | ||
{ | ||
file: { | ||
uri: 'file:///C:/process-application/.process-application', | ||
path: 'C://process-application/.process-application', | ||
dirname: 'C://process-application', | ||
contents: '{}' | ||
}, | ||
metadata: { | ||
type: 'processApplication' | ||
} | ||
}, | ||
...DEFAULT_ITEMS | ||
]; | ||
|
||
const DEFAULT_ACTIVE_TAB = { | ||
file: { | ||
...DEFAULT_ITEMS[0].file | ||
} | ||
}; |
This file contains 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