Version History (#768)
* Stash. Super rough progress * Stash * 'h' how toggles history panel Add documents.restore endpoint * Add tests for documents.restore endpoint * Document restore endpoint * Tiding, RevisionMenu, remove scroll dep * Add history menu item * Paginate loading * Fixed: Error boundary styling Select first revision faster * Diff summary, styling * Add history loading placeholder Fix move modal not opening * Fixes: Refreshing page on specific revision * documentation for document.revision * Better handle versions with no text changes (will no longer be created)
This commit is contained in:
58
app/components/DocumentHistory/components/DiffSummary.js
Normal file
58
app/components/DocumentHistory/components/DiffSummary.js
Normal file
@@ -0,0 +1,58 @@
|
||||
// @flow
|
||||
import * as React from 'react';
|
||||
import styled from 'styled-components';
|
||||
import Flex from 'shared/components/Flex';
|
||||
|
||||
type Props = {
|
||||
added: number,
|
||||
removed: number,
|
||||
max: number,
|
||||
color?: string,
|
||||
width: number,
|
||||
};
|
||||
|
||||
export default function DiffSummary({
|
||||
added,
|
||||
removed,
|
||||
max,
|
||||
color,
|
||||
width = 180,
|
||||
}: Props) {
|
||||
const summary = [];
|
||||
if (added) summary.push(`+${added}`);
|
||||
if (removed) summary.push(`-${removed}`);
|
||||
const hasChanges = !!summary.length;
|
||||
|
||||
return (
|
||||
<Flex align="center">
|
||||
{hasChanges && (
|
||||
<Diff>
|
||||
<Bar color={color} style={{ width: `${added / max * width}px` }} />
|
||||
<Bar color={color} style={{ width: `${removed / max * width}px` }} />
|
||||
</Diff>
|
||||
)}
|
||||
<Summary>{hasChanges ? summary.join(', ') : 'No changes'}</Summary>
|
||||
</Flex>
|
||||
);
|
||||
}
|
||||
|
||||
const Summary = styled.div`
|
||||
display: inline-block;
|
||||
font-size: 10px;
|
||||
opacity: 0.5;
|
||||
flex-grow: 100;
|
||||
text-transform: uppercase;
|
||||
`;
|
||||
|
||||
const Diff = styled(Flex)`
|
||||
height: 6px;
|
||||
margin-right: 2px;
|
||||
`;
|
||||
|
||||
const Bar = styled.div`
|
||||
display: inline-block;
|
||||
background: ${props => props.color || props.theme.text};
|
||||
height: 100%;
|
||||
opacity: 0.3;
|
||||
margin-right: 1px;
|
||||
`;
|
||||
80
app/components/DocumentHistory/components/Revision.js
Normal file
80
app/components/DocumentHistory/components/Revision.js
Normal file
@@ -0,0 +1,80 @@
|
||||
// @flow
|
||||
import * as React from 'react';
|
||||
import { NavLink } from 'react-router-dom';
|
||||
import styled, { withTheme } from 'styled-components';
|
||||
import format from 'date-fns/format';
|
||||
import { MoreIcon } from 'outline-icons';
|
||||
|
||||
import Flex from 'shared/components/Flex';
|
||||
import Time from 'shared/components/Time';
|
||||
import Avatar from 'components/Avatar';
|
||||
import RevisionMenu from 'menus/RevisionMenu';
|
||||
import DiffSummary from './DiffSummary';
|
||||
|
||||
import { documentHistoryUrl } from 'utils/routeHelpers';
|
||||
|
||||
class Revision extends React.Component<*> {
|
||||
render() {
|
||||
const { revision, document, maxChanges, showMenu, theme } = this.props;
|
||||
|
||||
return (
|
||||
<StyledNavLink
|
||||
to={documentHistoryUrl(document, revision.id)}
|
||||
activeStyle={{ background: theme.primary, color: theme.white }}
|
||||
>
|
||||
<Author>
|
||||
<StyledAvatar src={revision.createdBy.avatarUrl} />{' '}
|
||||
{revision.createdBy.name}
|
||||
</Author>
|
||||
<Meta>
|
||||
<Time dateTime={revision.createdAt}>
|
||||
{format(revision.createdAt, 'MMMM Do, YYYY h:mm a')}
|
||||
</Time>
|
||||
</Meta>
|
||||
<DiffSummary {...revision.diff} max={maxChanges} />
|
||||
{showMenu && (
|
||||
<StyledRevisionMenu
|
||||
document={document}
|
||||
revision={revision}
|
||||
label={<MoreIcon color={theme.white} />}
|
||||
/>
|
||||
)}
|
||||
</StyledNavLink>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const StyledAvatar = styled(Avatar)`
|
||||
border-color: transparent;
|
||||
margin-right: 4px;
|
||||
`;
|
||||
|
||||
const StyledRevisionMenu = styled(RevisionMenu)`
|
||||
position: absolute;
|
||||
right: 16px;
|
||||
top: 16px;
|
||||
`;
|
||||
|
||||
const StyledNavLink = styled(NavLink)`
|
||||
color: ${props => props.theme.text};
|
||||
display: block;
|
||||
padding: 16px;
|
||||
font-size: 15px;
|
||||
position: relative;
|
||||
height: 100px;
|
||||
`;
|
||||
|
||||
const Author = styled(Flex)`
|
||||
font-weight: 500;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
`;
|
||||
|
||||
const Meta = styled.p`
|
||||
font-size: 14px;
|
||||
opacity: 0.75;
|
||||
margin: 0 0 2px;
|
||||
padding: 0;
|
||||
`;
|
||||
|
||||
export default withTheme(Revision);
|
||||
Reference in New Issue
Block a user