Skip to content

Commit 1936d63

Browse files
feat: stringify object values (#24)
Fixes RM-2228 :---: ## 🧰 What's being changed? Allow using objects as variable values.
1 parent ae8e8b6 commit 1936d63

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

__tests__/index.test.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ describe('single variable', () => {
4747
});
4848

4949
it.todo('should set `selected` if nothing is selected');
50+
51+
it('should render objects as strings', () => {
52+
const variable = shallow(<Variable {...props} user={{ apiKey: { renderTo: 'string' } }} />);
53+
54+
expect(variable.text()).toBe(JSON.stringify({ renderTo: 'string' }));
55+
});
5056
});
5157

5258
describe('multiple variables', () => {

index.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ class Variable extends React.Component {
3333
// - uppercase key
3434
getValue() {
3535
const { variable } = this.props;
36-
if (this.props.user[variable]) return this.props.user[variable];
36+
const value = this.props.user[variable] || this.getDefault();
3737

38-
return this.getDefault();
38+
return typeof value === 'object' ? JSON.stringify(value) : value;
3939
}
4040

4141
toggleVarDropdown() {

0 commit comments

Comments
 (0)