Skip to content

Commit 9961068

Browse files
authored
Cleanup plots workspace state (#3518)
1 parent ab598a5 commit 9961068

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

extension/src/plots/model/index.test.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { PlotsModel } from '.'
22
import {
3+
CustomPlotType,
34
DEFAULT_NB_ITEMS_PER_ROW,
45
DEFAULT_SECTION_COLLAPSED,
56
DEFAULT_SECTION_NB_ITEMS_PER_ROW_OR_WIDTH,
@@ -22,7 +23,7 @@ const mockedRevisions = [
2223
describe('plotsModel', () => {
2324
let model: PlotsModel
2425
const exampleDvcRoot = 'test'
25-
const memento = buildMockMemento({
26+
let memento = buildMockMemento({
2627
[PersistenceKey.PLOTS_CUSTOM_ORDER + exampleDvcRoot]:
2728
customPlotsOrderFixture,
2829
[PersistenceKey.PLOT_NB_ITEMS_PER_ROW_OR_WIDTH + exampleDvcRoot]:
@@ -45,6 +46,41 @@ describe('plotsModel', () => {
4546
jest.clearAllMocks()
4647
})
4748

49+
it('should update outdated custom and trends state', () => {
50+
memento = buildMockMemento({
51+
[PersistenceKey.PLOTS_CUSTOM_ORDER + exampleDvcRoot]: [
52+
{
53+
metric: 'metrics:summary.json:loss',
54+
param: 'params:params.yaml:dropout'
55+
}
56+
],
57+
[PersistenceKey.PLOT_SELECTED_METRICS + exampleDvcRoot]: ['string'],
58+
[PersistenceKey.PLOT_METRIC_ORDER + exampleDvcRoot]: ['string']
59+
})
60+
model = new PlotsModel(
61+
exampleDvcRoot,
62+
{
63+
getFirstThreeColumnOrder: mockedGetFirstThreeColumnOrder,
64+
getSelectedRevisions: mockedGetSelectedRevisions,
65+
isReady: () => Promise.resolve(undefined)
66+
} as unknown as Experiments,
67+
memento
68+
)
69+
expect(model.getCustomPlotsOrder()).toStrictEqual([
70+
{
71+
metric: 'summary.json:loss',
72+
param: 'params.yaml:dropout',
73+
type: CustomPlotType.METRIC_VS_PARAM
74+
}
75+
])
76+
expect(
77+
memento.get(PersistenceKey.PLOT_SELECTED_METRICS + exampleDvcRoot)
78+
).toStrictEqual(undefined)
79+
expect(
80+
memento.get(PersistenceKey.PLOT_METRIC_ORDER + exampleDvcRoot)
81+
).toStrictEqual(undefined)
82+
})
83+
4884
it('should change the plotSize when calling setPlotSize', () => {
4985
expect(
5086
model.getNbItemsPerRowOrWidth(PlotsSection.CUSTOM_PLOTS)

extension/src/plots/model/index.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ export class PlotsModel extends ModelWithPersistence {
9191
)
9292
this.comparisonOrder = this.revive(PersistenceKey.PLOT_COMPARISON_ORDER, [])
9393
this.customPlotsOrder = this.revive(PersistenceKey.PLOTS_CUSTOM_ORDER, [])
94+
95+
this.cleanupOutdatedCustomPlotsState()
96+
this.cleanupOutdatedTrendsState()
9497
}
9598

9699
public transformAndSetExperiments() {
@@ -181,9 +184,7 @@ export class PlotsModel extends ModelWithPersistence {
181184
}
182185

183186
public getCustomPlotsOrder() {
184-
return this.customPlotsOrder.map(value =>
185-
cleanupOldOrderValue(value, FILE_SEPARATOR)
186-
)
187+
return this.customPlotsOrder
187188
}
188189

189190
public updateCustomPlotsOrder(plotsOrder: CustomPlotsOrderValue[]) {
@@ -401,6 +402,24 @@ export class PlotsModel extends ModelWithPersistence {
401402
return mapping
402403
}
403404

405+
private cleanupOutdatedCustomPlotsState() {
406+
const order = this.getCustomPlotsOrder()
407+
const workspaceHoldsUpToDateState =
408+
order.length === 0 || order[0].type !== undefined
409+
if (workspaceHoldsUpToDateState) {
410+
return
411+
}
412+
const newOrder = order.map(value =>
413+
cleanupOldOrderValue(value, FILE_SEPARATOR)
414+
)
415+
this.setCustomPlotsOrder(newOrder)
416+
}
417+
418+
private cleanupOutdatedTrendsState() {
419+
this.persist(PersistenceKey.PLOT_METRIC_ORDER, undefined)
420+
this.persist(PersistenceKey.PLOT_SELECTED_METRICS, undefined)
421+
}
422+
404423
private removeStaleData() {
405424
return Promise.all([this.removeStaleCommits(), this.removeStaleRevisions()])
406425
}

0 commit comments

Comments
 (0)