Add loading state to protoboards onboarding step
parent
726a011baa
commit
95203c10b2
|
@ -3,6 +3,7 @@
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
### UI Improvements
|
### UI Improvements
|
||||||
|
1. [#4809](https://github.com/influxdata/chronograf/pull/4809): Add loading spinners while fetching protoboards
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|
||||||
|
|
|
@ -20,3 +20,7 @@
|
||||||
color: $g12-forge;
|
color: $g12-forge;
|
||||||
margin: $ix-marg-b 0 $ix-marg-a 2px;
|
margin: $ix-marg-b 0 $ix-marg-a 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.dashboard-step--loading{
|
||||||
|
padding: 15px;
|
||||||
|
}
|
|
@ -18,6 +18,7 @@ import {getSuggestedProtoboards} from 'src/dashboards/utils/protoboardSuggestion
|
||||||
import GridSizer from 'src/reusable_ui/components/grid_sizer/GridSizer'
|
import GridSizer from 'src/reusable_ui/components/grid_sizer/GridSizer'
|
||||||
import CardSelectCard from 'src/reusable_ui/components/card_select/CardSelectCard'
|
import CardSelectCard from 'src/reusable_ui/components/card_select/CardSelectCard'
|
||||||
import SearchBar from 'src/hosts/components/SearchBar'
|
import SearchBar from 'src/hosts/components/SearchBar'
|
||||||
|
import PageSpinner from 'src/shared/components/PageSpinner'
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
import {notify as notifyAction} from 'src/shared/actions/notifications'
|
import {notify as notifyAction} from 'src/shared/actions/notifications'
|
||||||
|
@ -29,7 +30,7 @@ import {
|
||||||
} from 'src/shared/copy/notifications'
|
} from 'src/shared/copy/notifications'
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
import {Protoboard, Source} from 'src/types'
|
import {Protoboard, Source, RemoteDataState} from 'src/types'
|
||||||
import {NextReturn} from 'src/types/wizard'
|
import {NextReturn} from 'src/types/wizard'
|
||||||
|
|
||||||
interface SelectedDashboard {
|
interface SelectedDashboard {
|
||||||
|
@ -41,6 +42,8 @@ interface State {
|
||||||
protoboards: Protoboard[]
|
protoboards: Protoboard[]
|
||||||
selected: SelectedDashboard
|
selected: SelectedDashboard
|
||||||
suggestedProtoboards: Protoboard[]
|
suggestedProtoboards: Protoboard[]
|
||||||
|
fetchingProtoboards: RemoteDataState
|
||||||
|
fetchingSuggested: RemoteDataState
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
@ -52,6 +55,8 @@ interface Props {
|
||||||
|
|
||||||
@ErrorHandling
|
@ErrorHandling
|
||||||
class DashboardStep extends Component<Props, State> {
|
class DashboardStep extends Component<Props, State> {
|
||||||
|
private isComponentMounted: boolean
|
||||||
|
|
||||||
public constructor(props: Props) {
|
public constructor(props: Props) {
|
||||||
super(props)
|
super(props)
|
||||||
this.state = {
|
this.state = {
|
||||||
|
@ -59,12 +64,31 @@ class DashboardStep extends Component<Props, State> {
|
||||||
protoboards: [],
|
protoboards: [],
|
||||||
searchTerm: '',
|
searchTerm: '',
|
||||||
suggestedProtoboards: [],
|
suggestedProtoboards: [],
|
||||||
|
fetchingProtoboards: RemoteDataState.NotStarted,
|
||||||
|
fetchingSuggested: RemoteDataState.NotStarted,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async componentDidMount() {
|
public async componentDidMount() {
|
||||||
|
this.isComponentMounted = true
|
||||||
|
|
||||||
|
this.setState({fetchingProtoboards: RemoteDataState.Loading})
|
||||||
|
try {
|
||||||
const protoboards = await getProtoboards()
|
const protoboards = await getProtoboards()
|
||||||
this.setState({protoboards}, this.handleSuggest)
|
|
||||||
|
if (this.isComponentMounted) {
|
||||||
|
this.setState({protoboards, fetchingProtoboards: RemoteDataState.Done})
|
||||||
|
this.handleSuggest()
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
if (this.isComponentMounted) {
|
||||||
|
this.setState({fetchingProtoboards: RemoteDataState.Error})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public componentWillUnmount() {
|
||||||
|
this.isComponentMounted = false
|
||||||
}
|
}
|
||||||
|
|
||||||
public next = async (): Promise<NextReturn> => {
|
public next = async (): Promise<NextReturn> => {
|
||||||
|
@ -97,7 +121,12 @@ class DashboardStep extends Component<Props, State> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public render() {
|
public render() {
|
||||||
const {protoboards} = this.state
|
const {protoboards, fetchingProtoboards} = this.state
|
||||||
|
|
||||||
|
if (fetchingProtoboards === RemoteDataState.Loading) {
|
||||||
|
return <PageSpinner />
|
||||||
|
}
|
||||||
|
|
||||||
if (protoboards && protoboards.length) {
|
if (protoboards && protoboards.length) {
|
||||||
return (
|
return (
|
||||||
<div className="dashboard-step">
|
<div className="dashboard-step">
|
||||||
|
@ -112,6 +141,7 @@ class DashboardStep extends Component<Props, State> {
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return <div />
|
return <div />
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,6 +158,7 @@ class DashboardStep extends Component<Props, State> {
|
||||||
|
|
||||||
private get dashboardCards() {
|
private get dashboardCards() {
|
||||||
const {selected, protoboards, suggestedProtoboards, searchTerm} = this.state
|
const {selected, protoboards, suggestedProtoboards, searchTerm} = this.state
|
||||||
|
|
||||||
const filteredProtoboards = protoboards.filter(
|
const filteredProtoboards = protoboards.filter(
|
||||||
pb =>
|
pb =>
|
||||||
isSearchMatch(pb.meta.name, searchTerm) &&
|
isSearchMatch(pb.meta.name, searchTerm) &&
|
||||||
|
@ -156,7 +187,20 @@ class DashboardStep extends Component<Props, State> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private get suggestedDashboardCards() {
|
private get suggestedDashboardCards() {
|
||||||
const {selected, suggestedProtoboards, searchTerm} = this.state
|
const {
|
||||||
|
selected,
|
||||||
|
suggestedProtoboards,
|
||||||
|
searchTerm,
|
||||||
|
fetchingSuggested,
|
||||||
|
} = this.state
|
||||||
|
|
||||||
|
if (fetchingSuggested === RemoteDataState.Loading) {
|
||||||
|
return (
|
||||||
|
<div className="dashboard-step--loading">
|
||||||
|
<PageSpinner />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const filteredProtoboards = suggestedProtoboards.filter(pb =>
|
const filteredProtoboards = suggestedProtoboards.filter(pb =>
|
||||||
isSearchMatch(pb.meta.name, searchTerm)
|
isSearchMatch(pb.meta.name, searchTerm)
|
||||||
|
@ -196,6 +240,11 @@ class DashboardStep extends Component<Props, State> {
|
||||||
const {source} = this.props
|
const {source} = this.props
|
||||||
|
|
||||||
if (source) {
|
if (source) {
|
||||||
|
if (this.isComponentMounted) {
|
||||||
|
this.setState({fetchingSuggested: RemoteDataState.Loading})
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
const suggestedProtoboardsList = await getSuggestedProtoboards(
|
const suggestedProtoboardsList = await getSuggestedProtoboards(
|
||||||
source,
|
source,
|
||||||
protoboards
|
protoboards
|
||||||
|
@ -209,7 +258,15 @@ class DashboardStep extends Component<Props, State> {
|
||||||
suggestedProtoboardsList.includes(p.meta.name)
|
suggestedProtoboardsList.includes(p.meta.name)
|
||||||
)
|
)
|
||||||
|
|
||||||
this.setState({suggestedProtoboards})
|
if (this.isComponentMounted) {
|
||||||
|
this.setState({
|
||||||
|
suggestedProtoboards,
|
||||||
|
fetchingSuggested: RemoteDataState.Done,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
this.setState({fetchingSuggested: RemoteDataState.Error})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue