diff --git a/Dockerfile b/Dockerfile index d6a918c1f0..da24d60ac9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -35,6 +35,7 @@ ENV NODE_ENV production COPY --from=builder $APP_PATH/build ./build COPY --from=builder $APP_PATH/server ./server +COPY --from=builder $APP_PATH/public ./public COPY --from=builder $APP_PATH/.sequelizerc ./.sequelizerc COPY --from=deps-prod $APP_PATH/node_modules ./node_modules COPY --from=builder $APP_PATH/package.json ./package.json diff --git a/app/components/Button.js b/app/components/Button.js index 6ba2b8b559..fc3b4f64ad 100644 --- a/app/components/Button.js +++ b/app/components/Button.js @@ -66,7 +66,11 @@ const RealButton = styled.button` &:hover { - background: ${darken(0.05, props.theme.buttonNeutralBackground)}; + background: ${ + props.borderOnHover + ? props.theme.buttonNeutralBackground + : darken(0.05, props.theme.buttonNeutralBackground) + }; box-shadow: rgba(0, 0, 0, 0.07) 0px 1px 2px, ${ props.theme.buttonNeutralBorder } 0 0 0 1px inset; diff --git a/app/components/DocumentHistory.js b/app/components/DocumentHistory.js new file mode 100644 index 0000000000..264e9d2351 --- /dev/null +++ b/app/components/DocumentHistory.js @@ -0,0 +1,124 @@ +// @flow +import { observer } from "mobx-react"; +import { CloseIcon } from "outline-icons"; +import * as React from "react"; +import { useTranslation } from "react-i18next"; +import { useHistory, useRouteMatch } from "react-router-dom"; +import styled from "styled-components"; +import breakpoint from "styled-components-breakpoint"; +import Event from "models/Event"; +import Button from "components/Button"; +import Empty from "components/Empty"; +import Flex from "components/Flex"; +import PaginatedEventList from "components/PaginatedEventList"; +import Scrollable from "components/Scrollable"; +import useStores from "hooks/useStores"; +import { documentUrl } from "utils/routeHelpers"; + +const EMPTY_ARRAY = []; + +function DocumentHistory() { + const { events, documents } = useStores(); + const { t } = useTranslation(); + const match = useRouteMatch(); + const history = useHistory(); + + const document = documents.getByUrl(match.params.documentSlug); + const eventsInDocument = document + ? events.inDocument(document.id) + : EMPTY_ARRAY; + + const onCloseHistory = () => { + history.push(documentUrl(document)); + }; + + const items = React.useMemo(() => { + if ( + eventsInDocument[0] && + document && + eventsInDocument[0].createdAt !== document.updatedAt + ) { + eventsInDocument.unshift( + new Event({ + name: "documents.latest_version", + documentId: document.id, + createdAt: document.updatedAt, + actor: document.updatedBy, + }) + ); + } + + return eventsInDocument; + }, [eventsInDocument, document]); + + return ( + + {document ? ( + +
+ {t("History")} +
+ + {t("Oh weird, there's nothing here")}} + /> + +
+ ) : null} +
+ ); +} + +const Position = styled(Flex)` + position: fixed; + top: 0; + bottom: 0; + width: ${(props) => props.theme.sidebarWidth}px; +`; + +const Sidebar = styled(Flex)` + display: none; + position: relative; + flex-shrink: 0; + background: ${(props) => props.theme.background}; + width: ${(props) => props.theme.sidebarWidth}px; + border-left: 1px solid ${(props) => props.theme.divider}; + z-index: 1; + + ${breakpoint("tablet")` + display: flex; + `}; +`; + +const Title = styled(Flex)` + font-size: 16px; + font-weight: 600; + text-align: center; + align-items: center; + justify-content: flex-start; + text-overflow: ellipsis; + white-space: nowrap; + overflow: hidden; + width: 0; + flex-grow: 1; +`; + +const Header = styled(Flex)` + align-items: center; + position: relative; + padding: 12px; + color: ${(props) => props.theme.text}; + flex-shrink: 0; +`; + +export default observer(DocumentHistory); diff --git a/app/components/DocumentHistory/DocumentHistory.js b/app/components/DocumentHistory/DocumentHistory.js deleted file mode 100644 index 68c8576f24..0000000000 --- a/app/components/DocumentHistory/DocumentHistory.js +++ /dev/null @@ -1,199 +0,0 @@ -// @flow -import ArrowKeyNavigation from "boundless-arrow-key-navigation"; -import { action, observable } from "mobx"; -import { inject, observer } from "mobx-react"; -import { CloseIcon } from "outline-icons"; -import * as React from "react"; -import { type Match, Redirect, type RouterHistory } from "react-router-dom"; -import { Waypoint } from "react-waypoint"; -import styled from "styled-components"; - -import breakpoint from "styled-components-breakpoint"; -import { DEFAULT_PAGINATION_LIMIT } from "stores/BaseStore"; -import DocumentsStore from "stores/DocumentsStore"; -import RevisionsStore from "stores/RevisionsStore"; - -import Button from "components/Button"; -import Flex from "components/Flex"; -import PlaceholderList from "components/List/Placeholder"; -import Revision from "./components/Revision"; -import { documentHistoryUrl, documentUrl } from "utils/routeHelpers"; - -type Props = { - match: Match, - documents: DocumentsStore, - revisions: RevisionsStore, - history: RouterHistory, -}; - -@observer -class DocumentHistory extends React.Component { - @observable isLoaded: boolean = false; - @observable isFetching: boolean = false; - @observable offset: number = 0; - @observable allowLoadMore: boolean = true; - @observable redirectTo: ?string; - - async componentDidMount() { - await this.loadMoreResults(); - this.selectFirstRevision(); - } - - fetchResults = async () => { - this.isFetching = true; - - const limit = DEFAULT_PAGINATION_LIMIT; - const results = await this.props.revisions.fetchPage({ - limit, - offset: this.offset, - documentId: this.props.match.params.documentSlug, - }); - - if ( - results && - (results.length === 0 || results.length < DEFAULT_PAGINATION_LIMIT) - ) { - this.allowLoadMore = false; - } else { - this.offset += DEFAULT_PAGINATION_LIMIT; - } - - this.isLoaded = true; - this.isFetching = false; - }; - - selectFirstRevision = () => { - if (this.revisions.length) { - const document = this.props.documents.getByUrl( - this.props.match.params.documentSlug - ); - if (!document) return; - - this.props.history.replace( - documentHistoryUrl(document, this.revisions[0].id) - ); - } - }; - - @action - loadMoreResults = async () => { - // Don't paginate if there aren't more results or we’re in the middle of fetching - if (!this.allowLoadMore || this.isFetching) return; - await this.fetchResults(); - }; - - get revisions() { - const document = this.props.documents.getByUrl( - this.props.match.params.documentSlug - ); - if (!document) return []; - return this.props.revisions.getDocumentRevisions(document.id); - } - - onCloseHistory = () => { - const document = this.props.documents.getByUrl( - this.props.match.params.documentSlug - ); - - this.redirectTo = documentUrl(document); - }; - - render() { - const document = this.props.documents.getByUrl( - this.props.match.params.documentSlug - ); - const showLoading = (!this.isLoaded && this.isFetching) || !document; - - if (this.redirectTo) return ; - - return ( - - -
- History -
- {showLoading ? ( - - - - ) : ( - - {this.revisions.map((revision, index) => ( - - ))} - - )} - {this.allowLoadMore && ( - - )} -
-
- ); - } -} - -const Loading = styled.div` - margin: 0 16px; -`; - -const Wrapper = styled(Flex)` - position: fixed; - top: 0; - right: 0; - z-index: 1; - min-width: ${(props) => props.theme.sidebarWidth}px; - height: 100%; - overflow-y: auto; - overscroll-behavior: none; -`; - -const Sidebar = styled(Flex)` - display: none; - background: ${(props) => props.theme.background}; - min-width: ${(props) => props.theme.sidebarWidth}px; - border-left: 1px solid ${(props) => props.theme.divider}; - z-index: 1; - - ${breakpoint("tablet")` - display: flex; - `}; -`; - -const Title = styled(Flex)` - font-size: 16px; - font-weight: 600; - text-align: center; - align-items: center; - justify-content: flex-start; - text-overflow: ellipsis; - white-space: nowrap; - overflow: hidden; - width: 0; - flex-grow: 1; -`; - -const Header = styled(Flex)` - align-items: center; - position: relative; - padding: 12px; - border-bottom: 1px solid ${(props) => props.theme.divider}; - color: ${(props) => props.theme.text}; - flex-shrink: 0; -`; - -export default inject("documents", "revisions")(DocumentHistory); diff --git a/app/components/DocumentHistory/components/Revision.js b/app/components/DocumentHistory/components/Revision.js deleted file mode 100644 index f1469f89b0..0000000000 --- a/app/components/DocumentHistory/components/Revision.js +++ /dev/null @@ -1,87 +0,0 @@ -// @flow -import { format } from "date-fns"; -import * as React from "react"; -import { NavLink } from "react-router-dom"; -import styled, { withTheme } from "styled-components"; - -import Document from "models/Document"; -import Revision from "models/Revision"; -import Avatar from "components/Avatar"; -import Flex from "components/Flex"; -import Time from "components/Time"; -import RevisionMenu from "menus/RevisionMenu"; -import { type Theme } from "types"; - -import { documentHistoryUrl } from "utils/routeHelpers"; - -type Props = { - theme: Theme, - showMenu: boolean, - selected: boolean, - document: Document, - revision: Revision, -}; - -class RevisionListItem extends React.Component { - render() { - const { revision, document, showMenu, selected, theme } = this.props; - - return ( - - - {" "} - {revision.createdBy.name} - - - - - {showMenu && ( - - )} - - ); - } -} - -const StyledAvatar = styled(Avatar)` - border-color: transparent; - margin-right: 4px; -`; - -const StyledRevisionMenu = styled(RevisionMenu)` - position: absolute; - right: 16px; - top: 20px; -`; - -const StyledNavLink = styled(NavLink)` - color: ${(props) => props.theme.text}; - display: block; - padding: 8px 16px; - font-size: 15px; - position: relative; -`; - -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(RevisionListItem); diff --git a/app/components/DocumentHistory/index.js b/app/components/DocumentHistory/index.js deleted file mode 100644 index 7d566709c2..0000000000 --- a/app/components/DocumentHistory/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// @flow -import DocumentHistory from "./DocumentHistory"; -export default DocumentHistory; diff --git a/app/components/DocumentListItem.js b/app/components/DocumentListItem.js index 610a1b48df..78f04182b9 100644 --- a/app/components/DocumentListItem.js +++ b/app/components/DocumentListItem.js @@ -66,6 +66,7 @@ function DocumentListItem(props: Props, ref) { const canStar = !document.isDraft && !document.isArchived && !document.isTemplate; const can = policies.abilities(currentTeam.id); + const canCollection = policies.abilities(document.collectionId); return ( ); @@ -51,19 +67,7 @@ function NewDocumentMenu() {
{t("Choose a collection")}
-