diff --git a/src/components/table.js b/src/components/table.js index 9d593fe..1c1910d 100644 --- a/src/components/table.js +++ b/src/components/table.js @@ -85,10 +85,10 @@ class CustomTable extends Component { var labelContent = data[labelKey]; if (child.props.labelModifier) { - labelContent = child.props.labelModifier(labelContent); + labelContent = child.props.labelModifier(labelContent, data); } - cell.push( ); + cell.push( ); } if (child.props.dataIndex) { diff --git a/src/containers/simulators.js b/src/containers/simulators.js index 4c92992..76cc3e4 100644 --- a/src/containers/simulators.js +++ b/src/containers/simulators.js @@ -44,10 +44,13 @@ class Simulators extends Component { } static calculateState() { + const simulators = SimulatorStore.getState().sort((a, b) => { + return a.stateUpdatedAt < b.stateUpdatedAt; + }); + return { sessionToken: UserStore.getState().token, - simulators: SimulatorStore.getState(), - + simulators, modalSimulator: {}, deleteModal: false, @@ -162,6 +165,46 @@ class Simulators extends Component { } } + isSimulatorOutdated(simulator) { + const fiveMinutes = 5 * 60 * 1000; + + return Date.now() - new Date(simulator.stateUpdatedAt) > fiveMinutes; + } + + isSimulatorOnline(state) { + return state !== 'shutdown' && state !== 'unknown'; + } + + stateLabelStyle = (state, simulator) => { + if (this.isSimulatorOutdated(simulator)) { + return 'default'; + } + + if (this.isSimulatorOnline(state)) { + return 'success'; + } + + return 'danger'; + } + + stateLabelModifier = (state, simulator) => { + if (this.isSimulatorOutdated(simulator)) { + return 'unknown'; + } + + if (this.isSimulatorOnline(state)) { + return 'online'; + } + + return 'offline'; + } + + stateUpdateModifier = updatedAt => { + const date = new Date(updatedAt); + + return date.toLocaleString('de-DE'); + } + render() { const buttonStyle = { marginLeft: '10px' @@ -174,8 +217,8 @@ class Simulators extends Component { this.onSimulatorChecked(index, event)} width='30' /> - - + +