Skip to content

Commit

Permalink
feat: implement variable suggestions for input editor
Browse files Browse the repository at this point in the history
Related to #785
  • Loading branch information
barmac committed Oct 6, 2023
1 parent 7d3d685 commit 1cb97d3
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 3 deletions.
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/dmn-js-decision-table/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"inferno-test-utils": "~5.6.2"
},
"dependencies": {
"@bpmn-io/dmn-variable-resolver": "^0.3.0",
"css.escape": "^1.5.1",
"diagram-js": "^12.0.0",
"dmn-js-shared": "^14.4.1",
Expand Down
4 changes: 3 additions & 1 deletion packages/dmn-js-decision-table/src/Editor.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DmnVariableResolverModule } from '@bpmn-io/dmn-variable-resolver';
import Viewer from './Viewer';

import addRuleModule from './features/add-rule';
Expand Down Expand Up @@ -76,7 +77,8 @@ export default class Editor extends Viewer {
simpleDurationEditModule,
simpleNumberEditModule,
simpleStringEditModule,
simpleTimeEditModule
simpleTimeEditModule,
DmnVariableResolverModule
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export default class InputCellContextMenu extends Component {
<InputEditor
label={ this.getValue('label') }
text={ this.getValue('text') }
element={ this.props.context.input }
onChange={ this.handleChange } />
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default class InputEditor extends Component {

this.translate = context.injector ? context.injector.get('translate') : noopTranslate;
this.expressionLanguages = context.injector.get('expressionLanguages', false);
this.variableResolver = context.injector.get('variableResolver', false);

this.handleValue = (text) => {

Expand Down Expand Up @@ -54,6 +55,11 @@ export default class InputEditor extends Component {
}
};

_getVariables() {
return this.variableResolver &&
this.variableResolver.getVariables(this.props.element);
}

render() {

const {
Expand All @@ -63,6 +69,8 @@ export default class InputEditor extends Component {

const ExpressionEditor = this.getExpressionEditorComponent();

const variables = this._getVariables();

return (
<div className="context-menu-container ref-input-editor input-edit"
onKeyDown={ this.handleKeyDown }>
Expand Down Expand Up @@ -92,7 +100,8 @@ export default class InputEditor extends Component {
].join(' ')
}
onInput={ this.handleValue }
value={ text || '' } />
value={ text || '' }
variables={ variables } />
</div>
</div>
);
Expand Down
1 change: 1 addition & 0 deletions packages/dmn-js-literal-expression/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"inferno-test-utils": "~5.6.2"
},
"dependencies": {
"@bpmn-io/dmn-variable-resolver": "^0.3.0",
"diagram-js": "^12.0.0",
"dmn-js-shared": "^14.4.1",
"escape-html": "^1.0.3",
Expand Down
7 changes: 6 additions & 1 deletion packages/dmn-js-shared/src/components/LiteralExpression.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export default class LiteralExpression extends Component {
this.editor = new FeelEditor({
container: this.node,
onChange: this.handleChange,
value: this.state.value
value: this.state.value,
variables: this.props.variables || [],
});

this.node.addEventListener('mousedown', this.handleMouseEvent);
Expand All @@ -70,6 +71,10 @@ export default class LiteralExpression extends Component {
this.editor.setValue(value);
});
}

if (prevProps.variables !== this.props.variables) {
this.editor.setVariables(this.props.variables);
}
}

componentWillUnmount() {
Expand Down

0 comments on commit 1cb97d3

Please sign in to comment.