-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sync bundle row state and bundle detail state #4246
Changes from 9 commits
352c1c2
a506324
82d43ac
2cb7248
06b5480
439548f
56e5a3a
1bb08bc
6a49d0c
81a79c7
39e9c45
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
import React from 'react'; | ||
import { withStyles } from '@material-ui/core/styles'; | ||
import { FINAL_BUNDLE_STATES } from '../../../../constants'; | ||
import { | ||
FINAL_BUNDLE_STATES, | ||
RUN_BUNDLE_STATES, | ||
UPLOADED_BUNDLE_STATES, | ||
MAKE_BUNDLE_STATES, | ||
OFFLINE_STATE, | ||
} from '../../../../constants'; | ||
import BundleStateBox from '../BundleStateBox'; | ||
import BundleFieldRow from './BundleFieldRow'; | ||
|
||
|
@@ -14,36 +20,45 @@ import BundleFieldRow from './BundleFieldRow'; | |
class BundleStateTable extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
const states = this.getStates(); | ||
this.state = { | ||
states, | ||
}; | ||
const bundleType = this.props.bundle.bundle_type.value; | ||
const states = this.getStates(bundleType); | ||
this.state = { states }; | ||
} | ||
|
||
getStates() { | ||
const bundleType = this.props.bundle.bundle_type.value; | ||
getStates(bundleType) { | ||
if (bundleType === 'run') { | ||
return ['created', 'staged', 'starting', 'preparing', 'running', 'finalizing', 'ready']; | ||
return RUN_BUNDLE_STATES; | ||
} | ||
if (bundleType === 'dataset') { | ||
return ['created', 'uploading', 'ready']; | ||
return UPLOADED_BUNDLE_STATES; | ||
} | ||
if (bundleType === 'make') { | ||
return ['created', 'making', 'ready']; | ||
return MAKE_BUNDLE_STATES; | ||
} | ||
return []; | ||
} | ||
|
||
showTime(time) { | ||
return time && time !== '<none>' && time !== '0s'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like we should be able to access the raw value rather than the rendered one to avoid these rather brittle comparisons, so we could test whether There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will update the |
||
} | ||
|
||
getTime(state) { | ||
const bundle = this.props.bundle; | ||
let time; | ||
if (state === 'preparing') { | ||
time = bundle.time_preparing?.value; | ||
} else if (state === 'running') { | ||
time = bundle.time_running?.value || bundle.time?.value; | ||
const { showTime } = this; | ||
const { bundle } = this.props; | ||
const timePreparing = bundle.time_preparing?.value; | ||
const timeRunning = bundle.time_running?.value; | ||
const time = bundle.time?.value; | ||
|
||
if (state === 'preparing' && showTime(timePreparing)) { | ||
return timePreparing; | ||
} | ||
if (time && time !== '0s') { | ||
return time; | ||
if (state === 'running') { | ||
if (showTime(timeRunning)) { | ||
return timeRunning; | ||
} | ||
if (showTime(time)) { | ||
return time; | ||
} | ||
} | ||
} | ||
|
||
|
@@ -53,8 +68,9 @@ class BundleStateTable extends React.Component { | |
const stateDetails = bundle.state_details?.value; | ||
const currentState = bundle.state.value; | ||
const inFinalState = FINAL_BUNDLE_STATES.includes(currentState); | ||
const inOfflineState = currentState === OFFLINE_STATE; | ||
|
||
if (inFinalState) { | ||
if (inFinalState || inOfflineState) { | ||
return ( | ||
<BundleFieldRow | ||
label='State' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only is called once, so why not just inline?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like wrapping the logic in a named function makes it easier to figure out for someone else who might stumble across the code later.