Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-aranda committed Jan 4, 2022
1 parent d933f61 commit 9fcd820
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
12 changes: 2 additions & 10 deletions love/src/components/CSCSummary/CSCDetail/CSCDetail.container.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { getStreamData, getCSCHeartbeat, getCSCWithWarning, getServerTime } from
import CSCDetail from './CSCDetail';
import SubscriptionTableContainer from '../../GeneralPurpose/SubscriptionTable/SubscriptionTable.container';


export const schema = {
description: 'Displays the error code and message logs for a single CSC',
defaultSize: [12, 6],
Expand Down Expand Up @@ -52,17 +51,11 @@ export const schema = {
isPrivate: false,
default: false,
},
subscribeToStreamCallback: {
type: 'function',
description: 'Whether the component has a raw mode version',
isPrivate: true,
default: '() => {}',
},
_functionProps: {
type: 'array',
description: 'Array containing the props that are functions',
isPrivate: true,
default: ['subscribeToStreamCallback'],
default: [],
},
},
};
Expand All @@ -84,7 +77,7 @@ const CSCDetailContainer = ({
subscriptions,
}) => {
if (isRaw) {
return <SubscriptionTableContainer subscriptions={subscriptions}></SubscriptionTableContainer>;
return <SubscriptionTableContainer subscriptions={subscriptions} name={name} salindex={salindex} />;
}
return (
<CSCDetail
Expand Down Expand Up @@ -115,7 +108,6 @@ const mapDispatchToProps = (dispatch, ownProps) => {
subscriptions,
subscribeToStreams: () => {
subscriptions.forEach((s) => dispatch(addGroup(s)));
// ownProps.subscribeToStreamCallback(ownProps.name, ownProps.salindex);
},
unsubscribeToStreams: () => {
subscriptions.forEach((s) => dispatch(removeGroup(s)));
Expand Down
2 changes: 0 additions & 2 deletions love/src/components/CSCSummary/CSCDetail/CSCDetail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ export default class CSCDetail extends Component {
nLost = this.props.heartbeatData.lost;
if (this.props.heartbeatData.last_heartbeat_timestamp === -2) timeDiff = -2;
else if (this.props.heartbeatData.last_heartbeat_timestamp === -1) timeDiff = -1;
// else timeDiff = Math.ceil(new Date().getTime() / 1000 - this.props.heartbeatData.last_heartbeat_timestamp);
else timeDiff = Math.ceil(props.serverTime.tai * 1000 - this.props.heartbeatData.last_heartbeat_timestamp);
// console.log(new Date().getTime(), props.serverTime.tai * 1000, props.heartbeatData.last_heartbeat_timestamp);
heartbeatStatus = this.props.heartbeatData.lost > 0 || timeDiff < 0 ? 'alert' : 'ok';
}
if (props.hasHeartbeat === false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default class SubscriptionTable extends Component {
subscriptionsDict,
itemFilter: '',
topicFilter: '',
lastHeartbeat: {},
};
}

Expand All @@ -37,6 +38,15 @@ export default class SubscriptionTable extends Component {
this.props.unsubscribeToStreams(this.props.subscriptions);
};

componentDidUpdate = (prevProps) => {
if (prevProps.getStreamData !== this.props.getStreamData) {
const heartbeat = this.props.getStreamData('event-Heartbeat-0-stream');
if (heartbeat.csc === this.props.name && heartbeat.salindex === this.props.salindex) {
this.setState({ lastHeartbeat: heartbeat });
}
}
};

changeTopicFilter = (event) => {
this.setState({
topicFilter: event.target.value,
Expand All @@ -54,14 +64,8 @@ export default class SubscriptionTable extends Component {
getAccessor = (group) => {
if (Object.keys(this.props.accessors).includes(group)) return this.props.accessors[group];
if (group.startsWith('event-Heartbeat')) {
return (data) => {
const datum = typeof data === 'object' ? data : {};
const keys = Object.keys(datum).filter((value) => !value.startsWith('private_') && value !== 'priority');
const dict = {};
keys.forEach((key) => {
dict[key] = datum[key];
});
return dict;
return () => {
return this.state.lastHeartbeat;
};
}
if (group.startsWith('event')) {
Expand Down Expand Up @@ -115,7 +119,9 @@ export default class SubscriptionTable extends Component {

const [type, topic] = topicKey.split('-');
const groupKey = [type, cscKey, topic].join('-');
// console.log(groupKey);
const streamData = this.props.getStreamData(groupKey);
// console.log(streamData);
const accessor = this.getAccessor(groupKey);
const dict = accessor(streamData);
const dictKeys = Object.keys(dict);
Expand Down

0 comments on commit 9fcd820

Please sign in to comment.