Skip to content

Commit ad7410a

Browse files
committed
fixed schema-table for expand-level and expanded-description and intersection observer should be started only in read-mode
1 parent 380bdea commit ad7410a

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

src/components/schema-table.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ export default class SchemaTable extends LitElement {
6969
}
7070
7171
</style>
72-
<div class="table ${this.schemaDescriptionExpanded ? 'expanded-descr' : 'collapsed-descr'}">
72+
<div class="table ${this.schemaDescriptionExpanded === 'true' ? 'expanded-descr' : 'collapsed-descr'}">
7373
<div class='toolbar'>
7474
<div style="flex:1"></div>
75-
<div class='toolbar-item' @click='${() => { this.schemaDescriptionExpanded = !this.schemaDescriptionExpanded; }}'>
76-
${this.schemaDescriptionExpanded ? 'Collapse Details' : 'Expand Details'}
75+
<div class='toolbar-item' @click='${() => { this.schemaDescriptionExpanded = (this.schemaDescriptionExpanded === 'true' ? 'false' : 'true'); }}'>
76+
${this.schemaDescriptionExpanded === 'true' ? 'Collapse Details' : 'Expand Details'}
7777
</div>
7878
</div>
7979
@@ -110,16 +110,16 @@ export default class SchemaTable extends LitElement {
110110
return html`
111111
${level > 0
112112
? html`
113-
<div class='tr expanded ${data['::type']}' data-obj='${newPrevKey}'>
113+
<div class='tr ${level < this.schemaExpandLevel ? 'expanded' : 'collapsed'} ${data['::type']}' data-obj='${newPrevKey}'>
114114
<div class='td key' style='padding-left:${leftPadding}px'>
115115
${newPrevKey
116116
? html`
117117
<span
118-
class='obj-toggle expanded'
118+
class='obj-toggle ${level < this.schemaExpandLevel ? 'expanded' : 'collapsed'}'
119119
data-obj='${newPrevKey}'
120120
@click= ${(e) => this.toggleObjectExpand(e, newPrevKey)}
121121
>
122-
-
122+
${level < this.schemaExpandLevel ? '-' : '+'}
123123
</span>`
124124
: ''
125125
}

src/components/schema-tree.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export default class SchemaTree extends LitElement {
8787
<div class='toolbar'>
8888
<div class='toolbar-item bold-text upper' style='cursor:auto; color:var(--fg3)'> ${this.data ? this.data['::type'] : ''} </div>
8989
<div style="flex:1"></div>
90-
<div class='toolbar-item' @click='${() => { this.schemaDescriptionExpanded = this.schemaDescriptionExpanded === 'true' ? 'false' : 'true'; }}'>
90+
<div class='toolbar-item' @click='${() => { this.schemaDescriptionExpanded = (this.schemaDescriptionExpanded === 'true' ? 'false' : 'true'); }}'>
9191
${this.schemaDescriptionExpanded === 'true' ? 'Collapse Details' : 'Expand Details'}
9292
</div>
9393
</div>

src/rapidoc.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -885,9 +885,11 @@ export default class RapiDoc extends LitElement {
885885

886886
// Put it at the end of event loop, to allow loading all the child elements (must for larger specs)
887887
this.intersectionObserver.disconnect();
888-
window.setTimeout(() => {
889-
this.observeExpandedContent();
890-
}, 100);
888+
if (this.renderStyle === 'read') {
889+
window.setTimeout(() => {
890+
this.observeExpandedContent();
891+
}, 100);
892+
}
891893
this.requestUpdate();
892894
}
893895

src/utils/common-utils.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export function getSampleValueByType(schemaObj) {
168168
/* For changing JSON-Schema to a Sample Object, as per the schema */
169169
export function schemaToSampleObj(schema, config = { }) {
170170
let obj = {};
171-
if (schema === null) {
171+
if (!schema) {
172172
return;
173173
}
174174

@@ -244,9 +244,11 @@ export function schemaToSampleObj(schema, config = { }) {
244244
* This Object would further be an input to UI Components to generate an Object-Tree
245245
* @param {object} schema - Schema object from OpenAPI spec
246246
* @param {object} obj - recursivly pass this object to generate object notation
247+
* @param {number} level - recursion level
248+
* @param {string} suffix - used for suffixing property names to avoid duplicate props during object composion
247249
*/
248250
export function schemaInObjectNotation(schema, obj, level = 0, suffix = '') {
249-
if (schema == null) {
251+
if (!schema) {
250252
return;
251253
}
252254
if (schema.type === 'object' || schema.properties) {

0 commit comments

Comments
 (0)