From f6819749d3fe341c949ebff572d8bb39d08e0887 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Fri, 4 Dec 2026 21:02:47 +0800 Subject: [PATCH] refactor(views): share indexed JavaScript module paging (#16730) --- .../analysisView/javascriptApplicationView.ts | 44 +++++++------------ 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/src/domain/analysisView/javascriptApplicationView.ts b/src/domain/analysisView/javascriptApplicationView.ts index 68c8650a0a1..14641183f46 100644 --- a/src/domain/analysisView/javascriptApplicationView.ts +++ b/src/domain/analysisView/javascriptApplicationView.ts @@ -183,33 +183,23 @@ const modulePage = ( return paginateModuleEntries(moduleEntries(analysis.graph.nodes), view); const selectedKind = view.where?.kind; const selectedPath = view.where?.path; - if (selectedPath !== undefined && selectedKind === undefined) { - const candidates = index.nodesByPath.get(selectedPath) ?? []; - const slice = candidates.slice(view.offset, view.offset + view.limit); - return { - entries: - selectedPath === null - ? slice - : slice.map((entry) => ({ ...entry, path: selectedPath })), - total: candidates.length, - }; - } - if (selectedPath === undefined && selectedKind !== undefined) { - const candidates = index.nodesByKind.get(selectedKind) ?? []; - return { - entries: candidates.slice(view.offset, view.offset + view.limit), - total: candidates.length, - }; - } - if (selectedPath === undefined && selectedKind === undefined) - return { - entries: index.moduleEntries.slice(view.offset, view.offset + view.limit), - total: index.moduleEntries.length, - }; - return paginateModuleEntries( - index.nodesByPath.get(selectedPath!) ?? [], - view, - ); + const candidates = + selectedPath !== undefined + ? (index.nodesByPath.get(selectedPath) ?? []) + : selectedKind === undefined + ? index.moduleEntries + : (index.nodesByKind.get(selectedKind) ?? []); + if (selectedPath !== undefined && selectedKind !== undefined) + return paginateModuleEntries(candidates, view); + + const entries = candidates.slice(view.offset, view.offset + view.limit); + return { + entries: + selectedPath == null + ? entries + : entries.map((entry) => ({ ...entry, path: selectedPath })), + total: candidates.length, + }; }; const exportNames = (node: ApplicationNode): readonly string[] => {