Skip to content

Commit

Permalink
#276 move share button
Browse files Browse the repository at this point in the history
  • Loading branch information
tibor-postek-m2ms committed Apr 22, 2020
1 parent a95963a commit c42b0a1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 63 deletions.
64 changes: 3 additions & 61 deletions js/components/preview/projectHistory/index.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
import React, { memo, useContext, useEffect, useRef } from 'react';
import { Panel } from '../../common/Surfaces/Panel';
import {
Grid,
IconButton,
Typography,
Table,
TableBody,
TableRow,
TableCell,
TableHead,
makeStyles
} from '@material-ui/core';
import { templateExtend, TemplateName, Orientation, Gitgraph } from '@gitgraph/react';
import { MergeType, Share } from '@material-ui/icons';
import { MergeType } from '@material-ui/icons';
import { makeStyles } from '@material-ui/core';
import { Button } from '../../common/Inputs/Button';
import { useDispatch, useSelector } from 'react-redux';
import { useHistory, useRouteMatch } from 'react-router-dom';
import { base_url, URLS } from '../../routes/constants';
import { loadSnapshotTree } from '../../projects/redux/dispatchActions';
import palette from '../../../theme/palette';
import { ModalShareSnapshot } from '../../snapshot/modals/modalShareSnapshot';
import { setIsOpenModalBeforeExit, setSelectedSnapshotToSwitch, setSharedSnapshot } from '../../snapshot/redux/actions';
import { resetReducersBetweenSnapshots, switchBetweenSnapshots } from '../redux/dispatchActions';
import { setIsOpenModalBeforeExit, setSelectedSnapshotToSwitch } from '../../snapshot/redux/actions';
import { NglContext } from '../../nglView/nglProvider';

export const heightOfProjectHistory = '164px';
Expand Down Expand Up @@ -86,11 +74,7 @@ export const ProjectHistory = memo(({ setHeight, showFullHistory }) => {
let match = useRouteMatch();
const projectID = match && match.params && match.params.projectId;
const snapshotId = match && match.params && match.params.snapshotId;

const currentProjectID = useSelector(state => state.projectReducers.currentProject.projectID);
const currentSnapshotID = useSelector(state => state.projectReducers.currentSnapshot.id);
const currentSnapshotTitle = useSelector(state => state.projectReducers.currentSnapshot.title);
const currentSnapshotDescription = useSelector(state => state.projectReducers.currentSnapshot.description);
const currentSnapshotList = useSelector(state => state.projectReducers.currentSnapshotList);
const currentSnapshotTree = useSelector(state => state.projectReducers.currentSnapshotTree);
const isLoadingTree = useSelector(state => state.projectReducers.isLoadingTree);
Expand Down Expand Up @@ -146,23 +130,6 @@ export const ProjectHistory = memo(({ setHeight, showFullHistory }) => {
hasHeader
title="Project History"
headerActions={[
<Button
color="inherit"
variant="text"
size="small"
startIcon={<Share />}
onClick={() => {
dispatch(
setSharedSnapshot({
title: currentSnapshotTitle,
description: currentSnapshotDescription,
url: `${base_url}${URLS.projects}${currentProjectID}/${currentSnapshotID}`
})
);
}}
>
Share
</Button>,
<Button color="inherit" variant="text" size="small" onClick={showFullHistory} startIcon={<MergeType />}>
Detail
</Button>
Expand Down Expand Up @@ -202,31 +169,6 @@ export const ProjectHistory = memo(({ setHeight, showFullHistory }) => {
</Gitgraph>
)}
</div>
{/*<Grid item>*/}
{/* <Table>*/}
{/* <TableHead>*/}
{/* <TableRow>*/}
{/* <TableCell>Title</TableCell>*/}
{/* <TableCell align="right">Author</TableCell>*/}
{/* <TableCell align="right">Created</TableCell>*/}
{/* </TableRow>*/}
{/* </TableHead>*/}
{/* <TableBody>*/}
{/* <TableRow>*/}
{/* <TableCell component="th" scope="row">*/}
{/* {snapshotDetail.name}*/}
{/* </TableCell>*/}
{/* <TableCell align="right">*/}
{/* {snapshotDetail.author && snapshotDetail.author.username},*/}
{/* {snapshotDetail.author && snapshotDetail.author.email}*/}
{/* </TableCell>*/}
{/* <TableCell align="right">*/}
{/* {snapshotDetail.created && moment(snapshotDetail.created).format('LLL')}*/}
{/* </TableCell>*/}
{/* </TableRow>*/}
{/* </TableBody>*/}
{/* </Table>*/}
{/*</Grid>*/}
</Panel>
<ModalShareSnapshot />
</>
Expand Down
31 changes: 29 additions & 2 deletions js/components/snapshot/withSnapshotManagement.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React, { memo, useContext, useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { Button } from '@material-ui/core';
import { Save } from '@material-ui/icons';
import { Save, Share } from '@material-ui/icons';
import DownloadPdb from './downloadPdb';
import { savingStateConst } from './constants';
import { HeaderContext } from '../header/headerContext';
import { setOpenSnapshotSavingDialog } from './redux/actions';
import { setOpenSnapshotSavingDialog, setSharedSnapshot } from './redux/actions';
import { useRouteMatch } from 'react-router-dom';
import { DJANGO_CONTEXT } from '../../utils/djangoContext';
import { useDisableUserInteraction } from '../helpers/useEnableUserInteracion';
import { base_url, URLS } from '../routes/constants';

/**
* Created by ricgillams on 13/06/2018.
Expand All @@ -22,6 +23,10 @@ export const withSnapshotManagement = WrappedComponent => {
const savingState = useSelector(state => state.apiReducers.savingState);
const sessionTitle = useSelector(state => state.apiReducers.sessionTitle);

const currentSnapshotID = useSelector(state => state.projectReducers.currentSnapshot.id);
const currentSnapshotTitle = useSelector(state => state.projectReducers.currentSnapshot.title);
const currentSnapshotDescription = useSelector(state => state.projectReducers.currentSnapshot.description);

const targetIdList = useSelector(state => state.apiReducers.target_id_list);
const targetName = useSelector(state => state.apiReducers.target_on_name);
const currentProject = useSelector(state => state.projectReducers.currentProject);
Expand Down Expand Up @@ -51,6 +56,28 @@ export const withSnapshotManagement = WrappedComponent => {
>
Save
</Button>,
<Button
color="primary"
size="small"
startIcon={<Share />}
disabled={
!enableButton ||
disableUserInteraction ||
currentSnapshotID === null ||
(currentProject && currentProject.projectID === null)
}
onClick={() => {
dispatch(
setSharedSnapshot({
title: currentSnapshotTitle,
description: currentSnapshotDescription,
url: `${base_url}${URLS.projects}${currentProject.projectID}/${currentSnapshotID}`
})
);
}}
>
Share
</Button>,
<DownloadPdb key="download" />
]);
// setSnackBarTitle('Currently no active session.');
Expand Down

0 comments on commit c42b0a1

Please sign in to comment.