From 39b4c0a15bd8b58eb41bfdee87b935700bf2875b Mon Sep 17 00:00:00 2001 From: Dominik Guzei Date: Tue, 26 Mar 2019 14:47:06 +0100 Subject: handle get workspaces request errors in the ui --- .../settings/services/ServicesDashboard.js | 2 +- src/features/workspaces/api.js | 3 +- .../workspaces/components/WorkspacesDashboard.js | 61 +++++++++++++++------- .../workspaces/containers/WorkspacesScreen.js | 2 +- src/features/workspaces/store.js | 3 +- src/i18n/locales/defaultMessages.json | 34 ++++++++++-- src/i18n/locales/en-US.json | 4 +- .../workspaces/components/WorkspacesDashboard.json | 34 ++++++++++-- src/stores/lib/Request.js | 2 + 9 files changed, 112 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/components/settings/services/ServicesDashboard.js b/src/components/settings/services/ServicesDashboard.js index a12df7372..53bae12df 100644 --- a/src/components/settings/services/ServicesDashboard.js +++ b/src/components/settings/services/ServicesDashboard.js @@ -65,7 +65,7 @@ export default @observer class ServicesDashboard extends Component { static defaultProps = { searchNeedle: '', - } + }; static contextTypes = { intl: intlShape, diff --git a/src/features/workspaces/api.js b/src/features/workspaces/api.js index 634f9f989..3da265e5e 100644 --- a/src/features/workspaces/api.js +++ b/src/features/workspaces/api.js @@ -2,7 +2,6 @@ import { pick } from 'lodash'; import { sendAuthRequest } from '../../api/utils/auth'; import { API, API_VERSION } from '../../environment'; import Request from '../../stores/lib/Request'; -import CachedRequest from '../../stores/lib/CachedRequest'; import Workspace from './models/Workspace'; const debug = require('debug')('Franz:feature:workspaces:api'); @@ -54,7 +53,7 @@ export const workspaceApi = { }, }; -export const getUserWorkspacesRequest = new CachedRequest(workspaceApi, 'getUserWorkspaces'); +export const getUserWorkspacesRequest = new Request(workspaceApi, 'getUserWorkspaces'); export const createWorkspaceRequest = new Request(workspaceApi, 'createWorkspace'); export const deleteWorkspaceRequest = new Request(workspaceApi, 'deleteWorkspace'); export const updateWorkspaceRequest = new Request(workspaceApi, 'updateWorkspace'); diff --git a/src/features/workspaces/components/WorkspacesDashboard.js b/src/features/workspaces/components/WorkspacesDashboard.js index 17b3755d7..2ccea1d55 100644 --- a/src/features/workspaces/components/WorkspacesDashboard.js +++ b/src/features/workspaces/components/WorkspacesDashboard.js @@ -1,4 +1,4 @@ -import React, { Component } from 'react'; +import React, { Component, Fragment } from 'react'; import PropTypes from 'prop-types'; import { observer, PropTypes as MobxPropTypes } from 'mobx-react'; import { defineMessages, intlShape } from 'react-intl'; @@ -7,6 +7,8 @@ import injectSheet from 'react-jss'; import Loader from '../../../components/ui/Loader'; import WorkspaceItem from './WorkspaceItem'; import CreateWorkspaceForm from './CreateWorkspaceForm'; +import Request from '../../../stores/lib/Request'; +import Infobox from '../../../components/ui/Infobox'; const messages = defineMessages({ headline: { @@ -17,6 +19,14 @@ const messages = defineMessages({ id: 'settings.workspaces.noWorkspacesAdded', defaultMessage: '!!!You haven\'t added any workspaces yet.', }, + workspacesRequestFailed: { + id: 'settings.workspaces.workspacesRequestFailed', + defaultMessage: '!!!Could not load your workspaces', + }, + tryReloadWorkspaces: { + id: 'settings.workspaces.tryReloadWorkspaces', + defaultMessage: '!!!Try again', + }, }); const styles = () => ({ @@ -26,11 +36,11 @@ const styles = () => ({ }, }); -@observer @injectSheet(styles) +@injectSheet(styles) @observer class WorkspacesDashboard extends Component { static propTypes = { classes: PropTypes.object.isRequired, - isLoadingWorkspaces: PropTypes.bool.isRequired, + getUserWorkspacesRequest: PropTypes.instanceOf(Request).isRequired, onCreateWorkspaceSubmit: PropTypes.func.isRequired, onWorkspaceClick: PropTypes.func.isRequired, workspaces: MobxPropTypes.arrayOrObservableArray.isRequired, @@ -42,14 +52,13 @@ class WorkspacesDashboard extends Component { render() { const { - workspaces, - isLoadingWorkspaces, + classes, + getUserWorkspacesRequest, onCreateWorkspaceSubmit, onWorkspaceClick, - classes, + workspaces, } = this.props; const { intl } = this.context; - return (
@@ -60,20 +69,34 @@ class WorkspacesDashboard extends Component {
- {isLoadingWorkspaces ? ( + {getUserWorkspacesRequest.isExecuting ? ( ) : ( - - - {workspaces.map(workspace => ( - onWorkspaceClick(w)} - /> - ))} - -
+ + {getUserWorkspacesRequest.error ? ( + + {intl.formatMessage(messages.workspacesRequestFailed)} + + ) : ( + + + {workspaces.map(workspace => ( + onWorkspaceClick(w)} + /> + ))} + +
+ )} +
)}
diff --git a/src/features/workspaces/containers/WorkspacesScreen.js b/src/features/workspaces/containers/WorkspacesScreen.js index 5fdea217e..89bd2a2ef 100644 --- a/src/features/workspaces/containers/WorkspacesScreen.js +++ b/src/features/workspaces/containers/WorkspacesScreen.js @@ -22,7 +22,7 @@ class WorkspacesScreen extends Component { actions.workspaces.create(data)} onWorkspaceClick={w => actions.workspaces.edit({ workspace: w })} /> diff --git a/src/features/workspaces/store.js b/src/features/workspaces/store.js index 86a8a2c76..3cec5f360 100644 --- a/src/features/workspaces/store.js +++ b/src/features/workspaces/store.js @@ -30,7 +30,7 @@ export default class WorkspacesStore { @computed get workspaces() { if (!this.isFeatureActive) return []; - return getUserWorkspacesRequest.execute().result || []; + return getUserWorkspacesRequest.result || []; } constructor() { @@ -57,6 +57,7 @@ export default class WorkspacesStore { this.actions = actions; this._reactions.forEach(r => r.start()); this.isFeatureActive = true; + getUserWorkspacesRequest.execute(); } stop() { diff --git a/src/i18n/locales/defaultMessages.json b/src/i18n/locales/defaultMessages.json index 03e96fc40..afbacf28a 100644 --- a/src/i18n/locales/defaultMessages.json +++ b/src/i18n/locales/defaultMessages.json @@ -3388,26 +3388,52 @@ "defaultMessage": "!!!Your workspaces", "end": { "column": 3, - "line": 15 + "line": 17 }, "file": "src/features/workspaces/components/WorkspacesDashboard.js", "id": "settings.workspaces.headline", "start": { "column": 12, - "line": 12 + "line": 14 } }, { "defaultMessage": "!!!You haven't added any workspaces yet.", "end": { "column": 3, - "line": 19 + "line": 21 }, "file": "src/features/workspaces/components/WorkspacesDashboard.js", "id": "settings.workspaces.noWorkspacesAdded", "start": { "column": 19, - "line": 16 + "line": 18 + } + }, + { + "defaultMessage": "!!!Could not load your workspaces", + "end": { + "column": 3, + "line": 25 + }, + "file": "src/features/workspaces/components/WorkspacesDashboard.js", + "id": "settings.workspaces.workspacesRequestFailed", + "start": { + "column": 27, + "line": 22 + } + }, + { + "defaultMessage": "!!!Try again", + "end": { + "column": 3, + "line": 29 + }, + "file": "src/features/workspaces/components/WorkspacesDashboard.js", + "id": "settings.workspaces.tryReloadWorkspaces", + "start": { + "column": 23, + "line": 26 } } ], diff --git a/src/i18n/locales/en-US.json b/src/i18n/locales/en-US.json index 4206d4358..2b4e79621 100644 --- a/src/i18n/locales/en-US.json +++ b/src/i18n/locales/en-US.json @@ -251,6 +251,8 @@ "settings.workspace.form.yourWorkspaces": "Your workspaces", "settings.workspaces.headline": "Your workspaces", "settings.workspaces.noWorkspacesAdded": "You haven't added any workspaces yet.", + "settings.workspaces.tryReloadWorkspaces": "Try again", + "settings.workspaces.workspacesRequestFailed": "Could not load your workspaces", "sidebar.addNewService": "Add new service", "sidebar.closeWorkspaceDrawer": "Close workspace drawer", "sidebar.muteApp": "Disable notifications & audio", @@ -305,4 +307,4 @@ "workspaceDrawer.headline": "Workspaces", "workspaceDrawer.item.noServicesAddedYet": "No services added yet", "workspaces.switchingIndicator.switchingTo": "Switching to" -} \ No newline at end of file +} diff --git a/src/i18n/messages/src/features/workspaces/components/WorkspacesDashboard.json b/src/i18n/messages/src/features/workspaces/components/WorkspacesDashboard.json index 0e053a124..f875ace8a 100644 --- a/src/i18n/messages/src/features/workspaces/components/WorkspacesDashboard.json +++ b/src/i18n/messages/src/features/workspaces/components/WorkspacesDashboard.json @@ -4,11 +4,11 @@ "defaultMessage": "!!!Your workspaces", "file": "src/features/workspaces/components/WorkspacesDashboard.js", "start": { - "line": 12, + "line": 14, "column": 12 }, "end": { - "line": 15, + "line": 17, "column": 3 } }, @@ -17,11 +17,37 @@ "defaultMessage": "!!!You haven't added any workspaces yet.", "file": "src/features/workspaces/components/WorkspacesDashboard.js", "start": { - "line": 16, + "line": 18, "column": 19 }, "end": { - "line": 19, + "line": 21, + "column": 3 + } + }, + { + "id": "settings.workspaces.workspacesRequestFailed", + "defaultMessage": "!!!Could not load your workspaces", + "file": "src/features/workspaces/components/WorkspacesDashboard.js", + "start": { + "line": 22, + "column": 27 + }, + "end": { + "line": 25, + "column": 3 + } + }, + { + "id": "settings.workspaces.tryReloadWorkspaces", + "defaultMessage": "!!!Try again", + "file": "src/features/workspaces/components/WorkspacesDashboard.js", + "start": { + "line": 26, + "column": 23 + }, + "end": { + "line": 29, "column": 3 } } diff --git a/src/stores/lib/Request.js b/src/stores/lib/Request.js index 04f528156..1fb67cc15 100644 --- a/src/stores/lib/Request.js +++ b/src/stores/lib/Request.js @@ -85,6 +85,8 @@ export default class Request { return this.execute(...this._currentApiCall.args); } + retry = () => this.reload(); + isExecutingWithArgs(...args) { return this.isExecuting && this._currentApiCall && isEqual(this._currentApiCall.args, args); } -- cgit v1.2.3-54-g00ecf