Skip to content

Commit 338db03

Browse files
authored
feat: persist fastChart feature flag to url (#4348)
This change builds on top of already existing feature of deep linking to persist a state in the feature flag reducer for convenience of a user. With this change, when launching tensorboard with `?fastChart=true`, it will stay in the URL across navigations.
1 parent a9e1bba commit 338db03

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

tensorboard/webapp/routes/core_deeplink_provider.ts

+19-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ import {
2727
} from '../metrics/data_source/types';
2828
import {CardUniqueInfo} from '../metrics/types';
2929
import * as selectors from '../selectors';
30-
import {EXPERIMENTAL_PLUGIN_QUERY_PARAM_KEY} from '../webapp_data_source/tb_feature_flag_data_source_types';
30+
import {
31+
EXPERIMENTAL_PLUGIN_QUERY_PARAM_KEY,
32+
GPU_LINE_CHART_QUERY_PARAM_KEY,
33+
} from '../webapp_data_source/tb_feature_flag_data_source_types';
3134
import {DeserializedState} from './core_deeplink_provider_types';
3235

3336
/**
@@ -70,14 +73,24 @@ export class CoreDeepLinkProvider extends DeepLinkProvider {
7073
);
7174
}
7275

73-
private getExperimentalPluginList(
76+
private getFeatureFlagStates(
7477
store: Store<State>
7578
): Observable<SerializableQueryParams> {
76-
return store.select(selectors.getEnabledExperimentalPlugins).pipe(
77-
map((experimentalPlugins) => {
78-
return experimentalPlugins.map((pluginId) => {
79+
return combineLatest([
80+
store.select(selectors.getEnabledExperimentalPlugins),
81+
store.select(selectors.getIsGpuChartEnabled),
82+
]).pipe(
83+
map(([experimentalPlugins, isGpuChartEnabled]) => {
84+
const queryParams = experimentalPlugins.map((pluginId) => {
7985
return {key: EXPERIMENTAL_PLUGIN_QUERY_PARAM_KEY, value: pluginId};
8086
});
87+
if (isGpuChartEnabled) {
88+
queryParams.push({
89+
key: GPU_LINE_CHART_QUERY_PARAM_KEY,
90+
value: 'true',
91+
});
92+
}
93+
return queryParams;
8194
})
8295
);
8396
}
@@ -87,7 +100,7 @@ export class CoreDeepLinkProvider extends DeepLinkProvider {
87100
): Observable<SerializableQueryParams> {
88101
return combineLatest([
89102
this.getMetricsPinnedCards(store),
90-
this.getExperimentalPluginList(store),
103+
this.getFeatureFlagStates(store),
91104
]).pipe(
92105
map((queryParamList) => {
93106
return queryParamList.flat();

tensorboard/webapp/routes/core_deeplink_provider_test.ts

+10
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ describe('core deeplink provider', () => {
4444
store.overrideSelector(selectors.getPinnedCardsWithMetadata, []);
4545
store.overrideSelector(selectors.getUnresolvedImportedPinnedCards, []);
4646
store.overrideSelector(selectors.getEnabledExperimentalPlugins, []);
47+
store.overrideSelector(selectors.getIsGpuChartEnabled, false);
4748

4849
queryParamsSerialized = [];
4950

@@ -249,5 +250,14 @@ describe('core deeplink provider', () => {
249250
{key: 'experimentalPlugin', value: 'baz'},
250251
]);
251252
});
253+
254+
it('serializes enabled fast chart state', () => {
255+
store.overrideSelector(selectors.getIsGpuChartEnabled, true);
256+
store.refreshState();
257+
258+
expect(queryParamsSerialized[queryParamsSerialized.length - 1]).toEqual([
259+
{key: 'fastChart', value: 'true'},
260+
]);
261+
});
252262
});
253263
});

tensorboard/webapp/webapp_data_source/tb_feature_flag_data_source.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {Injectable} from '@angular/core';
1616

1717
import {
1818
EXPERIMENTAL_PLUGIN_QUERY_PARAM_KEY,
19+
GPU_LINE_CHART_QUERY_PARAM_KEY,
1920
TBFeatureFlagDataSource,
2021
} from './tb_feature_flag_data_source_types';
2122

@@ -39,7 +40,7 @@ export class QueryParamsFeatureFlagDataSource extends TBFeatureFlagDataSource {
3940
EXPERIMENTAL_PLUGIN_QUERY_PARAM_KEY
4041
),
4142
inColab: params.get('tensorboardColab') === 'true',
42-
enableGpuChart: params.get('fastChart') === 'true',
43+
enableGpuChart: params.get(GPU_LINE_CHART_QUERY_PARAM_KEY) === 'true',
4344
};
4445
}
4546
}

tensorboard/webapp/webapp_data_source/tb_feature_flag_data_source_types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,5 @@ export abstract class TBFeatureFlagDataSource {
2929
}
3030

3131
export const EXPERIMENTAL_PLUGIN_QUERY_PARAM_KEY = 'experimentalPlugin';
32+
33+
export const GPU_LINE_CHART_QUERY_PARAM_KEY = 'fastChart';

0 commit comments

Comments
 (0)