From 4f2e1a29e6c92fd65dff7cde82b2f4e229ac2afe Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Tue, 19 Apr 2016 18:56:20 +0300 Subject: [PATCH] Use dropdown instead of buttons for discriminator switch --- lib/components/JsonSchema/json-schema.html | 8 ++++---- lib/components/JsonSchema/json-schema.js | 11 ++++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/components/JsonSchema/json-schema.html b/lib/components/JsonSchema/json-schema.html index e764f016..91748eb2 100644 --- a/lib/components/JsonSchema/json-schema.html +++ b/lib/components/JsonSchema/json-schema.html @@ -29,10 +29,10 @@
This field value determines the exact schema: - + + +
diff --git a/lib/components/JsonSchema/json-schema.js b/lib/components/JsonSchema/json-schema.js index 05e964af..8c9950fa 100644 --- a/lib/components/JsonSchema/json-schema.js +++ b/lib/components/JsonSchema/json-schema.js @@ -3,14 +3,14 @@ import {ElementRef} from 'angular2/core'; import {RedocComponent, BaseComponent, SchemaManager} from '../base'; -import {Tabs, Tab} from '../../common/components/Tabs/tabs'; +import {DropDown} from '../../common/components/DropDown/dropdown'; import JsonPointer from '../../utils/JsonPointer'; @RedocComponent({ selector: 'json-schema', templateUrl: './lib/components/JsonSchema/json-schema.html', styleUrls: ['./lib/components/JsonSchema/json-schema.css'], - directives: [JsonSchema, Tabs, Tab], + directives: [JsonSchema, DropDown], inputs: ['isArray', 'final', 'nestOdd', 'childFor'] }) @Reflect.metadata('parameters', [[SchemaManager], [ElementRef]]) @@ -21,8 +21,9 @@ export default class JsonSchema extends BaseComponent { this.final = false; } - selectDerived(subClass) { - if (subClass.active) return; + selectDerived(subClassIdx) { + let subClass = this.schema.derived[subClassIdx]; + if (!subClass || subClass.active) return; this.schema.derived.forEach((subSchema) => { subSchema.active = false; }); @@ -62,7 +63,7 @@ export default class JsonSchema extends BaseComponent { } this.schema = schema; - if (schema.derived.length) this.selectDerived(schema.derived[0]); + this.selectDerived(0); } prepareObjectPropertiesData(schema) {