Skip to content

Commit 6e230c1

Browse files
show complex type
1 parent 4ca0fde commit 6e230c1

File tree

3 files changed

+72
-12
lines changed

3 files changed

+72
-12
lines changed

src/ApiTypeDocument.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,14 @@ export class ApiTypeDocument extends PropertyDocumentMixin(LitElement) {
819819
return this._multiTypeTemplate({ label, items, typeName, selected, selectTypeCallback, type });
820820
}
821821

822+
_getItemLabel(item){
823+
if(item.label==='Unknown type' && item.avroValue){
824+
return item.avroValue
825+
}
826+
return item.label
827+
828+
}
829+
822830
/**
823831
*
824832
* @param {Object} args
@@ -843,8 +851,8 @@ export class ApiTypeDocument extends PropertyDocumentMixin(LitElement) {
843851
aria-pressed="${selected === index ? 'true' : 'false'}"
844852
@click="${selectTypeCallback}"
845853
?compatibility="${this.compatibility}"
846-
title="Select ${item.label} type"
847-
>${item.label}</anypoint-button
854+
title="Select ${this._getItemLabel(item)} type"
855+
>${this._getItemLabel(item)}</anypoint-button
848856
>`
849857
)}
850858
</div>

src/PropertyDocumentMixin.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,37 @@ const mxFunction = (base) => {
361361
return this._hasProperty(range, this.ns.w3.shacl.and);
362362
}
363363

364+
/**
365+
* Computes source values of the property. Only for async / avro
366+
*
367+
* @param {Object} data Range object of current shape.
368+
*/
369+
_computeAvroSourceMap(data) {
370+
try{
371+
const sourcesKey = this._getAmfKey(this.ns.aml.vocabularies.docSourceMaps.sources)
372+
const avroSchemaKey = this._getAmfKey(this.ns.aml.vocabularies.docSourceMaps.avroSchema)
373+
const valueKey = this._getAmfKey(this.ns.aml.vocabularies.docSourceMaps.value)
374+
if(data[sourcesKey] && data[sourcesKey][0][avroSchemaKey]){
375+
const avroValues = this._ensureArray(data[sourcesKey][0][avroSchemaKey])
376+
return avroValues[0][valueKey][0]['@value']
377+
}
378+
return undefined
379+
}catch(_){
380+
return undefined
381+
}
382+
383+
}
384+
385+
/**
386+
* Computes source values of the property. Only for async / avro
387+
*
388+
* @param {Object} data Range object of current shape.
389+
* @return {Object} Size of the property
390+
*/
391+
_computeAvroShapeRangeSourceMap(data) {
392+
return this._computeAvroSourceMap(data)
393+
}
394+
364395
/**
365396
* Computes list of type labels to render.
366397
*
@@ -374,6 +405,7 @@ const mxFunction = (base) => {
374405
return undefined;
375406
}
376407
return list.map((obj) => {
408+
const avroValue = this._computeAvroShapeRangeSourceMap(obj) || null
377409
let item = obj;
378410
if (Array.isArray(item)) {
379411
[item] = item;
@@ -424,6 +456,7 @@ const mxFunction = (base) => {
424456
isArray,
425457
isType,
426458
label,
459+
avroValue
427460
};
428461
});
429462
}

src/PropertyShapeDocument.js

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
311311
this.isOneOf,
312312
this.isAllOf
313313
);
314-
console.log("🚀 ~ PropertyShapeDocument ~ _rangeChanged ~ this.isComple:", this.isComplex)
315314
this.isScalarArray = this.isArray
316315
? this._computeIsScalarArray(range)
317316
: false;
@@ -740,13 +739,24 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
740739
></api-type-document>`;
741740
}
742741

742+
_getTypeLabelData(){
743+
const { propertyDataType, avroValue } = this;
744+
if(avroValue==='map'){
745+
return {dataType:'Map',customValue:false}
746+
}
747+
if(propertyDataType==='Unknown type' && avroValue){
748+
return {dataType:avroValue,customValue:true}
749+
}
750+
return {dataType:propertyDataType,customValue:false}
751+
}
752+
743753
/**
744754
* @return {TemplateResult} Template for a type name label
745755
*/
746756
_getTypeNameTemplate() {
747-
let dataType = this.propertyDataType;
748-
const id = this._targetTypeId;
749757
const { isScalarArray } = this;
758+
let {dataType} = this._getTypeLabelData();
759+
const id = this._targetTypeId;
750760
if (id) {
751761
const label = this._targetTypeName;
752762
return html`
@@ -782,6 +792,18 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
782792
<div class="fixed-type-size"><span>Size: ${size}</span></div>`;
783793
}
784794

795+
/**
796+
* @return {TemplateResult | String} Template size value (only for async / avro)
797+
*/
798+
_getCustomAvroValueTemplate() {
799+
const {customValue} = this._getTypeLabelData()
800+
if(!customValue){
801+
return ''
802+
}
803+
return html`
804+
<div class="fixed-type-size"><span>This is a custom avro value</span></div>`;
805+
}
806+
785807
/**
786808
* @return {TemplateResult | String} Template size value (only for async / avro)
787809
*/
@@ -869,13 +891,9 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
869891
displayName,
870892
propertyName,
871893
parentTypeName,
872-
hasParentTypeName,
873-
isComplex,
874-
avroValue
894+
hasParentTypeName
875895
} = this;
876-
if(!hasDisplayName && !propertyName && isComplex && avroValue){
877-
return html`<div class="property-display-name">${avroValue}</div>`
878-
}
896+
879897
return html` ${hasDisplayName
880898
? html`<div class="property-display-name">${displayName}</div>`
881899
: ''}
@@ -904,7 +922,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
904922
avroValue,
905923
_renderToggleButton
906924
} = this;
907-
if(!hasDisplayName && !propertyName && isComplex && !avroValue && _renderToggleButton){
925+
if(!hasDisplayName && !propertyName && isComplex && avroValue && _renderToggleButton){
908926
return ' no-name'
909927
}
910928
return ''
@@ -942,6 +960,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
942960
>`
943961
: ''}
944962
</div>
963+
${this._getCustomAvroValueTemplate()}
945964
${this._getDefaultValueAvroTemplate()}
946965
${this._getFixedTypeSizeAvroTemplate()}
947966
${this._getTypeNamespaceAvroTemplate()}

0 commit comments

Comments
 (0)