From bf2d9ff1525c280bc6e1635ebaba4fca9769772f Mon Sep 17 00:00:00 2001 From: Kirill Shumilov Date: Wed, 13 Jun 2018 19:39:20 +0300 Subject: [PATCH] tweak(xod-client, xod-client-electron): make snack bar messages persistent by default --- .../src/shared/messages.js | 30 ++++++------ .../src/upload/messages.js | 4 +- .../xod-client-electron/src/view/actions.js | 15 +++--- .../src/view/autoupdate.js | 1 - .../src/view/containers/App.jsx | 2 +- .../src/core/crashReporterMiddleware.js | 2 +- packages/xod-client/src/editor/messages.js | 32 ++++++------- packages/xod-client/src/messages/actions.js | 16 ++++--- packages/xod-client/src/project/messages.js | 48 +++++++++++-------- .../containers/ProjectBrowser.jsx | 2 - 10 files changed, 81 insertions(+), 71 deletions(-) diff --git a/packages/xod-client-electron/src/shared/messages.js b/packages/xod-client-electron/src/shared/messages.js index c7a9bb6a..6364bd67 100644 --- a/packages/xod-client-electron/src/shared/messages.js +++ b/packages/xod-client-electron/src/shared/messages.js @@ -1,5 +1,4 @@ import composeMessage from './composeMessage'; -import * as EVENTS from './events'; export const CODE_TRANSPILED = 'Project was successfully transpiled. Searching for device...'; @@ -14,22 +13,23 @@ export const ENUMERATING_PORTS = 'Enumerating...'; export const ENUMERATING_BOARDS = 'Loading list of supported boards...'; export const NO_PORTS_FOUND = 'No connected boards found'; -export const SUCCESS = { - [EVENTS.SAVE_ALL]: 'Saved successfully', +export const SAVE_ALL_FAILED = { + title: 'Failed to save project.', +}; +export const SAVE_ALL_SUCCEED = { + title: 'Saved successfully!', }; -export const SAVE_ALL_PROCESSED = ''; -export const SAVE_ALL_FAILED = 'Failed to save project.'; -export const SAVE_ALL_SUCCEED = 'Saved successfully!'; - -export const DEBUG_SESSION_STOPPED_ON_CHANGE = composeMessage( - 'Debug session stopped', - 'Your Project has been changed.' -); -export const DEBUG_SESSION_STOPPED_ON_TAB_CLOSE = composeMessage( - 'Debug session stopped', - 'You closed Debugger tab.' -); +export const DEBUG_SESSION_STOPPED_ON_CHANGE = { + title: 'Debug session stopped', + note: 'Your Project has been changed.', + persistent: false, +}; +export const DEBUG_SESSION_STOPPED_ON_TAB_CLOSE = { + title: 'Debug session stopped', + note: 'You closed Debugger tab.', + persistent: false, +}; export const DEBUG_LOST_CONNECTION = 'Lost connection with the device.'; export const updateAvailableMessage = version => diff --git a/packages/xod-client-electron/src/upload/messages.js b/packages/xod-client-electron/src/upload/messages.js index cc7f08c3..764cedab 100644 --- a/packages/xod-client-electron/src/upload/messages.js +++ b/packages/xod-client-electron/src/upload/messages.js @@ -1,3 +1,5 @@ export default { - SUCCESS: 'Uploaded successfully', + SUCCESS: { + title: 'Uploaded successfully', + }, }; diff --git a/packages/xod-client-electron/src/view/actions.js b/packages/xod-client-electron/src/view/actions.js index c4ecf891..28accb27 100644 --- a/packages/xod-client-electron/src/view/actions.js +++ b/packages/xod-client-electron/src/view/actions.js @@ -10,7 +10,6 @@ import { addConfirmation, addError, SAVE_ALL, - composeMessage, } from 'xod-client'; import * as EVENTS from '../shared/events'; import * as MESSAGES from '../shared/messages'; @@ -60,13 +59,13 @@ const processCompleted = finishProcess(successProcess); const processFailed = finishProcess(failProcess); -export const createAsyncAction = ({ +const createAsyncAction = ({ eventName, actionType, messages: { - process: processMsg = '', - complete: completeMsg = '', - error: errorMsg = '', + process: processMsg, + complete: completeMsg, + error: errorMsg, } = {}, notify = true, silent = false, @@ -97,7 +96,7 @@ export const createAsyncAction = ({ processCompleted({ processId, actionType, payload }, dispatch); } if (notify) { - dispatch(addConfirmation(composeMessage(completeMsg))); + dispatch(addConfirmation(completeMsg)); } onComplete(payload, dispatch); @@ -122,7 +121,7 @@ export const createAsyncAction = ({ processFailed({ processId, actionType, payload: err }, dispatch); } if (notify) { - dispatch(addError(composeMessage(errorMsg))); + dispatch(addError(errorMsg)); } onError(err, dispatch); @@ -142,7 +141,7 @@ export const saveAll = createAsyncAction({ eventName: EVENTS.SAVE_ALL, actionType: SAVE_ALL, messages: { - process: MESSAGES.SAVE_ALL_PROCESSED, + process: null, complete: MESSAGES.SAVE_ALL_SUCCEED, error: MESSAGES.SAVE_ALL_FAILED, }, diff --git a/packages/xod-client-electron/src/view/autoupdate.js b/packages/xod-client-electron/src/view/autoupdate.js index d69d06d2..4e3b1627 100644 --- a/packages/xod-client-electron/src/view/autoupdate.js +++ b/packages/xod-client-electron/src/view/autoupdate.js @@ -14,7 +14,6 @@ export const subscribeAutoUpdaterEvents = (ipcRenderer, App) => { console.log('Update available: ', info); // eslint-disable-line no-console App.props.actions.addNotification( updateAvailableMessage(info.version), - true, UPDATE_IDE_MESSAGE_ID ); }); diff --git a/packages/xod-client-electron/src/view/containers/App.jsx b/packages/xod-client-electron/src/view/containers/App.jsx index 44ada36c..119a2eed 100644 --- a/packages/xod-client-electron/src/view/containers/App.jsx +++ b/packages/xod-client-electron/src/view/containers/App.jsx @@ -247,7 +247,7 @@ class App extends client.App { if (payload.success) { proc.success(payload.message); - this.props.actions.addConfirmation({ title: UPLOAD_MESSAGES.SUCCESS }); + this.props.actions.addConfirmation(UPLOAD_MESSAGES.SUCCESS); if (debug) { foldEither( diff --git a/packages/xod-client/src/core/crashReporterMiddleware.js b/packages/xod-client/src/core/crashReporterMiddleware.js index 95504aa1..00e22e68 100644 --- a/packages/xod-client/src/core/crashReporterMiddleware.js +++ b/packages/xod-client/src/core/crashReporterMiddleware.js @@ -8,6 +8,6 @@ export default () => next => action => { // eslint-disable-next-line no-console console.error(err); - return next(addError(formatUnexpectedError(err), true)); + return next(addError(formatUnexpectedError(err))); } }; diff --git a/packages/xod-client/src/editor/messages.js b/packages/xod-client/src/editor/messages.js index 918e0078..e2bfc1b9 100644 --- a/packages/xod-client/src/editor/messages.js +++ b/packages/xod-client/src/editor/messages.js @@ -1,24 +1,24 @@ -import composeMessage from '../messages/composeMessage'; - export const PATCH_FOR_NODE_IS_MISSING = 'Patch for this node is missing.'; -export const libInstalled = (libName, version) => - composeMessage(`${libName} @ ${version} installed successfully`); +export const libInstalled = (libName, version) => ({ + title: `${libName} @ ${version} installed successfully`, +}); -export const CLIPBOARD_RECURSION_PASTE_ERROR = composeMessage( - 'Canʼt paste a patch into itself' -); -export const clipboardMissingPatchPasteError = missingPatches => - composeMessage( - 'Canʼt paste', - `Canʼt find following patches: ${missingPatches}` - ); +export const CLIPBOARD_RECURSION_PASTE_ERROR = { + title: 'Canʼt paste a patch into itself', + persistent: false, +}; +export const clipboardMissingPatchPasteError = missingPatches => ({ + title: 'Canʼt paste', + note: `Canʼt find following patches: ${missingPatches}`, +}); export const LIB_SUGGESTER_TYPE_TO_BEGIN = 'Type owner/libname to find a library'; export const LIB_SUGGESTER_NOTHING_FOUND = 'No library found'; -export const NO_PATCH_TO_TRANSPILE = composeMessage( - 'No patch opened', - 'Open a patch to upload and try again' -); +export const NO_PATCH_TO_TRANSPILE = { + title: 'No patch opened', + solution: 'Open a patch to upload and try again', + persistent: false, +}; diff --git a/packages/xod-client/src/messages/actions.js b/packages/xod-client/src/messages/actions.js index 0ce78eaf..fb5c4294 100644 --- a/packages/xod-client/src/messages/actions.js +++ b/packages/xod-client/src/messages/actions.js @@ -1,21 +1,23 @@ +import * as R from 'ramda'; import * as ActionType from './actionTypes'; import { MESSAGE_TYPE } from './constants'; import { STATUS } from '../utils/constants'; const getTimestamp = () => new Date().getTime(); -export const addMessage = ( - type, - messageData, - persistent = false, - id = null -) => ({ +const getDefaultPersistencyByType = R.equals(MESSAGE_TYPE.ERROR); + +export const addMessage = (type, messageData, id = null) => ({ type: ActionType.MESSAGE_ADD, payload: messageData, meta: { id, type, - persistent, + persistent: R.propOr( + getDefaultPersistencyByType(type), + 'persistent', + messageData + ), timestamp: getTimestamp(), status: STATUS.STARTED, }, diff --git a/packages/xod-client/src/project/messages.js b/packages/xod-client/src/project/messages.js index 137035c8..41d47afb 100644 --- a/packages/xod-client/src/project/messages.js +++ b/packages/xod-client/src/project/messages.js @@ -1,35 +1,45 @@ -import composeMessage from '../messages/composeMessage'; import { LINK_ERRORS as LE, NODETYPE_ERROR_TYPES as NTE, } from '../editor/constants'; -export const SUCCESSFULLY_PUBLISHED = composeMessage('Library published'); +export const SUCCESSFULLY_PUBLISHED = { + title: 'Library published', +}; export const LINK_ERRORS = { - [LE.SAME_DIRECTION]: composeMessage( - 'Canʼt create link between pins of the same direction!' - ), - [LE.SAME_NODE]: composeMessage( - 'Canʼt create link between pins of the same node!' - ), - [LE.UNKNOWN_ERROR]: composeMessage('Canʼt create link', 'Unknown error!'), - [LE.INCOMPATIBLE_TYPES]: composeMessage('Incompatible pin types!'), + [LE.SAME_DIRECTION]: { + title: 'Canʼt create link between pins of the same direction!', + persistent: false, + }, + [LE.SAME_NODE]: { + title: 'Canʼt create link between pins of the same node!', + persistent: false, + }, + [LE.UNKNOWN_ERROR]: { + title: 'Canʼt create link', + note: 'Unknown error!', + persistent: false, + }, + [LE.INCOMPATIBLE_TYPES]: { + title: 'Incompatible pin types', + persistent: false, + }, }; export const NODETYPE_ERRORS = { - [NTE.CANT_DELETE_USED_PATCHNODE]: composeMessage( - 'Canʼt delete Patch', - 'Current Patch Node is used somewhere. You should remove it first!' - ), - [NTE.CANT_DELETE_USED_PIN_OF_PATCHNODE]: composeMessage( - 'Canʼt delete Pin', - [ + [NTE.CANT_DELETE_USED_PATCHNODE]: { + title: 'Canʼt delete Patch', + note: 'Current Patch Node is used somewhere. You should remove it first!', + }, + [NTE.CANT_DELETE_USED_PIN_OF_PATCHNODE]: { + title: 'Canʼt delete Pin', + note: [ 'Current IO Node is represents a Pin of Patch Node.', 'And it is used somewhere.', 'You should remove a linkage first!', - ].join(' ') - ), + ].join(' '), + }, }; export const missingPatchForNode = patchPath => diff --git a/packages/xod-client/src/projectBrowser/containers/ProjectBrowser.jsx b/packages/xod-client/src/projectBrowser/containers/ProjectBrowser.jsx index 3bdd20ba..9562c798 100644 --- a/packages/xod-client/src/projectBrowser/containers/ProjectBrowser.jsx +++ b/packages/xod-client/src/projectBrowser/containers/ProjectBrowser.jsx @@ -20,7 +20,6 @@ import { isAmong, notEquals, $Maybe, foldMaybe } from 'xod-func-tools'; import * as ProjectActions from '../../project/actions'; import * as ProjectBrowserActions from '../actions'; import * as EditorActions from '../../editor/actions'; -import * as MessagesActions from '../../messages/actions'; import * as PopupActions from '../../popups/actions'; import * as ProjectBrowserSelectors from '../selectors'; @@ -451,7 +450,6 @@ const mapDispatchToProps = dispatch => ({ closeAllPopups: PopupActions.hideAllPopups, - addNotification: MessagesActions.addNotification, showLibSuggester: EditorActions.showLibSuggester, showHelpbox: EditorActions.showHelpbox,