mirror of
https://github.com/outline/outline.git
synced 2026-12-01 09:22:14 +03:00
Merge branch 'main' of github.com:outline/outline into feat/5166/in-app-notifications
This commit is contained in:
commit
a7f0d206bf
204 files changed
+3602
-1872
No files matched your search
@@ -1,8 +1,8 @@
|
||||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: Feature request
|
||||
url: https://github.com/outline/outline/discussions/new
|
||||
url: https://github.com/outline/outline/discussions/new?category=ideas
|
||||
about: Request a feature to be added to the project
|
||||
- name: Self hosting questions
|
||||
url: https://github.com/outline/outline/discussions/new
|
||||
url: https://github.com/outline/outline/discussions/new?category=self-hosting
|
||||
about: Ask questions and discuss running Outline with community members
|
||||
@@ -7,6 +7,8 @@ WORKDIR $APP_PATH
|
||||
# ---
|
||||
FROM node:18-alpine AS runner
|
||||
|
||||
LABEL org.opencontainers.image.source="https://github.com/outline/outline"
|
||||
|
||||
ARG APP_PATH
|
||||
WORKDIR $APP_PATH
|
||||
ENV NODE_ENV production
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
ARG APP_PATH=/opt/outline
|
||||
FROM node:16.14.2-alpine3.15 AS deps
|
||||
FROM node:18-alpine AS deps
|
||||
|
||||
RUN apk --no-cache add curl
|
||||
|
||||
|
||||
@@ -3,13 +3,7 @@
|
||||
"description": "Open source wiki and knowledge base for growing teams",
|
||||
"website": "https://www.getoutline.com/",
|
||||
"repository": "https://github.com/outline/outline",
|
||||
"keywords": [
|
||||
"wiki",
|
||||
"team",
|
||||
"node",
|
||||
"markdown",
|
||||
"slack"
|
||||
],
|
||||
"keywords": ["wiki", "team", "node", "markdown", "slack"],
|
||||
"success_url": "/",
|
||||
"formation": {
|
||||
"web": {
|
||||
@@ -188,7 +182,7 @@
|
||||
"required": false
|
||||
},
|
||||
"GOOGLE_ANALYTICS_ID": {
|
||||
"description": "UA-xxxx (optional)",
|
||||
"description": "G-xxxx (optional)",
|
||||
"required": false
|
||||
},
|
||||
"SENTRY_DSN": {
|
||||
|
||||
@@ -37,8 +37,8 @@ import { DocumentSection } from "~/actions/sections";
|
||||
import env from "~/env";
|
||||
import history from "~/utils/history";
|
||||
import {
|
||||
documentInsightsUrl,
|
||||
documentHistoryUrl,
|
||||
documentInsightsPath,
|
||||
documentHistoryPath,
|
||||
homePath,
|
||||
newDocumentPath,
|
||||
searchPath,
|
||||
@@ -749,7 +749,7 @@ export const openDocumentHistory = createAction({
|
||||
if (!document) {
|
||||
return;
|
||||
}
|
||||
history.push(documentHistoryUrl(document));
|
||||
history.push(documentHistoryPath(document));
|
||||
},
|
||||
});
|
||||
|
||||
@@ -770,7 +770,7 @@ export const openDocumentInsights = createAction({
|
||||
if (!document) {
|
||||
return;
|
||||
}
|
||||
history.push(documentInsightsUrl(document));
|
||||
history.push(documentInsightsPath(document));
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -6,7 +6,10 @@ import stores from "~/stores";
|
||||
import { createAction } from "~/actions";
|
||||
import { RevisionSection } from "~/actions/sections";
|
||||
import history from "~/utils/history";
|
||||
import { documentHistoryUrl, matchDocumentHistory } from "~/utils/routeHelpers";
|
||||
import {
|
||||
documentHistoryPath,
|
||||
matchDocumentHistory,
|
||||
} from "~/utils/routeHelpers";
|
||||
|
||||
export const restoreRevision = createAction({
|
||||
name: ({ t }) => t("Restore revision"),
|
||||
@@ -57,7 +60,7 @@ export const copyLinkToRevision = createAction({
|
||||
return;
|
||||
}
|
||||
|
||||
const url = `${window.location.origin}${documentHistoryUrl(
|
||||
const url = `${window.location.origin}${documentHistoryPath(
|
||||
document,
|
||||
revisionId
|
||||
)}`;
|
||||
|
||||
@@ -2,6 +2,7 @@ import { PlusIcon } from "outline-icons";
|
||||
import * as React from "react";
|
||||
import stores from "~/stores";
|
||||
import Invite from "~/scenes/Invite";
|
||||
import { UserDeleteDialog } from "~/components/UserDialogs";
|
||||
import { createAction } from "~/actions";
|
||||
import { UserSection } from "~/actions/sections";
|
||||
|
||||
@@ -21,4 +22,31 @@ export const inviteUser = createAction({
|
||||
},
|
||||
});
|
||||
|
||||
export const deleteUserActionFactory = (userId: string) =>
|
||||
createAction({
|
||||
name: ({ t }) => `${t("Delete user")}…`,
|
||||
analyticsName: "Delete user",
|
||||
keywords: "leave",
|
||||
dangerous: true,
|
||||
section: UserSection,
|
||||
visible: ({ stores }) => stores.policies.abilities(userId).delete,
|
||||
perform: ({ t }) => {
|
||||
const user = stores.users.get(userId);
|
||||
if (!user) {
|
||||
return;
|
||||
}
|
||||
|
||||
stores.dialogs.openModal({
|
||||
title: t("Delete user"),
|
||||
isCentered: true,
|
||||
content: (
|
||||
<UserDeleteDialog
|
||||
user={user}
|
||||
onSubmit={stores.dialogs.closeAllModals}
|
||||
/>
|
||||
),
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export const rootUserActions = [inviteUser];
|
||||
@@ -8,7 +8,7 @@ import env from "~/env";
|
||||
const Analytics: React.FC = ({ children }) => {
|
||||
// Google Analytics 3
|
||||
React.useEffect(() => {
|
||||
if (!env.GOOGLE_ANALYTICS_ID) {
|
||||
if (!env.GOOGLE_ANALYTICS_ID?.startsWith("UA-")) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -37,25 +37,36 @@ const Analytics: React.FC = ({ children }) => {
|
||||
|
||||
// Google Analytics 4
|
||||
React.useEffect(() => {
|
||||
if (env.analytics.service !== IntegrationService.GoogleAnalytics) {
|
||||
const measurementIds = [];
|
||||
|
||||
if (env.analytics.service === IntegrationService.GoogleAnalytics) {
|
||||
measurementIds.push(escape(env.analytics.settings?.measurementId));
|
||||
}
|
||||
if (env.GOOGLE_ANALYTICS_ID?.startsWith("G-")) {
|
||||
measurementIds.push(env.GOOGLE_ANALYTICS_ID);
|
||||
}
|
||||
if (measurementIds.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const measurementId = escape(env.analytics.settings?.measurementId);
|
||||
const params = {
|
||||
allow_google_signals: false,
|
||||
restricted_data_processing: true,
|
||||
};
|
||||
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
window.gtag = function () {
|
||||
window.dataLayer.push(arguments);
|
||||
};
|
||||
window.gtag("js", new Date());
|
||||
window.gtag("config", measurementId, {
|
||||
allow_google_signals: false,
|
||||
restricted_data_processing: true,
|
||||
});
|
||||
|
||||
for (const measurementId of measurementIds) {
|
||||
window.gtag("config", measurementId, params);
|
||||
}
|
||||
|
||||
const script = document.createElement("script");
|
||||
script.type = "text/javascript";
|
||||
script.src = `https://www.googletagmanager.com/gtag/js?id=${measurementId}`;
|
||||
script.src = `https://www.googletagmanager.com/gtag/js?id=${measurementIds[0]}`;
|
||||
script.async = true;
|
||||
document.getElementsByTagName("head")[0]?.appendChild(script);
|
||||
}, []);
|
||||
|
||||
@@ -61,7 +61,7 @@ const AuthenticatedLayout: React.FC = ({ children }) => {
|
||||
return;
|
||||
}
|
||||
const { activeCollectionId } = ui;
|
||||
if (!activeCollectionId || !can.update) {
|
||||
if (!activeCollectionId || !can.createDocument) {
|
||||
return;
|
||||
}
|
||||
history.push(newDocumentPath(activeCollectionId));
|
||||
|
||||
@@ -39,7 +39,7 @@ function CollectionDeleteDialog({ collection, onSubmit }: Props) {
|
||||
<>
|
||||
<Text type="secondary">
|
||||
<Trans
|
||||
defaults="Are you sure about that? Deleting the <em>{{collectionName}}</em> collection is permanent and cannot be restored, however documents within will be moved to the trash."
|
||||
defaults="Are you sure about that? Deleting the <em>{{collectionName}}</em> collection is permanent and cannot be restored, however all published documents within will be moved to the trash."
|
||||
values={{
|
||||
collectionName: collection.name,
|
||||
}}
|
||||
|
||||
@@ -15,6 +15,8 @@ type Props = {
|
||||
savingText?: string;
|
||||
/** If true, the submit button will be a dangerous red */
|
||||
danger?: boolean;
|
||||
/** Keep the submit button disabled */
|
||||
disabled?: boolean;
|
||||
};
|
||||
|
||||
const ConfirmationDialog: React.FC<Props> = ({
|
||||
@@ -23,6 +25,7 @@ const ConfirmationDialog: React.FC<Props> = ({
|
||||
submitText,
|
||||
savingText,
|
||||
danger,
|
||||
disabled = false,
|
||||
}) => {
|
||||
const [isSaving, setIsSaving] = React.useState(false);
|
||||
const { dialogs } = useStores();
|
||||
@@ -50,7 +53,12 @@ const ConfirmationDialog: React.FC<Props> = ({
|
||||
<Flex column>
|
||||
<form onSubmit={handleSubmit}>
|
||||
<Text type="secondary">{children}</Text>
|
||||
<Button type="submit" disabled={isSaving} danger={danger} autoFocus>
|
||||
<Button
|
||||
type="submit"
|
||||
disabled={isSaving || disabled}
|
||||
danger={danger}
|
||||
autoFocus
|
||||
>
|
||||
{isSaving && savingText ? savingText : submitText}
|
||||
</Button>
|
||||
</form>
|
||||
|
||||
@@ -66,6 +66,7 @@ const SubMenu = React.forwardRef(
|
||||
{...menu}
|
||||
aria-label={t("Submenu")}
|
||||
onClick={parentMenuState.hide}
|
||||
parentMenuState={parentMenuState}
|
||||
>
|
||||
<MouseSafeArea parentRef={menu.unstable_popoverRef} />
|
||||
<Template {...menu} items={templateItems} />
|
||||
|
||||
@@ -39,7 +39,7 @@ export type Placement =
|
||||
type Props = MenuStateReturn & {
|
||||
"aria-label"?: string;
|
||||
/** The parent menu state if this is a submenu. */
|
||||
parentMenuState?: MenuStateReturn;
|
||||
parentMenuState?: Omit<MenuStateReturn, "items">;
|
||||
/** Called when the context menu is opened. */
|
||||
onOpen?: () => void;
|
||||
/** Called when the context menu is closed. */
|
||||
@@ -62,6 +62,7 @@ const ContextMenu: React.FC<Props> = ({
|
||||
const { t } = useTranslation();
|
||||
const { setIsMenuOpen } = useMenuContext();
|
||||
const isMobile = useMobile();
|
||||
const isSubMenu = !!parentMenuState;
|
||||
|
||||
useUnmount(() => {
|
||||
setIsMenuOpen(false);
|
||||
@@ -71,7 +72,7 @@ const ContextMenu: React.FC<Props> = ({
|
||||
if (rest.visible && !previousVisible) {
|
||||
onOpen?.();
|
||||
|
||||
if (!parentMenuState) {
|
||||
if (!isSubMenu) {
|
||||
setIsMenuOpen(true);
|
||||
}
|
||||
}
|
||||
@@ -79,7 +80,7 @@ const ContextMenu: React.FC<Props> = ({
|
||||
if (!rest.visible && previousVisible) {
|
||||
onClose?.();
|
||||
|
||||
if (!parentMenuState) {
|
||||
if (!isSubMenu) {
|
||||
setIsMenuOpen(false);
|
||||
}
|
||||
}
|
||||
@@ -90,7 +91,7 @@ const ContextMenu: React.FC<Props> = ({
|
||||
rest.visible,
|
||||
ui.sidebarCollapsed,
|
||||
setIsMenuOpen,
|
||||
parentMenuState,
|
||||
isSubMenu,
|
||||
t,
|
||||
]);
|
||||
|
||||
@@ -99,13 +100,15 @@ const ContextMenu: React.FC<Props> = ({
|
||||
// https://github.com/ariakit/ariakit/issues/469
|
||||
React.useEffect(() => {
|
||||
const scrollElement = backgroundRef.current;
|
||||
if (rest.visible && scrollElement) {
|
||||
disableBodyScroll(scrollElement);
|
||||
if (rest.visible && scrollElement && !isSubMenu) {
|
||||
disableBodyScroll(scrollElement, {
|
||||
reserveScrollBarGap: true,
|
||||
});
|
||||
}
|
||||
return () => {
|
||||
scrollElement && enableBodyScroll(scrollElement);
|
||||
scrollElement && !isSubMenu && enableBodyScroll(scrollElement);
|
||||
};
|
||||
}, [rest.visible]);
|
||||
}, [isSubMenu, rest.visible]);
|
||||
|
||||
// Perf win – don't render anything until the menu has been opened
|
||||
if (!rest.visible && !previousVisible) {
|
||||
|
||||
@@ -9,7 +9,12 @@ import Breadcrumb from "~/components/Breadcrumb";
|
||||
import CollectionIcon from "~/components/Icons/CollectionIcon";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import { MenuInternalLink } from "~/types";
|
||||
import { collectionUrl } from "~/utils/routeHelpers";
|
||||
import {
|
||||
archivePath,
|
||||
collectionPath,
|
||||
templatesPath,
|
||||
trashPath,
|
||||
} from "~/utils/routeHelpers";
|
||||
|
||||
type Props = {
|
||||
document: Document;
|
||||
@@ -24,7 +29,7 @@ function useCategory(document: Document): MenuInternalLink | null {
|
||||
type: "route",
|
||||
icon: <TrashIcon />,
|
||||
title: t("Trash"),
|
||||
to: "/trash",
|
||||
to: trashPath(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -33,7 +38,7 @@ function useCategory(document: Document): MenuInternalLink | null {
|
||||
type: "route",
|
||||
icon: <ArchiveIcon />,
|
||||
title: t("Archive"),
|
||||
to: "/archive",
|
||||
to: archivePath(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -42,7 +47,7 @@ function useCategory(document: Document): MenuInternalLink | null {
|
||||
type: "route",
|
||||
icon: <ShapesIcon />,
|
||||
title: t("Templates"),
|
||||
to: "/templates",
|
||||
to: templatesPath(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -57,7 +62,9 @@ const DocumentBreadcrumb: React.FC<Props> = ({
|
||||
const { collections } = useStores();
|
||||
const { t } = useTranslation();
|
||||
const category = useCategory(document);
|
||||
const collection = collections.get(document.collectionId);
|
||||
const collection = document.collectionId
|
||||
? collections.get(document.collectionId)
|
||||
: undefined;
|
||||
|
||||
let collectionNode: MenuInternalLink | undefined;
|
||||
|
||||
@@ -66,14 +73,14 @@ const DocumentBreadcrumb: React.FC<Props> = ({
|
||||
type: "route",
|
||||
title: collection.name,
|
||||
icon: <CollectionIcon collection={collection} expanded />,
|
||||
to: collectionUrl(collection.url),
|
||||
to: collectionPath(collection.url),
|
||||
};
|
||||
} else if (document.collectionId && !collection) {
|
||||
collectionNode = {
|
||||
type: "route",
|
||||
title: t("Deleted Collection"),
|
||||
icon: undefined,
|
||||
to: collectionUrl("deleted-collection"),
|
||||
to: collectionPath("deleted-collection"),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,9 @@ function DocumentCard(props: Props) {
|
||||
const { collections } = useStores();
|
||||
const theme = useTheme();
|
||||
const { document, pin, canUpdatePin, isDraggable } = props;
|
||||
const collection = collections.get(document.collectionId);
|
||||
const collection = document.collectionId
|
||||
? collections.get(document.collectionId)
|
||||
: undefined;
|
||||
const {
|
||||
attributes,
|
||||
listeners,
|
||||
|
||||
@@ -48,7 +48,6 @@ function DocumentExplorer({ onSubmit, onSelect, items }: Props) {
|
||||
const [initialScrollOffset, setInitialScrollOffset] = React.useState<number>(
|
||||
0
|
||||
);
|
||||
const [nodes, setNodes] = React.useState<NavigationNode[]>([]);
|
||||
const [activeNode, setActiveNode] = React.useState<number>(0);
|
||||
const [expandedNodes, setExpandedNodes] = React.useState<string[]>([]);
|
||||
const [itemRefs, setItemRefs] = React.useState<
|
||||
@@ -79,19 +78,6 @@ function DocumentExplorer({ onSubmit, onSelect, items }: Props) {
|
||||
setActiveNode(0);
|
||||
}, [searchTerm]);
|
||||
|
||||
React.useEffect(() => {
|
||||
let results;
|
||||
|
||||
if (searchTerm) {
|
||||
results = searchIndex.search(searchTerm);
|
||||
} else {
|
||||
results = items.filter((item) => item.type === "collection");
|
||||
}
|
||||
|
||||
setInitialScrollOffset(0);
|
||||
setNodes(results);
|
||||
}, [searchTerm, items, searchIndex]);
|
||||
|
||||
React.useEffect(() => {
|
||||
setItemRefs((itemRefs) =>
|
||||
map(
|
||||
@@ -105,6 +91,22 @@ function DocumentExplorer({ onSubmit, onSelect, items }: Props) {
|
||||
onSelect(selectedNode);
|
||||
}, [selectedNode, onSelect]);
|
||||
|
||||
function getNodes() {
|
||||
function includeDescendants(item: NavigationNode): NavigationNode[] {
|
||||
return expandedNodes.includes(item.id)
|
||||
? [item, ...descendants(item, 1).flatMap(includeDescendants)]
|
||||
: [item];
|
||||
}
|
||||
|
||||
return searchTerm
|
||||
? searchIndex.search(searchTerm)
|
||||
: items
|
||||
.filter((item) => item.type === "collection")
|
||||
.flatMap(includeDescendants);
|
||||
}
|
||||
|
||||
const nodes = getNodes();
|
||||
|
||||
const scrollNodeIntoView = React.useCallback(
|
||||
(node: number) => {
|
||||
if (itemRefs[node] && itemRefs[node].current) {
|
||||
@@ -130,7 +132,7 @@ function DocumentExplorer({ onSubmit, onSelect, items }: Props) {
|
||||
scrollOffset: number;
|
||||
};
|
||||
const itemsHeight = itemCount * itemSize;
|
||||
return itemsHeight < height ? 0 : scrollOffset;
|
||||
return itemsHeight < Number(height) ? 0 : scrollOffset;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
@@ -145,7 +147,6 @@ function DocumentExplorer({ onSubmit, onSelect, items }: Props) {
|
||||
const newNodes = filter(nodes, (node) => !includes(descendantIds, node.id));
|
||||
const scrollOffset = calculateInitialScrollOffset(newNodes.length);
|
||||
setInitialScrollOffset(scrollOffset);
|
||||
setNodes(newNodes);
|
||||
};
|
||||
|
||||
const expand = (node: number) => {
|
||||
@@ -156,9 +157,18 @@ function DocumentExplorer({ onSubmit, onSelect, items }: Props) {
|
||||
newNodes.splice(node + 1, 0, ...descendants(nodes[node], 1));
|
||||
const scrollOffset = calculateInitialScrollOffset(newNodes.length);
|
||||
setInitialScrollOffset(scrollOffset);
|
||||
setNodes(newNodes);
|
||||
};
|
||||
|
||||
React.useEffect(() => {
|
||||
collections.orderedData
|
||||
.filter(
|
||||
(collection) => expandedNodes.includes(collection.id) || searchTerm
|
||||
)
|
||||
.forEach((collection) => {
|
||||
collection.fetchDocuments();
|
||||
});
|
||||
}, [collections, expandedNodes, searchTerm]);
|
||||
|
||||
const isSelected = (node: number) => {
|
||||
if (!selectedNode) {
|
||||
return false;
|
||||
@@ -169,7 +179,8 @@ function DocumentExplorer({ onSubmit, onSelect, items }: Props) {
|
||||
return selectedNodeId === nodeId;
|
||||
};
|
||||
|
||||
const hasChildren = (node: number) => nodes[node].children.length > 0;
|
||||
const hasChildren = (node: number) =>
|
||||
nodes[node].children.length > 0 || nodes[node].type === "collection";
|
||||
|
||||
const toggleCollapse = (node: number) => {
|
||||
if (!hasChildren(node)) {
|
||||
@@ -219,7 +230,7 @@ function DocumentExplorer({ onSubmit, onSelect, items }: Props) {
|
||||
} else if (doc?.isStarred) {
|
||||
icon = <StarredIcon color={theme.yellow} />;
|
||||
} else {
|
||||
icon = <DocumentIcon />;
|
||||
icon = <DocumentIcon color={theme.textSecondary} />;
|
||||
}
|
||||
|
||||
path = ancestors(node)
|
||||
@@ -281,12 +292,14 @@ function DocumentExplorer({ onSubmit, onSelect, items }: Props) {
|
||||
switch (ev.key) {
|
||||
case "ArrowDown": {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
setActiveNode(next());
|
||||
scrollNodeIntoView(next());
|
||||
break;
|
||||
}
|
||||
case "ArrowUp": {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
if (activeNode === 0) {
|
||||
focusSearchInput();
|
||||
} else {
|
||||
|
||||
@@ -57,7 +57,9 @@ const DocumentMeta: React.FC<Props> = ({
|
||||
return null;
|
||||
}
|
||||
|
||||
const collection = collections.get(document.collectionId);
|
||||
const collection = document.collectionId
|
||||
? collections.get(document.collectionId)
|
||||
: undefined;
|
||||
const lastUpdatedByCurrentUser = user.id === updatedBy.id;
|
||||
const userName = updatedBy.name;
|
||||
let content;
|
||||
|
||||
@@ -6,7 +6,7 @@ import { useHistory } from "react-router-dom";
|
||||
import ConfirmationDialog from "~/components/ConfirmationDialog";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import useToasts from "~/hooks/useToasts";
|
||||
import { documentUrl } from "~/utils/routeHelpers";
|
||||
import { documentPath } from "~/utils/routeHelpers";
|
||||
|
||||
type Props = {
|
||||
documentId: string;
|
||||
@@ -23,7 +23,7 @@ function DocumentTemplatizeDialog({ documentId }: Props) {
|
||||
const handleSubmit = React.useCallback(async () => {
|
||||
const template = await document?.templatize();
|
||||
if (template) {
|
||||
history.push(documentUrl(template));
|
||||
history.push(documentPath(template));
|
||||
showToast(t("Template created, go ahead and customize it"), {
|
||||
type: "info",
|
||||
});
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import { observer } from "mobx-react";
|
||||
import * as React from "react";
|
||||
import Collection from "~/models/Collection";
|
||||
|
||||
type Props = {
|
||||
enabled: boolean;
|
||||
collection: Collection;
|
||||
children: React.ReactNode;
|
||||
};
|
||||
|
||||
function DocumentsLoader({ collection, enabled, children }: Props) {
|
||||
React.useEffect(() => {
|
||||
if (enabled) {
|
||||
void collection.fetchDocuments();
|
||||
}
|
||||
}, [collection, enabled]);
|
||||
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
export default observer(DocumentsLoader);
|
||||
@@ -350,6 +350,7 @@ function Editor(props: Props, ref: React.RefObject<SharedEditor> | null) {
|
||||
)}
|
||||
{activeLinkElement && !shareId && (
|
||||
<HoverPreview
|
||||
id={props.id}
|
||||
element={activeLinkElement}
|
||||
onClose={handleLinkInactive}
|
||||
/>
|
||||
|
||||
@@ -26,7 +26,7 @@ import Time from "~/components/Time";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import RevisionMenu from "~/menus/RevisionMenu";
|
||||
import Logger from "~/utils/Logger";
|
||||
import { documentHistoryUrl } from "~/utils/routeHelpers";
|
||||
import { documentHistoryPath } from "~/utils/routeHelpers";
|
||||
|
||||
type Props = {
|
||||
document: Document;
|
||||
@@ -62,7 +62,7 @@ const EventListItem = ({ event, latest, document, ...rest }: Props) => {
|
||||
icon = <EditIcon size={16} />;
|
||||
meta = t("{{userName}} edited", opts);
|
||||
to = {
|
||||
pathname: documentHistoryUrl(document, event.modelId || ""),
|
||||
pathname: documentHistoryPath(document, event.modelId || ""),
|
||||
state: { retainScrollPosition: true },
|
||||
};
|
||||
break;
|
||||
@@ -71,7 +71,7 @@ const EventListItem = ({ event, latest, document, ...rest }: Props) => {
|
||||
icon = <LightningIcon size={16} />;
|
||||
meta = t("Latest");
|
||||
to = {
|
||||
pathname: documentHistoryUrl(document),
|
||||
pathname: documentHistoryPath(document),
|
||||
state: { retainScrollPosition: true },
|
||||
};
|
||||
break;
|
||||
|
||||
@@ -14,11 +14,15 @@ const DELAY_OPEN = 300;
|
||||
const DELAY_CLOSE = 300;
|
||||
|
||||
type Props = {
|
||||
/* The document associated with the editor, if any */
|
||||
id?: string;
|
||||
/* The HTML element that is being hovered over */
|
||||
element: HTMLAnchorElement;
|
||||
/* A callback on close of the hover preview */
|
||||
onClose: () => void;
|
||||
};
|
||||
|
||||
function HoverPreviewInternal({ element, onClose }: Props) {
|
||||
function HoverPreviewInternal({ element, id, onClose }: Props) {
|
||||
const { documents } = useStores();
|
||||
const slug = parseDocumentSlug(element.href);
|
||||
const [isVisible, setVisible] = React.useState(false);
|
||||
@@ -104,7 +108,7 @@ function HoverPreviewInternal({ element, onClose }: Props) {
|
||||
aria-hidden
|
||||
>
|
||||
<div ref={cardRef}>
|
||||
<HoverPreviewDocument url={element.href}>
|
||||
<HoverPreviewDocument url={element.href} id={id}>
|
||||
{(content: React.ReactNode) =>
|
||||
isVisible ? (
|
||||
<Animate>
|
||||
|
||||
@@ -9,11 +9,14 @@ import Editor from "~/components/Editor";
|
||||
import useStores from "~/hooks/useStores";
|
||||
|
||||
type Props = {
|
||||
/* The document associated with the editor, if any */
|
||||
id?: string;
|
||||
/* The URL we want a preview for */
|
||||
url: string;
|
||||
children: (content: React.ReactNode) => React.ReactNode;
|
||||
};
|
||||
|
||||
function HoverPreviewDocument({ url, children }: Props) {
|
||||
function HoverPreviewDocument({ url, id, children }: Props) {
|
||||
const { documents } = useStores();
|
||||
const slug = parseDocumentSlug(url);
|
||||
|
||||
@@ -22,7 +25,7 @@ function HoverPreviewDocument({ url, children }: Props) {
|
||||
}
|
||||
|
||||
const document = slug ? documents.getByUrl(slug) : undefined;
|
||||
if (!document) {
|
||||
if (!document || document.id === id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -175,6 +175,7 @@ function Input(
|
||||
labelHidden,
|
||||
onFocus,
|
||||
onBlur,
|
||||
children,
|
||||
...rest
|
||||
} = props;
|
||||
|
||||
@@ -211,6 +212,7 @@ function Input(
|
||||
{...rest}
|
||||
/>
|
||||
)}
|
||||
{children}
|
||||
</Outline>
|
||||
</label>
|
||||
{error && (
|
||||
|
||||
@@ -1,35 +1,34 @@
|
||||
import { observer } from "mobx-react";
|
||||
import * as React from "react";
|
||||
import { Helmet } from "react-helmet-async";
|
||||
import { cdnPath } from "@shared/utils/urls";
|
||||
import env from "~/env";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import { useTeamContext } from "./TeamContext";
|
||||
|
||||
type Props = {
|
||||
title: React.ReactNode;
|
||||
favicon?: string;
|
||||
};
|
||||
|
||||
const originalShortcutHref = document
|
||||
.querySelector('link[rel="shortcut icon"]')
|
||||
?.getAttribute("href") as string;
|
||||
|
||||
const PageTitle = ({ title, favicon }: Props) => {
|
||||
const { auth } = useStores();
|
||||
const { team } = auth;
|
||||
const team = useTeamContext() ?? auth.team;
|
||||
|
||||
return (
|
||||
<Helmet>
|
||||
<title>
|
||||
{team?.name ? `${title} - ${team.name}` : `${title} - ${env.APP_NAME}`}
|
||||
</title>
|
||||
{favicon ? (
|
||||
<link rel="shortcut icon" href={favicon} key={favicon} />
|
||||
) : (
|
||||
<link
|
||||
rel="shortcut icon"
|
||||
type="image/png"
|
||||
key="favicon"
|
||||
href={cdnPath("/images/favicon-32.png")}
|
||||
sizes="32x32"
|
||||
/>
|
||||
)}
|
||||
<link
|
||||
rel="shortcut icon"
|
||||
type="image/png"
|
||||
href={favicon ?? originalShortcutHref}
|
||||
key={favicon ?? originalShortcutHref}
|
||||
/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
</Helmet>
|
||||
);
|
||||
|
||||
@@ -8,7 +8,7 @@ import SearchPopover from "~/components/SearchPopover";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import history from "~/utils/history";
|
||||
import { homePath, sharedDocumentPath } from "~/utils/routeHelpers";
|
||||
import { IAvatar } from "../Avatar/Avatar";
|
||||
import { useTeamContext } from "../TeamContext";
|
||||
import TeamLogo from "../TeamLogo";
|
||||
import Sidebar from "./Sidebar";
|
||||
import HeaderButton from "./components/HeaderButton";
|
||||
@@ -16,12 +16,12 @@ import Section from "./components/Section";
|
||||
import DocumentLink from "./components/SharedDocumentLink";
|
||||
|
||||
type Props = {
|
||||
team?: IAvatar & { name: string };
|
||||
rootNode: NavigationNode;
|
||||
shareId: string;
|
||||
};
|
||||
|
||||
function SharedSidebar({ rootNode, team, shareId }: Props) {
|
||||
function SharedSidebar({ rootNode, shareId }: Props) {
|
||||
const team = useTeamContext();
|
||||
const { ui, documents, auth } = useStores();
|
||||
const { t } = useTranslation();
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ const CollectionLink: React.FC<Props> = ({
|
||||
const { dialogs, documents, collections } = useStores();
|
||||
const [menuOpen, handleMenuOpen, handleMenuClose] = useBoolean();
|
||||
const [isEditing, setIsEditing] = React.useState(false);
|
||||
const canUpdate = usePolicy(collection).update;
|
||||
const can = usePolicy(collection);
|
||||
const { t } = useTranslation();
|
||||
const history = useHistory();
|
||||
const inStarredSection = useStarredContext();
|
||||
@@ -105,7 +105,7 @@ const CollectionLink: React.FC<Props> = ({
|
||||
}
|
||||
}
|
||||
},
|
||||
canDrop: () => canUpdate,
|
||||
canDrop: () => can.createDocument,
|
||||
collect: (monitor) => ({
|
||||
isOver: !!monitor.isOver({
|
||||
shallow: true,
|
||||
@@ -118,6 +118,10 @@ const CollectionLink: React.FC<Props> = ({
|
||||
setIsEditing(isEditing);
|
||||
}, []);
|
||||
|
||||
const handleMouseEnter = React.useCallback(() => {
|
||||
void collection.fetchDocuments();
|
||||
}, [collection]);
|
||||
|
||||
const context = useActionContext({
|
||||
activeCollectionId: collection.id,
|
||||
inStarredSection,
|
||||
@@ -134,6 +138,7 @@ const CollectionLink: React.FC<Props> = ({
|
||||
}}
|
||||
expanded={expanded}
|
||||
onDisclosureClick={onDisclosureClick}
|
||||
onMouseEnter={handleMouseEnter}
|
||||
icon={
|
||||
<CollectionIcon collection={collection} expanded={expanded} />
|
||||
}
|
||||
@@ -147,7 +152,7 @@ const CollectionLink: React.FC<Props> = ({
|
||||
title={collection.name}
|
||||
onSubmit={handleTitleChange}
|
||||
onEditing={handleTitleEditing}
|
||||
canUpdate={canUpdate}
|
||||
canUpdate={can.update}
|
||||
/>
|
||||
}
|
||||
exact={false}
|
||||
|
||||
@@ -2,8 +2,12 @@ import { observer } from "mobx-react";
|
||||
import * as React from "react";
|
||||
import { useDrop } from "react-dnd";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import styled from "styled-components";
|
||||
import Collection from "~/models/Collection";
|
||||
import Document from "~/models/Document";
|
||||
import DelayedMount from "~/components/DelayedMount";
|
||||
import DocumentsLoader from "~/components/DocumentsLoader";
|
||||
import { ResizingHeightContainer } from "~/components/ResizingHeightContainer";
|
||||
import usePolicy from "~/hooks/usePolicy";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import useToasts from "~/hooks/useToasts";
|
||||
@@ -11,6 +15,7 @@ import DocumentLink from "./DocumentLink";
|
||||
import DropCursor from "./DropCursor";
|
||||
import EmptyCollectionPlaceholder from "./EmptyCollectionPlaceholder";
|
||||
import Folder from "./Folder";
|
||||
import PlaceholderCollections from "./PlaceholderCollections";
|
||||
import { DragObject } from "./SidebarLink";
|
||||
import useCollectionDocuments from "./useCollectionDocuments";
|
||||
|
||||
@@ -63,28 +68,42 @@ function CollectionLinkChildren({
|
||||
|
||||
return (
|
||||
<Folder expanded={expanded}>
|
||||
{isDraggingAnyDocument && can.update && manualSort && (
|
||||
{isDraggingAnyDocument && can.createDocument && manualSort && (
|
||||
<DropCursor
|
||||
isActiveDrop={isOverReorder}
|
||||
innerRef={dropToReorder}
|
||||
position="top"
|
||||
/>
|
||||
)}
|
||||
{childDocuments.map((node, index) => (
|
||||
<DocumentLink
|
||||
key={node.id}
|
||||
node={node}
|
||||
collection={collection}
|
||||
activeDocument={documents.active}
|
||||
prefetchDocument={prefetchDocument}
|
||||
isDraft={node.isDraft}
|
||||
depth={2}
|
||||
index={index}
|
||||
/>
|
||||
))}
|
||||
{childDocuments.length === 0 && <EmptyCollectionPlaceholder />}
|
||||
<DocumentsLoader collection={collection} enabled={expanded}>
|
||||
{!childDocuments && (
|
||||
<ResizingHeightContainer hideOverflow>
|
||||
<DelayedMount>
|
||||
<Loading />
|
||||
</DelayedMount>
|
||||
</ResizingHeightContainer>
|
||||
)}
|
||||
{childDocuments?.map((node, index) => (
|
||||
<DocumentLink
|
||||
key={node.id}
|
||||
node={node}
|
||||
collection={collection}
|
||||
activeDocument={documents.active}
|
||||
prefetchDocument={prefetchDocument}
|
||||
isDraft={node.isDraft}
|
||||
depth={2}
|
||||
index={index}
|
||||
/>
|
||||
))}
|
||||
{childDocuments?.length === 0 && <EmptyCollectionPlaceholder />}
|
||||
</DocumentsLoader>
|
||||
</Folder>
|
||||
);
|
||||
}
|
||||
|
||||
const Loading = styled(PlaceholderCollections)`
|
||||
margin-left: 44px;
|
||||
min-height: 90px;
|
||||
`;
|
||||
|
||||
export default observer(CollectionLinkChildren);
|
||||
@@ -23,6 +23,13 @@ function Collections() {
|
||||
const { t } = useTranslation();
|
||||
const orderedCollections = collections.orderedData;
|
||||
|
||||
const params = React.useMemo(
|
||||
() => ({
|
||||
limit: 100,
|
||||
}),
|
||||
[]
|
||||
);
|
||||
|
||||
const [
|
||||
{ isCollectionDropping, isDraggingAnyCollection },
|
||||
dropToReorderCollection,
|
||||
@@ -47,7 +54,7 @@ function Collections() {
|
||||
<Relative>
|
||||
<PaginatedList
|
||||
fetch={collections.fetchPage}
|
||||
options={{ limit: 25 }}
|
||||
options={params}
|
||||
aria-label={t("Collections")}
|
||||
items={collections.orderedData}
|
||||
loading={<PlaceholderCollections />}
|
||||
|
||||
@@ -26,10 +26,14 @@ function DropToImport({ disabled, children, collectionId, documentId }: Props) {
|
||||
collectionId,
|
||||
documentId
|
||||
);
|
||||
const targetId = collectionId || documentId;
|
||||
invariant(targetId, "Must provide either collectionId or documentId");
|
||||
invariant(
|
||||
collectionId || documentId,
|
||||
"Must provide either collectionId or documentId"
|
||||
);
|
||||
|
||||
const canCollection = usePolicy(collectionId);
|
||||
const canDocument = usePolicy(documentId);
|
||||
|
||||
const can = usePolicy(targetId);
|
||||
const handleRejection = React.useCallback(() => {
|
||||
showToast(
|
||||
t("Document not supported – try Markdown, Plain text, HTML, or Word"),
|
||||
@@ -39,7 +43,11 @@ function DropToImport({ disabled, children, collectionId, documentId }: Props) {
|
||||
);
|
||||
}, [t, showToast]);
|
||||
|
||||
if (disabled || !can.update) {
|
||||
if (
|
||||
disabled ||
|
||||
(collectionId && !canCollection.createDocument) ||
|
||||
(documentId && !canDocument.createChildDocument)
|
||||
) {
|
||||
return children;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@ import * as React from "react";
|
||||
import styled from "styled-components";
|
||||
import PlaceholderText from "~/components/PlaceholderText";
|
||||
|
||||
function PlaceholderCollections() {
|
||||
function PlaceholderCollections(props: React.HTMLAttributes<HTMLDivElement>) {
|
||||
return (
|
||||
<Wrapper>
|
||||
<Wrapper {...props}>
|
||||
<PlaceholderText />
|
||||
<PlaceholderText delay={0.2} />
|
||||
<PlaceholderText delay={0.4} />
|
||||
|
||||
@@ -152,7 +152,9 @@ function StarredLink({ star }: Props) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const collection = collections.get(document.collectionId);
|
||||
const collection = document.collectionId
|
||||
? collections.get(document.collectionId)
|
||||
: undefined;
|
||||
const childDocuments = collection
|
||||
? collection.getDocumentChildren(documentId)
|
||||
: [];
|
||||
|
||||
@@ -8,8 +8,8 @@ export default function useCollectionDocuments(
|
||||
activeDocument: Document | undefined
|
||||
) {
|
||||
return React.useMemo(() => {
|
||||
if (!collection) {
|
||||
return [];
|
||||
if (!collection?.sortedDocuments) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const insertDraftDocument =
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import * as React from "react";
|
||||
import { PublicTeam } from "@shared/types";
|
||||
import Team from "~/models/Team";
|
||||
|
||||
export const TeamContext = React.createContext<Team | PublicTeam | undefined>(
|
||||
undefined
|
||||
);
|
||||
|
||||
export function useTeamContext() {
|
||||
return React.useContext(TeamContext);
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import * as React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import User from "~/models/User";
|
||||
import ConfirmationDialog from "~/components/ConfirmationDialog";
|
||||
import Input from "~/components/Input";
|
||||
import useStores from "~/hooks/useStores";
|
||||
|
||||
type Props = {
|
||||
@@ -57,6 +58,31 @@ export function UserChangeToMemberDialog({ user, onSubmit }: Props) {
|
||||
);
|
||||
}
|
||||
|
||||
export function UserDeleteDialog({ user, onSubmit }: Props) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const handleSubmit = async () => {
|
||||
await user.delete();
|
||||
onSubmit();
|
||||
};
|
||||
|
||||
return (
|
||||
<ConfirmationDialog
|
||||
onSubmit={handleSubmit}
|
||||
submitText={t("I understand, delete")}
|
||||
savingText={`${t("Deleting")}…`}
|
||||
danger
|
||||
>
|
||||
{t(
|
||||
"Are you sure you want to permanently delete {{ userName }}? This operation is unrecoverable, consider suspending the user instead.",
|
||||
{
|
||||
userName: user.name,
|
||||
}
|
||||
)}
|
||||
</ConfirmationDialog>
|
||||
);
|
||||
}
|
||||
|
||||
export function UserChangeToAdminDialog({ user, onSubmit }: Props) {
|
||||
const { t } = useTranslation();
|
||||
const { users } = useStores();
|
||||
@@ -106,3 +132,37 @@ export function UserSuspendDialog({ user, onSubmit }: Props) {
|
||||
</ConfirmationDialog>
|
||||
);
|
||||
}
|
||||
|
||||
export function UserChangeNameDialog({ user, onSubmit }: Props) {
|
||||
const { t } = useTranslation();
|
||||
const [name, setName] = React.useState<string>(user.name);
|
||||
|
||||
const handleSubmit = async () => {
|
||||
await user.save({ name });
|
||||
onSubmit();
|
||||
};
|
||||
|
||||
const handleChange = (ev: React.ChangeEvent<HTMLInputElement>) => {
|
||||
setName(ev.target.value);
|
||||
};
|
||||
|
||||
return (
|
||||
<ConfirmationDialog
|
||||
onSubmit={handleSubmit}
|
||||
submitText={t("Save")}
|
||||
savingText={`${t("Saving")}…`}
|
||||
disabled={!name}
|
||||
>
|
||||
<Input
|
||||
type="text"
|
||||
name="name"
|
||||
label={t("New name")}
|
||||
onChange={handleChange}
|
||||
error={!name ? t("Name can't be empty") : undefined}
|
||||
value={name}
|
||||
required
|
||||
flex
|
||||
/>
|
||||
</ConfirmationDialog>
|
||||
);
|
||||
}
|
||||
@@ -175,7 +175,7 @@ class WebsocketProvider extends React.Component<Props> {
|
||||
id: document.collectionId,
|
||||
});
|
||||
|
||||
if (!existing) {
|
||||
if (!existing && document.collectionId) {
|
||||
event.collectionIds.push({
|
||||
id: document.collectionId,
|
||||
});
|
||||
@@ -196,7 +196,7 @@ class WebsocketProvider extends React.Component<Props> {
|
||||
}
|
||||
|
||||
try {
|
||||
await collections.fetch(collectionId, {
|
||||
await collection?.fetchDocuments({
|
||||
force: true,
|
||||
});
|
||||
} catch (err) {
|
||||
@@ -293,15 +293,23 @@ class WebsocketProvider extends React.Component<Props> {
|
||||
collections.add(event);
|
||||
});
|
||||
|
||||
this.socket.on("collections.update", (event: PartialWithId<Collection>) => {
|
||||
collections.add(event);
|
||||
});
|
||||
|
||||
this.socket.on(
|
||||
"collections.delete",
|
||||
action((event: WebsocketEntityDeletedEvent) => {
|
||||
const collectionId = event.modelId;
|
||||
const deletedAt = new Date().toISOString();
|
||||
|
||||
const deletedDocuments = documents.inCollection(collectionId);
|
||||
deletedDocuments.forEach((doc) => {
|
||||
doc.deletedAt = deletedAt;
|
||||
if (!doc.publishedAt) {
|
||||
// draft is to be detached from collection, not deleted
|
||||
doc.collectionId = null;
|
||||
} else {
|
||||
doc.deletedAt = deletedAt;
|
||||
}
|
||||
policies.remove(doc.id);
|
||||
});
|
||||
documents.removeCollectionDocuments(collectionId);
|
||||
@@ -369,15 +377,29 @@ class WebsocketProvider extends React.Component<Props> {
|
||||
// or otherwise just remove any membership state we have for that user.
|
||||
this.socket.on(
|
||||
"collections.remove_user",
|
||||
action((event: WebsocketCollectionUserEvent) => {
|
||||
async (event: WebsocketCollectionUserEvent) => {
|
||||
if (auth.user && event.userId === auth.user.id) {
|
||||
collections.remove(event.collectionId);
|
||||
memberships.removeCollectionMemberships(event.collectionId);
|
||||
// check if we still have access to the collection
|
||||
try {
|
||||
await collections.fetch(event.collectionId, {
|
||||
force: true,
|
||||
});
|
||||
} catch (err) {
|
||||
if (
|
||||
err instanceof AuthorizationError ||
|
||||
err instanceof NotFoundError
|
||||
) {
|
||||
collections.remove(event.collectionId);
|
||||
memberships.remove(`${event.userId}-${event.collectionId}`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
documents.removeCollectionDocuments(event.collectionId);
|
||||
} else {
|
||||
memberships.remove(`${event.userId}-${event.collectionId}`);
|
||||
}
|
||||
})
|
||||
}
|
||||
);
|
||||
|
||||
this.socket.on(
|
||||
|
||||
@@ -11,7 +11,9 @@ import isMarkActive from "@shared/editor/queries/isMarkActive";
|
||||
import isNodeActive from "@shared/editor/queries/isNodeActive";
|
||||
import { MenuItem } from "@shared/editor/types";
|
||||
import { creatingUrlPrefix } from "@shared/utils/urls";
|
||||
import useBoolean from "~/hooks/useBoolean";
|
||||
import useDictionary from "~/hooks/useDictionary";
|
||||
import useEventListener from "~/hooks/useEventListener";
|
||||
import useMobile from "~/hooks/useMobile";
|
||||
import usePrevious from "~/hooks/usePrevious";
|
||||
import useToasts from "~/hooks/useToasts";
|
||||
@@ -73,6 +75,14 @@ function useIsActive(state: EditorState) {
|
||||
return some(nodes, (n) => n.content.size);
|
||||
}
|
||||
|
||||
function useIsDragging() {
|
||||
const [isDragging, setDragging, setNotDragging] = useBoolean();
|
||||
useEventListener("dragstart", setDragging);
|
||||
useEventListener("dragend", setNotDragging);
|
||||
useEventListener("drop", setNotDragging);
|
||||
return isDragging;
|
||||
}
|
||||
|
||||
export default function SelectionToolbar(props: Props) {
|
||||
const { onClose, onOpen } = props;
|
||||
const { view, commands } = useEditor();
|
||||
@@ -80,6 +90,7 @@ export default function SelectionToolbar(props: Props) {
|
||||
const dictionary = useDictionary();
|
||||
const menuRef = React.useRef<HTMLDivElement | null>(null);
|
||||
const isActive = useIsActive(view.state);
|
||||
const isDragging = useIsDragging();
|
||||
const previousIsActuve = usePrevious(isActive);
|
||||
const isMobile = useMobile();
|
||||
|
||||
@@ -182,7 +193,7 @@ export default function SelectionToolbar(props: Props) {
|
||||
const isDividerSelection = isNodeActive(state.schema.nodes.hr)(state);
|
||||
|
||||
// toolbar is disabled in code blocks, no bold / italic etc
|
||||
if (isCodeSelection) {
|
||||
if (isCodeSelection || isDragging) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
ClockIcon,
|
||||
CalendarIcon,
|
||||
MathIcon,
|
||||
DoneIcon,
|
||||
} from "outline-icons";
|
||||
import * as React from "react";
|
||||
import styled from "styled-components";
|
||||
@@ -116,6 +117,7 @@ export default function blockMenuItems(dictionary: Dictionary): MenuItem[] {
|
||||
name: "blockquote",
|
||||
title: dictionary.quote,
|
||||
icon: <BlockQuoteIcon />,
|
||||
keywords: "blockquote pullquote",
|
||||
shortcut: `${metaDisplay} ]`,
|
||||
},
|
||||
{
|
||||
@@ -173,6 +175,13 @@ export default function blockMenuItems(dictionary: Dictionary): MenuItem[] {
|
||||
keywords: "notice card information",
|
||||
attrs: { style: "info" },
|
||||
},
|
||||
{
|
||||
name: "container_notice",
|
||||
title: dictionary.successNotice,
|
||||
icon: <DoneIcon />,
|
||||
keywords: "notice card success",
|
||||
attrs: { style: "success" },
|
||||
},
|
||||
{
|
||||
name: "container_notice",
|
||||
title: dictionary.warningNotice,
|
||||
|
||||
@@ -73,9 +73,11 @@ export default function useCollectionTrees(): NavigationNode[] {
|
||||
return addParent(addCollectionId(addDepth(addType(collectionNode))));
|
||||
};
|
||||
|
||||
const key = collections.orderedData.map((o) => o.documents?.length).join("-");
|
||||
const collectionTrees = React.useMemo(
|
||||
() => collections.orderedData.map(getCollectionTree),
|
||||
[collections.orderedData]
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
[collections.orderedData, key]
|
||||
);
|
||||
|
||||
return collectionTrees;
|
||||
|
||||
@@ -76,6 +76,8 @@ export default function useDictionary() {
|
||||
showSource: t("Show source"),
|
||||
warning: t("Warning"),
|
||||
warningNotice: t("Warning notice"),
|
||||
success: t("Success"),
|
||||
successNotice: t("Success notice"),
|
||||
insertDate: t("Current date"),
|
||||
insertTime: t("Current time"),
|
||||
insertDateTime: t("Current date and time"),
|
||||
|
||||
@@ -8,7 +8,7 @@ import useToasts from "~/hooks/useToasts";
|
||||
let importingLock = false;
|
||||
|
||||
export default function useImportDocument(
|
||||
collectionId?: string,
|
||||
collectionId?: string | null,
|
||||
documentId?: string
|
||||
): {
|
||||
handleFiles: (files: File[]) => Promise<void>;
|
||||
|
||||
@@ -9,7 +9,7 @@ import useStores from "./useStores";
|
||||
* @param entity The model or model id
|
||||
* @returns The policy for the model
|
||||
*/
|
||||
export default function usePolicy(entity: string | BaseModel | undefined) {
|
||||
export default function usePolicy(entity?: string | BaseModel | null) {
|
||||
const { policies } = useStores();
|
||||
const triggered = React.useRef(false);
|
||||
const entityId = entity
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { mapValues } from "lodash";
|
||||
import {
|
||||
EmailIcon,
|
||||
ProfileIcon,
|
||||
@@ -40,19 +39,13 @@ import { accountPreferencesPath } from "~/utils/routeHelpers";
|
||||
import useCurrentTeam from "./useCurrentTeam";
|
||||
import usePolicy from "./usePolicy";
|
||||
|
||||
type SettingsGroups = "Account" | "Workspace" | "Integrations";
|
||||
|
||||
export type ConfigItem = {
|
||||
name: string;
|
||||
path: string;
|
||||
icon: React.FC<any>;
|
||||
component: () => JSX.Element;
|
||||
component: React.ComponentType<any>;
|
||||
enabled: boolean;
|
||||
group: SettingsGroups;
|
||||
};
|
||||
|
||||
type ConfigType = {
|
||||
[key in string]: ConfigItem;
|
||||
group: string;
|
||||
};
|
||||
|
||||
const useSettingsConfig = () => {
|
||||
@@ -60,9 +53,9 @@ const useSettingsConfig = () => {
|
||||
const can = usePolicy(team);
|
||||
const { t } = useTranslation();
|
||||
|
||||
const config: ConfigType = React.useMemo(
|
||||
() => ({
|
||||
Profile: {
|
||||
const config = React.useMemo(() => {
|
||||
const items: ConfigItem[] = [
|
||||
{
|
||||
name: t("Profile"),
|
||||
path: "/settings",
|
||||
component: Profile,
|
||||
@@ -70,7 +63,7 @@ const useSettingsConfig = () => {
|
||||
group: t("Account"),
|
||||
icon: ProfileIcon,
|
||||
},
|
||||
Preferences: {
|
||||
{
|
||||
name: t("Preferences"),
|
||||
path: accountPreferencesPath(),
|
||||
component: Preferences,
|
||||
@@ -78,7 +71,7 @@ const useSettingsConfig = () => {
|
||||
group: t("Account"),
|
||||
icon: SettingsIcon,
|
||||
},
|
||||
Notifications: {
|
||||
{
|
||||
name: t("Notifications"),
|
||||
path: "/settings/notifications",
|
||||
component: Notifications,
|
||||
@@ -86,7 +79,7 @@ const useSettingsConfig = () => {
|
||||
group: t("Account"),
|
||||
icon: EmailIcon,
|
||||
},
|
||||
Api: {
|
||||
{
|
||||
name: t("API Tokens"),
|
||||
path: "/settings/tokens",
|
||||
component: ApiKeys,
|
||||
@@ -95,7 +88,7 @@ const useSettingsConfig = () => {
|
||||
icon: CodeIcon,
|
||||
},
|
||||
// Team group
|
||||
Details: {
|
||||
{
|
||||
name: t("Details"),
|
||||
path: "/settings/details",
|
||||
component: Details,
|
||||
@@ -103,7 +96,7 @@ const useSettingsConfig = () => {
|
||||
group: t("Workspace"),
|
||||
icon: TeamIcon,
|
||||
},
|
||||
Security: {
|
||||
{
|
||||
name: t("Security"),
|
||||
path: "/settings/security",
|
||||
component: Security,
|
||||
@@ -111,7 +104,7 @@ const useSettingsConfig = () => {
|
||||
group: t("Workspace"),
|
||||
icon: PadlockIcon,
|
||||
},
|
||||
Features: {
|
||||
{
|
||||
name: t("Features"),
|
||||
path: "/settings/features",
|
||||
component: Features,
|
||||
@@ -119,7 +112,7 @@ const useSettingsConfig = () => {
|
||||
group: t("Workspace"),
|
||||
icon: BeakerIcon,
|
||||
},
|
||||
Members: {
|
||||
{
|
||||
name: t("Members"),
|
||||
path: "/settings/members",
|
||||
component: Members,
|
||||
@@ -127,7 +120,7 @@ const useSettingsConfig = () => {
|
||||
group: t("Workspace"),
|
||||
icon: UserIcon,
|
||||
},
|
||||
Groups: {
|
||||
{
|
||||
name: t("Groups"),
|
||||
path: "/settings/groups",
|
||||
component: Groups,
|
||||
@@ -135,7 +128,7 @@ const useSettingsConfig = () => {
|
||||
group: t("Workspace"),
|
||||
icon: GroupIcon,
|
||||
},
|
||||
Shares: {
|
||||
{
|
||||
name: t("Shared Links"),
|
||||
path: "/settings/shares",
|
||||
component: Shares,
|
||||
@@ -143,7 +136,7 @@ const useSettingsConfig = () => {
|
||||
group: t("Workspace"),
|
||||
icon: LinkIcon,
|
||||
},
|
||||
Import: {
|
||||
{
|
||||
name: t("Import"),
|
||||
path: "/settings/import",
|
||||
component: Import,
|
||||
@@ -151,7 +144,7 @@ const useSettingsConfig = () => {
|
||||
group: t("Workspace"),
|
||||
icon: ImportIcon,
|
||||
},
|
||||
Export: {
|
||||
{
|
||||
name: t("Export"),
|
||||
path: "/settings/export",
|
||||
component: Export,
|
||||
@@ -159,20 +152,7 @@ const useSettingsConfig = () => {
|
||||
group: t("Workspace"),
|
||||
icon: ExportIcon,
|
||||
},
|
||||
// Integrations
|
||||
...mapValues(
|
||||
PluginLoader.plugins,
|
||||
(plugin) =>
|
||||
({
|
||||
name: plugin.config.name,
|
||||
path: integrationSettingsPath(plugin.id),
|
||||
group: t("Integrations"),
|
||||
component: plugin.settings,
|
||||
enabled: !!plugin.settings && can.update,
|
||||
icon: plugin.icon,
|
||||
} as ConfigItem)
|
||||
),
|
||||
SelfHosted: {
|
||||
{
|
||||
name: t("Self Hosted"),
|
||||
path: integrationSettingsPath("self-hosted"),
|
||||
component: SelfHosted,
|
||||
@@ -180,7 +160,7 @@ const useSettingsConfig = () => {
|
||||
group: t("Integrations"),
|
||||
icon: BuildingBlocksIcon,
|
||||
},
|
||||
GoogleAnalytics: {
|
||||
{
|
||||
name: t("Google Analytics"),
|
||||
path: integrationSettingsPath("google-analytics"),
|
||||
component: GoogleAnalytics,
|
||||
@@ -188,7 +168,7 @@ const useSettingsConfig = () => {
|
||||
group: t("Integrations"),
|
||||
icon: GoogleIcon,
|
||||
},
|
||||
Zapier: {
|
||||
{
|
||||
name: "Zapier",
|
||||
path: integrationSettingsPath("zapier"),
|
||||
component: Zapier,
|
||||
@@ -196,21 +176,34 @@ const useSettingsConfig = () => {
|
||||
group: t("Integrations"),
|
||||
icon: ZapierIcon,
|
||||
},
|
||||
}),
|
||||
[t, can.createApiKey, can.update, can.createImport, can.createExport]
|
||||
);
|
||||
];
|
||||
|
||||
const enabledConfigs = React.useMemo(
|
||||
() =>
|
||||
Object.keys(config).reduce(
|
||||
(acc, key: string) =>
|
||||
config[key].enabled ? [...acc, config[key]] : acc,
|
||||
[]
|
||||
),
|
||||
[config]
|
||||
);
|
||||
// Plugins
|
||||
Object.values(PluginLoader.plugins).map((plugin) => {
|
||||
const hasSettings = !!plugin.settings;
|
||||
const enabledInDeployment =
|
||||
!plugin.config.deployments ||
|
||||
plugin.config.deployments.length === 0 ||
|
||||
(plugin.config.deployments.includes("cloud") && isCloudHosted) ||
|
||||
(plugin.config.deployments.includes("enterprise") && !isCloudHosted);
|
||||
|
||||
return enabledConfigs;
|
||||
const item = {
|
||||
name: t(plugin.config.name),
|
||||
path: integrationSettingsPath(plugin.id),
|
||||
group: plugin.id === "collections" ? t("Workspace") : t("Integrations"),
|
||||
component: plugin.settings,
|
||||
enabled: enabledInDeployment && hasSettings && can.update,
|
||||
icon: plugin.icon,
|
||||
} as ConfigItem;
|
||||
|
||||
const insertIndex = items.findIndex((i) => i.group === t("Integrations"));
|
||||
items.splice(insertIndex, 0, item);
|
||||
});
|
||||
|
||||
return items;
|
||||
}, [t, can.createApiKey, can.update, can.createImport, can.createExport]);
|
||||
|
||||
return config.filter((item) => item.enabled);
|
||||
};
|
||||
|
||||
export default useSettingsConfig;
|
||||
@@ -200,14 +200,14 @@ function CollectionMenu({
|
||||
{
|
||||
type: "button",
|
||||
title: t("New document"),
|
||||
visible: can.update,
|
||||
visible: can.createDocument,
|
||||
onClick: handleNewDocument,
|
||||
icon: <NewDocumentIcon />,
|
||||
},
|
||||
{
|
||||
type: "button",
|
||||
title: t("Import document"),
|
||||
visible: can.update,
|
||||
visible: can.createDocument,
|
||||
onClick: handleImportDocument,
|
||||
icon: <ImportIcon />,
|
||||
},
|
||||
@@ -239,7 +239,7 @@ function CollectionMenu({
|
||||
{
|
||||
type: "button",
|
||||
title: `${t("Export")}…`,
|
||||
visible: !!(collection && canUserInTeam.createExport),
|
||||
visible: !!(collection && canUserInTeam.createExport && can.export),
|
||||
onClick: handleExport,
|
||||
icon: <ExportIcon />,
|
||||
},
|
||||
@@ -261,6 +261,7 @@ function CollectionMenu({
|
||||
collection,
|
||||
can.unstar,
|
||||
can.star,
|
||||
can.createDocument,
|
||||
can.update,
|
||||
can.delete,
|
||||
handleStar,
|
||||
|
||||
@@ -47,7 +47,7 @@ import useRequest from "~/hooks/useRequest";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import useToasts from "~/hooks/useToasts";
|
||||
import { MenuItem } from "~/types";
|
||||
import { editDocumentUrl, newDocumentPath } from "~/utils/routeHelpers";
|
||||
import { documentEditPath, newDocumentPath } from "~/utils/routeHelpers";
|
||||
|
||||
type Props = {
|
||||
document: Document;
|
||||
@@ -123,14 +123,16 @@ function DocumentMenu({
|
||||
[showToast, t, document]
|
||||
);
|
||||
|
||||
const collection = collections.get(document.collectionId);
|
||||
const collection = document.collectionId
|
||||
? collections.get(document.collectionId)
|
||||
: undefined;
|
||||
const can = usePolicy(document);
|
||||
const restoreItems = React.useMemo(
|
||||
() => [
|
||||
...collections.orderedData.reduce<MenuItem[]>((filtered, collection) => {
|
||||
const can = policies.abilities(collection.id);
|
||||
|
||||
if (can.update) {
|
||||
if (can.createDocument) {
|
||||
filtered.push({
|
||||
type: "button",
|
||||
onClick: (ev) =>
|
||||
@@ -260,7 +262,7 @@ function DocumentMenu({
|
||||
{
|
||||
type: "route",
|
||||
title: t("Edit"),
|
||||
to: editDocumentUrl(document),
|
||||
to: documentEditPath(document),
|
||||
visible: !!can.update && !team.seamlessEditing,
|
||||
icon: <EditIcon />,
|
||||
},
|
||||
|
||||
@@ -1,19 +1,24 @@
|
||||
import * as React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useMenuState } from "reakit/Menu";
|
||||
import User from "~/models/User";
|
||||
import ContextMenu from "~/components/ContextMenu";
|
||||
import OverflowMenuButton from "~/components/ContextMenu/OverflowMenuButton";
|
||||
import Template from "~/components/ContextMenu/Template";
|
||||
import useCurrentUser from "~/hooks/useCurrentUser";
|
||||
|
||||
type Props = {
|
||||
user: User;
|
||||
onRemove: () => void;
|
||||
};
|
||||
|
||||
function MemberMenu({ onRemove }: Props) {
|
||||
function MemberMenu({ user, onRemove }: Props) {
|
||||
const { t } = useTranslation();
|
||||
const currentUser = useCurrentUser();
|
||||
const menu = useMenuState({
|
||||
modal: true,
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
<OverflowMenuButton aria-label={t("Show menu")} {...menu} />
|
||||
@@ -23,7 +28,7 @@ function MemberMenu({ onRemove }: Props) {
|
||||
items={[
|
||||
{
|
||||
type: "button",
|
||||
title: t("Remove"),
|
||||
title: currentUser.id === user.id ? t("Leave") : t("Remove"),
|
||||
dangerous: true,
|
||||
onClick: onRemove,
|
||||
},
|
||||
|
||||
@@ -19,7 +19,9 @@ function NewChildDocumentMenu({ document, label }: Props) {
|
||||
});
|
||||
const { collections } = useStores();
|
||||
const { t } = useTranslation();
|
||||
const collection = collections.get(document.collectionId);
|
||||
const collection = document.collectionId
|
||||
? collections.get(document.collectionId)
|
||||
: undefined;
|
||||
const collectionName = collection ? collection.name : t("collection");
|
||||
|
||||
return (
|
||||
|
||||
+34
-4
@@ -11,7 +11,11 @@ import {
|
||||
UserChangeToMemberDialog,
|
||||
UserChangeToViewerDialog,
|
||||
UserSuspendDialog,
|
||||
} from "~/components/UserRoleDialogs";
|
||||
UserChangeNameDialog,
|
||||
} from "~/components/UserDialogs";
|
||||
import { actionToMenuItem } from "~/actions";
|
||||
import { deleteUserActionFactory } from "~/actions/definitions/users";
|
||||
import useActionContext from "~/hooks/useActionContext";
|
||||
import usePolicy from "~/hooks/usePolicy";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import useToasts from "~/hooks/useToasts";
|
||||
@@ -28,6 +32,9 @@ function UserMenu({ user }: Props) {
|
||||
});
|
||||
const can = usePolicy(user.id);
|
||||
const { showToast } = useToasts();
|
||||
const context = useActionContext({
|
||||
isContextMenu: true,
|
||||
});
|
||||
|
||||
const handlePromote = React.useCallback(
|
||||
(ev: React.SyntheticEvent) => {
|
||||
@@ -80,11 +87,25 @@ function UserMenu({ user }: Props) {
|
||||
[dialogs, t, user]
|
||||
);
|
||||
|
||||
const handleChangeName = React.useCallback(
|
||||
(ev: React.SyntheticEvent) => {
|
||||
ev.preventDefault();
|
||||
dialogs.openModal({
|
||||
title: t("Change name"),
|
||||
isCentered: true,
|
||||
content: (
|
||||
<UserChangeNameDialog user={user} onSubmit={dialogs.closeAllModals} />
|
||||
),
|
||||
});
|
||||
},
|
||||
[dialogs, t, user]
|
||||
);
|
||||
|
||||
const handleSuspend = React.useCallback(
|
||||
(ev: React.SyntheticEvent) => {
|
||||
ev.preventDefault();
|
||||
dialogs.openModal({
|
||||
title: t("Suspend account"),
|
||||
title: t("Suspend user"),
|
||||
isCentered: true,
|
||||
content: (
|
||||
<UserSuspendDialog user={user} onSubmit={dialogs.closeAllModals} />
|
||||
@@ -154,6 +175,12 @@ function UserMenu({ user }: Props) {
|
||||
onClick: handlePromote,
|
||||
visible: can.promote && user.role !== "admin",
|
||||
},
|
||||
{
|
||||
type: "button",
|
||||
title: `${t("Change name")}…`,
|
||||
onClick: handleChangeName,
|
||||
visible: can.update && user.role !== "admin",
|
||||
},
|
||||
{
|
||||
type: "button",
|
||||
title: t("Resend invite"),
|
||||
@@ -178,11 +205,14 @@ function UserMenu({ user }: Props) {
|
||||
},
|
||||
{
|
||||
type: "button",
|
||||
title: `${t("Suspend account")}…`,
|
||||
dangerous: true,
|
||||
title: `${t("Suspend user")}…`,
|
||||
onClick: handleSuspend,
|
||||
visible: !user.isInvited && !user.isSuspended,
|
||||
},
|
||||
{
|
||||
type: "separator",
|
||||
},
|
||||
actionToMenuItem(deleteUserActionFactory(user.id), context),
|
||||
]}
|
||||
/>
|
||||
</ContextMenu>
|
||||
|
||||
@@ -60,7 +60,6 @@ export default abstract class BaseModel {
|
||||
};
|
||||
|
||||
updateFromJson = (data: any) => {
|
||||
// const isNew = !data.id && !this.id && this.isNew;
|
||||
set(this, { ...data, isNew: false });
|
||||
this.persistedAttributes = this.toAPI();
|
||||
};
|
||||
|
||||
+54
-17
@@ -1,5 +1,5 @@
|
||||
import { trim } from "lodash";
|
||||
import { action, computed, observable } from "mobx";
|
||||
import { action, computed, observable, runInAction } from "mobx";
|
||||
import {
|
||||
CollectionPermission,
|
||||
FileOperationFormat,
|
||||
@@ -18,6 +18,8 @@ export default class Collection extends ParanoidModel {
|
||||
@observable
|
||||
isSaving: boolean;
|
||||
|
||||
isFetching = false;
|
||||
|
||||
@Field
|
||||
@observable
|
||||
id: string;
|
||||
@@ -57,32 +59,34 @@ export default class Collection extends ParanoidModel {
|
||||
direction: "asc" | "desc";
|
||||
};
|
||||
|
||||
documents: NavigationNode[];
|
||||
@observable
|
||||
documents?: NavigationNode[];
|
||||
|
||||
url: string;
|
||||
|
||||
urlId: string;
|
||||
|
||||
@computed
|
||||
get isEmpty(): boolean {
|
||||
get isEmpty(): boolean | undefined {
|
||||
if (!this.documents) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return (
|
||||
this.documents.length === 0 &&
|
||||
this.store.rootStore.documents.inCollection(this.id).length === 0
|
||||
);
|
||||
}
|
||||
|
||||
@computed
|
||||
get documentIds(): string[] {
|
||||
const results: string[] = [];
|
||||
|
||||
const travelNodes = (nodes: NavigationNode[]) =>
|
||||
nodes.forEach((node) => {
|
||||
results.push(node.id);
|
||||
travelNodes(node.children);
|
||||
});
|
||||
|
||||
travelNodes(this.documents);
|
||||
return results;
|
||||
/**
|
||||
* Convenience method to return if a collection is considered private.
|
||||
* This means that a membership is required to view it rather than just being
|
||||
* a workspace member.
|
||||
*
|
||||
* @returns boolean
|
||||
*/
|
||||
get isPrivate(): boolean {
|
||||
return !this.permission;
|
||||
}
|
||||
|
||||
@computed
|
||||
@@ -98,10 +102,35 @@ export default class Collection extends ParanoidModel {
|
||||
}
|
||||
|
||||
@computed
|
||||
get sortedDocuments() {
|
||||
get sortedDocuments(): NavigationNode[] | undefined {
|
||||
if (!this.documents) {
|
||||
return undefined;
|
||||
}
|
||||
return sortNavigationNodes(this.documents, this.sort);
|
||||
}
|
||||
|
||||
fetchDocuments = async (options?: { force: boolean }) => {
|
||||
if (this.isFetching) {
|
||||
return;
|
||||
}
|
||||
if (this.documents && options?.force !== true) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
this.isFetching = true;
|
||||
const { data } = await client.post("/collections.documents", {
|
||||
id: this.id,
|
||||
});
|
||||
|
||||
runInAction("Collection#fetchDocuments", () => {
|
||||
this.documents = data;
|
||||
});
|
||||
} finally {
|
||||
this.isFetching = false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the document identified by the given id in the collection in memory.
|
||||
* Does not update the document in the database.
|
||||
@@ -110,6 +139,10 @@ export default class Collection extends ParanoidModel {
|
||||
*/
|
||||
@action
|
||||
updateDocument(document: Pick<Document, "id" | "title" | "url">) {
|
||||
if (!this.documents) {
|
||||
return;
|
||||
}
|
||||
|
||||
const travelNodes = (nodes: NavigationNode[]) =>
|
||||
nodes.forEach((node) => {
|
||||
if (node.id === document.id) {
|
||||
@@ -131,6 +164,10 @@ export default class Collection extends ParanoidModel {
|
||||
*/
|
||||
@action
|
||||
removeDocument(documentId: string) {
|
||||
if (!this.documents) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.documents = this.documents.filter(function f(node): boolean {
|
||||
if (node.id === documentId) {
|
||||
return false;
|
||||
@@ -163,7 +200,7 @@ export default class Collection extends ParanoidModel {
|
||||
});
|
||||
};
|
||||
|
||||
if (this.documents) {
|
||||
if (this.sortedDocuments) {
|
||||
travelNodes(this.sortedDocuments);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { computed } from "mobx";
|
||||
import { observable } from "mobx";
|
||||
import { CollectionPermission } from "@shared/types";
|
||||
import BaseModel from "./BaseModel";
|
||||
|
||||
@@ -9,12 +9,8 @@ class CollectionGroupMembership extends BaseModel {
|
||||
|
||||
collectionId: string;
|
||||
|
||||
@observable
|
||||
permission: CollectionPermission;
|
||||
|
||||
@computed
|
||||
get isEditor(): boolean {
|
||||
return this.permission === CollectionPermission.ReadWrite;
|
||||
}
|
||||
}
|
||||
|
||||
export default CollectionGroupMembership;
|
||||
@@ -46,7 +46,7 @@ export default class Document extends ParanoidModel {
|
||||
|
||||
@Field
|
||||
@observable
|
||||
collectionId: string;
|
||||
collectionId?: string | null;
|
||||
|
||||
@Field
|
||||
@observable
|
||||
@@ -261,7 +261,7 @@ export default class Document extends ParanoidModel {
|
||||
};
|
||||
|
||||
@action
|
||||
pin = (collectionId?: string) =>
|
||||
pin = (collectionId?: string | null) =>
|
||||
this.store.rootStore.pins.create({
|
||||
documentId: this.id,
|
||||
...(collectionId ? { collectionId } : {}),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { computed } from "mobx";
|
||||
import { observable } from "mobx";
|
||||
import { CollectionPermission } from "@shared/types";
|
||||
import BaseModel from "./BaseModel";
|
||||
|
||||
@@ -9,12 +9,8 @@ class Membership extends BaseModel {
|
||||
|
||||
collectionId: string;
|
||||
|
||||
@observable
|
||||
permission: CollectionPermission;
|
||||
|
||||
@computed
|
||||
get isEditor(): boolean {
|
||||
return this.permission === CollectionPermission.ReadWrite;
|
||||
}
|
||||
}
|
||||
|
||||
export default Membership;
|
||||
+16
-16
@@ -34,7 +34,7 @@ import useCommandBarActions from "~/hooks/useCommandBarActions";
|
||||
import useLastVisitedPath from "~/hooks/useLastVisitedPath";
|
||||
import usePolicy from "~/hooks/usePolicy";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import { collectionUrl, updateCollectionUrl } from "~/utils/routeHelpers";
|
||||
import { collectionPath, updateCollectionPath } from "~/utils/routeHelpers";
|
||||
import Actions from "./Collection/Actions";
|
||||
import DropToImport from "./Collection/DropToImport";
|
||||
import Empty from "./Collection/Empty";
|
||||
@@ -63,7 +63,7 @@ function CollectionScene() {
|
||||
|
||||
React.useEffect(() => {
|
||||
if (collection?.name) {
|
||||
const canonicalUrl = updateCollectionUrl(match.url, collection);
|
||||
const canonicalUrl = updateCollectionPath(match.url, collection);
|
||||
|
||||
if (match.url !== canonicalUrl) {
|
||||
history.replace(canonicalUrl, history.location.state);
|
||||
@@ -148,7 +148,7 @@ function CollectionScene() {
|
||||
>
|
||||
<DropToImport
|
||||
accept={documents.importFileTypes.join(", ")}
|
||||
disabled={!can.update}
|
||||
disabled={!can.createDocument}
|
||||
collectionId={collection.id}
|
||||
>
|
||||
<CenteredContent withStickyHeader>
|
||||
@@ -159,7 +159,7 @@ function CollectionScene() {
|
||||
<HeadingWithIcon $isStarred={collection.isStarred}>
|
||||
<HeadingIcon collection={collection} size={40} expanded />
|
||||
{collection.name}
|
||||
{!collection.permission && (
|
||||
{collection.isPrivate && (
|
||||
<Tooltip
|
||||
tooltip={t(
|
||||
"This collection is only visible to those given access"
|
||||
@@ -179,24 +179,24 @@ function CollectionScene() {
|
||||
/>
|
||||
|
||||
<Tabs>
|
||||
<Tab to={collectionUrl(collection.url)} exact>
|
||||
<Tab to={collectionPath(collection.url)} exact>
|
||||
{t("Documents")}
|
||||
</Tab>
|
||||
<Tab to={collectionUrl(collection.url, "updated")} exact>
|
||||
<Tab to={collectionPath(collection.url, "updated")} exact>
|
||||
{t("Recently updated")}
|
||||
</Tab>
|
||||
<Tab to={collectionUrl(collection.url, "published")} exact>
|
||||
<Tab to={collectionPath(collection.url, "published")} exact>
|
||||
{t("Recently published")}
|
||||
</Tab>
|
||||
<Tab to={collectionUrl(collection.url, "old")} exact>
|
||||
<Tab to={collectionPath(collection.url, "old")} exact>
|
||||
{t("Least recently updated")}
|
||||
</Tab>
|
||||
<Tab to={collectionUrl(collection.url, "alphabetical")} exact>
|
||||
<Tab to={collectionPath(collection.url, "alphabetical")} exact>
|
||||
{t("A–Z")}
|
||||
</Tab>
|
||||
</Tabs>
|
||||
<Switch>
|
||||
<Route path={collectionUrl(collection.url, "alphabetical")}>
|
||||
<Route path={collectionPath(collection.url, "alphabetical")}>
|
||||
<PaginatedDocumentList
|
||||
key="alphabetical"
|
||||
documents={documents.alphabeticalInCollection(
|
||||
@@ -208,7 +208,7 @@ function CollectionScene() {
|
||||
}}
|
||||
/>
|
||||
</Route>
|
||||
<Route path={collectionUrl(collection.url, "old")}>
|
||||
<Route path={collectionPath(collection.url, "old")}>
|
||||
<PaginatedDocumentList
|
||||
key="old"
|
||||
documents={documents.leastRecentlyUpdatedInCollection(
|
||||
@@ -220,10 +220,10 @@ function CollectionScene() {
|
||||
}}
|
||||
/>
|
||||
</Route>
|
||||
<Route path={collectionUrl(collection.url, "recent")}>
|
||||
<Redirect to={collectionUrl(collection.url, "published")} />
|
||||
<Route path={collectionPath(collection.url, "recent")}>
|
||||
<Redirect to={collectionPath(collection.url, "published")} />
|
||||
</Route>
|
||||
<Route path={collectionUrl(collection.url, "published")}>
|
||||
<Route path={collectionPath(collection.url, "published")}>
|
||||
<PaginatedDocumentList
|
||||
key="published"
|
||||
documents={documents.recentlyPublishedInCollection(
|
||||
@@ -236,7 +236,7 @@ function CollectionScene() {
|
||||
showPublished
|
||||
/>
|
||||
</Route>
|
||||
<Route path={collectionUrl(collection.url, "updated")}>
|
||||
<Route path={collectionPath(collection.url, "updated")}>
|
||||
<PaginatedDocumentList
|
||||
key="updated"
|
||||
documents={documents.recentlyUpdatedInCollection(
|
||||
@@ -248,7 +248,7 @@ function CollectionScene() {
|
||||
}}
|
||||
/>
|
||||
</Route>
|
||||
<Route path={collectionUrl(collection.url)} exact>
|
||||
<Route path={collectionPath(collection.url)} exact>
|
||||
<PaginatedDocumentList
|
||||
documents={documents.rootInCollection(collection.id)}
|
||||
fetch={documents.fetchPage}
|
||||
|
||||
@@ -37,9 +37,11 @@ function EmptyCollection({ collection }: Props) {
|
||||
}}
|
||||
/>
|
||||
<br />
|
||||
{can.update && <Trans>Get started by creating a new one!</Trans>}
|
||||
{can.createDocument && (
|
||||
<Trans>Get started by creating a new one!</Trans>
|
||||
)}
|
||||
</Text>
|
||||
{can.update && (
|
||||
{can.createDocument && (
|
||||
<Empty>
|
||||
<Link to={newDocumentPath(collection.id)}>
|
||||
<Button icon={<NewDocumentIcon />} neutral>
|
||||
|
||||
@@ -13,7 +13,6 @@ import PaginatedList from "~/components/PaginatedList";
|
||||
import Text from "~/components/Text";
|
||||
import useBoolean from "~/hooks/useBoolean";
|
||||
import useCurrentTeam from "~/hooks/useCurrentTeam";
|
||||
import useCurrentUser from "~/hooks/useCurrentUser";
|
||||
import useDebouncedCallback from "~/hooks/useDebouncedCallback";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import useToasts from "~/hooks/useToasts";
|
||||
@@ -26,7 +25,6 @@ type Props = {
|
||||
function AddPeopleToCollection({ collection }: Props) {
|
||||
const { memberships, users } = useStores();
|
||||
const { showToast } = useToasts();
|
||||
const user = useCurrentUser();
|
||||
const team = useCurrentTeam();
|
||||
const { t } = useTranslation();
|
||||
const [
|
||||
@@ -99,9 +97,7 @@ function AddPeopleToCollection({ collection }: Props) {
|
||||
<Empty>{t("No people left to add")}</Empty>
|
||||
)
|
||||
}
|
||||
items={users
|
||||
.notInCollection(collection.id, query)
|
||||
.filter((member) => member.id !== user.id)}
|
||||
items={users.notInCollection(collection.id, query)}
|
||||
fetch={query ? undefined : users.fetchPage}
|
||||
renderItem={(item: User) => (
|
||||
<MemberListItem
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
import * as React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import styled from "styled-components";
|
||||
import { s } from "@shared/styles";
|
||||
import { CollectionPermission } from "@shared/types";
|
||||
import CollectionGroupMembership from "~/models/CollectionGroupMembership";
|
||||
import Group from "~/models/Group";
|
||||
import GroupListItem from "~/components/GroupListItem";
|
||||
import InputSelect, { Props as SelectProps } from "~/components/InputSelect";
|
||||
import CollectionGroupMemberMenu from "~/menus/CollectionGroupMemberMenu";
|
||||
import InputMemberPermissionSelect from "./InputMemberPermissionSelect";
|
||||
|
||||
type Props = {
|
||||
group: Group;
|
||||
@@ -21,57 +18,27 @@ const CollectionGroupMemberListItem = ({
|
||||
collectionGroupMembership,
|
||||
onUpdate,
|
||||
onRemove,
|
||||
}: Props) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<GroupListItem
|
||||
group={group}
|
||||
showAvatar
|
||||
renderActions={({ openMembersModal }) => (
|
||||
<>
|
||||
<Select
|
||||
label={t("Permissions")}
|
||||
options={[
|
||||
{
|
||||
label: t("View only"),
|
||||
value: CollectionPermission.Read,
|
||||
},
|
||||
{
|
||||
label: t("View and edit"),
|
||||
value: CollectionPermission.ReadWrite,
|
||||
},
|
||||
]}
|
||||
value={
|
||||
collectionGroupMembership
|
||||
? collectionGroupMembership.permission
|
||||
: undefined
|
||||
}
|
||||
onChange={onUpdate}
|
||||
ariaLabel={t("Permissions")}
|
||||
labelHidden
|
||||
nude
|
||||
/>
|
||||
<CollectionGroupMemberMenu
|
||||
onMembers={openMembersModal}
|
||||
onRemove={onRemove}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
const Select = styled(InputSelect)`
|
||||
margin: 0;
|
||||
font-size: 14px;
|
||||
border-color: transparent;
|
||||
box-shadow: none;
|
||||
color: ${s("textSecondary")};
|
||||
|
||||
select {
|
||||
margin: 0;
|
||||
}
|
||||
` as React.ComponentType<SelectProps>;
|
||||
}: Props) => (
|
||||
<GroupListItem
|
||||
group={group}
|
||||
showAvatar
|
||||
renderActions={({ openMembersModal }) => (
|
||||
<>
|
||||
<InputMemberPermissionSelect
|
||||
value={
|
||||
collectionGroupMembership
|
||||
? collectionGroupMembership.permission
|
||||
: undefined
|
||||
}
|
||||
onChange={onUpdate}
|
||||
/>
|
||||
<CollectionGroupMemberMenu
|
||||
onMembers={openMembersModal}
|
||||
onRemove={onRemove}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
/>
|
||||
);
|
||||
|
||||
export default CollectionGroupMemberListItem;
|
||||
@@ -0,0 +1,48 @@
|
||||
import * as React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import styled from "styled-components";
|
||||
import { s } from "@shared/styles";
|
||||
import { CollectionPermission } from "@shared/types";
|
||||
import InputSelect, { Props as SelectProps } from "~/components/InputSelect";
|
||||
|
||||
export default function InputMemberPermissionSelect(
|
||||
props: Partial<SelectProps>
|
||||
) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<Select
|
||||
label={t("Permissions")}
|
||||
options={[
|
||||
{
|
||||
label: t("View only"),
|
||||
value: CollectionPermission.Read,
|
||||
},
|
||||
{
|
||||
label: t("View and edit"),
|
||||
value: CollectionPermission.ReadWrite,
|
||||
},
|
||||
{
|
||||
label: t("Admin"),
|
||||
value: CollectionPermission.Admin,
|
||||
},
|
||||
]}
|
||||
ariaLabel={t("Permissions")}
|
||||
labelHidden
|
||||
nude
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const Select = styled(InputSelect)`
|
||||
margin: 0;
|
||||
font-size: 14px;
|
||||
border-color: transparent;
|
||||
box-shadow: none;
|
||||
color: ${s("textSecondary")};
|
||||
|
||||
select {
|
||||
margin: 0;
|
||||
}
|
||||
` as React.ComponentType<SelectProps>;
|
||||
@@ -1,8 +1,6 @@
|
||||
import { observer } from "mobx-react";
|
||||
import * as React from "react";
|
||||
import { Trans, useTranslation } from "react-i18next";
|
||||
import styled from "styled-components";
|
||||
import { s } from "@shared/styles";
|
||||
import { CollectionPermission } from "@shared/types";
|
||||
import Membership from "~/models/Membership";
|
||||
import User from "~/models/User";
|
||||
@@ -10,10 +8,10 @@ import Avatar from "~/components/Avatar";
|
||||
import Badge from "~/components/Badge";
|
||||
import Button from "~/components/Button";
|
||||
import Flex from "~/components/Flex";
|
||||
import InputSelect, { Props as SelectProps } from "~/components/InputSelect";
|
||||
import ListItem from "~/components/List/Item";
|
||||
import Time from "~/components/Time";
|
||||
import MemberMenu from "~/menus/MemberMenu";
|
||||
import InputMemberPermissionSelect from "./InputMemberPermissionSelect";
|
||||
|
||||
type Props = {
|
||||
user: User;
|
||||
@@ -54,29 +52,15 @@ const MemberListItem = ({
|
||||
actions={
|
||||
<Flex align="center" gap={8}>
|
||||
{onUpdate && (
|
||||
<Select
|
||||
label={t("Permissions")}
|
||||
options={[
|
||||
{
|
||||
label: t("View only"),
|
||||
value: CollectionPermission.Read,
|
||||
},
|
||||
{
|
||||
label: t("View and edit"),
|
||||
value: CollectionPermission.ReadWrite,
|
||||
},
|
||||
]}
|
||||
<InputMemberPermissionSelect
|
||||
value={membership ? membership.permission : undefined}
|
||||
onChange={onUpdate}
|
||||
disabled={!canEdit}
|
||||
ariaLabel={t("Permissions")}
|
||||
labelHidden
|
||||
nude
|
||||
/>
|
||||
)}
|
||||
{canEdit && (
|
||||
<>
|
||||
{onRemove && <MemberMenu onRemove={onRemove} />}
|
||||
{onRemove && <MemberMenu user={user} onRemove={onRemove} />}
|
||||
{onAdd && (
|
||||
<Button onClick={onAdd} neutral>
|
||||
{t("Add")}
|
||||
@@ -90,16 +74,4 @@ const MemberListItem = ({
|
||||
);
|
||||
};
|
||||
|
||||
const Select = styled(InputSelect)`
|
||||
margin: 0;
|
||||
font-size: 14px;
|
||||
border-color: transparent;
|
||||
box-shadow: none;
|
||||
color: ${s("textSecondary")};
|
||||
|
||||
select {
|
||||
margin: 0;
|
||||
}
|
||||
` as React.ComponentType<SelectProps>;
|
||||
|
||||
export default observer(MemberListItem);
|
||||
@@ -211,7 +211,7 @@ function CollectionPermissions({ collectionId }: Props) {
|
||||
value={collection.permission || ""}
|
||||
/>
|
||||
<PermissionExplainer size="small">
|
||||
{!collection.permission && (
|
||||
{collection.isPrivate && (
|
||||
<Trans
|
||||
defaults="The <em>{{ collectionName }}</em> collection is private. Workspace members have no access to it by default."
|
||||
values={{
|
||||
@@ -318,7 +318,7 @@ function CollectionPermissions({ collectionId }: Props) {
|
||||
key={item.id}
|
||||
user={item}
|
||||
membership={memberships.get(`${item.id}-${collection.id}`)}
|
||||
canEdit={item.id !== user.id}
|
||||
canEdit={item.id !== user.id || user.isAdmin}
|
||||
onRemove={() => handleRemoveUser(item)}
|
||||
onUpdate={(permission) => handleUpdateUser(item, permission)}
|
||||
/>
|
||||
|
||||
@@ -7,12 +7,13 @@ import { RouteComponentProps, useLocation, Redirect } from "react-router-dom";
|
||||
import styled, { ThemeProvider } from "styled-components";
|
||||
import { setCookie } from "tiny-cookie";
|
||||
import { s } from "@shared/styles";
|
||||
import { CustomTheme, NavigationNode } from "@shared/types";
|
||||
import { NavigationNode, PublicTeam } from "@shared/types";
|
||||
import DocumentModel from "~/models/Document";
|
||||
import Error404 from "~/scenes/Error404";
|
||||
import ErrorOffline from "~/scenes/ErrorOffline";
|
||||
import Layout from "~/components/Layout";
|
||||
import Sidebar from "~/components/Sidebar/Shared";
|
||||
import { TeamContext } from "~/components/TeamContext";
|
||||
import Text from "~/components/Text";
|
||||
import env from "~/env";
|
||||
import useBuildTheme from "~/hooks/useBuildTheme";
|
||||
@@ -29,11 +30,7 @@ const EMPTY_OBJECT = {};
|
||||
|
||||
type Response = {
|
||||
document: DocumentModel;
|
||||
team?: {
|
||||
name: string;
|
||||
avatarUrl: string;
|
||||
customTheme?: Partial<CustomTheme>;
|
||||
};
|
||||
team?: PublicTeam;
|
||||
sharedTree?: NavigationNode | undefined;
|
||||
};
|
||||
|
||||
@@ -166,14 +163,6 @@ function SharedDocumentScene(props: Props) {
|
||||
return <Redirect to={response.document.url} />;
|
||||
}
|
||||
|
||||
const sidebar = response.sharedTree?.children.length ? (
|
||||
<Sidebar
|
||||
rootNode={response.sharedTree}
|
||||
team={response.team}
|
||||
shareId={shareId}
|
||||
/>
|
||||
) : undefined;
|
||||
|
||||
return (
|
||||
<>
|
||||
<Helmet>
|
||||
@@ -182,17 +171,26 @@ function SharedDocumentScene(props: Props) {
|
||||
href={canonicalOrigin + location.pathname.replace(/\/$/, "")}
|
||||
/>
|
||||
</Helmet>
|
||||
<ThemeProvider theme={theme}>
|
||||
<Layout title={response.document.title} sidebar={sidebar}>
|
||||
<Document
|
||||
abilities={EMPTY_OBJECT}
|
||||
document={response.document}
|
||||
sharedTree={response.sharedTree}
|
||||
shareId={shareId}
|
||||
readOnly
|
||||
/>
|
||||
</Layout>
|
||||
</ThemeProvider>
|
||||
<TeamContext.Provider value={response.team}>
|
||||
<ThemeProvider theme={theme}>
|
||||
<Layout
|
||||
title={response.document.title}
|
||||
sidebar={
|
||||
response.sharedTree?.children.length ? (
|
||||
<Sidebar rootNode={response.sharedTree} shareId={shareId} />
|
||||
) : undefined
|
||||
}
|
||||
>
|
||||
<Document
|
||||
abilities={EMPTY_OBJECT}
|
||||
document={response.document}
|
||||
sharedTree={response.sharedTree}
|
||||
shareId={shareId}
|
||||
readOnly
|
||||
/>
|
||||
</Layout>
|
||||
</ThemeProvider>
|
||||
</TeamContext.Provider>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -40,8 +40,6 @@ type Props = {
|
||||
onFocus?: () => void;
|
||||
/** Callback when the editor is blurred */
|
||||
onBlur?: () => void;
|
||||
/** Callback when the editor is clicked outside of */
|
||||
onClickOutside?: (event: MouseEvent | TouchEvent) => void;
|
||||
};
|
||||
|
||||
function CommentForm({
|
||||
@@ -50,7 +48,6 @@ function CommentForm({
|
||||
onTyping,
|
||||
onFocus,
|
||||
onBlur,
|
||||
onClickOutside,
|
||||
autoFocus,
|
||||
standalone,
|
||||
placeholder,
|
||||
@@ -124,7 +121,6 @@ function CommentForm({
|
||||
|
||||
setData(undefined);
|
||||
setForceRender((s) => ++s);
|
||||
setInputFocused(false);
|
||||
|
||||
const comment = new Comment(
|
||||
{
|
||||
@@ -148,6 +144,11 @@ function CommentForm({
|
||||
comment.isNew = false;
|
||||
comment.createdById = user.id;
|
||||
comment.createdBy = user;
|
||||
|
||||
// re-focus the comment editor
|
||||
setTimeout(() => {
|
||||
editorRef.current?.focusAtStart();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
const handleChange = (
|
||||
|
||||
@@ -116,7 +116,7 @@ function CommentThread({
|
||||
scrollIntoView(topRef.current, {
|
||||
scrollMode: "if-needed",
|
||||
behavior: "smooth",
|
||||
block: "start",
|
||||
block: "end",
|
||||
boundary: (parent) =>
|
||||
// Prevents body and other parent elements from being scrolled
|
||||
parent.id !== "comments",
|
||||
|
||||
@@ -39,9 +39,9 @@ import { emojiToUrl } from "~/utils/emoji";
|
||||
import { isModKey } from "~/utils/keyboard";
|
||||
|
||||
import {
|
||||
documentHistoryUrl,
|
||||
editDocumentUrl,
|
||||
updateDocumentUrl,
|
||||
documentHistoryPath,
|
||||
documentEditPath,
|
||||
updateDocumentPath,
|
||||
} from "~/utils/routeHelpers";
|
||||
import Container from "./Container";
|
||||
import Contents from "./Contents";
|
||||
@@ -211,7 +211,7 @@ class DocumentScene extends React.Component<Props> {
|
||||
const { document, abilities } = this.props;
|
||||
|
||||
if (abilities.update) {
|
||||
this.props.history.push(editDocumentUrl(document));
|
||||
this.props.history.push(documentEditPath(document));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -228,7 +228,7 @@ class DocumentScene extends React.Component<Props> {
|
||||
if (location.pathname.endsWith("history")) {
|
||||
this.props.history.push(document.url);
|
||||
} else {
|
||||
this.props.history.push(documentHistoryUrl(document));
|
||||
this.props.history.push(documentHistoryPath(document));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -307,7 +307,7 @@ class DocumentScene extends React.Component<Props> {
|
||||
this.props.history.push(savedDocument.url);
|
||||
this.props.ui.setActiveDocument(savedDocument);
|
||||
} else if (document.isNew) {
|
||||
this.props.history.push(editDocumentUrl(savedDocument));
|
||||
this.props.history.push(documentEditPath(savedDocument));
|
||||
this.props.ui.setActiveDocument(savedDocument);
|
||||
}
|
||||
} catch (err) {
|
||||
@@ -399,7 +399,7 @@ class DocumentScene extends React.Component<Props> {
|
||||
|
||||
const canonicalUrl = shareId
|
||||
? this.props.match.url
|
||||
: updateDocumentUrl(this.props.match.url, document);
|
||||
: updateDocumentPath(this.props.match.url, document);
|
||||
|
||||
return (
|
||||
<ErrorBoundary showTitle>
|
||||
|
||||
@@ -10,7 +10,7 @@ import Document from "~/models/Document";
|
||||
import DocumentMeta from "~/components/DocumentMeta";
|
||||
import Fade from "~/components/Fade";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import { documentUrl, documentInsightsUrl } from "~/utils/routeHelpers";
|
||||
import { documentPath, documentInsightsPath } from "~/utils/routeHelpers";
|
||||
|
||||
type Props = {
|
||||
/* The document to display meta data for */
|
||||
@@ -32,16 +32,32 @@ function TitleDocumentMeta({ to, isDraft, document, ...rest }: Props) {
|
||||
|
||||
const Wrapper = viewsLoadedOnMount.current ? React.Fragment : Fade;
|
||||
|
||||
const insightsUrl = documentInsightsUrl(document);
|
||||
const insightsPath = documentInsightsPath(document);
|
||||
const commentsCount = comments.inDocument(document.id).length;
|
||||
|
||||
return (
|
||||
<Meta document={document} to={to} replace {...rest}>
|
||||
{team?.getPreference(TeamPreference.Commenting) && (
|
||||
<>
|
||||
•
|
||||
<CommentLink
|
||||
to={documentPath(document)}
|
||||
onClick={() => ui.toggleComments(document.id)}
|
||||
>
|
||||
<CommentIcon size={18} />
|
||||
{commentsCount
|
||||
? t("{{ count }} comment", { count: commentsCount })
|
||||
: t("Comment")}
|
||||
</CommentLink>
|
||||
</>
|
||||
)}
|
||||
{totalViewers && !isDraft ? (
|
||||
<Wrapper>
|
||||
•
|
||||
<Link
|
||||
to={match.url === insightsUrl ? documentUrl(document) : insightsUrl}
|
||||
to={
|
||||
match.url === insightsPath ? documentPath(document) : insightsPath
|
||||
}
|
||||
>
|
||||
{t("Viewed by")}{" "}
|
||||
{onlyYou
|
||||
@@ -52,20 +68,6 @@ function TitleDocumentMeta({ to, isDraft, document, ...rest }: Props) {
|
||||
</Link>
|
||||
</Wrapper>
|
||||
) : null}
|
||||
{team?.getPreference(TeamPreference.Commenting) && (
|
||||
<>
|
||||
•
|
||||
<CommentLink
|
||||
to={documentUrl(document)}
|
||||
onClick={() => ui.toggleComments(document.id)}
|
||||
>
|
||||
<CommentIcon size={18} />
|
||||
{commentsCount
|
||||
? t("{{ count }} comment", { count: commentsCount })
|
||||
: t("Comment")}
|
||||
</CommentLink>
|
||||
</>
|
||||
)}
|
||||
</Meta>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -11,11 +11,12 @@ import { RefHandle } from "~/components/ContentEditable";
|
||||
import Editor, { Props as EditorProps } from "~/components/Editor";
|
||||
import Flex from "~/components/Flex";
|
||||
import useFocusedComment from "~/hooks/useFocusedComment";
|
||||
import useMobile from "~/hooks/useMobile";
|
||||
import usePolicy from "~/hooks/usePolicy";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import {
|
||||
documentHistoryUrl,
|
||||
documentUrl,
|
||||
documentHistoryPath,
|
||||
documentPath,
|
||||
matchDocumentHistory,
|
||||
} from "~/utils/routeHelpers";
|
||||
import { useDocumentContext } from "../../../components/DocumentContext";
|
||||
@@ -47,6 +48,7 @@ function DocumentEditor(props: Props, ref: React.RefObject<any>) {
|
||||
const titleRef = React.useRef<RefHandle>(null);
|
||||
const { t } = useTranslation();
|
||||
const match = useRouteMatch();
|
||||
const isMobile = useMobile();
|
||||
const focusedComment = useFocusedComment();
|
||||
const { ui, comments, auth } = useStores();
|
||||
const { user, team } = auth;
|
||||
@@ -165,8 +167,8 @@ function DocumentEditor(props: Props, ref: React.RefObject<any>) {
|
||||
document={document}
|
||||
to={
|
||||
match.path === matchDocumentHistory
|
||||
? documentUrl(document)
|
||||
: documentHistoryUrl(document)
|
||||
? documentPath(document)
|
||||
: documentHistoryPath(document)
|
||||
}
|
||||
rtl={
|
||||
titleRef.current?.getComputedDirection() === "rtl" ? true : false
|
||||
@@ -195,8 +197,8 @@ function DocumentEditor(props: Props, ref: React.RefObject<any>) {
|
||||
}
|
||||
extensions={extensions}
|
||||
editorStyle={{
|
||||
padding: "0 60px",
|
||||
margin: "0 -60px",
|
||||
padding: document.fullWidth || isMobile ? "0 32px" : "0 64px",
|
||||
margin: document.fullWidth || isMobile ? "0 -32px" : "0 -64px",
|
||||
paddingBottom: `calc(50vh - ${
|
||||
childRef.current?.offsetHeight || 0
|
||||
}px)`,
|
||||
|
||||
@@ -32,7 +32,7 @@ import NewChildDocumentMenu from "~/menus/NewChildDocumentMenu";
|
||||
import TableOfContentsMenu from "~/menus/TableOfContentsMenu";
|
||||
import TemplatesMenu from "~/menus/TemplatesMenu";
|
||||
import { metaDisplay } from "~/utils/keyboard";
|
||||
import { newDocumentPath, editDocumentUrl } from "~/utils/routeHelpers";
|
||||
import { newDocumentPath, documentEditPath } from "~/utils/routeHelpers";
|
||||
import ObservingBanner from "./ObservingBanner";
|
||||
import PublicBreadcrumb from "./PublicBreadcrumb";
|
||||
import ShareButton from "./ShareButton";
|
||||
@@ -133,7 +133,7 @@ function DocumentHeader({
|
||||
<Button
|
||||
as={Link}
|
||||
icon={<EditIcon />}
|
||||
to={editDocumentUrl(document)}
|
||||
to={documentEditPath(document)}
|
||||
neutral
|
||||
>
|
||||
{t("Edit")}
|
||||
|
||||
@@ -8,7 +8,7 @@ import Empty from "~/components/Empty";
|
||||
import PaginatedEventList from "~/components/PaginatedEventList";
|
||||
import useKeyDown from "~/hooks/useKeyDown";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import { documentUrl } from "~/utils/routeHelpers";
|
||||
import { documentPath } from "~/utils/routeHelpers";
|
||||
import Sidebar from "./SidebarLayout";
|
||||
|
||||
const EMPTY_ARRAY: Event[] = [];
|
||||
@@ -26,7 +26,7 @@ function History() {
|
||||
|
||||
const onCloseHistory = () => {
|
||||
if (document) {
|
||||
history.push(documentUrl(document));
|
||||
history.push(documentPath(document));
|
||||
} else {
|
||||
history.goBack();
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import Time from "~/components/Time";
|
||||
import useKeyDown from "~/hooks/useKeyDown";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import useTextSelection from "~/hooks/useTextSelection";
|
||||
import { documentUrl } from "~/utils/routeHelpers";
|
||||
import { documentPath } from "~/utils/routeHelpers";
|
||||
import Sidebar from "./SidebarLayout";
|
||||
|
||||
function Insights() {
|
||||
@@ -34,7 +34,7 @@ function Insights() {
|
||||
|
||||
const onCloseInsights = () => {
|
||||
if (document) {
|
||||
history.push(documentUrl(document));
|
||||
history.push(documentPath(document));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -36,7 +36,12 @@ type AwarenessChangeEvent = {
|
||||
|
||||
type ConnectionStatusEvent = { status: ConnectionStatus };
|
||||
|
||||
type MessageEvent = { message: string };
|
||||
type MessageEvent = {
|
||||
message: string;
|
||||
event: Event & {
|
||||
code?: number;
|
||||
};
|
||||
};
|
||||
|
||||
function MultiplayerEditor({ onSynced, ...props }: Props, ref: any) {
|
||||
const documentId = props.id;
|
||||
@@ -138,6 +143,17 @@ function MultiplayerEditor({ onSynced, ...props }: Props, ref: any) {
|
||||
setRemoteSynced(true);
|
||||
});
|
||||
|
||||
provider.on("close", (ev: MessageEvent) => {
|
||||
if ("code" in ev.event && ev.event.code === 1009) {
|
||||
provider.shouldConnect = false;
|
||||
showToast(
|
||||
t(
|
||||
"Sorry, this document is too large - edits will no longer be persisted."
|
||||
)
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
if (debug) {
|
||||
provider.on("close", (ev: MessageEvent) =>
|
||||
Logger.debug("collaboration", "close", ev)
|
||||
|
||||
@@ -23,7 +23,9 @@ function References({ document }: Props) {
|
||||
}, [documents, document.id]);
|
||||
|
||||
const backlinks = documents.getBacklinkedDocuments(document.id);
|
||||
const collection = collections.get(document.collectionId);
|
||||
const collection = document.collectionId
|
||||
? collections.get(document.collectionId)
|
||||
: undefined;
|
||||
const children = collection
|
||||
? collection.getDocumentChildren(document.id)
|
||||
: [];
|
||||
|
||||
@@ -5,7 +5,7 @@ import Document from "~/models/Document";
|
||||
import Revision from "~/models/Revision";
|
||||
import { Props as EditorProps } from "~/components/Editor";
|
||||
import Flex from "~/components/Flex";
|
||||
import { documentUrl } from "~/utils/routeHelpers";
|
||||
import { documentPath } from "~/utils/routeHelpers";
|
||||
import { Meta as DocumentMeta } from "./DocumentMeta";
|
||||
|
||||
type Props = Omit<EditorProps, "extensions"> & {
|
||||
@@ -28,7 +28,7 @@ function RevisionViewer(props: Props) {
|
||||
{!shareId && (
|
||||
<DocumentMeta
|
||||
document={document}
|
||||
to={documentUrl(document)}
|
||||
to={documentPath(document)}
|
||||
rtl={revision.rtl}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -8,7 +8,7 @@ import Flex from "~/components/Flex";
|
||||
import Text from "~/components/Text";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import useToasts from "~/hooks/useToasts";
|
||||
import { collectionUrl, documentUrl } from "~/utils/routeHelpers";
|
||||
import { collectionPath, documentPath } from "~/utils/routeHelpers";
|
||||
|
||||
type Props = {
|
||||
document: Document;
|
||||
@@ -23,7 +23,9 @@ function DocumentDelete({ document, onSubmit }: Props) {
|
||||
const [isArchiving, setArchiving] = React.useState(false);
|
||||
const { showToast } = useToasts();
|
||||
const canArchive = !document.isDraft && !document.isArchived;
|
||||
const collection = collections.get(document.collectionId);
|
||||
const collection = document.collectionId
|
||||
? collections.get(document.collectionId)
|
||||
: undefined;
|
||||
const nestedDocumentsCount = collection
|
||||
? collection.getDocumentChildren(document.id).length
|
||||
: 0;
|
||||
@@ -43,14 +45,14 @@ function DocumentDelete({ document, onSubmit }: Props) {
|
||||
const parent = documents.get(document.parentDocumentId);
|
||||
|
||||
if (parent) {
|
||||
history.push(documentUrl(parent));
|
||||
history.push(documentPath(parent));
|
||||
onSubmit();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// otherwise, redirect to the collection home
|
||||
history.push(collectionUrl(collection?.url || "/"));
|
||||
history.push(collectionPath(collection?.url || "/"));
|
||||
}
|
||||
|
||||
onSubmit();
|
||||
|
||||
@@ -28,13 +28,15 @@ function DocumentMove({ document }: Props) {
|
||||
null
|
||||
);
|
||||
|
||||
const moveOptions = React.useMemo(() => {
|
||||
// filter out the document itself and also its parent doc if any
|
||||
const items = React.useMemo(() => {
|
||||
// Filter out the document itself and its existing parent doc, if any.
|
||||
const nodes = flatten(collectionTrees.map(flattenTree)).filter(
|
||||
(node) => node.id !== document.id && node.id !== document.parentDocumentId
|
||||
);
|
||||
|
||||
// If the document we're moving is a template, only show collections as
|
||||
// move targets.
|
||||
if (document.isTemplate) {
|
||||
// only show collections with children stripped off to prevent node expansion
|
||||
return nodes
|
||||
.filter((node) => node.type === "collection")
|
||||
.map((node) => ({ ...node, children: [] }));
|
||||
@@ -80,11 +82,7 @@ function DocumentMove({ document }: Props) {
|
||||
|
||||
return (
|
||||
<FlexContainer column>
|
||||
<DocumentExplorer
|
||||
items={moveOptions}
|
||||
onSubmit={move}
|
||||
onSelect={selectPath}
|
||||
/>
|
||||
<DocumentExplorer items={items} onSubmit={move} onSelect={selectPath} />
|
||||
<Footer justify="space-between" align="center" gap={8}>
|
||||
<StyledText type="secondary">
|
||||
{selectedPath ? (
|
||||
|
||||
@@ -9,7 +9,7 @@ import Flex from "~/components/Flex";
|
||||
import PlaceholderDocument from "~/components/PlaceholderDocument";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import useToasts from "~/hooks/useToasts";
|
||||
import { editDocumentUrl } from "~/utils/routeHelpers";
|
||||
import { documentEditPath } from "~/utils/routeHelpers";
|
||||
|
||||
function DocumentNew() {
|
||||
const history = useHistory();
|
||||
@@ -37,7 +37,7 @@ function DocumentNew() {
|
||||
title: "",
|
||||
text: "",
|
||||
});
|
||||
history.replace(editDocumentUrl(document), location.state);
|
||||
history.replace(documentEditPath(document), location.state);
|
||||
} catch (err) {
|
||||
showToast(t("Couldn’t create the document, try again?"), {
|
||||
type: "error",
|
||||
|
||||
@@ -15,6 +15,7 @@ import Fade from "~/components/Fade";
|
||||
import Flex from "~/components/Flex";
|
||||
import Heading from "~/components/Heading";
|
||||
import OutlineIcon from "~/components/Icons/OutlineIcon";
|
||||
import Input from "~/components/Input";
|
||||
import LoadingIndicator from "~/components/LoadingIndicator";
|
||||
import PageTitle from "~/components/PageTitle";
|
||||
import TeamLogo from "~/components/TeamLogo";
|
||||
@@ -34,11 +35,11 @@ function Header({ config }: { config?: Config | undefined }) {
|
||||
const { t } = useTranslation();
|
||||
const isSubdomain = !!config?.hostname;
|
||||
|
||||
if (
|
||||
!isCloudHosted ||
|
||||
parseDomain(window.location.origin).custom ||
|
||||
Desktop.isElectron()
|
||||
) {
|
||||
if (!isCloudHosted || parseDomain(window.location.origin).custom) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (Desktop.isElectron() && !isSubdomain) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -56,6 +57,8 @@ type Props = {
|
||||
function Login({ children }: Props) {
|
||||
const location = useLocation();
|
||||
const query = useQuery();
|
||||
const notice = query.get("notice");
|
||||
|
||||
const { t, i18n } = useTranslation();
|
||||
const { auth } = useStores();
|
||||
const { config } = auth;
|
||||
@@ -74,6 +77,22 @@ function Login({ children }: Props) {
|
||||
setEmailLinkSentTo(email);
|
||||
}, []);
|
||||
|
||||
const handleGoSubdomain = React.useCallback(async (event) => {
|
||||
event.preventDefault();
|
||||
const data = Object.fromEntries(new FormData(event.target));
|
||||
const normalizedSubdomain = data.subdomain
|
||||
.toString()
|
||||
.toLowerCase()
|
||||
.trim()
|
||||
.replace(/^https?:\/\//, "");
|
||||
const host = `https://${normalizedSubdomain}.getoutline.com`;
|
||||
await Desktop.bridge.addCustomHost(host);
|
||||
|
||||
setTimeout(() => {
|
||||
window.location.href = host;
|
||||
}, 500);
|
||||
}, []);
|
||||
|
||||
React.useEffect(() => {
|
||||
auth.fetchConfig().catch(setError);
|
||||
}, [auth]);
|
||||
@@ -160,6 +179,43 @@ function Login({ children }: Props) {
|
||||
);
|
||||
}
|
||||
|
||||
if (Desktop.isElectron() && notice === "domain-required") {
|
||||
return (
|
||||
<Background>
|
||||
<Header config={config} />
|
||||
|
||||
<Centered
|
||||
as="form"
|
||||
onSubmit={handleGoSubdomain}
|
||||
align="center"
|
||||
justify="center"
|
||||
column
|
||||
auto
|
||||
>
|
||||
<Heading centered>{t("Choose workspace")}</Heading>
|
||||
<Note>
|
||||
{t(
|
||||
"This login method requires choosing your workspace to continue"
|
||||
)}
|
||||
…
|
||||
</Note>
|
||||
<Flex>
|
||||
<Input
|
||||
name="subdomain"
|
||||
style={{ textAlign: "right" }}
|
||||
placeholder={t("subdomain")}
|
||||
>
|
||||
<Domain>.getoutline.com</Domain>
|
||||
</Input>
|
||||
</Flex>
|
||||
<ButtonLarge type="submit" fullwidth>
|
||||
{t("Continue")}
|
||||
</ButtonLarge>
|
||||
</Centered>
|
||||
</Background>
|
||||
);
|
||||
}
|
||||
|
||||
const hasMultipleProviders = config.providers.length > 1;
|
||||
const defaultProvider = find(
|
||||
config.providers,
|
||||
@@ -275,6 +331,11 @@ const StyledHeading = styled(Heading)`
|
||||
margin: 0;
|
||||
`;
|
||||
|
||||
const Domain = styled.div`
|
||||
color: ${s("textSecondary")};
|
||||
padding: 0 8px 0 0;
|
||||
`;
|
||||
|
||||
const CheckEmailIcon = styled(EmailIcon)`
|
||||
margin-bottom: -1.5em;
|
||||
`;
|
||||
|
||||
@@ -7,7 +7,7 @@ import * as React from "react";
|
||||
import { useTranslation, Trans } from "react-i18next";
|
||||
import { ThemeProvider, useTheme } from "styled-components";
|
||||
import { buildDarkTheme, buildLightTheme } from "@shared/styles/theme";
|
||||
import { CustomTheme } from "@shared/types";
|
||||
import { CustomTheme, TeamPreference } from "@shared/types";
|
||||
import { getBaseDomain } from "@shared/utils/domains";
|
||||
import Button from "~/components/Button";
|
||||
import ButtonLink from "~/components/ButtonLink";
|
||||
@@ -16,6 +16,7 @@ import Heading from "~/components/Heading";
|
||||
import Input from "~/components/Input";
|
||||
import InputColor from "~/components/InputColor";
|
||||
import Scene from "~/components/Scene";
|
||||
import Switch from "~/components/Switch";
|
||||
import Text from "~/components/Text";
|
||||
import env from "~/env";
|
||||
import useCurrentTeam from "~/hooks/useCurrentTeam";
|
||||
@@ -40,6 +41,9 @@ function Details() {
|
||||
);
|
||||
const [name, setName] = useState(team.name);
|
||||
const [subdomain, setSubdomain] = useState(team.subdomain);
|
||||
const [publicBranding, setPublicBranding] = useState(
|
||||
team.preferences?.publicBranding
|
||||
);
|
||||
const [defaultCollectionId, setDefaultCollectionId] = useState<string | null>(
|
||||
team.defaultCollectionId
|
||||
);
|
||||
@@ -65,6 +69,7 @@ function Details() {
|
||||
defaultCollectionId,
|
||||
preferences: {
|
||||
...team.preferences,
|
||||
publicBranding,
|
||||
customTheme,
|
||||
},
|
||||
});
|
||||
@@ -83,6 +88,7 @@ function Details() {
|
||||
subdomain,
|
||||
defaultCollectionId,
|
||||
team.preferences,
|
||||
publicBranding,
|
||||
customTheme,
|
||||
showToast,
|
||||
t,
|
||||
@@ -214,6 +220,24 @@ function Details() {
|
||||
flex
|
||||
/>
|
||||
</SettingRow>
|
||||
{team.avatarUrl && (
|
||||
<SettingRow
|
||||
name={TeamPreference.PublicBranding}
|
||||
label={t("Public branding")}
|
||||
description={t(
|
||||
"Show your team’s logo on public pages like login and shared documents."
|
||||
)}
|
||||
>
|
||||
<Switch
|
||||
id={TeamPreference.PublicBranding}
|
||||
name={TeamPreference.PublicBranding}
|
||||
checked={publicBranding}
|
||||
onChange={(event: React.ChangeEvent<HTMLInputElement>) =>
|
||||
setPublicBranding(event.target.checked)
|
||||
}
|
||||
/>
|
||||
</SettingRow>
|
||||
)}
|
||||
|
||||
<Heading as="h2">{t("Behavior")}</Heading>
|
||||
|
||||
|
||||
@@ -69,22 +69,6 @@ function Features() {
|
||||
onChange={handlePreferenceChange}
|
||||
/>
|
||||
</SettingRow>
|
||||
{team.avatarUrl && (
|
||||
<SettingRow
|
||||
name={TeamPreference.PublicBranding}
|
||||
label={t("Public branding")}
|
||||
description={t(
|
||||
"Show your team’s logo on public pages like login and shared documents."
|
||||
)}
|
||||
>
|
||||
<Switch
|
||||
id={TeamPreference.PublicBranding}
|
||||
name={TeamPreference.PublicBranding}
|
||||
checked={team.getPreference(TeamPreference.PublicBranding)}
|
||||
onChange={handlePreferenceChange}
|
||||
/>
|
||||
</SettingRow>
|
||||
)}
|
||||
</Scene>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import invariant from "invariant";
|
||||
import { concat, find, last } from "lodash";
|
||||
import { concat, find, last, sortBy } from "lodash";
|
||||
import { computed, action } from "mobx";
|
||||
import {
|
||||
CollectionPermission,
|
||||
@@ -34,8 +34,14 @@ export default class CollectionsStore extends BaseStore<Collection> {
|
||||
super(rootStore, Collection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently active collection, or undefined if not in the context
|
||||
* of a collection.
|
||||
*
|
||||
* @returns The active Collection or undefined
|
||||
*/
|
||||
@computed
|
||||
get active(): Collection | null | undefined {
|
||||
get active(): Collection | undefined {
|
||||
return this.rootStore.ui.activeCollectionId
|
||||
? this.data.get(this.rootStore.ui.activeCollectionId)
|
||||
: undefined;
|
||||
@@ -44,9 +50,12 @@ export default class CollectionsStore extends BaseStore<Collection> {
|
||||
@computed
|
||||
get orderedData(): Collection[] {
|
||||
let collections = Array.from(this.data.values());
|
||||
collections = collections.filter((collection) =>
|
||||
collection.deletedAt ? false : true
|
||||
);
|
||||
collections = collections
|
||||
.filter((collection) => !collection.deletedAt)
|
||||
.filter(
|
||||
(collection) =>
|
||||
this.rootStore.policies.abilities(collection.id).readDocument
|
||||
);
|
||||
return collections.sort((a, b) => {
|
||||
if (a.index === b.index) {
|
||||
return a.updatedAt > b.updatedAt ? -1 : 1;
|
||||
@@ -56,6 +65,14 @@ export default class CollectionsStore extends BaseStore<Collection> {
|
||||
});
|
||||
}
|
||||
|
||||
@computed
|
||||
get all(): Collection[] {
|
||||
return sortBy(
|
||||
Array.from(this.data.values()),
|
||||
(collection) => collection.name
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* List of paths to each of the documents, where paths are composed of id and title/name pairs
|
||||
*/
|
||||
@@ -92,7 +109,10 @@ export default class CollectionsStore extends BaseStore<Collection> {
|
||||
url,
|
||||
};
|
||||
results.push([node]);
|
||||
travelDocuments(collection.documents, id, [node]);
|
||||
|
||||
if (collection.documents) {
|
||||
travelDocuments(collection.documents, id, [node]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -132,13 +152,9 @@ export default class CollectionsStore extends BaseStore<Collection> {
|
||||
// remove all locally cached policies for documents in the collection as they
|
||||
// are now invalid
|
||||
if (params.sharing !== undefined) {
|
||||
const collection = this.get(params.id);
|
||||
|
||||
if (collection) {
|
||||
collection.documentIds.forEach((id) => {
|
||||
this.rootStore.policies.remove(id);
|
||||
});
|
||||
}
|
||||
this.rootStore.documents.inCollection(params.id).forEach((document) => {
|
||||
this.rootStore.policies.remove(document.id);
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -199,8 +215,10 @@ export default class CollectionsStore extends BaseStore<Collection> {
|
||||
return this.pathsToDocuments.find((path) => path.id === documentId);
|
||||
}
|
||||
|
||||
titleForDocument(documentUrl: string): string | undefined {
|
||||
const path = this.pathsToDocuments.find((path) => path.url === documentUrl);
|
||||
titleForDocument(documentPath: string): string | undefined {
|
||||
const path = this.pathsToDocuments.find(
|
||||
(path) => path.url === documentPath
|
||||
);
|
||||
if (path) {
|
||||
return path.title;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import invariant from "invariant";
|
||||
import { find, orderBy, filter, compact, omitBy } from "lodash";
|
||||
import { observable, action, computed, runInAction } from "mobx";
|
||||
import { DateFilter, NavigationNode } from "@shared/types";
|
||||
import { DateFilter, NavigationNode, PublicTeam } from "@shared/types";
|
||||
import { subtractDate } from "@shared/utils/date";
|
||||
import { bytesToHumanReadable } from "@shared/utils/files";
|
||||
import naturalSort from "@shared/utils/naturalSort";
|
||||
@@ -9,7 +9,6 @@ import { DocumentValidation } from "@shared/validations";
|
||||
import BaseStore from "~/stores/BaseStore";
|
||||
import RootStore from "~/stores/RootStore";
|
||||
import Document from "~/models/Document";
|
||||
import Team from "~/models/Team";
|
||||
import env from "~/env";
|
||||
import { FetchOptions, PaginationParams, SearchResult } from "~/types";
|
||||
import { client } from "~/utils/ApiClient";
|
||||
@@ -38,7 +37,7 @@ type ImportOptions = {
|
||||
export default class DocumentsStore extends BaseStore<Document> {
|
||||
sharedCache: Map<
|
||||
string,
|
||||
{ sharedTree: NavigationNode; team: Team } | undefined
|
||||
{ sharedTree: NavigationNode; team: PublicTeam } | undefined
|
||||
> = new Map();
|
||||
|
||||
@observable
|
||||
@@ -139,7 +138,7 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
rootInCollection(collectionId: string): Document[] {
|
||||
const collection = this.rootStore.collections.get(collectionId);
|
||||
|
||||
if (!collection) {
|
||||
if (!collection || !collection.sortedDocuments) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -471,7 +470,7 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
options: FetchOptions = {}
|
||||
): Promise<{
|
||||
document: Document;
|
||||
team?: Team;
|
||||
team?: PublicTeam;
|
||||
sharedTree?: NavigationNode;
|
||||
}> => {
|
||||
if (!options.prefetch) {
|
||||
@@ -645,7 +644,11 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
|
||||
@action
|
||||
removeCollectionDocuments(collectionId: string) {
|
||||
const documents = this.inCollection(collectionId);
|
||||
// drafts are to be detached from collection rather than deleted, hence excluded here
|
||||
const documents = filter(
|
||||
this.inCollection(collectionId),
|
||||
(d) => !!d.publishedAt
|
||||
);
|
||||
const documentIds = documents.map((doc) => doc.id);
|
||||
documentIds.forEach((id) => this.remove(id));
|
||||
}
|
||||
@@ -795,6 +798,8 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
find(this.orderedData, (doc) => url.endsWith(doc.urlId));
|
||||
|
||||
getCollectionForDocument(document: Document) {
|
||||
return this.rootStore.collections.data.get(document.collectionId);
|
||||
return document.collectionId
|
||||
? this.rootStore.collections.get(document.collectionId)
|
||||
: undefined;
|
||||
}
|
||||
}
|
||||
@@ -78,7 +78,9 @@ export default class SharesStore extends BaseStore<Share> {
|
||||
return;
|
||||
}
|
||||
|
||||
const collection = this.rootStore.collections.get(document.collectionId);
|
||||
const collection = document.collectionId
|
||||
? this.rootStore.collections.get(document.collectionId)
|
||||
: undefined;
|
||||
if (!collection) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ class UiStore {
|
||||
activeDocumentId: string | undefined;
|
||||
|
||||
@observable
|
||||
activeCollectionId: string | undefined;
|
||||
activeCollectionId?: string | null;
|
||||
|
||||
@observable
|
||||
observingUserId: string | undefined;
|
||||
|
||||
+1
-1
@@ -76,7 +76,7 @@ export type ActionContext = {
|
||||
isCommandBar: boolean;
|
||||
isButton: boolean;
|
||||
inStarredSection?: boolean;
|
||||
activeCollectionId: string | undefined;
|
||||
activeCollectionId?: string | null;
|
||||
activeDocumentId: string | undefined;
|
||||
currentUserId: string | undefined;
|
||||
currentTeamId: string | undefined;
|
||||
|
||||
Vendored
+2
@@ -53,6 +53,8 @@ declare module "styled-components" {
|
||||
noticeTipText: string;
|
||||
noticeWarningBackground: string;
|
||||
noticeWarningText: string;
|
||||
noticeSuccessBackground: string;
|
||||
noticeSuccessText: string;
|
||||
}
|
||||
|
||||
interface Colors {
|
||||
|
||||
@@ -6,6 +6,7 @@ interface Plugin {
|
||||
name: string;
|
||||
description: string;
|
||||
requiredEnvVars?: string[];
|
||||
deployments?: string[];
|
||||
};
|
||||
settings: React.FC;
|
||||
icon: React.FC<{ size?: number; fill?: string }>;
|
||||
|
||||
+13
-14
@@ -44,17 +44,17 @@ export function groupSettingsPath(): string {
|
||||
}
|
||||
|
||||
export function commentPath(document: Document, comment: Comment): string {
|
||||
return `${documentUrl(document)}?commentId=${comment.id}`;
|
||||
return `${documentPath(document)}?commentId=${comment.id}`;
|
||||
}
|
||||
|
||||
export function collectionUrl(url: string, section?: string): string {
|
||||
export function collectionPath(url: string, section?: string): string {
|
||||
if (section) {
|
||||
return `${url}/${section}`;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
export function updateCollectionUrl(
|
||||
export function updateCollectionPath(
|
||||
oldUrl: string,
|
||||
collection: Collection
|
||||
): string {
|
||||
@@ -65,19 +65,22 @@ export function updateCollectionUrl(
|
||||
);
|
||||
}
|
||||
|
||||
export function documentUrl(doc: Document): string {
|
||||
export function documentPath(doc: Document): string {
|
||||
return doc.url;
|
||||
}
|
||||
|
||||
export function editDocumentUrl(doc: Document): string {
|
||||
export function documentEditPath(doc: Document): string {
|
||||
return `${doc.url}/edit`;
|
||||
}
|
||||
|
||||
export function documentInsightsUrl(doc: Document): string {
|
||||
export function documentInsightsPath(doc: Document): string {
|
||||
return `${doc.url}/insights`;
|
||||
}
|
||||
|
||||
export function documentHistoryUrl(doc: Document, revisionId?: string): string {
|
||||
export function documentHistoryPath(
|
||||
doc: Document,
|
||||
revisionId?: string
|
||||
): string {
|
||||
let base = `${doc.url}/history`;
|
||||
if (revisionId) {
|
||||
base += `/${revisionId}`;
|
||||
@@ -89,7 +92,7 @@ export function documentHistoryUrl(doc: Document, revisionId?: string): string {
|
||||
* Replace full url's document part with the new one in case
|
||||
* the document slug has been updated
|
||||
*/
|
||||
export function updateDocumentUrl(oldUrl: string, document: Document): string {
|
||||
export function updateDocumentPath(oldUrl: string, document: Document): string {
|
||||
// Update url to match the current one
|
||||
return oldUrl.replace(
|
||||
new RegExp("/doc/([0-9a-zA-Z-_~]*-[a-zA-z0-9]{10,15})"),
|
||||
@@ -98,7 +101,7 @@ export function updateDocumentUrl(oldUrl: string, document: Document): string {
|
||||
}
|
||||
|
||||
export function newDocumentPath(
|
||||
collectionId?: string,
|
||||
collectionId?: string | null,
|
||||
params: {
|
||||
parentDocumentId?: string;
|
||||
templateId?: string;
|
||||
@@ -132,12 +135,8 @@ export function sharedDocumentPath(shareId: string, docPath?: string) {
|
||||
return docPath ? `/s/${shareId}${docPath}` : `/s/${shareId}`;
|
||||
}
|
||||
|
||||
export function notFoundUrl(): string {
|
||||
return "/404";
|
||||
}
|
||||
|
||||
export function urlify(path: string): string {
|
||||
return `${window.location.host}${path}`;
|
||||
return `${window.location.origin}${path}`;
|
||||
}
|
||||
|
||||
export const matchDocumentSlug =
|
||||
|
||||
+29
-29
@@ -10,7 +10,7 @@
|
||||
"build:server": "node ./build.js",
|
||||
"build": "yarn clean && yarn vite:build && yarn build:i18n && yarn build:server",
|
||||
"start": "node ./build/server/index.js",
|
||||
"dev": "NODE_ENV=development yarn concurrently -n api,collaboration -c \"blue,magenta\" \"node --inspect=0.0.0.0 build/server/index.js --services=collaboration,websockets,admin,web,worker\"",
|
||||
"dev": "NODE_ENV=development yarn concurrently -n api,collaboration -c \"blue,magenta\" \"node --inspect=0.0.0.0 build/server/index.js --services=cron,collaboration,websockets,admin,web,worker\"",
|
||||
"dev:backend": "NODE_ENV=development nodemon --exec \"yarn build:server && yarn dev\" -e js,ts,tsx --ignore build/ --ignore app/ --ignore shared/editor --ignore server/migrations",
|
||||
"dev:watch": "NODE_ENV=development yarn concurrently -n backend,frontend \"yarn dev:backend\" \"yarn vite:dev\"",
|
||||
"lint": "eslint app server shared plugins",
|
||||
@@ -66,16 +66,15 @@
|
||||
"@outlinewiki/koa-passport": "^4.2.1",
|
||||
"@outlinewiki/passport-azure-ad-oauth2": "^0.1.0",
|
||||
"@renderlesskit/react": "^0.11.0",
|
||||
"@sentry/node": "^7.24.2",
|
||||
"@sentry/react": "^7.24.2",
|
||||
"@sentry/tracing": "^7.24.2",
|
||||
"@sentry/node": "^7.51.2",
|
||||
"@sentry/react": "^7.51.2",
|
||||
"@sentry/tracing": "^7.51.2",
|
||||
"@tippyjs/react": "^4.2.6",
|
||||
"@tommoor/remove-markdown": "^0.3.2",
|
||||
"@types/mermaid": "^9.2.0",
|
||||
"@vitejs/plugin-react": "^3.1.0",
|
||||
"addressparser": "^1.0.1",
|
||||
"autotrack": "^2.4.1",
|
||||
"aws-sdk": "^2.1290.0",
|
||||
"aws-sdk": "^2.1354.0",
|
||||
"babel-plugin-styled-components": "^2.0.7",
|
||||
"babel-plugin-transform-class-properties": "^6.24.1",
|
||||
"body-scroll-lock": "^4.0.0-beta.0",
|
||||
@@ -89,13 +88,13 @@
|
||||
"core-js": "^3.30.0",
|
||||
"crypto-js": "^4.1.1",
|
||||
"datadog-metrics": "^0.11.0",
|
||||
"date-fns": "^2.25.0",
|
||||
"dd-trace": "^3.14.1",
|
||||
"date-fns": "^2.30.0",
|
||||
"dd-trace": "^3.21.0",
|
||||
"dotenv": "^4.0.0",
|
||||
"email-providers": "^1.13.1",
|
||||
"emoji-regex": "^10.0.0",
|
||||
"emoji-regex": "^10.2.1",
|
||||
"es6-error": "^4.1.1",
|
||||
"fetch-retry": "^5.0.3",
|
||||
"fetch-retry": "^5.0.5",
|
||||
"fetch-with-proxy": "^3.0.1",
|
||||
"focus-visible": "^5.2.0",
|
||||
"fractional-index": "^1.0.0",
|
||||
@@ -110,14 +109,14 @@
|
||||
"i18next-http-backend": "^2.1.1",
|
||||
"inline-css": "^4.0.2",
|
||||
"invariant": "^2.2.4",
|
||||
"ioredis": "^5.3.1",
|
||||
"ioredis": "^5.3.2",
|
||||
"is-printable-key-event": "^1.0.0",
|
||||
"jsdom": "^21.1.1",
|
||||
"jsdom": "^22.0.0",
|
||||
"jsonwebtoken": "^9.0.0",
|
||||
"jszip": "^3.10.1",
|
||||
"katex": "^0.16.4",
|
||||
"katex": "^0.16.7",
|
||||
"kbar": "0.1.0-beta.40",
|
||||
"koa": "^2.13.4",
|
||||
"koa": "^2.14.2",
|
||||
"koa-body": "^6.0.1",
|
||||
"koa-compress": "^5.1.0",
|
||||
"koa-helmet": "^6.1.0",
|
||||
@@ -128,7 +127,7 @@
|
||||
"koa-sslify": "5.0.1",
|
||||
"koa-useragent": "^4.1.0",
|
||||
"lodash": "^4.17.21",
|
||||
"mammoth": "^1.4.19",
|
||||
"mammoth": "^1.5.1",
|
||||
"markdown-it": "^13.0.1",
|
||||
"markdown-it-container": "^3.0.0",
|
||||
"markdown-it-emoji": "^2.0.0",
|
||||
@@ -183,43 +182,43 @@
|
||||
"react-router-dom": "^5.2.0",
|
||||
"react-table": "^7.7.0",
|
||||
"react-virtualized-auto-sizer": "^1.0.5",
|
||||
"react-waypoint": "^10.1.0",
|
||||
"react-waypoint": "^10.3.0",
|
||||
"react-window": "^1.8.7",
|
||||
"reakit": "^1.3.11",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"refractor": "^3.6.0",
|
||||
"request-filtering-agent": "^1.1.2",
|
||||
"semver": "^7.3.7",
|
||||
"semver": "^7.5.1",
|
||||
"sequelize": "^6.29.0",
|
||||
"sequelize-cli": "^6.4.1",
|
||||
"sequelize-cli": "^6.6.0",
|
||||
"sequelize-encrypted": "^1.0.0",
|
||||
"sequelize-typescript": "^2.1.5",
|
||||
"slug": "^5.3.0",
|
||||
"slugify": "^1.6.5",
|
||||
"smooth-scroll-into-view-if-needed": "^1.1.32",
|
||||
"socket.io": "^4.5.4",
|
||||
"socket.io-client": "^4.5.4",
|
||||
"socket.io-client": "^4.6.1",
|
||||
"socket.io-redis": "^6.1.1",
|
||||
"stoppable": "^1.1.0",
|
||||
"string-replace-to-array": "^2.1.0",
|
||||
"styled-components": "^5.2.3",
|
||||
"styled-components-breakpoint": "^2.1.1",
|
||||
"styled-normalize": "^8.0.4",
|
||||
"styled-normalize": "^8.0.7",
|
||||
"throng": "^5.0.0",
|
||||
"tiny-cookie": "^2.4.0",
|
||||
"tiny-cookie": "^2.4.1",
|
||||
"tmp": "^0.2.1",
|
||||
"turndown": "^7.1.1",
|
||||
"turndown": "^7.1.2",
|
||||
"utf8": "^3.0.0",
|
||||
"utility-types": "^3.10.0",
|
||||
"uuid": "^8.3.2",
|
||||
"validator": "13.7.0",
|
||||
"vite": "^4.1.3",
|
||||
"vite-plugin-pwa": "^0.14.4",
|
||||
"winston": "^3.3.3",
|
||||
"winston": "^3.8.2",
|
||||
"ws": "^7.5.3",
|
||||
"y-indexeddb": "^9.0.9",
|
||||
"y-protocols": "^1.0.5",
|
||||
"yjs": "^13.5.39",
|
||||
"yjs": "^13.6.1",
|
||||
"zod": "^3.21.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -235,7 +234,7 @@
|
||||
"@types/enzyme": "^3.10.13",
|
||||
"@types/enzyme-adapter-react-16": "^1.0.6",
|
||||
"@types/express-useragent": "^1.0.2",
|
||||
"@types/formidable": "^2.0.5",
|
||||
"@types/formidable": "^2.0.6",
|
||||
"@types/fs-extra": "^11.0.1",
|
||||
"@types/fuzzy-search": "^2.1.2",
|
||||
"@types/glob": "^8.0.1",
|
||||
@@ -245,7 +244,7 @@
|
||||
"@types/jest": "^29.4.0",
|
||||
"@types/jsonwebtoken": "^8.5.8",
|
||||
"@types/katex": "^0.16.0",
|
||||
"@types/koa": "^2.13.4",
|
||||
"@types/koa": "^2.13.6",
|
||||
"@types/koa-compress": "^4.0.3",
|
||||
"@types/koa-helmet": "^6.0.4",
|
||||
"@types/koa-logger": "^3.1.2",
|
||||
@@ -257,6 +256,7 @@
|
||||
"@types/markdown-it": "^12.2.3",
|
||||
"@types/markdown-it-container": "^2.0.5",
|
||||
"@types/markdown-it-emoji": "^2.0.2",
|
||||
"@types/mermaid": "^9.2.0",
|
||||
"@types/mime-types": "^2.1.1",
|
||||
"@types/natural-sort": "^0.0.21",
|
||||
"@types/node": "18.0.6",
|
||||
@@ -321,12 +321,12 @@
|
||||
"eslint-plugin-react-hooks": "^4.6.0",
|
||||
"fetch-test-server": "^1.1.0",
|
||||
"husky": "^8.0.2",
|
||||
"i18next-parser": "^7.7.0",
|
||||
"i18next-parser": "^7.9.0",
|
||||
"jest-cli": "^29.5.0",
|
||||
"jest-environment-jsdom": "^29.4.1",
|
||||
"jest-fetch-mock": "^3.0.3",
|
||||
"lint-staged": "^13.1.0",
|
||||
"nodemon": "^2.0.21",
|
||||
"nodemon": "^2.0.22",
|
||||
"postinstall-postinstall": "^2.1.0",
|
||||
"prettier": "^2.0.5",
|
||||
"react-refresh": "^0.14.0",
|
||||
@@ -348,5 +348,5 @@
|
||||
"qs": "6.9.7",
|
||||
"rollup": "^3.14.0"
|
||||
},
|
||||
"version": "0.68.0"
|
||||
"version": "0.69.1"
|
||||
}
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
Team,
|
||||
User,
|
||||
} from "@server/models";
|
||||
import { AuthenticationResult } from "@server/types";
|
||||
import { AppContext, AuthenticationResult } from "@server/types";
|
||||
import {
|
||||
getClientFromContext,
|
||||
getTeamFromContext,
|
||||
@@ -132,9 +132,9 @@ if (env.SLACK_CLIENT_ID && env.SLACK_CLIENT_SECRET) {
|
||||
auth({
|
||||
optional: true,
|
||||
}),
|
||||
async (ctx) => {
|
||||
async (ctx: AppContext) => {
|
||||
const { code, state, error } = ctx.request.query;
|
||||
const { user } = ctx.state;
|
||||
const { user } = ctx.state.auth;
|
||||
assertPresent(code || error, "code is required");
|
||||
|
||||
if (error) {
|
||||
@@ -195,9 +195,9 @@ if (env.SLACK_CLIENT_ID && env.SLACK_CLIENT_SECRET) {
|
||||
auth({
|
||||
optional: true,
|
||||
}),
|
||||
async (ctx) => {
|
||||
async (ctx: AppContext) => {
|
||||
const { code, error, state } = ctx.request.query;
|
||||
const { user } = ctx.state;
|
||||
const { user } = ctx.state.auth;
|
||||
assertPresent(code || error, "code is required");
|
||||
|
||||
const collectionId = state;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { differenceInMilliseconds } from "date-fns";
|
||||
import fetch from "fetch-with-proxy";
|
||||
import { Op } from "sequelize";
|
||||
import { IntegrationService, IntegrationType } from "@shared/types";
|
||||
import { Minute } from "@shared/utils/time";
|
||||
import env from "@server/env";
|
||||
import { Document, Integration, Collection, Team } from "@server/models";
|
||||
import BaseProcessor from "@server/queues/processors/BaseProcessor";
|
||||
@@ -94,9 +96,12 @@ export default class SlackProcessor extends BaseProcessor {
|
||||
return;
|
||||
}
|
||||
|
||||
// if the document was published less than a minute ago, don't send a
|
||||
// separate notification.
|
||||
if (
|
||||
event.name === "revisions.create" &&
|
||||
document.updatedAt === document.publishedAt
|
||||
differenceInMilliseconds(document.updatedAt, document.publishedAt) <
|
||||
Minute
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import useCurrentTeam from "~/hooks/useCurrentTeam";
|
||||
import useMobile from "~/hooks/useMobile";
|
||||
|
||||
const WEBHOOK_EVENTS = {
|
||||
user: [
|
||||
users: [
|
||||
"users.create",
|
||||
"users.signin",
|
||||
"users.update",
|
||||
@@ -25,7 +25,7 @@ const WEBHOOK_EVENTS = {
|
||||
"users.promote",
|
||||
"users.demote",
|
||||
],
|
||||
document: [
|
||||
documents: [
|
||||
"documents.create",
|
||||
"documents.publish",
|
||||
"documents.unpublish",
|
||||
@@ -38,7 +38,7 @@ const WEBHOOK_EVENTS = {
|
||||
"documents.update",
|
||||
"documents.title_change",
|
||||
],
|
||||
collection: [
|
||||
collections: [
|
||||
"collections.create",
|
||||
"collections.update",
|
||||
"collections.delete",
|
||||
@@ -49,30 +49,30 @@ const WEBHOOK_EVENTS = {
|
||||
"collections.move",
|
||||
"collections.permission_changed",
|
||||
],
|
||||
comment: ["comments.create", "comments.update", "comments.delete"],
|
||||
revision: ["revisions.create"],
|
||||
fileOperation: [
|
||||
comments: ["comments.create", "comments.update", "comments.delete"],
|
||||
revisions: ["revisions.create"],
|
||||
fileOperations: [
|
||||
"fileOperations.create",
|
||||
"fileOperations.update",
|
||||
"fileOperations.delete",
|
||||
],
|
||||
group: [
|
||||
groups: [
|
||||
"groups.create",
|
||||
"groups.update",
|
||||
"groups.delete",
|
||||
"groups.add_user",
|
||||
"groups.remove_user",
|
||||
],
|
||||
integration: ["integrations.create", "integrations.update"],
|
||||
share: ["shares.create", "shares.update", "shares.revoke"],
|
||||
team: ["teams.update"],
|
||||
pin: ["pins.create", "pins.update", "pins.delete"],
|
||||
webhookSubscription: [
|
||||
integrations: ["integrations.create", "integrations.update"],
|
||||
shares: ["shares.create", "shares.update", "shares.revoke"],
|
||||
teams: ["teams.update"],
|
||||
pins: ["pins.create", "pins.update", "pins.delete"],
|
||||
webhookSubscriptions: [
|
||||
"webhookSubscriptions.create",
|
||||
"webhookSubscriptions.delete",
|
||||
"webhookSubscriptions.update",
|
||||
],
|
||||
view: ["views.create"],
|
||||
views: ["views.create"],
|
||||
};
|
||||
|
||||
const EventCheckboxLabel = styled.label`
|
||||
@@ -283,7 +283,9 @@ function WebhookSubscriptionForm({ handleSubmit, webhookSubscription }: Props) {
|
||||
.map(([group, events], i) => (
|
||||
<GroupWrapper key={i} isMobile={isMobile}>
|
||||
<EventCheckbox
|
||||
label={t(`All {{ groupName }} events`, { groupName: group })}
|
||||
label={t(`All {{ groupName }} events`, {
|
||||
groupName: group.replace(/s$/, ""),
|
||||
})}
|
||||
value={group}
|
||||
/>
|
||||
<FieldSet disabled={selectedGroups.includes(group)}>
|
||||
|
||||
@@ -109,7 +109,7 @@ export default async function documentCreator({
|
||||
);
|
||||
|
||||
if (publish) {
|
||||
await document.publish(user.id, { transaction });
|
||||
await document.publish(user.id, collectionId!, { transaction });
|
||||
await Event.create(
|
||||
{
|
||||
name: "documents.publish",
|
||||
|
||||
@@ -126,7 +126,9 @@ export default async function loadDocument({
|
||||
if (canReadDocument) {
|
||||
// Cannot use document.collection here as it does not include the
|
||||
// documentStructure by default through the relationship.
|
||||
collection = await Collection.findByPk(document.collectionId);
|
||||
if (document.collectionId) {
|
||||
collection = await Collection.findByPk(document.collectionId);
|
||||
}
|
||||
if (!collection) {
|
||||
throw NotFoundError("Collection could not be found for document");
|
||||
}
|
||||
@@ -146,7 +148,9 @@ export default async function loadDocument({
|
||||
}
|
||||
|
||||
// It is possible to disable sharing at the collection so we must check
|
||||
collection = await Collection.findByPk(document.collectionId);
|
||||
if (document.collectionId) {
|
||||
collection = await Collection.findByPk(document.collectionId);
|
||||
}
|
||||
invariant(collection, "collection not found");
|
||||
|
||||
if (!collection.sharing) {
|
||||
|
||||
@@ -153,4 +153,27 @@ describe("documentMover", () => {
|
||||
expect(response.documents[0].collection?.id).toEqual(newCollection.id);
|
||||
expect(response.documents[0].updatedBy.id).toEqual(user.id);
|
||||
});
|
||||
|
||||
it("should detach document from collection and move it to drafts", async () => {
|
||||
const { document, user, collection } = await seed();
|
||||
|
||||
const response = await sequelize.transaction(async (transaction) =>
|
||||
documentMover({
|
||||
user,
|
||||
document,
|
||||
collectionId: null,
|
||||
index: 0,
|
||||
ip,
|
||||
transaction,
|
||||
})
|
||||
);
|
||||
|
||||
expect(response.collections[0].id).toBe(collection.id);
|
||||
expect(response.collections.length).toEqual(1);
|
||||
expect(response.documents.length).toEqual(1);
|
||||
|
||||
expect(response.documents[0].collection).toBeNull();
|
||||
expect(response.documents[0].updatedBy.id).toEqual(user.id);
|
||||
expect(response.documents[0].publishedAt).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -5,12 +5,19 @@ import { User, Document, Collection, Pin, Event } from "@server/models";
|
||||
import pinDestroyer from "./pinDestroyer";
|
||||
|
||||
type Props = {
|
||||
/** User attempting to move the document */
|
||||
user: User;
|
||||
/** Document which is being moved */
|
||||
document: Document;
|
||||
collectionId: string;
|
||||
/** Destination collection to which the document is moved */
|
||||
collectionId: string | null;
|
||||
/** ID of parent under which the document is moved */
|
||||
parentDocumentId?: string | null;
|
||||
/** Position of moved document within document structure */
|
||||
index?: number;
|
||||
/** The IP address of the user moving the document */
|
||||
ip: string;
|
||||
/** The database transaction to run within */
|
||||
transaction?: Transaction;
|
||||
};
|
||||
|
||||
@@ -23,7 +30,7 @@ type Result = {
|
||||
async function documentMover({
|
||||
user,
|
||||
document,
|
||||
collectionId,
|
||||
collectionId = null,
|
||||
parentDocumentId = null,
|
||||
// convert undefined to null so parentId comparison treats them as equal
|
||||
index,
|
||||
@@ -43,6 +50,7 @@ async function documentMover({
|
||||
}
|
||||
|
||||
if (document.template) {
|
||||
invariant(collectionId, "collectionId should exist");
|
||||
document.collectionId = collectionId;
|
||||
document.parentDocumentId = null;
|
||||
document.lastModifiedById = user.id;
|
||||
@@ -51,20 +59,23 @@ async function documentMover({
|
||||
result.documents.push(document);
|
||||
} else {
|
||||
// Load the current and the next collection upfront and lock them
|
||||
const collection = await Collection.findByPk(document.collectionId, {
|
||||
const collection = await Collection.findByPk(document.collectionId!, {
|
||||
transaction,
|
||||
lock: Transaction.LOCK.UPDATE,
|
||||
paranoid: false,
|
||||
});
|
||||
|
||||
let newCollection = collectionChanged
|
||||
? await Collection.findByPk(collectionId, {
|
||||
let newCollection = collection;
|
||||
if (collectionChanged) {
|
||||
if (collectionId) {
|
||||
newCollection = await Collection.findByPk(collectionId, {
|
||||
transaction,
|
||||
lock: Transaction.LOCK.UPDATE,
|
||||
})
|
||||
: collection;
|
||||
|
||||
invariant(newCollection, "collection should exist");
|
||||
});
|
||||
} else {
|
||||
newCollection = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (document.publishedAt) {
|
||||
// Remove the document from the current collection
|
||||
@@ -99,11 +110,13 @@ async function documentMover({
|
||||
document.lastModifiedById = user.id;
|
||||
document.updatedBy = user;
|
||||
|
||||
// Add the document and it's tree to the new collection
|
||||
await newCollection.addDocumentToStructure(document, toIndex, {
|
||||
documentJson,
|
||||
transaction,
|
||||
});
|
||||
if (newCollection) {
|
||||
// Add the document and it's tree to the new collection
|
||||
await newCollection.addDocumentToStructure(document, toIndex, {
|
||||
documentJson,
|
||||
transaction,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
document.collectionId = collectionId;
|
||||
document.parentDocumentId = parentDocumentId;
|
||||
@@ -118,30 +131,48 @@ async function documentMover({
|
||||
// If the collection has changed then we also need to update the properties
|
||||
// on all of the documents children to reflect the new collectionId
|
||||
if (collectionChanged) {
|
||||
// Reload the collection to get relationship data
|
||||
newCollection = await Collection.scope({
|
||||
method: ["withMembership", user.id],
|
||||
}).findByPk(collectionId, {
|
||||
transaction,
|
||||
});
|
||||
invariant(newCollection, "collection should exist");
|
||||
|
||||
result.collections.push(newCollection);
|
||||
|
||||
// Efficiently find the ID's of all the documents that are children of
|
||||
// the moved document and update in one query
|
||||
const childDocumentIds = await document.getChildDocumentIds();
|
||||
await Document.update(
|
||||
{
|
||||
collectionId: newCollection.id,
|
||||
},
|
||||
{
|
||||
|
||||
if (collectionId) {
|
||||
// Reload the collection to get relationship data
|
||||
newCollection = await Collection.scope({
|
||||
method: ["withMembership", user.id],
|
||||
}).findByPk(collectionId, {
|
||||
transaction,
|
||||
where: {
|
||||
id: childDocumentIds,
|
||||
});
|
||||
invariant(newCollection, "collection should exist");
|
||||
result.collections.push(newCollection);
|
||||
|
||||
await Document.update(
|
||||
{
|
||||
collectionId: newCollection.id,
|
||||
},
|
||||
}
|
||||
);
|
||||
{
|
||||
transaction,
|
||||
where: {
|
||||
id: childDocumentIds,
|
||||
},
|
||||
}
|
||||
);
|
||||
} else {
|
||||
// document will be moved to drafts
|
||||
document.publishedAt = null;
|
||||
|
||||
// point children's parent to moved document's parent
|
||||
await Document.update(
|
||||
{
|
||||
parentDocumentId: document.parentDocumentId,
|
||||
},
|
||||
{
|
||||
transaction,
|
||||
where: {
|
||||
id: childDocumentIds,
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// We must reload from the database to get the relationship data
|
||||
const documents = await Document.findAll({
|
||||
|
||||
@@ -74,7 +74,7 @@ export default async function documentUpdater({
|
||||
if (!document.collectionId) {
|
||||
document.collectionId = collectionId as string;
|
||||
}
|
||||
await document.publish(user.id, { transaction });
|
||||
await document.publish(user.id, collectionId!, { transaction });
|
||||
|
||||
await Event.create(
|
||||
{
|
||||
|
||||
@@ -11,7 +11,7 @@ type Props = {
|
||||
/** The document to pin */
|
||||
documentId: string;
|
||||
/** The collection to pin the document in. If no collection is provided then it will be pinned to home */
|
||||
collectionId?: string | undefined;
|
||||
collectionId?: string | null;
|
||||
/** The index to pin the document at. If no index is provided then it will be pinned to the end of the collection */
|
||||
index?: string;
|
||||
/** The IP address of the user creating the pin */
|
||||
|
||||
@@ -111,13 +111,6 @@ async function teamPermanentDeleter(team: Team) {
|
||||
force: true,
|
||||
transaction,
|
||||
});
|
||||
await FileOperation.destroy({
|
||||
where: {
|
||||
teamId,
|
||||
},
|
||||
force: true,
|
||||
transaction,
|
||||
});
|
||||
await Collection.destroy({
|
||||
where: {
|
||||
teamId,
|
||||
@@ -132,6 +125,13 @@ async function teamPermanentDeleter(team: Team) {
|
||||
force: true,
|
||||
transaction,
|
||||
});
|
||||
await FileOperation.destroy({
|
||||
where: {
|
||||
teamId,
|
||||
},
|
||||
force: true,
|
||||
transaction,
|
||||
});
|
||||
await Group.unscoped().destroy({
|
||||
where: {
|
||||
teamId,
|
||||
|
||||
+1
-3
@@ -16,7 +16,6 @@ import {
|
||||
IsIn,
|
||||
IsEmail,
|
||||
IsBoolean,
|
||||
Contains,
|
||||
MaxLength,
|
||||
} from "class-validator";
|
||||
import { languages } from "@shared/i18n";
|
||||
@@ -344,9 +343,8 @@ export class Environment {
|
||||
public RELEASE = this.toOptionalString(process.env.RELEASE);
|
||||
|
||||
/**
|
||||
* A Google Analytics tracking ID, supports only v3 properties.
|
||||
* A Google Analytics tracking ID, supports v3 or v4 properties.
|
||||
*/
|
||||
@Contains("UA-")
|
||||
@IsOptional()
|
||||
public GOOGLE_ANALYTICS_ID = this.toOptionalString(
|
||||
process.env.GOOGLE_ANALYTICS_ID
|
||||
|
||||
@@ -24,6 +24,7 @@ import onerror from "./onerror";
|
||||
import ShutdownHelper, { ShutdownOrder } from "./utils/ShutdownHelper";
|
||||
import { sequelize } from "./database/sequelize";
|
||||
import RedisAdapter from "./redis";
|
||||
import Metrics from "./logging/Metrics";
|
||||
|
||||
// The default is to run all services to make development and OSS installations
|
||||
// easier to deal with. Separate services are only needed at scale.
|
||||
@@ -154,6 +155,8 @@ async function start(id: number, disconnect: () => void) {
|
||||
})
|
||||
);
|
||||
|
||||
ShutdownHelper.add("metrics", ShutdownOrder.last, () => Metrics.flush());
|
||||
|
||||
// Handle shutdown signals
|
||||
process.once("SIGTERM", () => ShutdownHelper.execute());
|
||||
process.once("SIGINT", () => ShutdownHelper.execute());
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import ddMetrics from "datadog-metrics";
|
||||
import env from "@server/env";
|
||||
import ShutdownHelper, { ShutdownOrder } from "@server/utils/ShutdownHelper";
|
||||
|
||||
class Metrics {
|
||||
enabled = !!env.DD_API_KEY;
|
||||
@@ -15,8 +14,6 @@ class Metrics {
|
||||
prefix: "outline.",
|
||||
defaultTags: [`env:${process.env.DD_ENV ?? env.ENVIRONMENT}`],
|
||||
});
|
||||
|
||||
ShutdownHelper.add("metrics", ShutdownOrder.last, () => this.flush());
|
||||
}
|
||||
|
||||
gauge(key: string, value: number, tags?: string[]): void {
|
||||
|
||||
Loaded 100 of 204 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user