Skip to content

Commit 7b1acc2

Browse files
authored
Fix plots not showing on first experiment run (#4412)
1 parent 473356b commit 7b1acc2

File tree

1 file changed

+44
-25
lines changed

1 file changed

+44
-25
lines changed

extension/src/plots/paths/collect.ts

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,10 @@ const collectType = (plots: Plot[]) => {
5151
? type.add(PathType.TEMPLATE_MULTI)
5252
: type.add(PathType.TEMPLATE_SINGLE)
5353
}
54-
5554
return type
5655
}
5756

58-
const getType = (
59-
data: PlotsData,
60-
hasChildren: boolean,
61-
path: string
62-
): Set<PathType> | undefined => {
63-
if (hasChildren) {
64-
return
65-
}
66-
57+
const getType = (data: PlotsData, path: string): Set<PathType> | undefined => {
6758
const plots = data[path]
6859
if (!definedAndNonEmpty(plots)) {
6960
return
@@ -118,6 +109,46 @@ const collectPathRevisions = (data: PlotsData, path: string): Set<string> => {
118109
return revisions
119110
}
120111

112+
const collectPlotPathType = (
113+
plotPath: PlotPath,
114+
data: PlotsData,
115+
hasChildren: boolean,
116+
path: string
117+
) => {
118+
if (hasChildren) {
119+
return
120+
}
121+
122+
const type = getType(data, path)
123+
124+
if (type) {
125+
plotPath.type = type
126+
}
127+
}
128+
129+
const updateExistingPlotPath = (
130+
acc: PlotPath[],
131+
data: PlotsData,
132+
hasChildren: boolean,
133+
revisions: Set<string>,
134+
path: string
135+
) =>
136+
acc.map(existing => {
137+
const plotPath = { ...existing }
138+
139+
if (existing.path !== path) {
140+
return plotPath
141+
}
142+
143+
plotPath.revisions = new Set([...existing.revisions, ...revisions])
144+
145+
if (!plotPath.type) {
146+
collectPlotPathType(plotPath, data, hasChildren, path)
147+
}
148+
149+
return plotPath
150+
})
151+
121152
const collectOrderedPath = (
122153
acc: PlotPath[],
123154
data: PlotsData,
@@ -126,31 +157,20 @@ const collectOrderedPath = (
126157
idx: number
127158
): PlotPath[] => {
128159
const path = getPath(pathArray, idx)
160+
const hasChildren = idx !== pathArray.length
129161

130162
if (acc.some(({ path: existingPath }) => existingPath === path)) {
131-
return acc.map(existing =>
132-
existing.path === path
133-
? {
134-
...existing,
135-
revisions: new Set([...existing.revisions, ...revisions])
136-
}
137-
: existing
138-
)
163+
return updateExistingPlotPath(acc, data, hasChildren, revisions, path)
139164
}
140165

141-
const hasChildren = idx !== pathArray.length
142-
143166
const plotPath: PlotPath = {
144167
hasChildren,
145168
parentPath: getParent(pathArray, idx),
146169
path,
147170
revisions
148171
}
149172

150-
const type = getType(data, hasChildren, path)
151-
if (type) {
152-
plotPath.type = type
153-
}
173+
collectPlotPathType(plotPath, data, hasChildren, path)
154174

155175
acc.push(plotPath)
156176
return acc
@@ -228,7 +248,6 @@ export const collectPaths = (
228248
if (errors?.length) {
229249
acc = collectErrorPaths(acc, data, errors)
230250
}
231-
232251
return acc
233252
}
234253

0 commit comments

Comments
 (0)