Skip to content

Commit 5ea918e

Browse files
authored
HParam UI: reset ColumnHeaders if using obsolete interface (#6358)
## Motivation for features / changes In #6346 we updated the ColumnHeader interface. However, objects using this interface are stored in localStorage. This checks localStorage to ensure it has the new interface. If it does not then it ignores those values. ## Technical description of changes I am simply checking if the first value has the name property to ensure the values are valid. I could do a more thorough check but it seems unnecessary. ## Detailed steps to verify changes work correctly (as executed by you) It worked for me when running locally.
1 parent ff83494 commit 5ea918e

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

tensorboard/webapp/persistent_settings/_data_source/persistent_settings_data_source.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,17 @@ export class OSSSettingsConverter extends SettingsConverter<
209209
}
210210

211211
if (
212-
backendSettings.hasOwnProperty('singleSelectionHeaders') &&
213-
typeof backendSettings.singleSelectionHeaders === 'object'
212+
Array.isArray(backendSettings.singleSelectionHeaders) &&
213+
// If the settings stored in the backend are invalid, reset back to default.
214+
backendSettings.singleSelectionHeaders[0].name !== undefined
214215
) {
215216
settings.singleSelectionHeaders = backendSettings.singleSelectionHeaders;
216217
}
217218

218219
if (
219-
backendSettings.hasOwnProperty('rangeSelectionHeaders') &&
220-
typeof backendSettings.rangeSelectionHeaders === 'object'
220+
Array.isArray(backendSettings.rangeSelectionHeaders) &&
221+
// If the settings stored in the backend are invalid, reset back to default.
222+
backendSettings.rangeSelectionHeaders[0].name !== undefined
221223
) {
222224
settings.rangeSelectionHeaders = backendSettings.rangeSelectionHeaders;
223225
}

tensorboard/webapp/persistent_settings/_data_source/persistent_settings_data_source_test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,48 @@ describe('persistent_settings data_source test', () => {
261261
],
262262
});
263263
});
264+
265+
it('resets singleSelectionEnabled if old ColumnHeader is stored', async () => {
266+
getItemSpy.withArgs(TEST_ONLY.GLOBAL_LOCAL_STORAGE_KEY).and.returnValue(
267+
JSON.stringify({
268+
singleSelectionHeaders: [
269+
{
270+
type: ColumnHeaderType.RUN,
271+
enabled: true,
272+
},
273+
{
274+
type: ColumnHeaderType.VALUE,
275+
enabled: false,
276+
},
277+
],
278+
})
279+
);
280+
281+
const actual = await firstValueFrom(dataSource.getSettings());
282+
283+
expect(actual).toEqual({});
284+
});
285+
286+
it('resets rangeSelectionEnabled if old ColumnHeader is stored', async () => {
287+
getItemSpy.withArgs(TEST_ONLY.GLOBAL_LOCAL_STORAGE_KEY).and.returnValue(
288+
JSON.stringify({
289+
rangeSelectionHeaders: [
290+
{
291+
type: ColumnHeaderType.RUN,
292+
enabled: true,
293+
},
294+
{
295+
type: ColumnHeaderType.MIN_VALUE,
296+
enabled: true,
297+
},
298+
],
299+
})
300+
);
301+
302+
const actual = await firstValueFrom(dataSource.getSettings());
303+
304+
expect(actual).toEqual({});
305+
});
264306
});
265307

266308
describe('#setSettings', () => {

0 commit comments

Comments
 (0)