Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/#602' into allfunctionality
Browse files Browse the repository at this point in the history
  • Loading branch information
boriskovar-m2ms committed Apr 20, 2021
2 parents 923f609 + 6ac9da5 commit 5ffddf1
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 47 deletions.
30 changes: 16 additions & 14 deletions js/components/snapshot/modals/newSnapshotForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useDispatch, useSelector } from 'react-redux';
import { DJANGO_CONTEXT } from '../../../utils/djangoContext';
import { Form, Formik, Field } from 'formik';
import { InputFieldAvatar } from '../../projects/projectModal/inputFieldAvatar';
import { Description, Title, QuestionAnswer } from '@material-ui/icons';
import { Description, Title, QuestionAnswer, FindReplace } from '@material-ui/icons';
import { TextField } from 'formik-material-ui';
import { Button } from '../../common/Inputs/Button';
import { SnapshotType } from '../../projects/redux/constants';
Expand Down Expand Up @@ -144,20 +144,22 @@ export const NewSnapshotForm = memo(({ handleCloseModal }) => {
</Grid>
{currentSnapshotId && (
<Grid item>
<FormControlLabel
control={
<Checkbox
name="overwrite"
color="primary"
onChange={() => {
toggleoverwriteSnapshot();
}}
<InputFieldAvatar
icon={<FindReplace />}
field={
<FormControlLabel
control={
<Checkbox
onChange={() => {
toggleoverwriteSnapshot();
}}
disabled={isLoadingSnapshotDialog || isSubmitting}
name="overwrite"
/>
}
label="Overwrite current snapshot"
/>
}
label="Overwrite current snapshot"
labelPlacement="end"
className={classes.checkbox}
disabled={isLoadingSnapshotDialog || isSubmitting}
/>
</Grid>
)}
Expand All @@ -170,7 +172,7 @@ export const NewSnapshotForm = memo(({ handleCloseModal }) => {
<Checkbox
checked={createDiscourse}
onChange={() => setCreateDiscourse(!createDiscourse)}
disabled={!discourseAvailable}
disabled={!discourseAvailable || isSubmitting}
name="createDisTopic"
/>
}
Expand Down
73 changes: 40 additions & 33 deletions js/components/snapshot/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ export const createNewSnapshot = ({
if (res.data.id && session_project) {
let snapshot = { id: res.data.id, title: title };
let project = { projectID: session_project, authorID: author };
console.log('created snapshot id: ' + res.data.id);

Promise.resolve(dispatch(saveCurrentActionsList(snapshot, project, nglViewList))).then(() => {
if (disableRedirect === false) {
Expand All @@ -276,43 +277,49 @@ export const createNewSnapshot = ({
const response = await api({
url: `${base_url}/api/snapshots/?session_project=${session_project}`
});

const length = response.data.results.length;
if (length === 0) {
dispatch(resetCurrentSnapshot());
} else if (response.data.results[length - 1] !== undefined) {
// If the tree fails to load, bail out first without modifying the store
await dispatch(loadSnapshotTree(projectResponse.data.id));
// Pick the latest snapshot which should be the last one
await dispatch(
setCurrentSnapshot({
id: response.data.results[length - 1].id,
type: response.data.results[length - 1].type,
title: response.data.results[length - 1].title,
author: response.data.results[length - 1].author,
description: response.data.results[length - 1].description,
created: response.data.results[length - 1].created,
children: response.data.results[length - 1].children,
parent: response.data.results[length - 1].parent,
data: '[]'
})
);
await dispatch(
setCurrentProject({
projectID: projectResponse.data.id,
authorID: (projectResponse.data.author && projectResponse.data.author.id) || null,
title: projectResponse.data.title,
description: projectResponse.data.description,
targetID: projectResponse.data.target.id,
tags: JSON.parse(projectResponse.data.tags)
})
);
if (createDiscourse) {
dispatch(createSnapshotDiscoursePost());
} else {
const createdSnapshot =
response.data.results && response.data.results.find(r => r.id === res.data.id);
console.log('new snapshot id: ' + JSON.stringify(createdSnapshot?.id));

if (createdSnapshot !== undefined && createdSnapshot !== null) {
// If the tree fails to load, bail out first without modifying the store
await dispatch(loadSnapshotTree(projectResponse.data.id));
await dispatch(
setCurrentSnapshot({
id: createdSnapshot.id,
type: createdSnapshot.type,
title: createdSnapshot.title,
author: createdSnapshot.author,
description: createdSnapshot.description,
created: createdSnapshot.created,
children: createdSnapshot.children,
parent: createdSnapshot.parent,
data: '[]'
})
);
await dispatch(
setCurrentProject({
projectID: projectResponse.data.id,
authorID: (projectResponse.data.author && projectResponse.data.author.id) || null,
title: projectResponse.data.title,
description: projectResponse.data.description,
targetID: projectResponse.data.target.id,
tags: JSON.parse(projectResponse.data.tags)
})
);
if (createDiscourse) {
dispatch(createSnapshotDiscoursePost());
}
dispatch(setOpenSnapshotSavingDialog(false));
dispatch(setIsLoadingSnapshotDialog(false));
dispatch(setSnapshotJustSaved(projectResponse.data.id));
dispatch(setDialogCurrentStep());
}
dispatch(setOpenSnapshotSavingDialog(false));
dispatch(setIsLoadingSnapshotDialog(false));
dispatch(setSnapshotJustSaved(projectResponse.data.id));
dispatch(setDialogCurrentStep());
}
})
.catch(error => {
Expand Down

0 comments on commit 5ffddf1

Please sign in to comment.