Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix issue rendering delete properties action #2460

Merged
merged 4 commits into from
Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}