Skip to content

Commit 78ceaf7

Browse files
authored
Cleanup: Simplify Polymer Router implementation (#6322)
Remove the ability to create and inject Polymer Router instances with customizations. The customizations are no longer necessary. * The`dataDir` argument may be a remnant of internal extensions of the Router that no longer exist. * The `urlSearchParams` argument may be a remnant from when the polymer code had tests. Additionally, the setRouter() function is no longer necessary as its Google-internal usage was recently removed. Tested: * There are no tests for the polymer code so this was tested by hand. I ensured the Scalars, Images, and Hparams dashboards all continued to work with these changes. * Additionally I imported the changes internally and ran presubmit tests.
1 parent bf68efb commit 78ceaf7

File tree

1 file changed

+8
-50
lines changed

1 file changed

+8
-50
lines changed

tensorboard/components/tf_backend/router.ts

Lines changed: 8 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ limitations under the License.
1414
==============================================================================*/
1515
import {FEATURE_FLAGS_QUERY_STRING_NAME} from '../../webapp/feature_flag/http/const';
1616
import {getFeatureFlagsToSendToServer} from '../tf_feature_flags/feature-flags';
17-
import {ExperimentId} from './type';
1817
import {QueryParams} from './urlPathHelpers';
1918

2019
const EXPERIMENTAL_PLUGINS_QUERY_PARAM = 'experimentalPlugin';
@@ -34,7 +33,6 @@ export interface Router {
3433
) => string;
3534
pluginsListing: () => string;
3635
runs: () => string;
37-
runsForExperiment: (id: ExperimentId) => string;
3836
}
3937

4038
/**
@@ -47,29 +45,17 @@ let _router: Router = createRouter();
4745
/**
4846
* Create a router for communicating with the TensorBoard backend. You
4947
* can pass this to `setRouter` to make it the global router.
50-
*
51-
* @param dataDir {string=} The base prefix for data endpoints.
5248
*/
53-
export function createRouter(
54-
dataDir = 'data',
55-
urlSearchParams = initialURLSearchParams
56-
): Router {
57-
if (dataDir[dataDir.length - 1] === '/') {
58-
dataDir = dataDir.slice(0, dataDir.length - 1);
59-
}
49+
export function createRouter(): Router {
6050
return {
61-
environment: () => createDataPath(dataDir, '/environment'),
62-
experiments: () => createDataPath(dataDir, '/experiments'),
51+
environment: () => createDataPath('/environment'),
52+
experiments: () => createDataPath('/experiments'),
6353
pluginRoute: (
6454
pluginName: string,
6555
route: string,
6656
params?: URLSearchParams
6757
): string => {
68-
return createDataPath(
69-
dataDir + '/plugin',
70-
`/${pluginName}${route}`,
71-
params
72-
);
58+
return createDataPath(`/plugin/${pluginName}${route}`, params);
7359
},
7460
pluginRouteForSrc: (
7561
pluginName: string,
@@ -83,30 +69,18 @@ export function createRouter(
8369
JSON.stringify(featureFlags)
8470
);
8571
}
86-
return createDataPath(
87-
dataDir + '/plugin',
88-
`/${pluginName}${route}`,
89-
params
90-
);
72+
return createDataPath(`/plugin/${pluginName}${route}`, params);
9173
},
9274
pluginsListing: () =>
9375
createDataPath(
94-
dataDir,
9576
'/plugins_listing',
9677
createSearchParam({
97-
[EXPERIMENTAL_PLUGINS_QUERY_PARAM]: urlSearchParams.getAll(
78+
[EXPERIMENTAL_PLUGINS_QUERY_PARAM]: initialURLSearchParams.getAll(
9879
EXPERIMENTAL_PLUGINS_QUERY_PARAM
9980
),
10081
})
10182
),
102-
runs: () => createDataPath(dataDir, '/runs'),
103-
runsForExperiment: (id) => {
104-
return createDataPath(
105-
dataDir,
106-
'/experiment_runs',
107-
createSearchParam({experiment: String(id)})
108-
);
109-
},
83+
runs: () => createDataPath('/runs'),
11084
};
11185
}
11286

@@ -117,27 +91,11 @@ export function getRouter(): Router {
11791
return _router;
11892
}
11993

120-
/**
121-
* Set the global router, to be returned by future calls to `getRouter`.
122-
* You may wish to invoke this if you are running a demo server with a
123-
* custom path prefix, or if you have customized the TensorBoard backend
124-
* to use a different path.
125-
*
126-
* @param {Router} router the new global router
127-
*/
128-
export function setRouter(router: Router): void {
129-
if (router == null) {
130-
throw new Error('Router required, but got: ' + router);
131-
}
132-
_router = router;
133-
}
134-
13594
function createDataPath(
136-
dataDir: string,
13795
route: string,
13896
params: URLSearchParams = new URLSearchParams()
13997
): string {
140-
let relativePath = dataDir + route;
98+
let relativePath = 'data' + route;
14199
if (String(params)) {
142100
const delimiter = route.includes('?') ? '&' : '?';
143101
relativePath += delimiter + String(params);

0 commit comments

Comments
 (0)