Skip to content

Commit 2e77681

Browse files
committed
fix: ProfileExplorer should sort the tree nodes to offer a consistent ordering
This PR also adds some more meta rules.
1 parent c1f5f56 commit 2e77681

File tree

1 file changed

+47
-11
lines changed

1 file changed

+47
-11
lines changed

Diff for: plugins/plugin-codeflare/src/components/ProfileExplorer.tsx

+47-11
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@ class ProfileCard extends React.PureComponent<ProfileCardProps, ProfileCardState
261261
title: "Compute",
262262
name: "The computational aspects of this computer",
263263
},
264+
Storage: {
265+
title: "Storage",
266+
name: "The storage aspects of this computer",
267+
},
264268
}
265269

266270
private readonly meta: Record<string, Metadata> = {
@@ -276,6 +280,14 @@ class ProfileCard extends React.PureComponent<ProfileCardProps, ProfileCardState
276280
title: "Resources",
277281
group: this.groups.Compute,
278282
},
283+
".*constraints/compute/workers": {
284+
title: "Resources",
285+
group: this.groups.Compute,
286+
},
287+
".*constraints/compute/accelerators/gpu": {
288+
title: "GPU Class",
289+
group: this.groups.Compute,
290+
},
279291
"kubernetes/context": {
280292
title: "Cluster",
281293
group: this.groups.Compute,
@@ -284,6 +296,14 @@ class ProfileCard extends React.PureComponent<ProfileCardProps, ProfileCardState
284296
title: "Namespace",
285297
group: this.groups.Compute,
286298
},
299+
"aws/choose/profile": {
300+
title: "AWS Profile",
301+
group: this.groups.Storage,
302+
},
303+
".*constraints/workload/type": {
304+
title: "Workload Type",
305+
group: this.groups.Application,
306+
},
287307
}
288308

289309
private form(form: Record<string, string>) {
@@ -352,18 +372,21 @@ class ProfileCard extends React.PureComponent<ProfileCardProps, ProfileCardState
352372
.filter((_) => !/expand\(|####/.test(_[0])) // filter out old style of choices
353373
.filter((_) => !/test\/inputs/.test(_[0])) // filter out test residuals
354374
.reduce((groups, [title, value]) => {
355-
const meta = this.meta[title]
356-
if (meta) {
357-
if (!groups[meta.group.title]) {
358-
groups[meta.group.title] = {
359-
title: meta.group.title,
360-
name: meta.group.name,
361-
children: [],
375+
const metaKey = this.meta[title] ? title : Object.keys(this.meta).find((_) => new RegExp(_).test(title))
376+
if (metaKey) {
377+
const meta = this.meta[metaKey]
378+
if (meta) {
379+
if (!groups[meta.group.title]) {
380+
groups[meta.group.title] = {
381+
title: meta.group.title,
382+
name: meta.group.name,
383+
children: [],
384+
}
362385
}
363-
}
364-
const { children } = groups[meta.group.title]
386+
const { children } = groups[meta.group.title]
365387

366-
children.push(this.editable(title, this.treeNode(meta, value)))
388+
children.push(this.editable(title, this.treeNode(meta, value)))
389+
}
367390
}
368391

369392
return groups
@@ -373,15 +396,28 @@ class ProfileCard extends React.PureComponent<ProfileCardProps, ProfileCardState
373396
if (data.length === 0) {
374397
// oops, this profile has no "shape", no choices have been
375398
// made for us to visualize
376-
data.push({ name: "Empty", children: [] })
399+
data.push({ title: "Empty", name: "So far, this profile has no constraints", children: [] })
377400
}
401+
this.sort(data)
378402

379403
return <TreeView hasGuides defaultAllExpanded data={data} variant="compactNoBackground" />
380404
}
381405

382406
return "Internal Error"
383407
}
384408

409+
private sort(data: TreeViewDataItem[]) {
410+
data.sort((a, b) => (a.title || "").toString().localeCompare((b.title || "").toString()))
411+
412+
data.forEach((_) => {
413+
if (Array.isArray(_.children)) {
414+
_.children = this.sort(_.children)
415+
}
416+
})
417+
418+
return data
419+
}
420+
385421
private footer() {
386422
return (
387423
<Flex>

0 commit comments

Comments
 (0)