Skip to content

Commit

Permalink
#14 add not completed manual snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
tibor-postek-m2ms committed Mar 12, 2020
1 parent fa30e1f commit a710bbd
Show file tree
Hide file tree
Showing 24 changed files with 331 additions and 82 deletions.
8 changes: 5 additions & 3 deletions js/components/preview/Preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ import { CompoundList } from './compounds/compoundList';
import { ViewerControls } from './viewerControls';
import { ComputeSize } from '../../utils/computeSize';
import { withUpdatingTarget } from '../target/withUpdatingTarget';
import ModalStateSave from '../session/modalStateSave';
import ModalStateSave from '../snapshot/modals/modalStateSave';
import { VIEWS } from '../../constants/constants';
import { withLoadingProtein } from './withLoadingProtein';
import { withSnapshotManagement } from '../session/withSnapshotManagement';
import { withSnapshotManagement } from '../snapshot/withSnapshotManagement';
import { useDispatch } from 'react-redux';
import { ProjectHistory } from './projectHistory';
import { ProjectDetailDrawer } from '../projects/projectDetailDrawer';
import { removeAllNglComponents } from '../../reducers/ngl/actions';
import { resetCurrentCompoundsSettings } from './compounds/redux/actions';
import { resetProjectsReducer } from '../projects/redux/actions';
import { NewSnapshotModal } from '../snapshot/modals/newSnapshotModal';
//import HotspotList from '../hotspot/hotspotList';

const hitNavigatorWidth = 504;
Expand Down Expand Up @@ -62,7 +63,7 @@ const useStyles = makeStyles(theme => ({
}
}));

const Preview = memo(({ isStateLoaded, headerHeight }) => {
const Preview = memo(({ isStateLoaded, headerHeight, match }) => {
const classes = useStyles();
const theme = useTheme();

Expand Down Expand Up @@ -152,6 +153,7 @@ const Preview = memo(({ isStateLoaded, headerHeight }) => {
</Grid>
<ModalStateSave />
<ProjectDetailDrawer showHistory={showHistory} setShowHistory={setShowHistory} />
<NewSnapshotModal match={match} />
</>
);
});
Expand Down
6 changes: 0 additions & 6 deletions js/components/preview/molecule/moleculeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ import { useDisableUserInteraction } from '../../helpers/useEnableUserInteracion
import { addVector, removeVector, addComplex, removeComplex, addLigand, removeLigand } from './redux/dispatchActions';
import { base_url } from '../../routes/constants';
import { moleculeProperty } from './helperConstants';
import { api } from '../../../utils/api';
import { generateObjectList } from '../../session/helpers';
import { getTotalCountOfCompounds } from './molecules_helpers';

const useStyles = makeStyles(theme => ({
container: {
Expand Down Expand Up @@ -62,9 +59,6 @@ const useStyles = makeStyles(theme => ({
color: theme.palette.black
}
},
contColButtonHalfSelected: {
backgroundColor: theme.palette.primary.semidark
},
detailsCol: {
border: 'solid 1px',
borderColor: theme.palette.background.divider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export const withLoadingMolGroupList = WrappedComponent => {
setOldUrl,
oldUrl: oldUrl.current,
onCancel,
isStateLoaded
isStateLoaded,
projectId
})
).catch(error => {
setState(() => {
Expand All @@ -46,6 +47,6 @@ export const withLoadingMolGroupList = WrappedComponent => {
};
}, [isStateLoaded, onCancel, dispatch, oldUrl, getNglView, projectId, wasLoaded]);

return <WrappedComponent {...rest} />;
return <WrappedComponent {...rest} match={match} />;
});
};
2 changes: 1 addition & 1 deletion js/components/preview/withLoadingProtein.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const withLoadingProtein = WrappedComponent => {
shouldLoadProtein(nglViewList, isStateLoaded, projectId);
}, [isStateLoaded, nglViewList, projectId, shouldLoadProtein]);

return <WrappedComponent isStateLoaded={isStateLoaded} {...rest} />;
return <WrappedComponent isStateLoaded={isStateLoaded} {...rest} match={match} />;
});

function mapStateToProps(state) {
Expand Down
185 changes: 185 additions & 0 deletions js/components/projects/addProjectDetail/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
import React, { memo, useState } from 'react';
import {
FormControl,
FormControlLabel,
FormHelperText,
Grid,
InputLabel,
makeStyles,
MenuItem,
Radio,
Typography
} from '@material-ui/core';
import Modal from '../../common/Modal';
import { DJANGO_CONTEXT } from '../../../utils/djangoContext';
import { setCurrentProjectProperty, setProjectModalIsLoading, setProjectModalOpen } from '../redux/actions';
import { api, METHOD } from '../../../utils/api';
import { base_url, URLS } from '../../routes/constants';
import { Form, Formik } from 'formik';
import { RadioGroup, Select, TextField } from 'formik-material-ui';
import { ProjectCreationType } from '../redux/constants';
import { InputFieldAvatar } from '../projectModal/inputFieldAvatar';
import { Description, Label, Link, Title } from '@material-ui/icons';
import { Autocomplete } from '@material-ui/lab';
import { Button } from '../../common/Inputs/Button';
import { useDispatch, useSelector } from 'react-redux';
import { setDialogCurrentStep } from '../../snapshot/redux/actions';

const useStyles = makeStyles(theme => ({
body: {
width: '100%',
marginTop: theme.spacing(1),
marginBottom: theme.spacing(1)
},
input: {
width: 400
},
margin: {
margin: theme.spacing(1)
},
formControl: {
margin: theme.spacing(1),
width: 400
}
}));

export const AddProjectDetail = memo(() => {
const classes = useStyles();
const [state, setState] = useState();

const dispatch = useDispatch();
const targetId = useSelector(state => state.apiReducers.target_on);

const [tags, setTags] = React.useState([]);

return (
<>
<Typography variant="h3">Add Project Detail</Typography>
<Formik
initialValues={{
title: '',
description: '',
tags: ''
}}
validate={values => {
const errors = {};
if (!values.title) {
errors.title = 'Required!';
}
if (!values.description) {
errors.description = 'Required!';
}
return errors;
}}
onSubmit={values => {
const data = {
...values,
author: {
username: DJANGO_CONTEXT['username'],
email: DJANGO_CONTEXT['email']
},
tags
};
dispatch(setProjectModalIsLoading(true));
api({ url: `${base_url}/api/project`, method: METHOD.POST, data })
.then(response => {
const projectID = response.data.id;
dispatch(setCurrentProjectProperty('projectID', projectID));
})
.catch(error => {
setState(() => {
throw error;
});
})
.finally(() => {
dispatch(setDialogCurrentStep(1));
});
}}
>
{({ submitForm, errors }) => (
<Form>
<Grid container direction="column" className={classes.body}>
<Grid item>
<InputFieldAvatar
icon={<Title />}
field={
<TextField
className={classes.input}
name="title"
label="Title"
required
// disabled={isProjectModalLoading}
/>
}
/>
</Grid>
<Grid item>
<InputFieldAvatar
icon={<Description />}
field={
<TextField
className={classes.input}
name="description"
label="Description"
required
// disabled={isProjectModalLoading}
/>
}
/>
</Grid>
<Grid item>
<InputFieldAvatar
icon={<Label />}
field={
<Autocomplete
multiple
freeSolo
id="tags-standard"
options={tags}
getOptionLabel={option => option}
onChange={(e, data) => {
setTags(data);
}}
// disabled={isProjectModalLoading}
renderInput={params => (
<TextField
{...params}
className={classes.input}
label="Tags"
name="tags"
fullWidth
onKeyPress={e => {
if (e.key === 'Enter') {
setTags([...tags, e.target.value]);
}
}}
/>
)}
/>
}
/>
</Grid>
</Grid>
<Grid container justify="flex-end" direction="row">
<Grid item>
<Button
color="secondary" //disabled={isProjectModalLoading} onClick={handleCloseModal}
>
Cancel
</Button>
</Grid>
<Grid item>
<Button
color="primary"
onClick={submitForm} //loading={isProjectModalLoading}
>
Create
</Button>
</Grid>
</Grid>
</Form>
)}
</Formik>
</>
);
});
5 changes: 1 addition & 4 deletions js/components/projects/projectModal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,7 @@ export const ProjectModal = memo(({ history }) => {
onSubmit={values => {
const data = {
...values,
author: {
username: DJANGO_CONTEXT['username'],
email: DJANGO_CONTEXT['email']
},
authorID: DJANGO_CONTEXT['pt'],
tags
};
dispatch(setProjectModalIsLoading(true));
Expand Down
3 changes: 2 additions & 1 deletion js/components/projects/redux/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { constants } from './constants';

export const INITIAL_STATE = {
currentProject: {
projectID: null, // TODO change to null
author: null,
title: null,
description: null,
targetId: 1, //change to null,
targetId: 1, //TODO change to null,
tags: [],
type: null
},
Expand Down
3 changes: 1 addition & 2 deletions js/components/routes/Routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import { BrowserCheck } from '../errorHandling/browserCheck';
import { URLS } from './constants';
import { HeaderContext } from '../header/headerContext';
import { Close } from '@material-ui/icons';
import SessionList from '../session/sessionList';
import { snackbarColors } from '../header/constants';
import SessionList from '../snapshot/sessionList';
import { Projects } from '../projects';
import { ProjectDetailSessionList } from '../projects/projectDetailSessionList';
import { useSelector } from 'react-redux';
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

import React, { memo, useState, useEffect, useContext } from 'react';
import { connect } from 'react-redux';
import Modal from '../common/Modal';
import Modal from '../../common/Modal';
import { Grid, makeStyles } from '@material-ui/core';
import * as apiActions from '../../reducers/api/actions';
import { TextField } from '../common/Inputs/TextField';
import { Button } from '../common/Inputs/Button';
import { savingStateConst } from './constants';
import { updateClipboard } from './helpers';
import { api } from '../../utils/api';
import { HeaderContext } from '../header/headerContext';
import * as apiActions from '../../../reducers/api/actions';
import { TextField } from '../../common/Inputs/TextField';
import { Button } from '../../common/Inputs/Button';
import { savingStateConst } from '../constants';
import { updateClipboard } from '../helpers';
import { api } from '../../../utils/api';
import { HeaderContext } from '../../header/headerContext';

const useStyles = makeStyles(theme => ({
row: {
Expand Down
5 changes: 5 additions & 0 deletions js/components/snapshot/modals/newSnapshotForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React, { memo, useState } from 'react';

export const NewSnapshotForm = memo(() => {
return;
});
29 changes: 29 additions & 0 deletions js/components/snapshot/modals/newSnapshotModal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React, { memo } from 'react';
import Modal from '../../common/Modal';
import { useDispatch, useSelector } from 'react-redux';
import { setOpenSnapshotSavingDialog } from '../redux/actions';
import { Typography } from '@material-ui/core';
import { AddProjectDetail } from '../../projects/addProjectDetail';

export const NewSnapshotModal = memo(({ match }) => {
const dispatch = useDispatch();
const openSavingDialog = useSelector(state => state.snapshotReducers.openSavingDialog);
const dialogCurrentStep = useSelector(state => state.snapshotReducers.dialogCurrentStep);
const currectProject = useSelector(state => state.projectReducers.currentProject);

const projectId = (match && match.params && match.params.projectId) || (currectProject && currectProject.projectID);

const handleCloseModal = () => {
dispatch(setOpenSnapshotSavingDialog(false));
};

return (
<>
<Modal open={openSavingDialog} onClose={handleCloseModal}>
{projectId && <Typography variant="h3">Save Session</Typography>}
{!projectId && dialogCurrentStep === 0 && <AddProjectDetail />}
{!projectId && dialogCurrentStep === 1 && <AddProjectDetail />}
</Modal>
</>
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,13 @@ export const setNextUUID = uuid => ({ type: constants.SET_NEXT_UUID, payload: uu
export const setNewSessionFlag = flag => ({ type: constants.SET_NEW_SESSION_FLAG, payload: flag });

export const setLoadedSession = loadedSession => ({ type: constants.SET_LOADED_SESSION, payload: loadedSession });

export const setOpenSnapshotSavingDialog = (isOpen = false) => ({
type: constants.SET_OPEN_SAVING_DIALOG,
payload: isOpen
});

export const setDialogCurrentStep = (currentStep = 0) => ({
type: constants.SET_DIALOG_CURRENT_STEP,
payload: currentStep
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ export const constants = {
SET_SAVE_TYPE: prefix + 'SET_SAVE_TYPE',
SET_NEXT_UUID: prefix + 'SET_NEXT_UUID',
SET_NEW_SESSION_FLAG: prefix + 'SET_NEW_SESSION_FLAG',
SET_LOADED_SESSION: prefix + 'SET_LOADED_SESSION'
SET_LOADED_SESSION: prefix + 'SET_LOADED_SESSION',

SET_OPEN_SAVING_DIALOG: prefix + 'SET_OPEN_SAVING_DIALOG',
SET_DIALOG_CURRENT_STEP: prefix + 'SET_DIALOG_CURRENT_STEP'
};
Loading

0 comments on commit a710bbd

Please sign in to comment.