Skip to content

Commit

Permalink
fix: fix issue rendering delete properties action (microsoft#2460)
Browse files Browse the repository at this point in the history
* fix issues rendering delete properties actions

* no longer recurse on schema

Co-authored-by: Chris Whitten <christopher.whitten@microsoft.com>
  • Loading branch information
a-b-r-o-w-n and cwhitten authored Apr 2, 2020
1 parent 085acbe commit ddfd5e3
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { resolvePropSchema } from '../resolvePropSchema';
import { resolveRef } from '../resolveRef';

jest.mock('../resolveRef', () => ({
resolveRef: jest.fn().mockImplementation(obj => ({
...obj,
resolved: true,
})),
}));

describe('resolvePropSchema', () => {
const definitions = {
foo: {
title: 'Foo Title',
},
};

it('returns undefined if the schema does not have properties', () => {
expect(resolvePropSchema({}, 'foo', definitions)).toBe(undefined);
});

it('resolves the property schema', () => {
const schema = {
type: 'object',
properties: {
foo: {
type: 'object',
properties: {
bar: {
type: 'string',
},
},
},
},
};

// @ts-ignore
const resolved = resolvePropSchema(schema, 'foo', definitions);
expect(resolveRef).toBeCalledWith(schema.properties.foo, definitions);

expect(resolved).toMatchObject({
...schema.properties.foo,
resolved: true,
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ export * from './getUISchema';
export * from './mergePluginConfigs';
export * from './resolveBaseSchema';
export * from './resolveFieldWidget';
export * from './resolvePropertySchema';
export * from './resolvePropSchema';
export * from './resolveRef';
export * from './uiOptionsHelpers';
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,11 @@ export function resolvePropSchema(
[k: string]: JSONSchema7Definition;
} = {}
): JSONSchema7 | undefined {
if (!schema.properties) {
return;
}
const propSchema = schema.properties?.[path];

const pathParts = path.split('.');
let propSchema: JSONSchema7 = schema.properties;

for (const part of pathParts) {
propSchema = resolveRef((propSchema?.properties || propSchema)?.[part], definitions);
if (!propSchema || typeof propSchema !== 'object') {
return;
}

return propSchema;
return resolveRef(propSchema, definitions);
}

0 comments on commit ddfd5e3

Please sign in to comment.