Skip to content
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
1 change: 1 addition & 0 deletions tensorboard/webapp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ tf_ng_web_test_suite(
"//tensorboard/webapp/core/views:test_lib",
"//tensorboard/webapp/customization:customization_test_lib",
"//tensorboard/webapp/deeplink:deeplink_test_lib",
"//tensorboard/webapp/experiments/store:store_test_lib",
Copy link
Contributor

Choose a reason for hiding this comment

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

Wow

"//tensorboard/webapp/header:test_lib",
"//tensorboard/webapp/metrics:integration_test",
"//tensorboard/webapp/metrics:test_lib",
Expand Down
1 change: 1 addition & 0 deletions tensorboard/webapp/experiments/store/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ tf_ts_library(
deps = [
":selectors",
":testing",
":types",
"//tensorboard/webapp/types",
"@npm//@types/jasmine",
],
Expand Down
17 changes: 17 additions & 0 deletions tensorboard/webapp/experiments/store/experiments_selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,20 @@ export const getExperiment = createSelector(
return state.experimentMap[experimentId] || null;
}
);

/**
* Returns Observable that emits an object mapping the provided
* experiment ids to experiment names.
*/
export const getExperimentNames = (experimentIds: string[]) =>
createSelector(
getDataState,
(state: ExperimentsDataState): Record<string, string> =>
experimentIds
.map((experimentId) => state.experimentMap[experimentId])
.filter(Boolean)
.reduce((map, experiment) => {
map[experiment.id] = experiment.name;
return map;
}, {} as Record<string, string>)
);
30 changes: 30 additions & 0 deletions tensorboard/webapp/experiments/store/experiments_selectors_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
import * as selectors from './experiments_selectors';
import {State} from './experiments_types';
import {buildExperiment, buildStateFromExperimentsState} from './testing';

describe('experiments selectors', () => {
Expand Down Expand Up @@ -47,4 +48,33 @@ describe('experiments selectors', () => {
);
});
});

describe('#getExperimentNames', () => {
let state: State;

beforeEach(() => {
const foo = buildExperiment({id: 'foo', name: 'foo name'});
const bar = buildExperiment({id: 'bar', name: 'bar name'});

state = buildStateFromExperimentsState({
data: {
experimentMap: {foo, bar},
},
});
});

it('translates experiment ids to experiment names', () => {
expect(
selectors.getExperimentNames(['foo', 'bar', 'baz'])(state)
).toEqual({
foo: 'foo name',
bar: 'bar name',
});
});

it('returns an empty object when no experiments are provided', () => {
expect(selectors.getExperimentNames([])(state)).toEqual({});
expect(selectors.getExperimentNames(['abc', '123'])(state)).toEqual({});
});
});
});