Skip to content

Commit d10c445

Browse files
committed
Fix crash in MaterialTableControl
When the item object schema doesn't specify properties the control crashed. We now check the type of the properties before (not) accessing them.
1 parent 4b9bbbd commit d10c445

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

packages/material/src/complex/MaterialTableControl.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ const generateCells = (
116116
};
117117

118118
const getValidColumnProps = (scopedSchema: JsonSchema) => {
119-
if (scopedSchema.type === 'object') {
119+
if (scopedSchema.type === 'object' && typeof scopedSchema.properties === 'object') {
120120
return Object.keys(scopedSchema.properties).filter(
121121
prop => scopedSchema.properties[prop].type !== 'array'
122122
);

packages/material/test/renderers/MaterialArrayControl.test.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,41 @@ describe('Material array control', () => {
167167
expect(headerColumns).toHaveLength(3);
168168
});
169169

170+
it('should render even without properties', () => {
171+
const store = initJsonFormsStore();
172+
// re-init
173+
const data: any = { test: [] };
174+
const schema: JsonSchema = {
175+
type: 'object',
176+
properties: {
177+
test: {
178+
type: 'array',
179+
items: { type: 'object' }
180+
}
181+
}
182+
};
183+
const uischema: ControlElement = {
184+
type: 'Control',
185+
scope: '#/properties/test'
186+
};
187+
store.dispatch(Actions.init(data, schema, uischema));
188+
189+
wrapper = mount(
190+
<Provider store={store}>
191+
<JsonFormsReduxContext>
192+
<MaterialArrayControlRenderer schema={schema} uischema={uischema} />
193+
</JsonFormsReduxContext>
194+
</Provider>
195+
);
196+
197+
const rows = wrapper.find('tr');
198+
// two header rows + no data row
199+
expect(rows.length).toBe(3);
200+
const headerColumns = rows.at(1).children();
201+
// 2 columns: content + buttons
202+
expect(headerColumns).toHaveLength(2);
203+
});
204+
170205
it('should render empty primitives', () => {
171206
const store = initJsonFormsStore();
172207
// re-init

0 commit comments

Comments
 (0)