Skip to content

Commit

Permalink
[eeg_modelling] Fix minor bugs
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 238668435
  • Loading branch information
pdpino authored and copybara-github committed Mar 15, 2019
1 parent bcfbf98 commit 55247eb
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 199 deletions.
3 changes: 1 addition & 2 deletions eeg_modelling/eeg_viewer/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ def CreateDataResponse(request):

elif request.tf_ex_file_path:
tf_example = FetchTfExFromFile(request.tf_ex_file_path)
waveform_data_source = TfExDataSourceConstructor(tf_example,
request.tf_ex_file_path)
waveform_data_source = TfExDataSourceConstructor(tf_example, '')

if request.prediction_file_path:
pred_outputs = FetchPredictionsFromFile(request.prediction_file_path)
Expand Down
14 changes: 3 additions & 11 deletions eeg_modelling/eeg_viewer/static/js/dispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const log = goog.require('goog.log');
*/
const ActionType = {
ANNOTATION_SELECTION: 'annotationSelection',
ERROR: 'error',
GRAPH_TIME_CLICK: 'graphTimeClick',
MAPLE_DISABLE_ANNOTATIONS: 'mapleDisableAnnotations',
MAPLE_ENABLE_ANNOTATIONS: 'mapleEnableAnnotations',
Expand All @@ -46,9 +47,8 @@ const ActionType = {
TOOL_BAR_PREV_CHUNK: 'toolBarPrevChunk',
TOOL_BAR_PREV_SEC: 'toolBarPrevSec',
TOOL_BAR_SENSITIVITY: 'toolBarSensitivity',
TOOL_BAR_WARNING: 'toolBarWarning',
TOOL_BAR_ZOOM: 'toolBarZoom',
WINDOW_LOCATION_ERROR: 'windowLocationError',
WARNING: 'warning',
WINDOW_LOCATION_PENDING_REQUEST: 'windowLocationPendingRequest',
};

Expand Down Expand Up @@ -109,18 +109,11 @@ let FragmentData;

/**
* @typedef {{
* errorMessage: string,
* message: string,
* }}
*/
let ErrorData;

/**
* @typedef {{
* warningMessage: string,
* }}
*/
let WarningData;

/**
* @typedef {{
* selectedValue: (string|number|!Array<string>),
Expand Down Expand Up @@ -179,6 +172,5 @@ exports.TimeData = TimeData;
exports.RoiData = RoiData;
exports.FileParamData = FileParamData;
exports.ErrorData = ErrorData;
exports.WarningData = WarningData;
exports.SelectionData = SelectionData;
exports.RequestStartData = RequestStartData;
24 changes: 11 additions & 13 deletions eeg_modelling/eeg_viewer/static/js/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,24 @@ class Error {
constructor() {
const store = Store.getInstance();
// This listener callback will display a toast error message.
store.registerListener([Store.Property.ERROR_MESSAGE],
'Error', (store) => this.handleError(store));
// This listener callback will display a toast warning message.
store.registerListener([Store.Property.WARNING_MESSAGE],
'Error', (store) => this.handleWarning(store));
store.registerListener([Store.Property.ERROR],
'Error', (store) => void this.handleError(store));
}

/**
* Handles a change in the ERROR property.
* @param {!Store.StoreData} store Snapshot of the store data.
*/
handleError(store) {
this.display(store.errorMessage);
}

handleWarning(store) {
this.display(store.warningMessage);
this.display(store.error);
}

/**
* Displays an error message in a snackbar
* Displays an error message in a snackbar.
* @param {?Store.ErrorInfo} errorInfo
*/
display(data) {
const text = data ? data.message : 'Unknown Error';
display(errorInfo) {
const text = errorInfo ? errorInfo.message : 'Unknown Error';
const notificationSnackbar = /** @type {!MaterialSnackbarElement} */ (document.querySelector('#notification-snackbar'));
notificationSnackbar.MaterialSnackbar.showSnackbar({
message: text,
Expand Down
37 changes: 22 additions & 15 deletions eeg_modelling/eeg_viewer/static/js/error_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,40 @@ let mockControl;
let error;
const _ = mockmatchers.ignoreArgument;

const mockMaterialSnackbar = {
showSnackbar: () => {},
};

testSuite({

setUp() {
mockControl = new MockControl();
error = Error.getInstance();

const notificationSnackbar = document.createElement('div');
notificationSnackbar.id = 'notification-snackbar';
notificationSnackbar.MaterialSnackbar = mockMaterialSnackbar;

document.body.append(notificationSnackbar);
},

testHandleError() {
const chunkData = {
errorMessage: 'Test error',
const storeData = {
error: {
message: 'Test error',
timestamp: 1,
},
};
const mockDisplay = mockControl.createMethodMock(error, 'display');
mockDisplay('Test error').$once();
mockControl.$replayAll();
error.handleError(chunkData);
mockControl.$verifyAll();
},

testHandleWarning() {
const chunkData = {
warningMessage: 'Test warning',
};
const mockDisplay = mockControl.createMethodMock(error, 'display');
mockDisplay('Test warning').$once();
const mockShowSnackbar = mockControl.createMethodMock(mockMaterialSnackbar, 'showSnackbar');

const snackbarArgMatcher = new mockmatchers.ArgumentMatcher((arg) =>
arg.message === 'Test error' && arg.timeout >= 3000);

mockShowSnackbar(snackbarArgMatcher).$once();

mockControl.$replayAll();
error.handleWarning(chunkData);
error.handleError(storeData);
mockControl.$verifyAll();
},

Expand Down
10 changes: 5 additions & 5 deletions eeg_modelling/eeg_viewer/static/js/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Requests {

/**
* Creates a new XhrIO object (used for testing HTTP requests).
* @returns {!XhrIo} An XhrIo object.
* @return {!XhrIo} An XhrIo object.
*/
getXhrIo() {
return new XhrIo();
Expand All @@ -79,7 +79,7 @@ class Requests {
* @param {string} url The path to send the request to.
* @param {!DataRequest} requestContent A request protobuf.
* @param {function(!Object): !Object} formatResponse Formats response data.
* @returns {!Promise} A promise returning an XhrIo response.
* @return {!Promise} A promise returning an XhrIo response.
*/
createXhrIoPromise(url, requestContent, formatResponse) {
const parseJsonResponse = function(response) {
Expand Down Expand Up @@ -107,7 +107,7 @@ class Requests {
/**
* Creates a data request Uri from the ChunkStore.
* @param {!Store.StoreData} store Snapshot of chunk data store.
* @returns {!Promise} A promise that makes an Xhr request.
* @return {!Promise} A promise that makes an Xhr request.
*/
createDataResponsePromise(store) {
const url = '/waveform_data/chunk';
Expand Down Expand Up @@ -170,7 +170,7 @@ class Requests {
Dispatcher.getInstance().sendAction({
actionType: Dispatcher.ActionType.REQUEST_RESPONSE_ERROR,
data: {
errorMessage: errorResponse.message || 'Unknown Request Error',
message: errorResponse.message || 'Unknown Request Error',
},
});
});
Expand All @@ -179,7 +179,7 @@ class Requests {
/**
* Converts channel ID's expressed in string form to proto format.
* @param {string} channelStr The channel ID in string format.
* @returns {?ChannelDataId} Converted string channel ID.
* @return {?ChannelDataId} Converted string channel ID.
*/
convertIndexStrToChannelDataId(channelStr) {
const channelIndices = channelStr.split('-')
Expand Down
Loading

0 comments on commit 55247eb

Please sign in to comment.