From d15713079b2c4134e8bd7483428f8c1660daa168 Mon Sep 17 00:00:00 2001 From: Ismael Bejarano Date: Tue, 29 Oct 2024 20:38:44 -0300 Subject: [PATCH] Fix channel status --- assets/css/_global.scss | 7 ++++++ assets/js/actions/channel.js | 12 +++++----- assets/js/api.js | 8 +++---- .../js/components/channels/ChannelIndex.jsx | 22 +++++-------------- .../js/components/channels/ChannelPause.jsx | 6 ++--- .../channels/DownChannelsStatus.jsx | 15 ++++++++----- locales/template/translation.json | 4 ++-- 7 files changed, 36 insertions(+), 38 deletions(-) diff --git a/assets/css/_global.scss b/assets/css/_global.scss index 5bc336113..ecbe1a04f 100644 --- a/assets/css/_global.scss +++ b/assets/css/_global.scss @@ -833,6 +833,13 @@ i.survey-status { height: 12px; } +.channel-paused { + display: block; + color: var(--reference-color12); + width: 12px; + height: 12px; +} + .wizard-content { > div { min-height: 110vh; diff --git a/assets/js/actions/channel.js b/assets/js/actions/channel.js index c5e3c38e3..ed21efa73 100644 --- a/assets/js/actions/channel.js +++ b/assets/js/actions/channel.js @@ -130,14 +130,14 @@ export const deletePattern = (index: number) => (dispatch: Function, getState: ( dispatch(removePattern(index)) } -export const pause = (channel: Channel) => (dispatch) => { +export const pause = (id: number) => (dispatch: Function) => { return api - .pauseChannel(channel) - .then((response) => dispatch(fetchChannel(channel.id))) + .pauseChannel(id) + .then((response) => dispatch(fetchChannel(id))) } -export const unpause = (channel: Channel) => (dispatch) => { +export const unpause = (id: number) => (dispatch: Function) => { return api - .unpauseChannel(channel) - .then((response) => dispatch(fetchChannel(channel.id))) + .unpauseChannel(id) + .then((response) => dispatch(fetchChannel(id))) } diff --git a/assets/js/api.js b/assets/js/api.js index 5713ab74b..25994da3e 100644 --- a/assets/js/api.js +++ b/assets/js/api.js @@ -368,12 +368,12 @@ export const createChannel = (provider, baseUrl, channel) => { return apiPostJSON(`channels`, channelSchema, { provider, baseUrl, channel }) } -export const pauseChannel = (channel) => { - return apiPostJSON(`channels/${channel.id}/pause`, channelSchema) +export const pauseChannel = (channelId) => { + return apiPostJSON(`channels/${channelId}/pause`) } -export const unpauseChannel = (channel) => { - return apiPostJSON(`channels/${channel.id}/unpause`, channelSchema) +export const unpauseChannel = (channelId) => { + return apiPostJSON(`channels/${channelId}/unpause`) } export const updateQuestionnaire = (projectId, questionnaire) => { diff --git a/assets/js/components/channels/ChannelIndex.jsx b/assets/js/components/channels/ChannelIndex.jsx index 26cb3b602..9feadcf31 100644 --- a/assets/js/components/channels/ChannelIndex.jsx +++ b/assets/js/components/channels/ChannelIndex.jsx @@ -18,7 +18,6 @@ import { ConfirmationModal, PagingFooter, channelFriendlyName, - Tooltip, } from "../ui" import { Preloader } from "react-materialize" import { config } from "../../config" @@ -230,21 +229,6 @@ class ChannelIndex extends Component { ) } - - const pauseIconForChannel = (channel) => { - const { statusInfo } = channel - console.log({statusInfo, label: "1--------"}) - const { t } = this.props - return ( - - - this.pause(e, channel)}> - pause - - - - ) - } let providerUIs = [] config.verboice.forEach((_, index) => { @@ -327,8 +311,12 @@ class ChannelIndex extends Component { {`${channel.provider}${channelFriendlyName(channel)}`} - {status == "down" || status == "error" || status == "paused" ? ( + {status == "down" || status == "error" ? ( + ) : status == "paused" ? ( + + pause + ) : null} diff --git a/assets/js/components/channels/ChannelPause.jsx b/assets/js/components/channels/ChannelPause.jsx index 87d3875bc..99073aeca 100644 --- a/assets/js/components/channels/ChannelPause.jsx +++ b/assets/js/components/channels/ChannelPause.jsx @@ -1,4 +1,4 @@ -import React, { PropTypes } from "react" +import { PropTypes } from "react" import { bindActionCreators } from "redux" import { connect } from "react-redux" import { translate } from "react-i18next" @@ -16,9 +16,9 @@ const ChannelPause = ({ channel, t, actions }) => { const pauseChannel = (channel, pause) => { console.log(`About to ${pause ? "pause" : "unpause"} channel ${channel.id}`) if (pause) { - actions.pause(channel) + actions.pause(channel.id) } else { - actions.unpause(channel) + actions.unpause(channel.id) } } diff --git a/assets/js/components/channels/DownChannelsStatus.jsx b/assets/js/components/channels/DownChannelsStatus.jsx index 16f79832b..e032de28c 100644 --- a/assets/js/components/channels/DownChannelsStatus.jsx +++ b/assets/js/components/channels/DownChannelsStatus.jsx @@ -1,6 +1,7 @@ import React, { PureComponent, PropTypes } from "react" import TimeAgo from "react-timeago" import { translate, Trans } from "react-i18next" +import every from "lodash/every" import map from "lodash/map" class DownChannelsStatus extends PureComponent { @@ -12,7 +13,9 @@ class DownChannelsStatus extends PureComponent { render() { const { channels, timestamp } = this.props const channelNames = map(channels, (channel) => channel.name) - return this.downChannelsDescription(channelNames, timestamp) + const paused = every(channels, (channel) => channel.statusInfo && channel.statusInfo.status == "paused") + const text = paused ? "paused" : "down" + return this.downChannelsDescription(channelNames, timestamp, text) } downChannelsFormatter(number, unit, suffix, date, defaultFormatter) { @@ -36,21 +39,21 @@ class DownChannelsStatus extends PureComponent { } } - downChannelsDescription(channelNames, timestamp) { + downChannelsDescription(channelNames, timestamp, text) { const names = channelNames.join(", ") if (channelNames.length > 1) { return ( - Channels {{ names }} down{" "} - + Channels {{ names }} {{text}}{" "} + {timestamp && } ) } else { const name = channelNames[0] return ( - Channel {{ name }} down{" "} - + Channel {{ name }} {{text}}{" "} + {timestamp && } ) } diff --git a/locales/template/translation.json b/locales/template/translation.json index 2048132d4..21ff7e9fe 100644 --- a/locales/template/translation.json +++ b/locales/template/translation.json @@ -79,9 +79,9 @@ "Changed description of {{surveyName}} survey": "", "Changes are still being saved. Please wait": "", "Channel": "", - "Channel <1><0>{{ name }} down<3>{\" \"} <5>": "Channel <1><0>{{ name }} down<3>{\" \"} <5>", + "Channel <1><0>{{ name }} <3>{{text}}<4>{\" \"} {timestamp && <6>}": "Channel <1><0>{{ name }} <3>{{text}}<4>{\" \"} {timestamp && <6>}", "Channels": "", - "Channels <1><0>{{ names }} down<3>{\" \"} <5>": "Channels <1><0>{{ names }} down<3>{\" \"} <5>", + "Channels <1><0>{{ names }} <3>{{text}}<4>{\" \"} {timestamp && <6>}": "Channels <1><0>{{ names }} <3>{{text}}<4>{\" \"} {timestamp && <6>}", "Checking this box will make the survey accept written numbers as valid numeric responses, like \"one\" or \"fifty five\". Written numbers are supported up to one hundred (100).": "", "Choose a key for each language": "", "Choose the data you want to be able to access through a public link": "",