diff --git a/src/features/forwards/options/actionCreators.js b/src/features/forwards/options/actionCreators.js new file mode 100644 index 0000000..bb53843 --- /dev/null +++ b/src/features/forwards/options/actionCreators.js @@ -0,0 +1,24 @@ +import * as types from "./actionTypes"; +import api from "./api"; +import { sendHttpRequest } from "../../../redux/actions/httpActions"; + +export function loadForwardOptions(optionId) { + return async function(dispatch, getState) { + try { + const options = getState().options[optionId]; + if (options && (options.loading || options.loaded)) return; + + dispatch({ type: types.LOAD_FORWARD_OPTIONS_STARTED, id: optionId }); + const data = await dispatch( + sendHttpRequest(api.getForwardOptions(optionId)) + ); + dispatch({ + type: types.LOAD_FORWARD_OPTIONS_SUCCESS, + payload: data, + id: optionId + }); + } catch (error) { + throw error; + } + }; +} diff --git a/src/features/forwards/options/actionTypes.js b/src/features/forwards/options/actionTypes.js new file mode 100644 index 0000000..f6e0d27 --- /dev/null +++ b/src/features/forwards/options/actionTypes.js @@ -0,0 +1,2 @@ +export const LOAD_FORWARD_OPTIONS_STARTED = "LOAD_FORWARD_OPTIONS_STARTED"; +export const LOAD_FORWARD_OPTIONS_SUCCESS = "LOAD_FORWARD_OPTIONS_SUCCESS"; diff --git a/src/features/forwards/options/api.js b/src/features/forwards/options/api.js new file mode 100644 index 0000000..677307a --- /dev/null +++ b/src/features/forwards/options/api.js @@ -0,0 +1,9 @@ +import { get } from "../../../api/axiosApi"; +const baseUrl = `${process.env.REVERSE_PROXY_API_URL}/server`; + +const getForwardOptions = optionId => + get(`${baseUrl}/forward-options/${optionId}`); + +export default { + getForwardOptions +}; diff --git a/src/features/forwards/options/components/advanced/ForwardOptionsAdvancedView.js b/src/features/forwards/options/components/advanced/ForwardOptionsAdvancedView.js new file mode 100644 index 0000000..2709b68 --- /dev/null +++ b/src/features/forwards/options/components/advanced/ForwardOptionsAdvancedView.js @@ -0,0 +1 @@ +//ForwardOptions diff --git a/src/features/session/components/ForwardOptionsComponent.js b/src/features/forwards/options/components/simple/ForwardOptionsComponent.js similarity index 93% rename from src/features/session/components/ForwardOptionsComponent.js rename to src/features/forwards/options/components/simple/ForwardOptionsComponent.js index 9daf883..659f5d8 100644 --- a/src/features/session/components/ForwardOptionsComponent.js +++ b/src/features/forwards/options/components/simple/ForwardOptionsComponent.js @@ -11,12 +11,12 @@ import { Tooltip } from "@material-ui/core"; import { useTranslation } from "react-i18next"; -import styles from "../../../components/common/styles/tableStyles"; +import styles from "../../../../../components/common/styles/tableStyles"; import { StyledTableCell, StyledTableRow -} from "../../../components/common/MaterialTable"; -import ActiveIcon from "../../../components/common/ActiveIcon"; +} from "../../../../../components/common/MaterialTable"; +import ActiveIcon from "../../../../../components/common/ActiveIcon"; import Typography from "@material-ui/core/Typography"; const useStyles = makeStyles(styles); diff --git a/src/features/session/components/ForwardOptionsContainer.js b/src/features/forwards/options/components/simple/ForwardOptionsContainer.js similarity index 94% rename from src/features/session/components/ForwardOptionsContainer.js rename to src/features/forwards/options/components/simple/ForwardOptionsContainer.js index 385bdbc..698bdb3 100644 --- a/src/features/session/components/ForwardOptionsContainer.js +++ b/src/features/forwards/options/components/simple/ForwardOptionsContainer.js @@ -2,7 +2,7 @@ import React, { useEffect } from "react"; import { connect } from "react-redux"; import { bindActionCreators } from "redux"; import PropTypes from "prop-types"; -import { loadForwardOptions } from "../actionCreators"; +import { loadForwardOptions } from "../../actionCreators"; import ForwardOptionsComponent from "./ForwardOptionsComponent"; const ForwardOptionsContainer = ({ actions, forward, options }) => { diff --git a/src/features/session/components/ForwardOptionsDialog.js b/src/features/forwards/options/components/simple/ForwardOptionsDialog.js similarity index 100% rename from src/features/session/components/ForwardOptionsDialog.js rename to src/features/forwards/options/components/simple/ForwardOptionsDialog.js diff --git a/src/features/forwards/options/reducers.js b/src/features/forwards/options/reducers.js new file mode 100644 index 0000000..c9d5552 --- /dev/null +++ b/src/features/forwards/options/reducers.js @@ -0,0 +1,25 @@ +import * as types from "./actionTypes"; +import initialState from "../../../redux/reducers/initialState"; + +export function optionsReducer(state = initialState.options, action) { + switch (action.type) { + case types.LOAD_FORWARD_OPTIONS_STARTED: + return { + ...state, + [action.id]: { loading: true, loaded: false } + }; + + case types.LOAD_FORWARD_OPTIONS_SUCCESS: + return { + ...state, + [action.id]: { + ...action.payload, + loading: false, + loaded: true + } + }; + + default: + return state; + } +} diff --git a/src/features/server/components/ActiveSessionContainer.js b/src/features/server/components/ActiveSessionContainer.js index 1ace773..735ce3e 100644 --- a/src/features/server/components/ActiveSessionContainer.js +++ b/src/features/server/components/ActiveSessionContainer.js @@ -6,7 +6,7 @@ import { loadActiveSession } from "../actionCreators"; import { loadSessionForwards } from "../../session/actionCreators"; import { getActiveForwards } from "../selectors"; import ActiveSessionComponent from "./ActiveSessionComponent"; -import ForwardOptionsDialog from "../../session/components/ForwardOptionsDialog"; +import ForwardOptionsDialog from "../../forwards/options/components/simple/ForwardOptionsDialog"; const ActiveSessionContainer = ({ actions, session, forwards, domain }) => { const [expanded, setExpanded] = useState(false); diff --git a/src/features/session/actionCreators.js b/src/features/session/actionCreators.js index 783a71d..d79b66c 100644 --- a/src/features/session/actionCreators.js +++ b/src/features/session/actionCreators.js @@ -34,24 +34,3 @@ export function loadSessionForwards(sessionId) { } }; } - -export function loadForwardOptions(optionId) { - return async function(dispatch, getState) { - try { - const options = getState().options[optionId]; - if (options && (options.loading || options.loaded)) return; - - dispatch({ type: types.LOAD_FORWARD_OPTIONS_STARTED, id: optionId }); - const data = await dispatch( - sendHttpRequest(api.getForwardOptions(optionId)) - ); - dispatch({ - type: types.LOAD_FORWARD_OPTIONS_SUCCESS, - payload: data, - id: optionId - }); - } catch (error) { - throw error; - } - }; -} diff --git a/src/features/session/actionTypes.js b/src/features/session/actionTypes.js index 023a04f..ad67e26 100644 --- a/src/features/session/actionTypes.js +++ b/src/features/session/actionTypes.js @@ -3,6 +3,3 @@ 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"; - -export const LOAD_FORWARD_OPTIONS_STARTED = "LOAD_FORWARD_OPTIONS_STARTED"; -export const LOAD_FORWARD_OPTIONS_SUCCESS = "LOAD_FORWARD_OPTIONS_SUCCESS"; diff --git a/src/features/session/api.js b/src/features/session/api.js index de95b3f..3a55cb2 100644 --- a/src/features/session/api.js +++ b/src/features/session/api.js @@ -5,11 +5,7 @@ const getServerSessions = () => get(`${baseUrl}/sessions`); const getSessionForwards = sessionId => get(`${baseUrl}/session-forwards/${sessionId}`); -const getForwardOptions = optionId => - get(`${baseUrl}/forward-options/${optionId}`); - export default { getServerSessions, - getSessionForwards, - getForwardOptions + getSessionForwards }; diff --git a/src/features/session/components/SessionContainer.js b/src/features/session/components/SessionContainer.js index ffa0781..b768651 100644 --- a/src/features/session/components/SessionContainer.js +++ b/src/features/session/components/SessionContainer.js @@ -3,7 +3,7 @@ import { connect } from "react-redux"; import { bindActionCreators } from "redux"; import PropTypes from "prop-types"; import SessionListComponent from "./SessionListComponent"; -import ForwardOptionsDialog from "./ForwardOptionsDialog"; +import ForwardOptionsDialog from "../../forwards/options/components/simple/ForwardOptionsDialog"; import { loadServerSessions, loadSessionForwards } from "../actionCreators"; const SessionContainer = ({ actions, sessions, forwards }) => { diff --git a/src/features/session/reducers.js b/src/features/session/reducers.js index 4c1a1e0..0c22bc4 100644 --- a/src/features/session/reducers.js +++ b/src/features/session/reducers.js @@ -35,26 +35,3 @@ export function forwardsReducer(state = initialState.forwards, action) { return state; } } - -export function optionsReducer(state = initialState.options, action) { - switch (action.type) { - case types.LOAD_FORWARD_OPTIONS_STARTED: - return { - ...state, - [action.id]: { loading: true, loaded: false } - }; - - case types.LOAD_FORWARD_OPTIONS_SUCCESS: - return { - ...state, - [action.id]: { - ...action.payload, - loading: false, - loaded: true - } - }; - - default: - return state; - } -} diff --git a/src/redux/reducers/index.js b/src/redux/reducers/index.js index d65cf26..280a9cf 100644 --- a/src/redux/reducers/index.js +++ b/src/redux/reducers/index.js @@ -3,9 +3,9 @@ import ajaxStatusReducer from "./ajaxStatusReducer"; import serverReducer from "../../features/server/reducer"; import { sessionsReducer, - forwardsReducer, - optionsReducer + forwardsReducer } from "../../features/session/reducers"; +import { optionsReducer } from "../../features/forwards/options/reducers"; import releaseNotesReducer from "../../features/releaseNotes/reducer"; import frontendSessionReducer from "../../features/frontendSession/reducer"; import snackbarReducer from "../../features/snackbar/reducer";