Skip to content

Commit 0e86ca3

Browse files
Merge pull request #80 from advanced-rest-client/feat/W-16450169/map-type
Feat/w-16450169/map type
2 parents 72944f4 + 6e230c1 commit 0e86ca3

File tree

4 files changed

+102
-45
lines changed

4 files changed

+102
-45
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: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -739,13 +739,24 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
739739
></api-type-document>`;
740740
}
741741

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+
742753
/**
743754
* @return {TemplateResult} Template for a type name label
744755
*/
745756
_getTypeNameTemplate() {
746-
let dataType = this.propertyDataType;
747-
const id = this._targetTypeId;
748757
const { isScalarArray } = this;
758+
let {dataType} = this._getTypeLabelData();
759+
const id = this._targetTypeId;
749760
if (id) {
750761
const label = this._targetTypeName;
751762
return html`
@@ -781,6 +792,18 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
781792
<div class="fixed-type-size"><span>Size: ${size}</span></div>`;
782793
}
783794

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+
784807
/**
785808
* @return {TemplateResult | String} Template size value (only for async / avro)
786809
*/
@@ -868,8 +891,9 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
868891
displayName,
869892
propertyName,
870893
parentTypeName,
871-
hasParentTypeName,
894+
hasParentTypeName
872895
} = this;
896+
873897
return html` ${hasDisplayName
874898
? html`<div class="property-display-name">${displayName}</div>`
875899
: ''}
@@ -890,6 +914,20 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
890914
return html`<div class="deprecated-warning">Warning: Deprecated</div>`
891915
}
892916

917+
_noNameAvroClass() {
918+
const {
919+
hasDisplayName,
920+
propertyName,
921+
isComplex,
922+
avroValue,
923+
_renderToggleButton
924+
} = this;
925+
if(!hasDisplayName && !propertyName && isComplex && avroValue && _renderToggleButton){
926+
return ' no-name'
927+
}
928+
return ''
929+
}
930+
893931
/**
894932
* @return {TemplateResult} Main render function.
895933
*/
@@ -898,7 +936,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
898936
${this.styles}
899937
</style>
900938
${this._headerTemplate()}
901-
<div class="property-traits">
939+
<div class="property-traits${this._noNameAvroClass()}">
902940
${this._getTypeNameTemplate()}
903941
${this.isRequired
904942
? html`<span
@@ -922,6 +960,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
922960
>`
923961
: ''}
924962
</div>
963+
${this._getCustomAvroValueTemplate()}
925964
${this._getDefaultValueAvroTemplate()}
926965
${this._getFixedTypeSizeAvroTemplate()}
927966
${this._getTypeNamespaceAvroTemplate()}

src/ShapeStyles.js

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
import { css } from 'lit-element';
1+
import { css } from "lit-element";
22

33
export default css`
44
:host {
55
display: block;
66
border-bottom-width: 1px;
7-
border-bottom-color: var(
8-
--property-shape-document-border-bottom-color,
9-
#cfd8dc
10-
);
11-
border-bottom-style: var(
12-
--property-shape-document-border-bottom-style,
13-
dashed
14-
);
7+
border-bottom-color: var(--property-shape-document-border-bottom-color, #cfd8dc);
8+
border-bottom-style: var(--property-shape-document-border-bottom-style, dashed);
159
padding: var(--property-shape-document-padding);
1610
}
1711
@@ -24,38 +18,20 @@ export default css`
2418
}
2519
2620
.property-title {
27-
font-family: var(
28-
--property-shape-document-title-font-family,
29-
var(--arc-font-subhead-font-family)
30-
);
31-
font-size: var(
32-
--property-shape-document-title-font-size,
33-
var(--arc-font-subhead-font-size, 1rem)
34-
);
35-
font-weight: var(
36-
--property-shape-document-title-font-weight,
37-
var(--arc-font-subhead-font-weight)
38-
);
39-
line-height: var(
40-
--property-shape-document-title-line-height,
41-
var(--arc-font-subhead-line-height)
42-
);
43-
44-
margin: var(
45-
--property-shape-document-title-margin,
46-
4px 0 4px 0
47-
);
21+
font-family: var(--property-shape-document-title-font-family, var(--arc-font-subhead-font-family));
22+
font-size: var(--property-shape-document-title-font-size, var(--arc-font-subhead-font-size, 1rem));
23+
font-weight: var(--property-shape-document-title-font-weight, var(--arc-font-subhead-font-weight));
24+
line-height: var(--property-shape-document-title-line-height, var(--arc-font-subhead-line-height));
25+
26+
margin: var(--property-shape-document-title-margin, 4px 0 4px 0);
4827
font-size: 1rem;
4928
font-weight: var(--api-type-document-property-title-font-weight, 500);
5029
word-break: break-word;
5130
color: var(--api-type-document-property-title-color);
5231
}
5332
5433
.property-title[secondary] {
55-
font-weight: var(
56-
--api-type-document-property-title-secondary-font-weight,
57-
400
58-
);
34+
font-weight: var(--api-type-document-property-title-secondary-font-weight, 400);
5935
color: var(--api-type-document-property-title-secondary-color, #616161);
6036
}
6137
@@ -65,10 +41,7 @@ export default css`
6541
6642
.property-display-name {
6743
font-weight: var(--api-type-document-property-name-font-weight, 500);
68-
color: var(
69-
--api-type-document-property-name-color,
70-
var(--api-type-document-property-color, #212121)
71-
);
44+
color: var(--api-type-document-property-name-color, var(--api-type-document-property-color, #212121));
7245
margin: 4px 0 4px 0;
7346
font-size: var(--api-type-document-property-name-font-size, 16px);
7447
}
@@ -117,6 +90,10 @@ export default css`
11790
margin-bottom: 8px;
11891
}
11992
93+
.property-traits.no-name {
94+
margin-top: -33px;
95+
}
96+
12097
.property-traits > span {
12198
display: inline-block;
12299
margin-right: 8px;
@@ -163,7 +140,7 @@ export default css`
163140
-ms-flex: 1;
164141
flex: 1;
165142
}
166-
143+
167144
.property-traits > span.readonly-type {
168145
background-color: var(--api-type-readonly-property-background-color, #ff9292);
169146
color: var(--api-type-readonly-property-color, black);

0 commit comments

Comments
 (0)