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 6 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 {pluginQueryParams} = partialState as URLDeserializedState;
return {
...state,
pluginQueryParams,
};
})
);

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 pluginQueryParams', () => {
const state = createCoreState();
const state2 = reducers(
state,
stateRehydratedFromUrl({
routeKind: RouteKind.EXPERIMENT,
partialState: {pluginQueryParams: {foo: 'bar'}},
})
);
expect(state2.pluginQueryParams).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 getPluginQueryParams = createSelector(
selectCoreState,
(state: CoreState) => {
return state.pluginQueryParams;
}
);

export const getEnvironment = createSelector(
selectCoreState,
(state: CoreState): Environment => {
Expand Down
2 changes: 2 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;
pluginQueryParams: Record<string, string>;
}

/*
Expand Down Expand Up @@ -102,4 +103,5 @@ export const initialState: CoreState = {
polymerInteropRunSelection: new Set(),
sideBarWidthInPercent: 20,
runsTableFullScreen: false,
pluginQueryParams: {},
};
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,
pluginQueryParams: {},
...override,
};
}
Expand Down
4 changes: 4 additions & 0 deletions tensorboard/webapp/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ export enum PluginsListFailureCode {
export const TB_BRAND_NAME = new InjectionToken<string>(
'TensorBoard brand name'
);

export interface URLDeserializedState {
pluginQueryParams: Record<string, string>;
rileyajones marked this conversation as resolved.
Show resolved Hide resolved
rileyajones marked this conversation as resolved.
Show resolved Hide resolved
}
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.getPluginQueryParams)
.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 pluginQueryParams: 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:
pluginQueryParams[key] = value;
break;
}
}

return {
pluginQueryParams,
metrics: {
pinnedCards: pinnedCards || [],
smoothing,
Expand Down
13 changes: 13 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,15 @@ 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'},
]);
expect(state.pluginQueryParams).toEqual({
foo: 'bar',
});
});
});

describe('tag filter', () => {
Expand Down Expand Up @@ -358,10 +367,14 @@ describe('core deeplink provider', () => {
store.overrideSelector(selectors.getOverriddenFeatureFlags, {
enabledExperimentalPlugins: ['foo', 'bar', 'baz'],
});
store.overrideSelector(selectors.getPluginQueryParams, {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense for this to live in 'serializes feature flags'? Should it be its own test?

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 think it makes sense here because these are (were?) query parameters and they are being serialized.
If you feel strongly about it I'm happy to make another test.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand what the additions to this test have to do with 'feature flags'. They don't seem necessary.

The comment for the test:

  /**
   * One test to verify that feature flags are correctly serialized using
   * featureFlagsToSerializableQueryParams.
   */

The name for the test:

it('serializes feature flags', () => {

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 fully read "feature flags" as "query params". I guess working on TB has created an alias for me

foo: 'bar',
});
store.refreshState();

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

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 {
pluginQueryParams: {},
runs: {
groupBy: null,
regexFilter: null,
Expand Down
Loading