Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit 897b2af

Browse files
committed
fix(plugins/plugin-client-common): add support for iterating the subtask hoisting algo
We deferred this in the first work. The algorithm needs to iterate till convergence.
1 parent 9e8e831 commit 897b2af

File tree

3 files changed

+113
-143
lines changed

3 files changed

+113
-143
lines changed

plugins/plugin-client-common/src/components/Content/Markdown/components/Imports.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { encodeComponent, pexecInCurrentTab } from '@kui-shell/core'
2121
import { TreeView, TreeViewProps } from '@patternfly/react-core'
2222

2323
import {
24+
isEmpty,
2425
isSequence,
2526
isParallel,
2627
isTitledSteps,
@@ -195,6 +196,10 @@ class ImportsImpl extends React.PureComponent<Props, State> {
195196
.flatMap(_ => _.data)
196197
)
197198

199+
if (children.length === 0) {
200+
return
201+
}
202+
198203
const hasAction = !!filepath
199204
const hasBadge = hasAction && rollupStatus.nDone > 0
200205

@@ -330,6 +335,7 @@ class ImportsImpl extends React.PureComponent<Props, State> {
330335
depth = 0
331336
) {
332337
const _children = graph.choices
338+
.filter(_ => !isEmpty(_.graph))
333339
.map(_ =>
334340
this.treeModelForLeaf(
335341
_.graph,

plugins/plugin-client-common/src/components/Content/Markdown/components/code/graph.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,25 +177,25 @@ export type OrderedGraph = Graph<Ordered>
177177
export type OrderedCodeBlock = CodeBlockProps & Ordered
178178

179179
export function isChoice<T extends Unordered | Ordered = Unordered>(graph: Graph<T>): graph is Choice<T> {
180-
return Array.isArray((graph as Choice).choices)
180+
return graph && Array.isArray((graph as Choice).choices)
181181
}
182182

183183
export function isSequence<T extends Unordered | Ordered = Unordered>(graph: Graph<T>): graph is Sequence<T> {
184-
return Array.isArray((graph as Sequence).sequence)
184+
return graph && Array.isArray((graph as Sequence).sequence)
185185
}
186186

187187
export function isParallel<T extends Unordered | Ordered = Unordered>(graph: Graph<T>): graph is Parallel<T> {
188-
return Array.isArray((graph as Parallel).parallel)
188+
return graph && Array.isArray((graph as Parallel).parallel)
189189
}
190190

191191
export function isTitledSteps<T extends Unordered | Ordered = Unordered>(graph: Graph<T>): graph is TitledSteps<T> {
192192
const ts = graph as TitledSteps<T>
193-
return typeof ts.title === 'string' && Array.isArray(ts.steps)
193+
return ts && typeof ts.title === 'string' && Array.isArray(ts.steps)
194194
}
195195

196196
export function isSubTask<T extends Unordered | Ordered = Unordered>(graph: Graph<T>): graph is SubTask<T> {
197197
const subtask = graph as SubTask
198-
return typeof subtask.key === 'string' && typeof subtask.filepath === 'string'
198+
return subtask && typeof subtask.key === 'string' && typeof subtask.filepath === 'string'
199199
}
200200

201201
function sameCodeBlock(a: CodeBlockProps, b: CodeBlockProps) {
@@ -208,6 +208,15 @@ function sameCodeBlock(a: CodeBlockProps, b: CodeBlockProps) {
208208
)
209209
}
210210

211+
export function isEmpty(A: Graph): boolean {
212+
return (
213+
(isSequence(A) && A.sequence.length === 0) ||
214+
(isParallel(A) && A.parallel.length === 0) ||
215+
(isTitledSteps(A) && A.steps.length === 0) ||
216+
(isChoice(A) && A.choices.length === 0)
217+
)
218+
}
219+
211220
export function sameGraph(A: Graph, B: Graph) {
212221
if (isChoice(A)) {
213222
return isChoice(B) && sameChoice(A, B)

0 commit comments

Comments
 (0)