cleanup, right template tab

This commit is contained in:
Tom Moor committed 2020-07-29 23:00:58 -07:00
1 parent b5927ae6b4
commit 6d4a6a7fe9
15 files changed
+116 -79

No files matched your search

+1 -1
View File
@@ -51,7 +51,7 @@ const Breadcrumb = observer(({ document, collections, onlyText }: Props) => {
}
const isTemplate = document.template;
const isDraft = !document.publishedAt && !document.template;
const isDraft = !document.publishedAt && !isTemplate;
const isNestedDocument = path.length > 1;
const lastPath = path.length ? path[path.length - 1] : undefined;
const menuPath = isNestedDocument ? path.slice(0, -1) : [];
+2 -1
View File
@@ -126,7 +126,8 @@ class MainSidebar extends React.Component<Props> {
active={
documents.active
? !documents.active.publishedAt &&
!documents.active.isDeleted
!documents.active.isDeleted &&
!documents.active.isTemplate
: undefined
}
/>
+1
View File
@@ -9,6 +9,7 @@ import {
ProfileIcon,
PadlockIcon,
CodeIcon,
ShapesIcon,
UserIcon,
GroupIcon,
LinkIcon,
+16 -2
View File
@@ -10,7 +10,7 @@ type Props = {
const StyledNavLink = styled(NavLink)`
position: relative;
top: 1px;
bottom: -1px;
display: inline-block;
font-weight: 500;
@@ -43,4 +43,18 @@ function Tab({ theme, ...rest }: Props) {
return <StyledNavLink {...rest} activeStyle={activeStyle} />;
}
export default withTheme(Tab);
const TabWithTheme = withTheme(Tab);
const RightTabWithTheme = styled(TabWithTheme)`
position: absolute;
right: 0;
margin-left: 24px;
margin-right: 0;
`;
export function RightTab(props: Props) {
return <RightTabWithTheme {...props} />;
}
export default TabWithTheme;
+1
View File
@@ -2,6 +2,7 @@
import styled from "styled-components";
const Tabs = styled.nav`
position: relative;
border-bottom: 1px solid ${props => props.theme.divider};
margin-top: 22px;
margin-bottom: 12px;
+3 -2
View File
@@ -42,13 +42,14 @@ class NewDocumentMenu extends React.Component<Props> {
if (this.redirectTo) return <Redirect to={this.redirectTo} push />;
const { collections, policies, label, ...rest } = this.props;
const singleCollection = collections.orderedData.length === 1;
return (
<DropdownMenu
label={
label || (
<Button icon={<PlusIcon />} small>
New doc…
New doc{singleCollection ? "" : "…"}
</Button>
)
}
@@ -65,7 +66,7 @@ class NewDocumentMenu extends React.Component<Props> {
onClick={() => this.handleNewDocument(collection.id)}
disabled={!can.update}
>
<CollectionIcon collection={collection} /> {collection.name}
<CollectionIcon collection={collection} />&nbsp;{collection.name}
</DropdownMenuItem>
);
})}
+70
View File
@@ -0,0 +1,70 @@
// @flow
import * as React from "react";
import { observable } from "mobx";
import { inject, observer } from "mobx-react";
import { Redirect } from "react-router-dom";
import { PlusIcon } from "outline-icons";
import { newDocumentUrl } from "utils/routeHelpers";
import CollectionsStore from "stores/CollectionsStore";
import PoliciesStore from "stores/PoliciesStore";
import { DropdownMenu, DropdownMenuItem } from "components/DropdownMenu";
import Button from "components/Button";
import CollectionIcon from "components/CollectionIcon";
type Props = {
label?: React.Node,
collections: CollectionsStore,
policies: PoliciesStore,
};
@observer
class NewTemplateMenu extends React.Component<Props> {
@observable redirectTo: ?string;
componentDidUpdate() {
this.redirectTo = undefined;
}
handleNewDocument = (collectionId: string) => {
this.redirectTo = newDocumentUrl(collectionId, {
template: true,
});
};
render() {
if (this.redirectTo) return <Redirect to={this.redirectTo} push />;
const { collections, policies, label, ...rest } = this.props;
return (
<DropdownMenu
label={
label || (
<Button icon={<PlusIcon />} small>
New template…
</Button>
)
}
{...rest}
>
<DropdownMenuItem disabled>Choose a collection…</DropdownMenuItem>
{collections.orderedData.map(collection => {
const can = policies.abilities(collection.id);
return (
<DropdownMenuItem
key={collection.id}
onClick={() => this.handleNewDocument(collection.id)}
disabled={!can.update}
>
<CollectionIcon collection={collection} />&nbsp;{collection.name}
</DropdownMenuItem>
);
})}
</DropdownMenu>
);
}
}
export default inject("collections", "policies")(NewTemplateMenu);
+5
View File
@@ -79,6 +79,11 @@ export default class Document extends BaseModel {
return !!this.deletedAt;
}
@computed
get isTemplate(): boolean {
return !!this.template;
}
@computed
get isDraft(): boolean {
return !this.publishedAt;
-2
View File
@@ -11,7 +11,6 @@ import Trash from "scenes/Trash";
import Collection from "scenes/Collection";
import KeyedDocument from "scenes/Document/KeyedDocument";
import DocumentNew from "scenes/DocumentNew";
import TemplateNew from "scenes/TemplateNew";
import Search from "scenes/Search";
import Settings from "scenes/Settings";
import Details from "scenes/Settings/Details";
@@ -53,7 +52,6 @@ export default function Routes() {
<Route exact path="/starred" component={Starred} />
<Route exact path="/starred/:sort" component={Starred} />
<Route exact path="/templates" component={Templates} />
<Route exact path="/templates/new" component={TemplateNew} />
<Route exact path="/templates/:sort" component={Templates} />
<Route exact path="/drafts" component={Drafts} />
<Route exact path="/archive" component={Archive} />
+6 -3
View File
@@ -34,7 +34,7 @@ import Flex from "components/Flex";
import Modal from "components/Modal";
import CollectionMembers from "scenes/CollectionMembers";
import Tabs from "components/Tabs";
import Tab from "components/Tab";
import Tab, { RightTab } from "components/Tab";
import PaginatedDocumentList from "components/PaginatedDocumentList";
import CollectionIcon from "components/CollectionIcon";
@@ -241,9 +241,12 @@ class CollectionScene extends React.Component<Props> {
<Tab to={collectionUrl(collection.id, "alphabetical")} exact>
A–Z
</Tab>
<Tab to={collectionUrl(collection.id, "templates")} exact>
<RightTab
to={collectionUrl(collection.id, "templates")}
exact
>
Templates
</Tab>
</RightTab>
</Tabs>
<Switch>
<Route path={collectionUrl(collection.id, "alphabetical")}>
+3 -1
View File
@@ -80,7 +80,9 @@ class DocumentEditor extends React.Component<Props> {
type="text"
onChange={onChangeTitle}
onKeyDown={this.handleTitleKeyDown}
placeholder="Start with a title…"
placeholder={
document.template ? "Start your template…" : "Start with a title…"
}
value={!title && readOnly ? "Untitled" : title}
style={startsWithEmojiAndSpace ? { marginLeft: "-1.2em" } : undefined}
readOnlyWriteCheckboxes
+4 -1
View File
@@ -133,6 +133,7 @@ class Header extends React.Component<Props> {
const share = shares.getByDocumentId(document.id);
const isPubliclyShared = share && share.published;
const isTemplate = document.template;
const can = policies.abilities(document.id);
const canShareDocuments = auth.team && auth.team.sharing && can.share;
const canToggleEmbeds = auth.team && auth.team.documentEmbeds;
@@ -314,7 +315,9 @@ class Header extends React.Component<Props> {
</Action>
)}
{canEdit &&
document.template && (
isTemplate &&
!isDraft &&
!isRevision && (
<Action>
<Button
icon={<PlusIcon />}
+1
View File
@@ -27,6 +27,7 @@ class DocumentNew extends React.Component<Props> {
collectionId: this.props.match.params.id,
parentDocumentId: params.parentDocumentId,
templateId: params.templateId,
template: params.template,
title: "",
text: "",
});
-46
View File
@@ -1,46 +0,0 @@
// @flow
import * as React from "react";
import { inject } from "mobx-react";
import type { RouterHistory, Location } from "react-router-dom";
import Flex from "components/Flex";
import CenteredContent from "components/CenteredContent";
import LoadingPlaceholder from "components/LoadingPlaceholder";
import DocumentsStore from "stores/DocumentsStore";
import UiStore from "stores/UiStore";
import { editDocumentUrl } from "utils/routeHelpers";
type Props = {
history: RouterHistory,
location: Location,
documents: DocumentsStore,
ui: UiStore,
match: Object,
};
class TemplateNew extends React.Component<Props> {
async componentDidMount() {
try {
const document = await this.props.documents.create({
template: true,
title: "",
text: "",
});
this.props.history.replace(editDocumentUrl(document));
} catch (err) {
this.props.ui.showToast("Couldn’t create the template, try again?");
this.props.history.goBack();
}
}
render() {
return (
<Flex column auto>
<CenteredContent>
<LoadingPlaceholder />
</CenteredContent>
</Flex>
);
}
}
export default inject("documents", "ui")(TemplateNew);
+3 -20
View File
@@ -1,11 +1,7 @@
// @flow
import * as React from "react";
import { observable } from "mobx";
import { observer, inject } from "mobx-react";
import { PlusIcon } from "outline-icons";
import { Redirect } from "react-router-dom";
import { newTemplateUrl } from "utils/routeHelpers";
import CenteredContent from "components/CenteredContent";
import Empty from "components/Empty";
import PageTitle from "components/PageTitle";
@@ -13,7 +9,7 @@ import Heading from "components/Heading";
import PaginatedDocumentList from "components/PaginatedDocumentList";
import Tabs from "components/Tabs";
import Tab from "components/Tab";
import Button from "components/Button";
import NewTemplateMenu from "menus/NewTemplateMenu";
import Actions, { Action } from "components/Actions";
import DocumentsStore from "stores/DocumentsStore";
@@ -24,19 +20,7 @@ type Props = {
@observer
class Starred extends React.Component<Props> {
@observable redirectTo: ?string;
componentDidUpdate() {
this.redirectTo = undefined;
}
handleNewTemplate = () => {
this.redirectTo = newTemplateUrl();
};
render() {
if (this.redirectTo) return <Redirect to={this.redirectTo} push />;
const {
fetchTemplates,
templates,
@@ -65,13 +49,12 @@ class Starred extends React.Component<Props> {
sort === "alphabetical" ? templatesAlphabetical : templates
}
showCollection
showDraft
/>
<Actions align="center" justify="flex-end">
<Action>
<Button icon={<PlusIcon />} onClick={this.handleNewTemplate} small>
New template
</Button>
<NewTemplateMenu />
</Action>
</Actions>
</CenteredContent>