SessionForwards
parent
7a8cc1b36e
commit
6463b1acb3
|
@ -13,3 +13,21 @@ export function loadServerSessions() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function loadSessionForwards(sessionId) {
|
||||||
|
return async function (dispatch) {
|
||||||
|
try {
|
||||||
|
dispatch({ type: types.LOAD_SESSION_FORWARDS_STARTED, id: sessionId });
|
||||||
|
const data = await dispatch(
|
||||||
|
sendHttpRequest(api.getSessionForwards(sessionId))
|
||||||
|
);
|
||||||
|
dispatch({
|
||||||
|
type: types.LOAD_SESSION_FORWARDS_SUCCESS,
|
||||||
|
payload: data,
|
||||||
|
id: sessionId
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -1,2 +1,5 @@
|
||||||
export const LOAD_SERVER_SESSIONS_STARTED = "LOAD_SERVER_SESSIONS_STARTED";
|
export const LOAD_SERVER_SESSIONS_STARTED = "LOAD_SERVER_SESSIONS_STARTED";
|
||||||
export const LOAD_SERVER_SESSIONS_SUCCESS = "LOAD_SERVER_SESSIONS_SUCCESS";
|
export const LOAD_SERVER_SESSIONS_SUCCESS = "LOAD_SERVER_SESSIONS_SUCCESS";
|
||||||
|
|
||||||
|
export const LOAD_SESSION_FORWARDS_STARTED = "LOAD_SESSION_FORWARDS_STARTED";
|
||||||
|
export const LOAD_SESSION_FORWARDS_SUCCESS = "LOAD_SESSION_FORWARDS_SUCCESS";
|
||||||
|
|
|
@ -2,7 +2,10 @@ import { get } from "../../api/axiosApi";
|
||||||
const baseUrl = `${process.env.REVERSE_PROXY_API_URL}/server`;
|
const baseUrl = `${process.env.REVERSE_PROXY_API_URL}/server`;
|
||||||
|
|
||||||
const getServerSessions = () => get(`${baseUrl}/sessions`);
|
const getServerSessions = () => get(`${baseUrl}/sessions`);
|
||||||
|
const getSessionForwards = (sessionId) =>
|
||||||
|
get(`${baseUrl}/session-forwards/${sessionId}`);
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
getServerSessions
|
getServerSessions,
|
||||||
|
getSessionForwards
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,30 +3,45 @@ import { connect } from "react-redux";
|
||||||
import { bindActionCreators } from "redux";
|
import { bindActionCreators } from "redux";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import SessionListComponent from "./SessionListComponent";
|
import SessionListComponent from "./SessionListComponent";
|
||||||
import { loadServerSessions } from "../actionCreators";
|
import { loadServerSessions, loadSessionForwards } from "../actionCreators";
|
||||||
|
|
||||||
const SessionContainer = ({ actions, sessions }) => {
|
const SessionContainer = ({ actions, sessions, forwards }) => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
actions.loadServerSessions();
|
actions.loadServerSessions();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return <SessionListComponent sessions={sessions} />;
|
const handleToggle = (sessionId) => (_, expanded) => {
|
||||||
|
if (expanded) actions.loadSessionForwards(sessionId);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SessionListComponent
|
||||||
|
sessions={sessions}
|
||||||
|
handleToggle={handleToggle}
|
||||||
|
forwards={forwards}
|
||||||
|
/>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
SessionContainer.propTypes = {
|
SessionContainer.propTypes = {
|
||||||
actions: PropTypes.object.isRequired,
|
actions: PropTypes.object.isRequired,
|
||||||
sessions: PropTypes.array.isRequired
|
sessions: PropTypes.array.isRequired,
|
||||||
|
forwards: PropTypes.object.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
function mapStateToProps(state) {
|
function mapStateToProps(state) {
|
||||||
return {
|
return {
|
||||||
sessions: state.sessions
|
sessions: state.sessions,
|
||||||
|
forwards: state.forwards
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function mapDispatchToProps(dispatch) {
|
function mapDispatchToProps(dispatch) {
|
||||||
return {
|
return {
|
||||||
actions: bindActionCreators({ loadServerSessions }, dispatch)
|
actions: bindActionCreators(
|
||||||
|
{ loadServerSessions, loadSessionForwards },
|
||||||
|
dispatch
|
||||||
|
)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import TableContainer from "@material-ui/core/TableContainer";
|
||||||
import TableHead from "@material-ui/core/TableHead";
|
import TableHead from "@material-ui/core/TableHead";
|
||||||
import TableRow from "@material-ui/core/TableRow";
|
import TableRow from "@material-ui/core/TableRow";
|
||||||
import Paper from "@material-ui/core/Paper";
|
import Paper from "@material-ui/core/Paper";
|
||||||
|
import Spinner from "../../../components/common/Spinner";
|
||||||
|
|
||||||
const StyledTableCell = withStyles((theme) => ({
|
const StyledTableCell = withStyles((theme) => ({
|
||||||
head: {
|
head: {
|
||||||
|
@ -27,28 +28,19 @@ const StyledTableRow = withStyles((theme) => ({
|
||||||
}
|
}
|
||||||
}))(TableRow);
|
}))(TableRow);
|
||||||
|
|
||||||
function createData(name, calories, fat, carbs, protein) {
|
|
||||||
return { name, calories, fat, carbs, protein };
|
|
||||||
}
|
|
||||||
|
|
||||||
const rows = [
|
|
||||||
createData("Frozen yoghurt", 159, 6.0, 24, 4.0),
|
|
||||||
createData("Ice cream sandwich", 237, 9.0, 37, 4.3),
|
|
||||||
createData("Eclair", 262, 16.0, 24, 6.0),
|
|
||||||
createData("Cupcake", 305, 3.7, 67, 4.3),
|
|
||||||
createData("Gingerbread", 356, 16.0, 49, 3.9)
|
|
||||||
];
|
|
||||||
|
|
||||||
const useStyles = makeStyles({
|
const useStyles = makeStyles({
|
||||||
table: {
|
table: {
|
||||||
minWidth: 700
|
minWidth: 700
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const SessionDetailsComponent = () => {
|
const SessionDetailsComponent = ({ forwards }) => {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
|
|
||||||
return (
|
return !forwards || forwards.loading ? (
|
||||||
|
<Spinner />
|
||||||
|
) : (
|
||||||
|
forwards.loaded && (
|
||||||
<TableContainer component={Paper}>
|
<TableContainer component={Paper}>
|
||||||
<Table
|
<Table
|
||||||
className={classes.table}
|
className={classes.table}
|
||||||
|
@ -57,31 +49,28 @@ const SessionDetailsComponent = () => {
|
||||||
>
|
>
|
||||||
<TableHead>
|
<TableHead>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<StyledTableCell>Dessert (100g serving)</StyledTableCell>
|
<StyledTableCell />
|
||||||
<StyledTableCell align="right">Calories</StyledTableCell>
|
<StyledTableCell>From</StyledTableCell>
|
||||||
<StyledTableCell align="right">Fat (g)</StyledTableCell>
|
<StyledTableCell>To</StyledTableCell>
|
||||||
<StyledTableCell align="right">Carbs (g)</StyledTableCell>
|
|
||||||
<StyledTableCell align="right">Protein (g)</StyledTableCell>
|
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHead>
|
</TableHead>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{rows.map((row) => (
|
{forwards.map((row) => (
|
||||||
<StyledTableRow key={row.name}>
|
<StyledTableRow key={row.forwardId}>
|
||||||
<StyledTableCell component="th" scope="row">
|
<StyledTableCell>{forwards.indexOf(row) + 1}</StyledTableCell>
|
||||||
{row.name}
|
<StyledTableCell>{row.from}</StyledTableCell>
|
||||||
</StyledTableCell>
|
<StyledTableCell>{row.to}</StyledTableCell>
|
||||||
<StyledTableCell align="right">{row.calories}</StyledTableCell>
|
|
||||||
<StyledTableCell align="right">{row.fat}</StyledTableCell>
|
|
||||||
<StyledTableCell align="right">{row.carbs}</StyledTableCell>
|
|
||||||
<StyledTableCell align="right">{row.protein}</StyledTableCell>
|
|
||||||
</StyledTableRow>
|
</StyledTableRow>
|
||||||
))}
|
))}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</TableContainer>
|
</TableContainer>
|
||||||
|
)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
SessionDetailsComponent.propTypes = {};
|
SessionDetailsComponent.propTypes = {
|
||||||
|
forwards: PropTypes.array
|
||||||
|
};
|
||||||
|
|
||||||
export default SessionDetailsComponent;
|
export default SessionDetailsComponent;
|
||||||
|
|
|
@ -20,7 +20,7 @@ const useStyles = makeStyles((theme) => ({
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const SessionListComponent = ({ sessions }) => {
|
const SessionListComponent = ({ sessions, handleToggle, forwards }) => {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
@ -33,7 +33,10 @@ const SessionListComponent = ({ sessions }) => {
|
||||||
sessions.loaded &&
|
sessions.loaded &&
|
||||||
sessions.map((session) => {
|
sessions.map((session) => {
|
||||||
return (
|
return (
|
||||||
<ExpansionPanel key={session.sessionId}>
|
<ExpansionPanel
|
||||||
|
key={session.sessionId}
|
||||||
|
onChange={handleToggle(session.sessionId)}
|
||||||
|
>
|
||||||
<ExpansionPanelSummary
|
<ExpansionPanelSummary
|
||||||
expandIcon={<ExpandMoreIcon />}
|
expandIcon={<ExpandMoreIcon />}
|
||||||
aria-controls={`panel-${session.sessionId}-content`}
|
aria-controls={`panel-${session.sessionId}-content`}
|
||||||
|
@ -42,7 +45,9 @@ const SessionListComponent = ({ sessions }) => {
|
||||||
<SessionSummary session={session} />
|
<SessionSummary session={session} />
|
||||||
</ExpansionPanelSummary>
|
</ExpansionPanelSummary>
|
||||||
<ExpansionPanelDetails>
|
<ExpansionPanelDetails>
|
||||||
<SessionDetailsComponent />
|
<SessionDetailsComponent
|
||||||
|
forwards={forwards[session.sessionId]}
|
||||||
|
/>
|
||||||
</ExpansionPanelDetails>
|
</ExpansionPanelDetails>
|
||||||
</ExpansionPanel>
|
</ExpansionPanel>
|
||||||
);
|
);
|
||||||
|
@ -53,7 +58,9 @@ const SessionListComponent = ({ sessions }) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
SessionListComponent.propTypes = {
|
SessionListComponent.propTypes = {
|
||||||
sessions: PropTypes.array.isRequired
|
sessions: PropTypes.array.isRequired,
|
||||||
|
handleToggle: PropTypes.func.isRequired,
|
||||||
|
forwards: PropTypes.object.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
export default SessionListComponent;
|
export default SessionListComponent;
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
import * as types from "./actionTypes";
|
|
||||||
import initialState from "../../redux/reducers/initialState";
|
|
||||||
|
|
||||||
export default function sessionsReducer(state = initialState.sessions, action) {
|
|
||||||
switch (action.type) {
|
|
||||||
case types.LOAD_SERVER_SESSIONS_STARTED:
|
|
||||||
return Object.assign([], { loading: true, loaded: false });
|
|
||||||
|
|
||||||
case types.LOAD_SERVER_SESSIONS_SUCCESS:
|
|
||||||
return Object.assign(action.payload, { loading: false, loaded: true });
|
|
||||||
|
|
||||||
default:
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
import * as types from "./actionTypes";
|
||||||
|
import initialState from "../../redux/reducers/initialState";
|
||||||
|
|
||||||
|
export function sessionsReducer(state = initialState.sessions, action) {
|
||||||
|
switch (action.type) {
|
||||||
|
case types.LOAD_SERVER_SESSIONS_STARTED:
|
||||||
|
return Object.assign([], { loading: true, loaded: false });
|
||||||
|
|
||||||
|
case types.LOAD_SERVER_SESSIONS_SUCCESS:
|
||||||
|
return Object.assign(action.payload, { loading: false, loaded: true });
|
||||||
|
|
||||||
|
default:
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function forwardsReducer(state = initialState.forwards, action) {
|
||||||
|
switch (action.type) {
|
||||||
|
case types.LOAD_SESSION_FORWARDS_STARTED:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
[action.id]: Object.assign([], { loading: true, loaded: false })
|
||||||
|
};
|
||||||
|
|
||||||
|
case types.LOAD_SESSION_FORWARDS_SUCCESS:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
[action.id]: Object.assign(action.payload, {
|
||||||
|
loading: false,
|
||||||
|
loaded: true
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
default:
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,11 +1,15 @@
|
||||||
import { combineReducers } from "redux";
|
import { combineReducers } from "redux";
|
||||||
import ajaxStatusReducer from "./ajaxStatusReducer";
|
import ajaxStatusReducer from "./ajaxStatusReducer";
|
||||||
import systemReducer from "../../features/system/reducer";
|
import systemReducer from "../../features/system/reducer";
|
||||||
import sessionsReducer from "../../features/session/reducer";
|
import {
|
||||||
|
sessionsReducer,
|
||||||
|
forwardsReducer
|
||||||
|
} from "../../features/session/reducers";
|
||||||
|
|
||||||
const rootReducer = combineReducers({
|
const rootReducer = combineReducers({
|
||||||
system: systemReducer,
|
system: systemReducer,
|
||||||
sessions: sessionsReducer,
|
sessions: sessionsReducer,
|
||||||
|
forwards: forwardsReducer,
|
||||||
ajaxCallsInProgress: ajaxStatusReducer
|
ajaxCallsInProgress: ajaxStatusReducer
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
export default {
|
export default {
|
||||||
system: {},
|
system: {},
|
||||||
sessions: Object.assign([], { loading: false, loaded: false }),
|
sessions: Object.assign([], { loading: false, loaded: false }),
|
||||||
|
forwards: {},
|
||||||
ajaxCallsInProgress: 0
|
ajaxCallsInProgress: 0
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue