Skip to content

Commit 44e2340

Browse files
authored
Merge pull request #529 from fractal-analytics-platform/fix-custom-json-schema-key
Fixed custom key not displayed in JSON Schema form
2 parents 683b9fd + 6f7926a commit 44e2340

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# Unreleased
44

5+
* Fixed custom key not displayed in JSON Schema form (\#529);
56
* Added dropdown for Python version in tasks (\#526);
67
* Improved formatting of errors in standard error alert component (\#526);
78
* Used `postgres-psycopg` adapter in CI (\#525);

jschema/__tests__/properties/object.test.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,4 +242,45 @@ describe('Object properties', () => {
242242
expect(screen.getByRole('textbox', { name: 'key1' })).toHaveValue('foo');
243243
expect(screen.getByRole('textbox', { name: 'key2' })).toHaveValue('');
244244
});
245+
246+
it('Display object with custom key and title - key prevails over title', async function () {
247+
const { component } = renderSchema(
248+
{
249+
type: 'object',
250+
properties: {
251+
map: {
252+
type: 'object',
253+
additionalProperties: {
254+
type: 'object',
255+
title: 'PropertyTitle',
256+
properties: {
257+
test: {
258+
type: 'string'
259+
}
260+
}
261+
}
262+
}
263+
}
264+
},
265+
{ map: { k1: { test: 'foo' } } }
266+
);
267+
expect(component.getArguments()).deep.eq({ map: { k1: { test: 'foo' } } });
268+
expect(screen.queryByText('PropertyTitle')).toBeNull();
269+
expect(screen.queryByText('k1')).not.toBeNull();
270+
});
271+
272+
it('Display root schema having only additionalProperties', async function () {
273+
const { component } = renderSchema(
274+
{
275+
type: 'object',
276+
additionalProperties: {
277+
type: 'string'
278+
}
279+
},
280+
{ k1: 'foo', k2: 'bar' }
281+
);
282+
expect(component.getArguments()).deep.eq({ k1: 'foo', k2: 'bar' });
283+
expect(screen.queryByText('k1')).not.toBeNull();
284+
expect(screen.queryByText('k2')).not.toBeNull();
285+
});
245286
});

jschema/src/lib/components/form_manager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ export class FormManager {
328328
manager: this,
329329
id: this.getUniqueId(),
330330
type: property.type || null,
331-
title: property.title || key || '',
331+
title: key && removable ? key : property.title || key || '',
332332
description: property.description || '',
333333
property: deepCopy(property),
334334
notifyChange: this.notifyChange

jschema/src/lib/components/jschema_adapter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function adaptJsonSchema(originalJsonSchema, propertiesToIgnore = []) {
2121
*/
2222
export function stripIgnoredProperties(originalJsonSchema, propertiesToIgnore = []) {
2323
const adaptedSchema = deepCopy(originalJsonSchema);
24-
for (const k of Object.keys(adaptedSchema.properties)) {
24+
for (const k of Object.keys(adaptedSchema.properties || {})) {
2525
if (propertiesToIgnore.includes(k)) {
2626
delete adaptedSchema.properties[k];
2727
}

0 commit comments

Comments
 (0)