Skip to content

Commit

Permalink
Merge pull request #1284 from xodio/tweak-1234-persistent-messages-by…
Browse files Browse the repository at this point in the history
…-default

Make snack bar messages persistent by default
  • Loading branch information
brusherru authored Jun 18, 2018
2 parents c77fd35 + bf2d9ff commit f464ed5
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 71 deletions.
30 changes: 15 additions & 15 deletions packages/xod-client-electron/src/shared/messages.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import composeMessage from './composeMessage';
import * as EVENTS from './events';

export const CODE_TRANSPILED =
'Project was successfully transpiled. Searching for device...';
Expand All @@ -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 =>
Expand Down
4 changes: 3 additions & 1 deletion packages/xod-client-electron/src/upload/messages.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export default {
SUCCESS: 'Uploaded successfully',
SUCCESS: {
title: 'Uploaded successfully',
},
};
15 changes: 7 additions & 8 deletions packages/xod-client-electron/src/view/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -97,7 +96,7 @@ export const createAsyncAction = ({
processCompleted({ processId, actionType, payload }, dispatch);
}
if (notify) {
dispatch(addConfirmation(composeMessage(completeMsg)));
dispatch(addConfirmation(completeMsg));
}

onComplete(payload, dispatch);
Expand All @@ -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);
Expand All @@ -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,
},
Expand Down
1 change: 0 additions & 1 deletion packages/xod-client-electron/src/view/autoupdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/xod-client-electron/src/view/containers/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion packages/xod-client/src/core/crashReporterMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
};
32 changes: 16 additions & 16 deletions packages/xod-client/src/editor/messages.js
Original file line number Diff line number Diff line change
@@ -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,
};
16 changes: 9 additions & 7 deletions packages/xod-client/src/messages/actions.js
Original file line number Diff line number Diff line change
@@ -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,
},
Expand Down
48 changes: 29 additions & 19 deletions packages/xod-client/src/project/messages.js
Original file line number Diff line number Diff line change
@@ -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 =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -451,7 +450,6 @@ const mapDispatchToProps = dispatch => ({

closeAllPopups: PopupActions.hideAllPopups,

addNotification: MessagesActions.addNotification,
showLibSuggester: EditorActions.showLibSuggester,
showHelpbox: EditorActions.showHelpbox,

Expand Down

0 comments on commit f464ed5

Please sign in to comment.