Skip to content

Commit

Permalink
Merge branch '#454' into #455
Browse files Browse the repository at this point in the history
# Conflicts:
#	js/components/snapshot/redux/dispatchActions.js
#	js/components/target/redux/dispatchActions.js
#	js/components/tracking/trackingModal.js
  • Loading branch information
Adriána Kohanová committed Nov 25, 2020
2 parents 36f49fe + 6187266 commit 83bdb85
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 171 deletions.
16 changes: 12 additions & 4 deletions js/components/projects/addProjectDetail/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Autocomplete } from '@material-ui/lab';
import { Button } from '../../common/Inputs/Button';
import { useDispatch, useSelector } from 'react-redux';
import { createProjectFromSnapshotDialog } from '../redux/dispatchActions';
import { manageSendTrackingActions } from '../../../reducers/tracking/dispatchActions';

const useStyles = makeStyles(theme => ({
body: {
Expand All @@ -34,6 +35,7 @@ export const AddProjectDetail = memo(({ handleCloseModal }) => {

const dispatch = useDispatch();
const targetId = useSelector(state => state.apiReducers.target_on);
const projectID = useSelector(state => state.projectReducers.currentProject.projectID);
const isProjectModalLoading = useSelector(state => state.projectReducers.isProjectModalLoading);

const [tags, setTags] = React.useState([]);
Expand Down Expand Up @@ -65,11 +67,17 @@ export const AddProjectDetail = memo(({ handleCloseModal }) => {
author: DJANGO_CONTEXT['pk'] || null,
tags: JSON.stringify(tags)
};
dispatch(createProjectFromSnapshotDialog(data)).catch(error => {
setState(() => {
throw error;

const oldProjectID = projectID;
dispatch(createProjectFromSnapshotDialog(data))
.then(() => {
dispatch(manageSendTrackingActions(oldProjectID, true));
})
.catch(error => {
setState(() => {
throw error;
});
});
});
}}
>
{({ submitForm, isSubmitting }) => (
Expand Down
6 changes: 4 additions & 2 deletions js/components/snapshot/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
sendTruckingActionsByProjectId,
appendAndSendTruckingActions
} from '../../../reducers/tracking/dispatchActions';
import { sendTrackingActionsByProjectId, manageSendTrackingActions } from '../../../reducers/tracking/dispatchActions';

export const getListOfSnapshots = () => (dispatch, getState) => {
const userID = DJANGO_CONTEXT['pk'] || null;
Expand Down Expand Up @@ -256,6 +257,7 @@ export const activateSnapshotDialog = (loggedInUserID = undefined, finallyShareS
const projectID = state.projectReducers.currentProject.projectID;
const currentSnapshotAuthor = state.projectReducers.currentSnapshot.author;

dispatch(manageSendTrackingActions());
dispatch(setDisableRedirect(finallyShareSnapshot));

if (!loggedInUserID && targetId) {
Expand All @@ -268,7 +270,7 @@ export const activateSnapshotDialog = (loggedInUserID = undefined, finallyShareS
};
dispatch(createProjectFromSnapshotDialog(data))
.then(() => {
dispatch(appendAndSendTruckingActions(null));
dispatch(manageSendTrackingActions(projectID, true));
dispatch(setOpenSnapshotSavingDialog(true));
})
.catch(error => {
Expand Down Expand Up @@ -361,7 +363,7 @@ export const saveAndShareSnapshot = (target = undefined) => (dispatch, getState)
const parent = null;
const session_project = projectID;

dispatch(sendTruckingActionsByProjectId(projectID, author));
dispatch(sendTrackingActionsByProjectId(projectID, author));

return dispatch(
createNewSnapshotWithoutStateModification({ title, description, type, author, parent, session_project })
Expand Down
2 changes: 1 addition & 1 deletion js/components/target/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const updateTarget = ({ target, setIsLoading, targetIdList, projectId, sn
.then(response => {
let promises = [];
if (!snapshotId) {
promises.push(dispatch(setTargetOn(response.data.target.id)));
promises.push(dispatch(setTargetOn(response.data.target.id, true)));
}
promises.push(
dispatch(
Expand Down
24 changes: 4 additions & 20 deletions js/components/tracking/trackingModal.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import React, { memo, useContext, useCallback, useEffect } from 'react';
import React, { memo, useCallback, useEffect } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import Modal from '../common/Modal';
import { Grid, makeStyles, IconButton, Tooltip } from '@material-ui/core';
import { Timeline, TimelineEvent } from 'react-event-timeline';
import { Check, Clear, Save, Restore, Close } from '@material-ui/icons';
import { Check, Clear, Close } from '@material-ui/icons';
import palette from '../../theme/palette';
import { Panel } from '../common';
import {
saveCurrentActionsList,
restoreCurrentActionsList,
setProjectTruckingActions
} from '../../reducers/tracking/dispatchActions';
import { NglContext } from '../nglView/nglProvider';
import { setProjectTrackingActions } from '../../reducers/tracking/dispatchActions';

const useStyles = makeStyles(theme => ({
customModal: {
Expand Down Expand Up @@ -41,14 +36,13 @@ const useStyles = makeStyles(theme => ({
export const TrackingModal = memo(({ openModal, onModalClose }) => {
const classes = useStyles();
const dispatch = useDispatch();
const { nglViewList } = useContext(NglContext);

const actionList = useSelector(state => state.trackingReducers.project_actions_list);
const orderedActionList = (actionList && actionList.sort((a, b) => a.timestamp - b.timestamp)) || [];

const loadAllActions = useCallback(() => {
if (openModal === true) {
dispatch(setProjectTruckingActions());
dispatch(setProjectTrackingActions());
}
}, [dispatch, openModal]);

Expand All @@ -62,16 +56,6 @@ export const TrackingModal = memo(({ openModal, onModalClose }) => {
}

const actions = [
<IconButton color={'inherit'} onClick={() => dispatch(saveCurrentActionsList())}>
<Tooltip title="Save">
<Save />
</Tooltip>
</IconButton>,
<IconButton color={'inherit'} onClick={() => dispatch(restoreCurrentActionsList(nglViewList))}>
<Tooltip title="Restore">
<Restore />
</Tooltip>
</IconButton>,
<IconButton color={'inherit'} onClick={() => onModalClose()}>
<Tooltip title="Close">
<Close />
Expand Down
4 changes: 2 additions & 2 deletions js/constants/constants.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const main_identifier = 'x';
const sub_identifier = '_';
const count_send_truck_actions = 5;
const count_send_track_actions = 5;

export const CONSTANTS = {
MAIN_IDENTIFIER: main_identifier,
SUB_IDENTIFIER: sub_identifier,
COUNT_SEND_TRUCK_ACTIONS: count_send_truck_actions
COUNT_SEND_TRUCK_ACTIONS: count_send_track_actions
};

export const VIEWS = {
Expand Down
9 changes: 5 additions & 4 deletions js/reducers/api/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ export const setDuckYankData = function(input_json) {
};
};

export const setTargetOn = function(target_id) {
export const setTargetOn = function(target_id, skipTracking = false) {
return {
type: constants.SET_TARGET_ON,
target_on: target_id
target_on: target_id,
skipTracking: skipTracking
};
};

Expand Down Expand Up @@ -156,14 +157,14 @@ export const setUuid = function(uuid) {
};
};

export const setDirectAccess = (directAccessParams) => {
export const setDirectAccess = directAccessParams => {
return {
type: constants.SET_DIRECT_ACCESS,
direct_access: directAccessParams
};
};

export const setDirectAccessProcessed = (directAccessProcessedParams) => {
export const setDirectAccessProcessed = directAccessProcessedParams => {
return {
type: constants.SET_DIRECT_ACCESS_PROCESSED,
direct_access_processed: directAccessProcessedParams
Expand Down
16 changes: 8 additions & 8 deletions js/reducers/tracking/actions.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { constants } from './constants';

export const setActionsList = function(truck_actions_list) {
export const setActionsList = function(track_actions_list) {
return {
type: constants.SET_ACTIONS_LIST,
truck_actions_list: truck_actions_list
track_actions_list: track_actions_list
};
};

export const appendToActionList = function(truck_action) {
export const appendToActionList = function(track_action) {
return {
type: constants.APPEND_ACTIONS_LIST,
truck_action: truck_action
track_action: track_action
};
};

Expand Down Expand Up @@ -56,17 +56,17 @@ export const setIsActionsLoading = function(isActionsLoading) {
};
};

export const setSendActionsList = function(truck_actions_list) {
export const setSendActionsList = function(track_actions_list) {
return {
type: constants.SET_SEND_ACTIONS_LIST,
send_actions_list: truck_actions_list
send_actions_list: track_actions_list
};
};

export const appendToSendActionList = function(truck_action) {
export const appendToSendActionList = function(track_action) {
return {
type: constants.APPEND_SEND_ACTIONS_LIST,
truck_action: truck_action
track_action: track_action
};
};

Expand Down
Loading

0 comments on commit 83bdb85

Please sign in to comment.