-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #446 - Improve data loading errors notification
- Loading branch information
Alexander Matyushentsev
authored and
Alexander Matyushentsev
committed
Aug 2, 2018
1 parent
a930b4f
commit 7c60ff0
Showing
9 changed files
with
431 additions
and
355 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/app/applications/components/application-details/application-details.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
307 changes: 155 additions & 152 deletions
307
src/app/applications/components/application-details/application-details.tsx
Large diffs are not rendered by default.
Oops, something went wrong.
222 changes: 99 additions & 123 deletions
222
src/app/applications/components/applications-list/applications-list.tsx
Large diffs are not rendered by default.
Oops, something went wrong.
89 changes: 35 additions & 54 deletions
89
src/app/settings/components/clusters-list/clusters-list.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,43 @@ | ||
import { MockupList } from 'argo-ui'; | ||
import * as React from 'react'; | ||
import { RouteComponentProps } from 'react-router'; | ||
|
||
import { ConnectionStateIcon, Page } from '../../../shared/components'; | ||
import { ConnectionStateIcon, DataLoader, Page } from '../../../shared/components'; | ||
|
||
import * as models from '../../../shared/models'; | ||
import { services } from '../../../shared/services'; | ||
|
||
export class ClustersList extends React.Component<RouteComponentProps<any>, { clusters: models.Cluster[] }> { | ||
|
||
constructor(props: RouteComponentProps<any>) { | ||
super(props); | ||
this.state = { clusters: null }; | ||
} | ||
|
||
public componentDidMount() { | ||
this.reloadClusters(); | ||
} | ||
|
||
public render() { | ||
return ( | ||
<Page title='Clusters' toolbar={{ breadcrumbs: [{title: 'Settings', path: '/settings' }, {title: 'Clusters'}] }}> | ||
<div className='repos-list'> | ||
<div className='argo-container'> | ||
{this.state.clusters ? ( | ||
this.state.clusters.length > 0 && ( | ||
<div className='argo-table-list'> | ||
<div className='argo-table-list__head'> | ||
<div className='row'> | ||
<div className='columns small-3'>NAME</div> | ||
<div className='columns small-6'>URL</div> | ||
<div className='columns small-3'>CONNECTION STATUS</div> | ||
</div> | ||
export const ClustersList = () => ( | ||
<Page title='Clusters' toolbar={{ breadcrumbs: [{title: 'Settings', path: '/settings' }, {title: 'Clusters'}] }}> | ||
<div className='repos-list'> | ||
<div className='argo-container'> | ||
<DataLoader load={() => services.clustersService.list()}> | ||
{(clusters: models.Cluster[]) => ( | ||
clusters.length > 0 && ( | ||
<div className='argo-table-list'> | ||
<div className='argo-table-list__head'> | ||
<div className='row'> | ||
<div className='columns small-3'>NAME</div> | ||
<div className='columns small-6'>URL</div> | ||
<div className='columns small-3'>CONNECTION STATUS</div> | ||
</div> | ||
{this.state.clusters.map((cluster) => ( | ||
<div className='argo-table-list__row' key={cluster.server}> | ||
<div className='row'> | ||
<div className='columns small-3'> | ||
<i className='icon argo-icon-hosts'/> {cluster.name} | ||
</div> | ||
<div className='columns small-6'> | ||
{cluster.server} | ||
</div> | ||
<div className='columns small-3'> | ||
<ConnectionStateIcon state={cluster.connectionState}/> {cluster.connectionState.status} | ||
</div> | ||
</div> | ||
{clusters.map((cluster) => ( | ||
<div className='argo-table-list__row' key={cluster.server}> | ||
<div className='row'> | ||
<div className='columns small-3'> | ||
<i className='icon argo-icon-hosts'/> {cluster.name} | ||
</div> | ||
<div className='columns small-6'> | ||
{cluster.server} | ||
</div> | ||
<div className='columns small-3'> | ||
<ConnectionStateIcon state={cluster.connectionState}/> {cluster.connectionState.status} | ||
</div> | ||
</div> | ||
))} | ||
</div> ) | ||
) : <MockupList height={50} marginTop={30}/>} | ||
</div> | ||
</div> | ||
</Page> | ||
); | ||
} | ||
|
||
private async reloadClusters() { | ||
this.setState({ clusters: await services.clustersService.list() }); | ||
} | ||
} | ||
</div> | ||
))} | ||
</div> ) | ||
)} | ||
</DataLoader> | ||
</div> | ||
</div> | ||
</Page> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import { NotificationType } from 'argo-ui'; | ||
import * as PropTypes from 'prop-types'; | ||
import * as React from 'react'; | ||
import { Observable, Subscription } from 'rxjs'; | ||
import { AppContext } from '../context'; | ||
import { ErrorNotification } from './error-notification'; | ||
|
||
interface LoaderProps<I, D> { | ||
load: (input: I) => Promise<D>; | ||
input?: I; | ||
loadingRenderer?: React.ComponentType; | ||
errorRenderer?: (children: React.ReactNode) => React.ReactNode; | ||
children: (data: D) => React.ReactNode; | ||
dataChanges?: Observable<D>; | ||
} | ||
|
||
export class DataLoader<D = {}, I = {}> extends React.Component<LoaderProps<I, D>, { loading: boolean; data: D; error: boolean; input: I}> { | ||
public static contextTypes = { | ||
router: PropTypes.object, | ||
apis: PropTypes.object, | ||
}; | ||
|
||
public static getDerivedStateFromProps(nextProps: LoaderProps<any, any>, prevState: { input: any }) { | ||
if (JSON.stringify(nextProps.input) !== JSON.stringify(prevState.input)) { | ||
return { data: null as any, input: nextProps.input }; | ||
} | ||
return null; | ||
} | ||
|
||
private subscription: Subscription; | ||
|
||
constructor(props: LoaderProps<I, D>) { | ||
super(props); | ||
this.state = { loading: false, error: false, data: null, input: props.input }; | ||
} | ||
|
||
public getData() { | ||
return this.state.data; | ||
} | ||
|
||
public setData(data: D) { | ||
return this.setState({ data }); | ||
} | ||
|
||
public componentDidMount() { | ||
this.loadData(); | ||
this.subscribe(); | ||
} | ||
|
||
public componentDidUpdate(prevProps: LoaderProps<I, D>) { | ||
this.loadData(); | ||
if (this.props.dataChanges !== prevProps.dataChanges) { | ||
this.subscribe(); | ||
} | ||
} | ||
|
||
public componentWillUnmount() { | ||
this.ensureUnsubscribed(); | ||
} | ||
|
||
public render() { | ||
const style: React.CSSProperties = {padding: '0.5em', textAlign: 'center'}; | ||
if (this.state.error) { | ||
const error = <p style={style}>Failed to load data, please <a onClick={() => this.reload()}>try again</a>.</p>; | ||
if (this.props.errorRenderer) { | ||
return this.props.errorRenderer(error); | ||
} | ||
return error; | ||
} | ||
if (this.state.data) { | ||
return this.props.children(this.state.data); | ||
} | ||
return this.props.loadingRenderer ? <this.props.loadingRenderer/> : <p style={style}>Loading...</p>; | ||
} | ||
|
||
public reload() { | ||
this.setState({ data: null, error: false }); | ||
} | ||
|
||
private async loadData() { | ||
if (!this.state.error && !this.state.loading && this.state.data == null) { | ||
this.setState({ error: false, loading: true }); | ||
try { | ||
const data = await this.props.load(this.props.input); | ||
this.setState({ data, loading: false }); | ||
} catch (e) { | ||
this.setState({ error: true, loading: false }); | ||
this.appContext.apis.notifications.show({ | ||
content: <ErrorNotification title='Unable to load data' e={e}/>, | ||
type: NotificationType.Error, | ||
}); | ||
} | ||
} | ||
} | ||
|
||
private subscribe() { | ||
this.ensureUnsubscribed(); | ||
if (this.props.dataChanges) { | ||
this.subscription = this.props.dataChanges.subscribe((data: D) => this.setState({ data })); | ||
} | ||
} | ||
|
||
private ensureUnsubscribed() { | ||
if (this.subscription) { | ||
this.subscription.unsubscribe(); | ||
} | ||
this.subscription = null; | ||
} | ||
|
||
private get appContext(): AppContext { | ||
return this.context as AppContext; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters