diff options
author | 2019-03-26 14:47:06 +0100 | |
---|---|---|
committer | 2019-03-26 14:47:06 +0100 | |
commit | 39b4c0a15bd8b58eb41bfdee87b935700bf2875b (patch) | |
tree | 33b748e0513ed6dbb9a5940585fd0d7ffa712708 | |
parent | hide workspace feature if it is disabled (diff) | |
download | ferdium-app-39b4c0a15bd8b58eb41bfdee87b935700bf2875b.tar.gz ferdium-app-39b4c0a15bd8b58eb41bfdee87b935700bf2875b.tar.zst ferdium-app-39b4c0a15bd8b58eb41bfdee87b935700bf2875b.zip |
handle get workspaces request errors in the ui
-rw-r--r-- | src/components/settings/services/ServicesDashboard.js | 2 | ||||
-rw-r--r-- | src/features/workspaces/api.js | 3 | ||||
-rw-r--r-- | src/features/workspaces/components/WorkspacesDashboard.js | 61 | ||||
-rw-r--r-- | src/features/workspaces/containers/WorkspacesScreen.js | 2 | ||||
-rw-r--r-- | src/features/workspaces/store.js | 3 | ||||
-rw-r--r-- | src/i18n/locales/defaultMessages.json | 34 | ||||
-rw-r--r-- | src/i18n/locales/en-US.json | 4 | ||||
-rw-r--r-- | src/i18n/messages/src/features/workspaces/components/WorkspacesDashboard.json | 34 | ||||
-rw-r--r-- | src/stores/lib/Request.js | 2 |
9 files changed, 112 insertions, 33 deletions
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 { | |||
65 | 65 | ||
66 | static defaultProps = { | 66 | static defaultProps = { |
67 | searchNeedle: '', | 67 | searchNeedle: '', |
68 | } | 68 | }; |
69 | 69 | ||
70 | static contextTypes = { | 70 | static contextTypes = { |
71 | intl: intlShape, | 71 | 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'; | |||
2 | import { sendAuthRequest } from '../../api/utils/auth'; | 2 | import { sendAuthRequest } from '../../api/utils/auth'; |
3 | import { API, API_VERSION } from '../../environment'; | 3 | import { API, API_VERSION } from '../../environment'; |
4 | import Request from '../../stores/lib/Request'; | 4 | import Request from '../../stores/lib/Request'; |
5 | import CachedRequest from '../../stores/lib/CachedRequest'; | ||
6 | import Workspace from './models/Workspace'; | 5 | import Workspace from './models/Workspace'; |
7 | 6 | ||
8 | const debug = require('debug')('Franz:feature:workspaces:api'); | 7 | const debug = require('debug')('Franz:feature:workspaces:api'); |
@@ -54,7 +53,7 @@ export const workspaceApi = { | |||
54 | }, | 53 | }, |
55 | }; | 54 | }; |
56 | 55 | ||
57 | export const getUserWorkspacesRequest = new CachedRequest(workspaceApi, 'getUserWorkspaces'); | 56 | export const getUserWorkspacesRequest = new Request(workspaceApi, 'getUserWorkspaces'); |
58 | export const createWorkspaceRequest = new Request(workspaceApi, 'createWorkspace'); | 57 | export const createWorkspaceRequest = new Request(workspaceApi, 'createWorkspace'); |
59 | export const deleteWorkspaceRequest = new Request(workspaceApi, 'deleteWorkspace'); | 58 | export const deleteWorkspaceRequest = new Request(workspaceApi, 'deleteWorkspace'); |
60 | export const updateWorkspaceRequest = new Request(workspaceApi, 'updateWorkspace'); | 59 | 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 @@ | |||
1 | import React, { Component } from 'react'; | 1 | import React, { Component, Fragment } from 'react'; |
2 | import PropTypes from 'prop-types'; | 2 | import PropTypes from 'prop-types'; |
3 | import { observer, PropTypes as MobxPropTypes } from 'mobx-react'; | 3 | import { observer, PropTypes as MobxPropTypes } from 'mobx-react'; |
4 | import { defineMessages, intlShape } from 'react-intl'; | 4 | import { defineMessages, intlShape } from 'react-intl'; |
@@ -7,6 +7,8 @@ import injectSheet from 'react-jss'; | |||
7 | import Loader from '../../../components/ui/Loader'; | 7 | import Loader from '../../../components/ui/Loader'; |
8 | import WorkspaceItem from './WorkspaceItem'; | 8 | import WorkspaceItem from './WorkspaceItem'; |
9 | import CreateWorkspaceForm from './CreateWorkspaceForm'; | 9 | import CreateWorkspaceForm from './CreateWorkspaceForm'; |
10 | import Request from '../../../stores/lib/Request'; | ||
11 | import Infobox from '../../../components/ui/Infobox'; | ||
10 | 12 | ||
11 | const messages = defineMessages({ | 13 | const messages = defineMessages({ |
12 | headline: { | 14 | headline: { |
@@ -17,6 +19,14 @@ const messages = defineMessages({ | |||
17 | id: 'settings.workspaces.noWorkspacesAdded', | 19 | id: 'settings.workspaces.noWorkspacesAdded', |
18 | defaultMessage: '!!!You haven\'t added any workspaces yet.', | 20 | defaultMessage: '!!!You haven\'t added any workspaces yet.', |
19 | }, | 21 | }, |
22 | workspacesRequestFailed: { | ||
23 | id: 'settings.workspaces.workspacesRequestFailed', | ||
24 | defaultMessage: '!!!Could not load your workspaces', | ||
25 | }, | ||
26 | tryReloadWorkspaces: { | ||
27 | id: 'settings.workspaces.tryReloadWorkspaces', | ||
28 | defaultMessage: '!!!Try again', | ||
29 | }, | ||
20 | }); | 30 | }); |
21 | 31 | ||
22 | const styles = () => ({ | 32 | const styles = () => ({ |
@@ -26,11 +36,11 @@ const styles = () => ({ | |||
26 | }, | 36 | }, |
27 | }); | 37 | }); |
28 | 38 | ||
29 | @observer @injectSheet(styles) | 39 | @injectSheet(styles) @observer |
30 | class WorkspacesDashboard extends Component { | 40 | class WorkspacesDashboard extends Component { |
31 | static propTypes = { | 41 | static propTypes = { |
32 | classes: PropTypes.object.isRequired, | 42 | classes: PropTypes.object.isRequired, |
33 | isLoadingWorkspaces: PropTypes.bool.isRequired, | 43 | getUserWorkspacesRequest: PropTypes.instanceOf(Request).isRequired, |
34 | onCreateWorkspaceSubmit: PropTypes.func.isRequired, | 44 | onCreateWorkspaceSubmit: PropTypes.func.isRequired, |
35 | onWorkspaceClick: PropTypes.func.isRequired, | 45 | onWorkspaceClick: PropTypes.func.isRequired, |
36 | workspaces: MobxPropTypes.arrayOrObservableArray.isRequired, | 46 | workspaces: MobxPropTypes.arrayOrObservableArray.isRequired, |
@@ -42,14 +52,13 @@ class WorkspacesDashboard extends Component { | |||
42 | 52 | ||
43 | render() { | 53 | render() { |
44 | const { | 54 | const { |
45 | workspaces, | 55 | classes, |
46 | isLoadingWorkspaces, | 56 | getUserWorkspacesRequest, |
47 | onCreateWorkspaceSubmit, | 57 | onCreateWorkspaceSubmit, |
48 | onWorkspaceClick, | 58 | onWorkspaceClick, |
49 | classes, | 59 | workspaces, |
50 | } = this.props; | 60 | } = this.props; |
51 | const { intl } = this.context; | 61 | const { intl } = this.context; |
52 | |||
53 | return ( | 62 | return ( |
54 | <div className="settings__main"> | 63 | <div className="settings__main"> |
55 | <div className="settings__header"> | 64 | <div className="settings__header"> |
@@ -60,20 +69,34 @@ class WorkspacesDashboard extends Component { | |||
60 | <div className={classes.createForm}> | 69 | <div className={classes.createForm}> |
61 | <CreateWorkspaceForm onSubmit={onCreateWorkspaceSubmit} /> | 70 | <CreateWorkspaceForm onSubmit={onCreateWorkspaceSubmit} /> |
62 | </div> | 71 | </div> |
63 | {isLoadingWorkspaces ? ( | 72 | {getUserWorkspacesRequest.isExecuting ? ( |
64 | <Loader /> | 73 | <Loader /> |
65 | ) : ( | 74 | ) : ( |
66 | <table className="workspace-table"> | 75 | <Fragment> |
67 | <tbody> | 76 | {getUserWorkspacesRequest.error ? ( |
68 | {workspaces.map(workspace => ( | 77 | <Infobox |
69 | <WorkspaceItem | 78 | icon="alert" |
70 | key={workspace.id} | 79 | type="danger" |
71 | workspace={workspace} | 80 | ctaLabel={intl.formatMessage(messages.tryReloadWorkspaces)} |
72 | onItemClick={w => onWorkspaceClick(w)} | 81 | ctaLoading={getUserWorkspacesRequest.isExecuting} |
73 | /> | 82 | ctaOnClick={getUserWorkspacesRequest.retry} |
74 | ))} | 83 | > |
75 | </tbody> | 84 | {intl.formatMessage(messages.workspacesRequestFailed)} |
76 | </table> | 85 | </Infobox> |
86 | ) : ( | ||
87 | <table className="workspace-table"> | ||
88 | <tbody> | ||
89 | {workspaces.map(workspace => ( | ||
90 | <WorkspaceItem | ||
91 | key={workspace.id} | ||
92 | workspace={workspace} | ||
93 | onItemClick={w => onWorkspaceClick(w)} | ||
94 | /> | ||
95 | ))} | ||
96 | </tbody> | ||
97 | </table> | ||
98 | )} | ||
99 | </Fragment> | ||
77 | )} | 100 | )} |
78 | </div> | 101 | </div> |
79 | </div> | 102 | </div> |
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 { | |||
22 | <ErrorBoundary> | 22 | <ErrorBoundary> |
23 | <WorkspacesDashboard | 23 | <WorkspacesDashboard |
24 | workspaces={workspaceStore.workspaces} | 24 | workspaces={workspaceStore.workspaces} |
25 | isLoadingWorkspaces={getUserWorkspacesRequest.isExecuting} | 25 | getUserWorkspacesRequest={getUserWorkspacesRequest} |
26 | onCreateWorkspaceSubmit={data => actions.workspaces.create(data)} | 26 | onCreateWorkspaceSubmit={data => actions.workspaces.create(data)} |
27 | onWorkspaceClick={w => actions.workspaces.edit({ workspace: w })} | 27 | onWorkspaceClick={w => actions.workspaces.edit({ workspace: w })} |
28 | /> | 28 | /> |
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 { | |||
30 | 30 | ||
31 | @computed get workspaces() { | 31 | @computed get workspaces() { |
32 | if (!this.isFeatureActive) return []; | 32 | if (!this.isFeatureActive) return []; |
33 | return getUserWorkspacesRequest.execute().result || []; | 33 | return getUserWorkspacesRequest.result || []; |
34 | } | 34 | } |
35 | 35 | ||
36 | constructor() { | 36 | constructor() { |
@@ -57,6 +57,7 @@ export default class WorkspacesStore { | |||
57 | this.actions = actions; | 57 | this.actions = actions; |
58 | this._reactions.forEach(r => r.start()); | 58 | this._reactions.forEach(r => r.start()); |
59 | this.isFeatureActive = true; | 59 | this.isFeatureActive = true; |
60 | getUserWorkspacesRequest.execute(); | ||
60 | } | 61 | } |
61 | 62 | ||
62 | stop() { | 63 | 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 @@ | |||
3388 | "defaultMessage": "!!!Your workspaces", | 3388 | "defaultMessage": "!!!Your workspaces", |
3389 | "end": { | 3389 | "end": { |
3390 | "column": 3, | 3390 | "column": 3, |
3391 | "line": 15 | 3391 | "line": 17 |
3392 | }, | 3392 | }, |
3393 | "file": "src/features/workspaces/components/WorkspacesDashboard.js", | 3393 | "file": "src/features/workspaces/components/WorkspacesDashboard.js", |
3394 | "id": "settings.workspaces.headline", | 3394 | "id": "settings.workspaces.headline", |
3395 | "start": { | 3395 | "start": { |
3396 | "column": 12, | 3396 | "column": 12, |
3397 | "line": 12 | 3397 | "line": 14 |
3398 | } | 3398 | } |
3399 | }, | 3399 | }, |
3400 | { | 3400 | { |
3401 | "defaultMessage": "!!!You haven't added any workspaces yet.", | 3401 | "defaultMessage": "!!!You haven't added any workspaces yet.", |
3402 | "end": { | 3402 | "end": { |
3403 | "column": 3, | 3403 | "column": 3, |
3404 | "line": 19 | 3404 | "line": 21 |
3405 | }, | 3405 | }, |
3406 | "file": "src/features/workspaces/components/WorkspacesDashboard.js", | 3406 | "file": "src/features/workspaces/components/WorkspacesDashboard.js", |
3407 | "id": "settings.workspaces.noWorkspacesAdded", | 3407 | "id": "settings.workspaces.noWorkspacesAdded", |
3408 | "start": { | 3408 | "start": { |
3409 | "column": 19, | 3409 | "column": 19, |
3410 | "line": 16 | 3410 | "line": 18 |
3411 | } | ||
3412 | }, | ||
3413 | { | ||
3414 | "defaultMessage": "!!!Could not load your workspaces", | ||
3415 | "end": { | ||
3416 | "column": 3, | ||
3417 | "line": 25 | ||
3418 | }, | ||
3419 | "file": "src/features/workspaces/components/WorkspacesDashboard.js", | ||
3420 | "id": "settings.workspaces.workspacesRequestFailed", | ||
3421 | "start": { | ||
3422 | "column": 27, | ||
3423 | "line": 22 | ||
3424 | } | ||
3425 | }, | ||
3426 | { | ||
3427 | "defaultMessage": "!!!Try again", | ||
3428 | "end": { | ||
3429 | "column": 3, | ||
3430 | "line": 29 | ||
3431 | }, | ||
3432 | "file": "src/features/workspaces/components/WorkspacesDashboard.js", | ||
3433 | "id": "settings.workspaces.tryReloadWorkspaces", | ||
3434 | "start": { | ||
3435 | "column": 23, | ||
3436 | "line": 26 | ||
3411 | } | 3437 | } |
3412 | } | 3438 | } |
3413 | ], | 3439 | ], |
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 @@ | |||
251 | "settings.workspace.form.yourWorkspaces": "Your workspaces", | 251 | "settings.workspace.form.yourWorkspaces": "Your workspaces", |
252 | "settings.workspaces.headline": "Your workspaces", | 252 | "settings.workspaces.headline": "Your workspaces", |
253 | "settings.workspaces.noWorkspacesAdded": "You haven't added any workspaces yet.", | 253 | "settings.workspaces.noWorkspacesAdded": "You haven't added any workspaces yet.", |
254 | "settings.workspaces.tryReloadWorkspaces": "Try again", | ||
255 | "settings.workspaces.workspacesRequestFailed": "Could not load your workspaces", | ||
254 | "sidebar.addNewService": "Add new service", | 256 | "sidebar.addNewService": "Add new service", |
255 | "sidebar.closeWorkspaceDrawer": "Close workspace drawer", | 257 | "sidebar.closeWorkspaceDrawer": "Close workspace drawer", |
256 | "sidebar.muteApp": "Disable notifications & audio", | 258 | "sidebar.muteApp": "Disable notifications & audio", |
@@ -305,4 +307,4 @@ | |||
305 | "workspaceDrawer.headline": "Workspaces", | 307 | "workspaceDrawer.headline": "Workspaces", |
306 | "workspaceDrawer.item.noServicesAddedYet": "No services added yet", | 308 | "workspaceDrawer.item.noServicesAddedYet": "No services added yet", |
307 | "workspaces.switchingIndicator.switchingTo": "Switching to" | 309 | "workspaces.switchingIndicator.switchingTo": "Switching to" |
308 | } \ No newline at end of file | 310 | } |
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 @@ | |||
4 | "defaultMessage": "!!!Your workspaces", | 4 | "defaultMessage": "!!!Your workspaces", |
5 | "file": "src/features/workspaces/components/WorkspacesDashboard.js", | 5 | "file": "src/features/workspaces/components/WorkspacesDashboard.js", |
6 | "start": { | 6 | "start": { |
7 | "line": 12, | 7 | "line": 14, |
8 | "column": 12 | 8 | "column": 12 |
9 | }, | 9 | }, |
10 | "end": { | 10 | "end": { |
11 | "line": 15, | 11 | "line": 17, |
12 | "column": 3 | 12 | "column": 3 |
13 | } | 13 | } |
14 | }, | 14 | }, |
@@ -17,11 +17,37 @@ | |||
17 | "defaultMessage": "!!!You haven't added any workspaces yet.", | 17 | "defaultMessage": "!!!You haven't added any workspaces yet.", |
18 | "file": "src/features/workspaces/components/WorkspacesDashboard.js", | 18 | "file": "src/features/workspaces/components/WorkspacesDashboard.js", |
19 | "start": { | 19 | "start": { |
20 | "line": 16, | 20 | "line": 18, |
21 | "column": 19 | 21 | "column": 19 |
22 | }, | 22 | }, |
23 | "end": { | 23 | "end": { |
24 | "line": 19, | 24 | "line": 21, |
25 | "column": 3 | ||
26 | } | ||
27 | }, | ||
28 | { | ||
29 | "id": "settings.workspaces.workspacesRequestFailed", | ||
30 | "defaultMessage": "!!!Could not load your workspaces", | ||
31 | "file": "src/features/workspaces/components/WorkspacesDashboard.js", | ||
32 | "start": { | ||
33 | "line": 22, | ||
34 | "column": 27 | ||
35 | }, | ||
36 | "end": { | ||
37 | "line": 25, | ||
38 | "column": 3 | ||
39 | } | ||
40 | }, | ||
41 | { | ||
42 | "id": "settings.workspaces.tryReloadWorkspaces", | ||
43 | "defaultMessage": "!!!Try again", | ||
44 | "file": "src/features/workspaces/components/WorkspacesDashboard.js", | ||
45 | "start": { | ||
46 | "line": 26, | ||
47 | "column": 23 | ||
48 | }, | ||
49 | "end": { | ||
50 | "line": 29, | ||
25 | "column": 3 | 51 | "column": 3 |
26 | } | 52 | } |
27 | } | 53 | } |
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 { | |||
85 | return this.execute(...this._currentApiCall.args); | 85 | return this.execute(...this._currentApiCall.args); |
86 | } | 86 | } |
87 | 87 | ||
88 | retry = () => this.reload(); | ||
89 | |||
88 | isExecutingWithArgs(...args) { | 90 | isExecutingWithArgs(...args) { |
89 | return this.isExecuting && this._currentApiCall && isEqual(this._currentApiCall.args, args); | 91 | return this.isExecuting && this._currentApiCall && isEqual(this._currentApiCall.args, args); |
90 | } | 92 | } |