Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop clearing unrecognized query params #6784

Merged
merged 8 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tensorboard/webapp/core/store/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ tf_ng_module(
],
deps = [
"//tensorboard/webapp/app_routing:namespaced_state_reducer_helper",
"//tensorboard/webapp/app_routing/actions",
"//tensorboard/webapp/core:types",
"//tensorboard/webapp/core/actions",
"//tensorboard/webapp/deeplink",
Expand All @@ -35,6 +36,8 @@ tf_ts_library(
],
deps = [
":store",
"//tensorboard/webapp/app_routing:types",
"//tensorboard/webapp/app_routing/actions",
"//tensorboard/webapp/core:types",
"//tensorboard/webapp/core/actions",
"//tensorboard/webapp/core/testing",
Expand Down
9 changes: 9 additions & 0 deletions tensorboard/webapp/core/store/core_reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
import {Action, createReducer, on} from '@ngrx/store';
import {stateRehydratedFromUrl} from '../../app_routing/actions/app_routing_actions';
import {createNamespaceContextedState} from '../../app_routing/namespaced_state_reducer_helper';
import {persistentSettingsLoaded} from '../../persistent_settings';
import {DataLoadState} from '../../types/data';
import {composeReducers} from '../../util/ngrx';
import * as actions from '../actions';
import {CoreState, initialState} from './core_types';
import {URLDeserializedState} from '../types';

const reducer = createReducer(
initialState,
Expand Down Expand Up @@ -173,6 +175,13 @@ const reducer = createReducer(
...state,
runsTableFullScreen: !state.runsTableFullScreen,
};
}),
on(stateRehydratedFromUrl, (state, {partialState}) => {
const {unknownQueryParams} = partialState as URLDeserializedState;
return {
...state,
unknownQueryParams,
};
})
);

Expand Down
18 changes: 18 additions & 0 deletions tensorboard/webapp/core/store/core_reducers_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
import {stateRehydratedFromUrl} from '../../app_routing/actions/app_routing_actions';
import {RouteKind} from '../../app_routing/types';
import {persistentSettingsLoaded} from '../../persistent_settings';
import {DataLoadState} from '../../types/data';
import * as actions from '../actions';
Expand Down Expand Up @@ -657,4 +659,20 @@ describe('core reducer', () => {
expect(state3.runsTableFullScreen).toBeFalse();
});
});

describe('#stateRehydratedFromUrl', () => {
it('stores unknownQueryParams', () => {
const state = createCoreState();
const state2 = reducers(
state,
stateRehydratedFromUrl({
routeKind: RouteKind.EXPERIMENT,
partialState: {unknownQueryParams: {foo: 'bar'}},
})
);
expect(state2.unknownQueryParams).toEqual({
foo: 'bar',
});
});
});
});
7 changes: 7 additions & 0 deletions tensorboard/webapp/core/store/core_selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ export const getPlugins = createSelector(
}
);

export const getUnknownQueryParams = createSelector(
selectCoreState,
(state: CoreState) => {
return state.unknownQueryParams;
}
);

export const getEnvironment = createSelector(
selectCoreState,
(state: CoreState): Environment => {
Expand Down
5 changes: 5 additions & 0 deletions tensorboard/webapp/core/store/core_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface CoreState {
sideBarWidthInPercent: number;
// Whether the runs table should occupy the full screen.
runsTableFullScreen: boolean;
unknownQueryParams: Record<string, string>;
}

/*
Expand Down Expand Up @@ -102,4 +103,8 @@ export const initialState: CoreState = {
polymerInteropRunSelection: new Set(),
sideBarWidthInPercent: 20,
runsTableFullScreen: false,
// Query parameters not recognized by TensorBoard will be stored here.
// This is necessary so that they can be readded to the query params
// when the application serializes itself in the deeplink_provider.
unknownQueryParams: {},
};
1 change: 1 addition & 0 deletions tensorboard/webapp/core/testing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export function createCoreState(override?: Partial<CoreState>): CoreState {
polymerInteropRunSelection: new Set(),
sideBarWidthInPercent: 0,
runsTableFullScreen: false,
unknownQueryParams: {},
...override,
};
}
Expand Down
7 changes: 7 additions & 0 deletions tensorboard/webapp/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,10 @@ export enum PluginsListFailureCode {
export const TB_BRAND_NAME = new InjectionToken<string>(
'TensorBoard brand name'
);

export interface URLDeserializedState {
// Query parameters not recognized by TensorBoard will be stored here.
// This is necessary so that they can be readded to the query params
// when the application serializes itself in the deeplink_provider.
unknownQueryParams: Record<string, string>;
}
1 change: 1 addition & 0 deletions tensorboard/webapp/routes/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ tf_ts_library(
"dashboard_deeplink_provider_types.ts",
],
deps = [
"//tensorboard/webapp/core:types",
"//tensorboard/webapp/metrics:types",
"//tensorboard/webapp/runs:types",
],
Expand Down
12 changes: 12 additions & 0 deletions tensorboard/webapp/routes/dashboard_deeplink_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ export class DashboardDeepLinkProvider extends DeepLinkProvider {
return [{key: RUN_FILTER_KEY, value}];
})
),
store
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice (but not necessary) to also have this handled in the internal CorpExperimentListDeepLinkProvider (the CorpDashboardDeepLinkProvider, on the other hand, would get this for free already with the way you've coded this).

Not necessary to do but if you don't do it, I want to ensure it's a conscious choice rather than an oversight.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did remember CorpDashboardDeepLinkProvider and . I did not remember CorpExperimentListDeepLinkProvider but it should be simple enough to update once this makes it's way to google3

.select(selectors.getUnknownQueryParams)
.pipe(
map((queryParams) =>
Object.entries(queryParams).map(([key, value]) => ({key, value}))
)
),
]).pipe(
map((queryParamList) => {
return queryParamList.flat();
Expand All @@ -163,6 +170,7 @@ export class DashboardDeepLinkProvider extends DeepLinkProvider {
let tagFilter = null;
let groupBy: GroupBy | null = null;
let runFilter = null;
const unknownQueryParams: Record<string, string> = {};

for (const {key, value} of queryParams) {
switch (key) {
Expand Down Expand Up @@ -196,10 +204,14 @@ export class DashboardDeepLinkProvider extends DeepLinkProvider {
case RUN_FILTER_KEY:
runFilter = value;
break;
default:
unknownQueryParams[key] = value;
break;
}
}

return {
unknownQueryParams,
metrics: {
pinnedCards: pinnedCards || [],
smoothing,
Expand Down
26 changes: 26 additions & 0 deletions tensorboard/webapp/routes/dashboard_deeplink_provider_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,19 @@ describe('core deeplink provider', () => {
expect(state.metrics.pinnedCards).toEqual(expectedPinnedCards);
}
});

it('associated unrecognized query params with other plugins', () => {
rileyajones marked this conversation as resolved.
Show resolved Hide resolved
const state = provider.deserializeQueryParams([
{key: 'foo', value: 'bar'},
{key: 'bar', value: 'foo'},
{key: 'smoothing', value: '4'},
{key: 'tagFilter', value: 'mytagfilter'},
]);
expect(state.unknownQueryParams).toEqual({
foo: 'bar',
bar: 'foo',
});
});
});

describe('tag filter', () => {
Expand Down Expand Up @@ -365,6 +378,19 @@ describe('core deeplink provider', () => {
]);
});

it('serializes unknown query params', () => {
store.overrideSelector(selectors.getUnknownQueryParams, {
foo: 'bar',
bar: 'foo',
});
store.refreshState();

expect(queryParamsSerialized[queryParamsSerialized.length - 1]).toEqual([
{key: 'foo', value: 'bar'},
{key: 'bar', value: 'foo'},
]);
});

describe('runs', () => {
describe('color group', () => {
it('does not put state in the URL when user set color group is null', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ limitations under the License.
==============================================================================*/
import {URLDeserializedState as MetricsURLDeserializedState} from '../metrics/types';
import {URLDeserializedState as RunsURLDeserializedState} from '../runs/types';
import {URLDeserializedState as CoreURLDeserializedState} from '../core/types';

// No need to deserialize the Experimental Plugins as it is immutable and is only read at
// the start of the application.
export type DeserializedState = MetricsURLDeserializedState &
RunsURLDeserializedState;
RunsURLDeserializedState &
CoreURLDeserializedState;

export const SMOOTHING_KEY = 'smoothing';

Expand Down
1 change: 1 addition & 0 deletions tensorboard/webapp/routes/testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export function buildDeserializedState(
override: Partial<DeserializedState> = {}
) {
return {
unknownQueryParams: {},
runs: {
groupBy: null,
regexFilter: null,
Expand Down
Loading