Skip to content

Commit

Permalink
feat: add autocompletions
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme committed Jan 9, 2025
1 parent 9241f46 commit 3714f6a
Show file tree
Hide file tree
Showing 4 changed files with 211 additions and 0 deletions.
2 changes: 2 additions & 0 deletions client/src/app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import ProcessApplications from './process-applications';
import { ProcessApplicationsStatusBar } from './process-applications/components';

import References from './process-applications/References';
import AutoCompletions from './process-applications/AutoCompletions';

import { PluginsRoot } from './plugins';

Expand Down Expand Up @@ -161,6 +162,7 @@ export class App extends PureComponent {
});

this.references = new References(processApplications);
this.autoCompletions = new AutoCompletions(processApplications);

this.tabRef = React.createRef();

Expand Down
59 changes: 59 additions & 0 deletions client/src/app/process-applications/AutoCompletions.js
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 client/src/app/process-applications/__tests__/AutoCompletionsSpec.js
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
}
};
5 changes: 5 additions & 0 deletions client/src/app/process-applications/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export type Reference = {
}
};

export type AutoCompletion = {
value: string,
uri: string
};

export type File = {
contents: string,
dirname: string,
Expand Down

0 comments on commit 3714f6a

Please sign in to comment.