Skip to content

Commit

Permalink
feat: provide variables for input expression
Browse files Browse the repository at this point in the history
  • Loading branch information
barmac committed Aug 3, 2023
1 parent 90099ac commit 075c2aa
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 3 deletions.
41 changes: 41 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": "github:bpmn-io/dmn-variable-resolver",
"css.escape": "^1.5.1",
"diagram-js": "^12.0.0",
"dmn-js-shared": "^14.1.5",
Expand Down
5 changes: 4 additions & 1 deletion packages/dmn-js-decision-table/src/Editor.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { DmnVariableResolverModule } from '@bpmn-io/dmn-variable-resolver';

import Viewer from './Viewer';

import addRuleModule from './features/add-rule';
Expand Down Expand Up @@ -76,7 +78,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 @@ -75,8 +75,10 @@ export default class InputCellContextMenu extends Component {
}

render() {
const variables = this.variableResolver.getVariables(this.props.context.input);
return (
<InputEditor
variables={ variables }
label={ this.getValue('label') }
text={ this.getValue('text') }
onChange={ this.handleChange } />
Expand All @@ -87,6 +89,7 @@ export default class InputCellContextMenu extends Component {
InputCellContextMenu.$inject = [
'debounceInput',
'modeling',
'variableResolver',
'injector'
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ export default class InputEditor extends Component {
].join(' ')
}
onInput={ this.handleValue }
value={ text || '' } />
value={ text || '' }
variables={ this.props.variables }
/>
</div>
</div>
);
Expand Down
13 changes: 12 additions & 1 deletion packages/dmn-js-shared/src/components/LiteralExpression.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ export default class LiteralExpression extends Component {
this.editor = new FeelEditor({
container: this.node,
onChange: this.props.onInput,
value: this.props.value
value: this.props.value,
variables: this.props.variables || []
});
}

componentDidUpdate(prevProps) {
if (!jsonEqual(prevProps.variables, this.props.variables)) {
this.editor.setVariables(this.props.variables);
}
}

handleMouseEvent = (event) => {
event.stopPropagation();
};
Expand All @@ -44,3 +51,7 @@ export default class LiteralExpression extends Component {
);
}
}

function jsonEqual(a, b) {
return JSON.stringify(a) === JSON.stringify(b);
}

0 comments on commit 075c2aa

Please sign in to comment.