Skip to content

Commit e05b70f

Browse files
author
Dorin Paslaru
authored
Merge pull request #218 from smiclea/replica-executions
Replica execution shown twice after wizard finish
2 parents 737e207 + ea09362 commit e05b70f

4 files changed

Lines changed: 49 additions & 11 deletions

File tree

src/components/organisms/Executions/index.jsx

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { observer } from 'mobx-react'
1919
import styled from 'styled-components'
2020

2121
import StatusPill from '../../atoms/StatusPill'
22+
import StatusImage from '../../atoms/StatusImage'
2223
import CopyValue from '../../atoms/CopyValue'
2324
import Button from '../../atoms/Button'
2425
import Timeline from '../../molecules/Timeline'
@@ -31,7 +32,16 @@ import DateUtils from '../../../utils/DateUtils'
3132

3233
import executionImage from './images/execution.svg'
3334

34-
const Wrapper = styled.div`
35+
const Wrapper = styled.div``
36+
const LoadingWrapper = styled.div`
37+
margin-top: 32px;
38+
display: flex;
39+
flex-direction: column;
40+
align-items: center;
41+
`
42+
const LoadingText = styled.div`
43+
margin-top: 38px;
44+
font-size: 18px;
3545
`
3646
const ExecutionInfo = styled.div`
3747
background: ${Palette.grayscale[1]};
@@ -78,6 +88,7 @@ const NoExecutionText = styled.div`
7888

7989
type Props = {
8090
item: ?MainItem,
91+
loading: boolean,
8192
onCancelExecutionClick: (execution: ?Execution) => void,
8293
onDeleteExecutionClick: (execution: ?Execution) => void,
8394
onExecuteClick: () => void,
@@ -185,7 +196,24 @@ class Executions extends React.Component<Props, State> {
185196
this.props.onCancelExecutionClick(this.state.selectedExecution)
186197
}
187198

199+
renderLoading() {
200+
if (!this.props.loading) {
201+
return null
202+
}
203+
204+
return (
205+
<LoadingWrapper>
206+
<StatusImage loading />
207+
<LoadingText>Loading executions...</LoadingText>
208+
</LoadingWrapper>
209+
)
210+
}
211+
188212
renderTimeline() {
213+
if (this.props.loading) {
214+
return null
215+
}
216+
189217
return (
190218
<Timeline
191219
items={this.props.item ? this.props.item.executions : null}
@@ -224,7 +252,7 @@ class Executions extends React.Component<Props, State> {
224252
}
225253

226254
renderExecutionInfo() {
227-
if (!this.state.selectedExecution) {
255+
if (!this.state.selectedExecution || this.props.loading) {
228256
return null
229257
}
230258

@@ -248,7 +276,8 @@ class Executions extends React.Component<Props, State> {
248276

249277
renderTasks() {
250278
if (!this.state.selectedExecution || !this.state.selectedExecution.tasks
251-
|| !this.state.selectedExecution.tasks.length) {
279+
|| !this.state.selectedExecution.tasks.length
280+
|| this.props.loading) {
252281
return null
253282
}
254283

@@ -258,7 +287,7 @@ class Executions extends React.Component<Props, State> {
258287
}
259288

260289
renderNoExecution() {
261-
if (this.hasExecutions(this.props)) {
290+
if (this.hasExecutions(this.props) || this.props.loading) {
262291
return null
263292
}
264293

@@ -275,6 +304,7 @@ class Executions extends React.Component<Props, State> {
275304
render() {
276305
return (
277306
<Wrapper>
307+
{this.renderLoading()}
278308
{this.renderTimeline()}
279309
{this.renderExecutionInfo()}
280310
{this.renderTasks()}

src/components/organisms/ReplicaDetailsContent/index.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ type Props = {
7474
scheduleStore: typeof ScheduleStore,
7575
page: string,
7676
detailsLoading: boolean,
77+
executionsLoading: boolean,
7778
onCancelExecutionClick: (execution: ?Execution) => void,
7879
onDeleteExecutionClick: (execution: ?Execution) => void,
7980
onExecuteClick: () => void,
@@ -176,6 +177,7 @@ class ReplicaDetailsContent extends React.Component<Props, State> {
176177
onCancelExecutionClick={this.props.onCancelExecutionClick}
177178
onDeleteExecutionClick={this.props.onDeleteExecutionClick}
178179
onExecuteClick={this.props.onExecuteClick}
180+
loading={this.props.executionsLoading}
179181
data-test-id="rdContent-executions"
180182
/>
181183
)

src/components/pages/ReplicaDetailsPage/index.jsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class ReplicaDetailsPage extends React.Component<Props, State> {
7878
ReplicaStore.getReplica(this.props.match.params.id)
7979
EndpointStore.getEndpoints()
8080
ScheduleStore.getSchedules(this.props.match.params.id)
81-
this.pollData()
81+
this.pollData(true)
8282
}
8383

8484
componentWillUnmount() {
@@ -231,9 +231,9 @@ class ReplicaDetailsPage extends React.Component<Props, State> {
231231
window.location.href = `/#/replica/executions/${ReplicaStore.replicaDetails ? ReplicaStore.replicaDetails.id : ''}`
232232
}
233233

234-
pollData() {
235-
ReplicaStore.getReplicaExecutions(this.props.match.params.id).then(() => {
236-
this.pollTimeout = setTimeout(() => { this.pollData() }, requestPollTimeout)
234+
pollData(showLoading: boolean) {
235+
ReplicaStore.getReplicaExecutions(this.props.match.params.id, showLoading).then(() => {
236+
this.pollTimeout = setTimeout(() => { this.pollData(false) }, requestPollTimeout)
237237
})
238238
}
239239

@@ -264,6 +264,7 @@ class ReplicaDetailsPage extends React.Component<Props, State> {
264264
endpoints={EndpointStore.endpoints}
265265
scheduleStore={ScheduleStore}
266266
detailsLoading={ReplicaStore.detailsLoading || EndpointStore.loading}
267+
executionsLoading={ReplicaStore.executionsLoading}
267268
page={this.props.match.params.page || ''}
268269
onCancelExecutionClick={execution => { this.handleCancelExecutionClick(execution) }}
269270
onDeleteExecutionClick={execution => { this.handleDeleteExecutionClick(execution) }}

src/stores/ReplicaStore.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ReplicaStoreUtils {
2727
if (replicaDetails.executions) {
2828
return {
2929
...replicaDetails,
30-
executions: [...replicaDetails.executions, execution],
30+
executions: [...replicaDetails.executions.filter(e => e.id !== execution.id), execution],
3131
}
3232
}
3333

@@ -44,6 +44,7 @@ class ReplicaStore {
4444
@observable loading: boolean = true
4545
@observable backgroundLoading: boolean = false
4646
@observable detailsLoading: boolean = true
47+
@observable executionsLoading: boolean = false
4748

4849
replicasLoaded: boolean = false
4950

@@ -65,7 +66,9 @@ class ReplicaStore {
6566
})
6667
}
6768

68-
@action getReplicaExecutions(replicaId: string): Promise<void> {
69+
@action getReplicaExecutions(replicaId: string, showLoading: boolean = false): Promise<void> {
70+
if (showLoading) this.executionsLoading = true
71+
6972
return ReplicaSource.getReplicaExecutions(replicaId).then(executions => {
7073
let replica = this.replicas.find(replica => replica.id === replicaId)
7174

@@ -79,7 +82,9 @@ class ReplicaStore {
7982
executions,
8083
}
8184
}
82-
})
85+
86+
this.executionsLoading = false
87+
}).catch(() => { this.executionsLoading = false })
8388
}
8489

8590
@action getReplica(replicaId: string): Promise<void> {

0 commit comments

Comments
 (0)