From dcc91dbf3adca51f5862da1098397c447be379cc Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Tue, 19 May 2020 01:33:52 +0300 Subject: [PATCH] forwards table in active session card --- public/locales/ro/translations.json | 2 +- .../components/ActiveSessionComponent.js | 39 ++++++++----- .../components/ActiveSessionContainer.js | 55 +++++++++++++++++-- src/features/server/selectors.js | 4 ++ .../components/SessionForwardsComponent.js | 26 ++++++--- .../components/SessionListComponent.js | 1 + 6 files changed, 99 insertions(+), 28 deletions(-) create mode 100644 src/features/server/selectors.js diff --git a/public/locales/ro/translations.json b/public/locales/ro/translations.json index fd6305e..a8a19f7 100644 --- a/public/locales/ro/translations.json +++ b/public/locales/ro/translations.json @@ -44,6 +44,6 @@ }, "Server": { "ActiveSession": "Sesiune activă", - "ActiveSessionSubtitle": "Extindeţi pentru a vedea redirecţionările" + "ActiveSessionSubtitle": "Extindeţi pentru a vedea redirectările" } } diff --git a/src/features/server/components/ActiveSessionComponent.js b/src/features/server/components/ActiveSessionComponent.js index bfcf1e9..edc81a8 100644 --- a/src/features/server/components/ActiveSessionComponent.js +++ b/src/features/server/components/ActiveSessionComponent.js @@ -9,23 +9,25 @@ import CardActions from "@material-ui/core/CardActions"; import Collapse from "@material-ui/core/Collapse"; import Avatar from "@material-ui/core/Avatar"; import IconButton from "@material-ui/core/IconButton"; -import Typography from "@material-ui/core/Typography"; import ExpandMoreIcon from "@material-ui/icons/ExpandMore"; import SurroundSoundRoundedIcon from "@material-ui/icons/SurroundSoundRounded"; import ActiveSessionSummary from "./ActiveSessionSummary"; import styles from "../../../components/common/styles/expandableCardStyles"; import { useTranslation } from "react-i18next"; +import SessionForwardsComponent from "../../session/components/SessionForwardsComponent"; +import Spinner from "../../../components/common/Spinner"; const useStyles = makeStyles(styles); -const ActiveSessionComponent = ({ session }) => { +const ActiveSessionComponent = ({ + session, + expanded, + handleExpandClick, + forwards, + openOptionsDialog +}) => { const classes = useStyles(); const { t } = useTranslation(); - const [expanded, setExpanded] = React.useState(false); - - const handleExpandClick = () => { - setExpanded(!expanded); - }; return ( @@ -56,11 +58,18 @@ const ActiveSessionComponent = ({ session }) => { - Method: - - Tabel ca cel de pana acum cu redirectarile. From va fi link si la - click va deschide in tab nou aplicatia - + {!forwards || forwards.loading ? ( + + ) : ( + forwards.loaded && ( + + ) + )} @@ -68,7 +77,11 @@ const ActiveSessionComponent = ({ session }) => { }; ActiveSessionComponent.propTypes = { - session: PropTypes.object.isRequired + session: PropTypes.object.isRequired, + expanded: PropTypes.bool.isRequired, + handleExpandClick: PropTypes.func.isRequired, + forwards: PropTypes.array, + openOptionsDialog: PropTypes.func.isRequired }; export default ActiveSessionComponent; diff --git a/src/features/server/components/ActiveSessionContainer.js b/src/features/server/components/ActiveSessionContainer.js index 2e4794e..fcd3060 100644 --- a/src/features/server/components/ActiveSessionContainer.js +++ b/src/features/server/components/ActiveSessionContainer.js @@ -1,32 +1,75 @@ -import React, { useEffect } from "react"; +import React, { useEffect, useState } from "react"; import { connect } from "react-redux"; import { bindActionCreators } from "redux"; import PropTypes from "prop-types"; import { loadActiveSession } from "../actionCreators"; +import { loadSessionForwards } from "../../session/actionCreators"; +import { getActiveForwards } from "../selectors"; import ActiveSessionComponent from "./ActiveSessionComponent"; +import ForwardOptionsDialog from "../../session/components/ForwardOptionsDialog"; + +const ActiveSessionContainer = ({ actions, session, forwards }) => { + const [expanded, setExpanded] = useState(false); + const [optionsDialogOpen, setOptionsDialogOpen] = useState(false); + const [forwardOptions, setForwardOptions] = useState(null); -const ActiveSessionContainer = ({ actions, session }) => { useEffect(() => { actions.loadActiveSession(); }, []); - return ; + const handleExpandClick = () => { + const expand = !expanded; + setExpanded(expand); + if (expand) actions.loadSessionForwards(session.sessionId); + }; + + const handleOptionsDialogOpen = (options) => () => { + setForwardOptions(options); + setOptionsDialogOpen(true); + }; + + const handleOptionsDialogClose = () => { + setOptionsDialogOpen(false); + setForwardOptions(null); + }; + + return ( + <> + + + + ); }; ActiveSessionContainer.propTypes = { actions: PropTypes.object.isRequired, - session: PropTypes.object.isRequired + session: PropTypes.object.isRequired, + forwards: PropTypes.array }; function mapStateToProps(state) { return { - session: state.server.activeSession + session: state.server.activeSession, + forwards: getActiveForwards(state) }; } function mapDispatchToProps(dispatch) { return { - actions: bindActionCreators({ loadActiveSession }, dispatch) + actions: bindActionCreators( + { loadActiveSession, loadSessionForwards }, + dispatch + ) }; } diff --git a/src/features/server/selectors.js b/src/features/server/selectors.js new file mode 100644 index 0000000..818422c --- /dev/null +++ b/src/features/server/selectors.js @@ -0,0 +1,4 @@ +export const getActiveForwards = (state) => { + const { sessionId } = state.server.activeSession; + return state.forwards[sessionId]; +}; diff --git a/src/features/session/components/SessionForwardsComponent.js b/src/features/session/components/SessionForwardsComponent.js index 0e2b0c0..42c6dd7 100644 --- a/src/features/session/components/SessionForwardsComponent.js +++ b/src/features/session/components/SessionForwardsComponent.js @@ -23,7 +23,12 @@ import { const useStyles = makeStyles(styles); -const SessionForwardsComponent = ({ session, forwards, openOptionsDialog }) => { +const SessionForwardsComponent = ({ + session, + forwards, + openOptionsDialog, + showSessionInfo +}) => { const classes = useStyles(); const { t } = useTranslation(); @@ -91,12 +96,16 @@ const SessionForwardsComponent = ({ session, forwards, openOptionsDialog }) => { ) )} - -
-
- - - + {showSessionInfo && ( + <> + +
+
+ + + + + )} ); }; @@ -104,7 +113,8 @@ const SessionForwardsComponent = ({ session, forwards, openOptionsDialog }) => { SessionForwardsComponent.propTypes = { session: PropTypes.object.isRequired, forwards: PropTypes.array, - openOptionsDialog: PropTypes.func.isRequired + openOptionsDialog: PropTypes.func.isRequired, + showSessionInfo: PropTypes.bool.isRequired }; export default SessionForwardsComponent; diff --git a/src/features/session/components/SessionListComponent.js b/src/features/session/components/SessionListComponent.js index d4e603c..3b4ffad 100644 --- a/src/features/session/components/SessionListComponent.js +++ b/src/features/session/components/SessionListComponent.js @@ -47,6 +47,7 @@ const SessionListComponent = ({ session={session} forwards={forwards[session.sessionId]} openOptionsDialog={openOptionsDialog} + showSessionInfo={true} />