From 3d1944e95fb9696dcf39e6ff8e47308f9aeeeae0 Mon Sep 17 00:00:00 2001 From: Ayeshas09 Date: Mon, 10 Nov 2025 09:35:04 +0500 Subject: [PATCH 1/4] chore: avoid adding empty events section in toc --- src/actions/portal/toc/new-toc.ts | 24 ++- .../portal/toc/toc-structure-generator.ts | 147 ++++++++++++------ 2 files changed, 106 insertions(+), 65 deletions(-) diff --git a/src/actions/portal/toc/new-toc.ts b/src/actions/portal/toc/new-toc.ts index cae2d3543..dfe01f8d7 100644 --- a/src/actions/portal/toc/new-toc.ts +++ b/src/actions/portal/toc/new-toc.ts @@ -75,10 +75,6 @@ export class PortalNewTocAction { callbackGroups: new Map() }; - if (!expandEndpoints && !expandModels && !expandWebhooks && !expandCallbacks) { - return defaultComponents; - } - const specDirectory = buildDirectory.join('spec'); if (!(await this.fileService.directoryExists(specDirectory))) { @@ -103,12 +99,12 @@ export class PortalNewTocAction { return defaultComponents; } - const endpointGroups = expandEndpoints ? extractEndpointGroupsForToc(result.value) : new Map(); - const models = expandModels ? extractModelsForToc(result.value) : []; - const webhookGroups = expandWebhooks ? extractWebhooksForToc(result.value) : new Map(); - const callbackGroups = expandCallbacks ? extractCallbacksForToc(result.value) : new Map(); - - return { endpointGroups, models, webhookGroups, callbackGroups }; + return { + endpointGroups: extractEndpointGroupsForToc(result.value), + models: extractModelsForToc(result.value), + webhookGroups: extractWebhooksForToc(result.value), + callbackGroups: extractCallbacksForToc(result.value) + }; }); })(); const contentContext = new ContentContext(contentDirectory); @@ -123,10 +119,10 @@ export class PortalNewTocAction { } const toc = this.tocGenerator.createTocStructure( - sdlTocComponents.endpointGroups, - sdlTocComponents.models, - sdlTocComponents.webhookGroups, - sdlTocComponents.callbackGroups, + { data: sdlTocComponents.endpointGroups, expand: expandEndpoints }, + { data: sdlTocComponents.models, expand: expandModels }, + { data: sdlTocComponents.webhookGroups, expand: expandWebhooks }, + { data: sdlTocComponents.callbackGroups, expand: expandCallbacks }, contentGroups ); const yamlString = this.tocGenerator.transformToYaml(toc); diff --git a/src/application/portal/toc/toc-structure-generator.ts b/src/application/portal/toc/toc-structure-generator.ts index 954b09d5b..6440b4fb4 100644 --- a/src/application/portal/toc/toc-structure-generator.ts +++ b/src/application/portal/toc/toc-structure-generator.ts @@ -12,14 +12,36 @@ import { // TODO: Refactor +type Endpoints = { + data: Map; + expand: boolean; +}; + +type Webhooks = { + data: Map; + expand: boolean; +}; + +type Callbacks = { + data: Map; + expand: boolean; +}; + +type Models = { + data: TocModelPage[]; + expand: boolean; +}; + export class TocStructureGenerator { createTocStructure( - endpointGroups: Map, - models: TocModelPage[], - webhookGroups: Map, - callbackGroups: Map, + endpoints: Endpoints, + models: Models, + webhooks: Webhooks, + callbacks: Callbacks, contentGroups: TocGroup[] = [] ): Toc { + const events = [...this.getCallbacksSection(callbacks), ...this.getWebhooksSection(webhooks)]; + return { toc: [ { @@ -32,11 +54,16 @@ export class TocStructureGenerator { ] }, ...contentGroups, - this.getEndpointsSection(endpointGroups), - { - group: 'Events', - items: [this.getCallbacksSection(callbackGroups), this.getWebhooksSection(webhookGroups)] - }, + this.getEndpointsSection(endpoints), + // only add if events exist + ...(events.length > 0 + ? [ + { + group: 'Events', + items: events + } + ] + : []), this.getModelsSection(models), { generate: 'SDK Infrastructure', @@ -54,8 +81,8 @@ export class TocStructureGenerator { }); } - private getEndpointsSection(endpointGroups: Map): TocGroup | TocGenerated { - if (endpointGroups.size === 0) { + private getEndpointsSection(endpoints: Endpoints): TocGroup | TocGenerated { + if (!endpoints.expand || endpoints.data.size === 0) { return { generate: 'API Endpoints', from: 'endpoints' @@ -63,7 +90,7 @@ export class TocStructureGenerator { } return { group: 'API Endpoints', - items: Array.from(endpointGroups).map(([groupName, endpoints]) => ({ + items: Array.from(endpoints.data).map(([groupName, endpoints]) => ({ group: groupName, items: [ { @@ -77,52 +104,70 @@ export class TocStructureGenerator { }; } - private getCallbacksSection(callbackGroups: Map): TocGroup | TocGenerated { - if (callbackGroups.size === 0) { - return { - generate: null, - from: 'callbacks' - }; + private getCallbacksSection(callbacks: Callbacks): (TocGroup | TocGenerated)[] { + if (callbacks.data.size === 0) { + return []; } - if (callbackGroups.size === 1) { - return { - group: Array.from(callbackGroups.keys())[0], - items: Array.from(callbackGroups.values())[0] - }; + if (callbacks.expand === true) { + if (callbacks.data.size === 1) { + return [ + { + group: Array.from(callbacks.data.keys())[0], + items: Array.from(callbacks.data.values())[0] + } + ]; + } + return [ + { + group: 'Callbacks', + items: Array.from(callbacks.data).map(([groupName, eventList]) => ({ + group: groupName, + items: eventList + })) + } + ]; } - return { - group: 'Callbacks', - items: Array.from(callbackGroups).map(([groupName, eventList]) => ({ - group: groupName, - items: eventList - })) - }; + return [ + { + generate: null, + from: 'callbacks' + } + ]; } - private getWebhooksSection(webhookGroups: Map): TocGroup | TocGenerated { - if (webhookGroups.size === 0) { - return { - generate: null, - from: 'webhooks' - }; + private getWebhooksSection(webhooks: Webhooks): (TocGroup | TocGenerated)[] { + if (webhooks.data.size === 0) { + return []; } - if (webhookGroups.size === 1) { - return { - group: Array.from(webhookGroups.keys())[0], - items: Array.from(webhookGroups.values())[0] - }; + if (webhooks.expand === true) { + if (webhooks.data.size === 1) { + return [ + { + group: Array.from(webhooks.data.keys())[0], + items: Array.from(webhooks.data.values())[0] + } + ]; + } + return [ + { + group: 'Webhooks', + items: Array.from(webhooks.data).map(([groupName, eventList]) => ({ + group: groupName, + items: eventList + })) + } + ]; } - return { - group: 'Webhooks', - items: Array.from(webhookGroups).map(([groupName, eventList]) => ({ - group: groupName, - items: eventList - })) - }; + return [ + { + generate: null, + from: 'webhooks' + } + ]; } - private getModelsSection(models: TocModelPage[]): TocGroup | TocGenerated { - if (models.length === 0) { + private getModelsSection(models: Models): TocGroup | TocGenerated { + if (!models.expand || models.data.length === 0) { return { generate: 'Models', from: 'models' @@ -130,7 +175,7 @@ export class TocStructureGenerator { } return { group: 'Models', - items: models + items: models.data }; } From d3498bbfd5ae56c1172bcab046f45fd7cf62af8e Mon Sep 17 00:00:00 2001 From: Ayeshas09 Date: Mon, 10 Nov 2025 10:02:06 +0500 Subject: [PATCH 2/4] fix: avoid adding empty models section in toc --- .../portal/toc/toc-structure-generator.ts | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/application/portal/toc/toc-structure-generator.ts b/src/application/portal/toc/toc-structure-generator.ts index 6440b4fb4..edf265f57 100644 --- a/src/application/portal/toc/toc-structure-generator.ts +++ b/src/application/portal/toc/toc-structure-generator.ts @@ -55,7 +55,6 @@ export class TocStructureGenerator { }, ...contentGroups, this.getEndpointsSection(endpoints), - // only add if events exist ...(events.length > 0 ? [ { @@ -64,7 +63,7 @@ export class TocStructureGenerator { } ] : []), - this.getModelsSection(models), + ...this.getModelsSection(models), { generate: 'SDK Infrastructure', from: 'sdk-infra' @@ -166,17 +165,24 @@ export class TocStructureGenerator { ]; } - private getModelsSection(models: Models): TocGroup | TocGenerated { - if (!models.expand || models.data.length === 0) { - return { - generate: 'Models', - from: 'models' - }; + private getModelsSection(models: Models): (TocGroup | TocGenerated)[] { + if (models.data.length === 0) { + return []; } - return { - group: 'Models', - items: models.data - }; + if (!models.expand) { + return [ + { + generate: 'Models', + from: 'models' + } + ]; + } + return [ + { + group: 'Models', + items: models.data + } + ]; } private transformKeys(obj: any): any { From 7d66f05d7570682a01e781b60657b375bce36b56 Mon Sep 17 00:00:00 2001 From: Ayeshas09 Date: Tue, 11 Nov 2025 13:10:22 +0500 Subject: [PATCH 3/4] fix: add labels for callbacks and webhooks when not expanded --- src/application/portal/toc/toc-structure-generator.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/application/portal/toc/toc-structure-generator.ts b/src/application/portal/toc/toc-structure-generator.ts index edf265f57..22be46642 100644 --- a/src/application/portal/toc/toc-structure-generator.ts +++ b/src/application/portal/toc/toc-structure-generator.ts @@ -128,7 +128,7 @@ export class TocStructureGenerator { } return [ { - generate: null, + generate: "Callbacks", from: 'callbacks' } ]; @@ -159,7 +159,7 @@ export class TocStructureGenerator { } return [ { - generate: null, + generate: "Webhooks", from: 'webhooks' } ]; From 37669828a96e81d44f65b8f61ba983b907c58cde Mon Sep 17 00:00:00 2001 From: Ayeshas09 Date: Tue, 11 Nov 2025 13:40:13 +0500 Subject: [PATCH 4/4] refactor: formatting fix --- src/application/portal/toc/toc-structure-generator.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/application/portal/toc/toc-structure-generator.ts b/src/application/portal/toc/toc-structure-generator.ts index 22be46642..cc497eecb 100644 --- a/src/application/portal/toc/toc-structure-generator.ts +++ b/src/application/portal/toc/toc-structure-generator.ts @@ -128,7 +128,7 @@ export class TocStructureGenerator { } return [ { - generate: "Callbacks", + generate: 'Callbacks', from: 'callbacks' } ]; @@ -159,7 +159,7 @@ export class TocStructureGenerator { } return [ { - generate: "Webhooks", + generate: 'Webhooks', from: 'webhooks' } ];