diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml
index 77f4417543..082ccc7141 100644
--- a/.github/ISSUE_TEMPLATE/config.yml
+++ b/.github/ISSUE_TEMPLATE/config.yml
@@ -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
diff --git a/Dockerfile b/Dockerfile
index dfbd27a7da..3e63fa589e 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -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
diff --git a/Dockerfile.base b/Dockerfile.base
index 4c322b0a64..16401bd4f7 100644
--- a/Dockerfile.base
+++ b/Dockerfile.base
@@ -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
diff --git a/app.json b/app.json
index e7d5919b76..a062974554 100644
--- a/app.json
+++ b/app.json
@@ -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": {
diff --git a/app/actions/definitions/documents.tsx b/app/actions/definitions/documents.tsx
index b8d53177f7..fe69dfa718 100644
--- a/app/actions/definitions/documents.tsx
+++ b/app/actions/definitions/documents.tsx
@@ -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));
},
});
diff --git a/app/actions/definitions/revisions.tsx b/app/actions/definitions/revisions.tsx
index 55f1ba1cdc..4ecb1bc03b 100644
--- a/app/actions/definitions/revisions.tsx
+++ b/app/actions/definitions/revisions.tsx
@@ -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
)}`;
diff --git a/app/actions/definitions/users.tsx b/app/actions/definitions/users.tsx
index 07ddcc276e..c2ba446118 100644
--- a/app/actions/definitions/users.tsx
+++ b/app/actions/definitions/users.tsx
@@ -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: (
+
+ ),
+ });
+ },
+ });
+
export const rootUserActions = [inviteUser];
diff --git a/app/components/Analytics.tsx b/app/components/Analytics.tsx
index 79af34d880..d942668c55 100644
--- a/app/components/Analytics.tsx
+++ b/app/components/Analytics.tsx
@@ -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);
}, []);
diff --git a/app/components/AuthenticatedLayout.tsx b/app/components/AuthenticatedLayout.tsx
index fc4c29fff7..92b422a3cd 100644
--- a/app/components/AuthenticatedLayout.tsx
+++ b/app/components/AuthenticatedLayout.tsx
@@ -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));
diff --git a/app/components/CollectionDeleteDialog.tsx b/app/components/CollectionDeleteDialog.tsx
index 27a82ec638..f51da8ed26 100644
--- a/app/components/CollectionDeleteDialog.tsx
+++ b/app/components/CollectionDeleteDialog.tsx
@@ -39,7 +39,7 @@ function CollectionDeleteDialog({ collection, onSubmit }: Props) {
<>
= ({
@@ -23,6 +25,7 @@ const ConfirmationDialog: React.FC = ({
submitText,
savingText,
danger,
+ disabled = false,
}) => {
const [isSaving, setIsSaving] = React.useState(false);
const { dialogs } = useStores();
@@ -50,7 +53,12 @@ const ConfirmationDialog: React.FC = ({
diff --git a/app/components/ContextMenu/Template.tsx b/app/components/ContextMenu/Template.tsx
index 84cb0053c1..1b68bfc840 100644
--- a/app/components/ContextMenu/Template.tsx
+++ b/app/components/ContextMenu/Template.tsx
@@ -66,6 +66,7 @@ const SubMenu = React.forwardRef(
{...menu}
aria-label={t("Submenu")}
onClick={parentMenuState.hide}
+ parentMenuState={parentMenuState}
>
diff --git a/app/components/ContextMenu/index.tsx b/app/components/ContextMenu/index.tsx
index 387ac63b46..c615f6efc2 100644
--- a/app/components/ContextMenu/index.tsx
+++ b/app/components/ContextMenu/index.tsx
@@ -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;
/** Called when the context menu is opened. */
onOpen?: () => void;
/** Called when the context menu is closed. */
@@ -62,6 +62,7 @@ const ContextMenu: React.FC = ({
const { t } = useTranslation();
const { setIsMenuOpen } = useMenuContext();
const isMobile = useMobile();
+ const isSubMenu = !!parentMenuState;
useUnmount(() => {
setIsMenuOpen(false);
@@ -71,7 +72,7 @@ const ContextMenu: React.FC = ({
if (rest.visible && !previousVisible) {
onOpen?.();
- if (!parentMenuState) {
+ if (!isSubMenu) {
setIsMenuOpen(true);
}
}
@@ -79,7 +80,7 @@ const ContextMenu: React.FC = ({
if (!rest.visible && previousVisible) {
onClose?.();
- if (!parentMenuState) {
+ if (!isSubMenu) {
setIsMenuOpen(false);
}
}
@@ -90,7 +91,7 @@ const ContextMenu: React.FC = ({
rest.visible,
ui.sidebarCollapsed,
setIsMenuOpen,
- parentMenuState,
+ isSubMenu,
t,
]);
@@ -99,13 +100,15 @@ const ContextMenu: React.FC = ({
// 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) {
diff --git a/app/components/DocumentBreadcrumb.tsx b/app/components/DocumentBreadcrumb.tsx
index 952ef2c1b6..09f94b90ba 100644
--- a/app/components/DocumentBreadcrumb.tsx
+++ b/app/components/DocumentBreadcrumb.tsx
@@ -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: ,
title: t("Trash"),
- to: "/trash",
+ to: trashPath(),
};
}
@@ -33,7 +38,7 @@ function useCategory(document: Document): MenuInternalLink | null {
type: "route",
icon: ,
title: t("Archive"),
- to: "/archive",
+ to: archivePath(),
};
}
@@ -42,7 +47,7 @@ function useCategory(document: Document): MenuInternalLink | null {
type: "route",
icon: ,
title: t("Templates"),
- to: "/templates",
+ to: templatesPath(),
};
}
@@ -57,7 +62,9 @@ const DocumentBreadcrumb: React.FC = ({
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 = ({
type: "route",
title: collection.name,
icon: ,
- 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"),
};
}
diff --git a/app/components/DocumentCard.tsx b/app/components/DocumentCard.tsx
index 81a74aa224..4e05e057ca 100644
--- a/app/components/DocumentCard.tsx
+++ b/app/components/DocumentCard.tsx
@@ -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,
diff --git a/app/components/DocumentExplorer.tsx b/app/components/DocumentExplorer.tsx
index 4a0ccdab7d..9790b494f6 100644
--- a/app/components/DocumentExplorer.tsx
+++ b/app/components/DocumentExplorer.tsx
@@ -48,7 +48,6 @@ function DocumentExplorer({ onSubmit, onSelect, items }: Props) {
const [initialScrollOffset, setInitialScrollOffset] = React.useState(
0
);
- const [nodes, setNodes] = React.useState([]);
const [activeNode, setActiveNode] = React.useState(0);
const [expandedNodes, setExpandedNodes] = React.useState([]);
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 = ;
} else {
- icon = ;
+ icon = ;
}
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 {
diff --git a/app/components/DocumentMeta.tsx b/app/components/DocumentMeta.tsx
index 92e8c28e10..787d629d4b 100644
--- a/app/components/DocumentMeta.tsx
+++ b/app/components/DocumentMeta.tsx
@@ -57,7 +57,9 @@ const DocumentMeta: React.FC = ({
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;
diff --git a/app/components/DocumentTemplatizeDialog.tsx b/app/components/DocumentTemplatizeDialog.tsx
index ad643f9744..d83338de63 100644
--- a/app/components/DocumentTemplatizeDialog.tsx
+++ b/app/components/DocumentTemplatizeDialog.tsx
@@ -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",
});
diff --git a/app/components/DocumentsLoader.tsx b/app/components/DocumentsLoader.tsx
new file mode 100644
index 0000000000..7e37837e00
--- /dev/null
+++ b/app/components/DocumentsLoader.tsx
@@ -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);
diff --git a/app/components/Editor.tsx b/app/components/Editor.tsx
index b0e8235dd9..195042df22 100644
--- a/app/components/Editor.tsx
+++ b/app/components/Editor.tsx
@@ -350,6 +350,7 @@ function Editor(props: Props, ref: React.RefObject | null) {
)}
{activeLinkElement && !shareId && (
diff --git a/app/components/EventListItem.tsx b/app/components/EventListItem.tsx
index 713b518ec5..90c9efacee 100644
--- a/app/components/EventListItem.tsx
+++ b/app/components/EventListItem.tsx
@@ -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 = ;
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 = ;
meta = t("Latest");
to = {
- pathname: documentHistoryUrl(document),
+ pathname: documentHistoryPath(document),
state: { retainScrollPosition: true },
};
break;
diff --git a/app/components/HoverPreview.tsx b/app/components/HoverPreview.tsx
index bd15ed46ab..2c7fbdbab9 100644
--- a/app/components/HoverPreview.tsx
+++ b/app/components/HoverPreview.tsx
@@ -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
>
-
+
{(content: React.ReactNode) =>
isVisible ? (
diff --git a/app/components/HoverPreviewDocument.tsx b/app/components/HoverPreviewDocument.tsx
index a4c6238c75..874a5cb1ee 100644
--- a/app/components/HoverPreviewDocument.tsx
+++ b/app/components/HoverPreviewDocument.tsx
@@ -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;
}
diff --git a/app/components/Input.tsx b/app/components/Input.tsx
index bb8893d4b2..fd13ff7aee 100644
--- a/app/components/Input.tsx
+++ b/app/components/Input.tsx
@@ -175,6 +175,7 @@ function Input(
labelHidden,
onFocus,
onBlur,
+ children,
...rest
} = props;
@@ -211,6 +212,7 @@ function Input(
{...rest}
/>
)}
+ {children}
{error && (
diff --git a/app/components/PageTitle.tsx b/app/components/PageTitle.tsx
index 47e94ec425..24fbd2901b 100644
--- a/app/components/PageTitle.tsx
+++ b/app/components/PageTitle.tsx
@@ -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 (
{team?.name ? `${title} - ${team.name}` : `${title} - ${env.APP_NAME}`}
- {favicon ? (
-
- ) : (
-
- )}
+
);
diff --git a/app/components/Sidebar/Shared.tsx b/app/components/Sidebar/Shared.tsx
index 314e88b463..0618beb9af 100644
--- a/app/components/Sidebar/Shared.tsx
+++ b/app/components/Sidebar/Shared.tsx
@@ -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();
diff --git a/app/components/Sidebar/components/CollectionLink.tsx b/app/components/Sidebar/components/CollectionLink.tsx
index fa78d3d8f2..7890351dbd 100644
--- a/app/components/Sidebar/components/CollectionLink.tsx
+++ b/app/components/Sidebar/components/CollectionLink.tsx
@@ -44,7 +44,7 @@ const CollectionLink: React.FC = ({
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 = ({
}
}
},
- canDrop: () => canUpdate,
+ canDrop: () => can.createDocument,
collect: (monitor) => ({
isOver: !!monitor.isOver({
shallow: true,
@@ -118,6 +118,10 @@ const CollectionLink: React.FC = ({
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 = ({
}}
expanded={expanded}
onDisclosureClick={onDisclosureClick}
+ onMouseEnter={handleMouseEnter}
icon={
}
@@ -147,7 +152,7 @@ const CollectionLink: React.FC = ({
title={collection.name}
onSubmit={handleTitleChange}
onEditing={handleTitleEditing}
- canUpdate={canUpdate}
+ canUpdate={can.update}
/>
}
exact={false}
diff --git a/app/components/Sidebar/components/CollectionLinkChildren.tsx b/app/components/Sidebar/components/CollectionLinkChildren.tsx
index c1f3d7854e..c303c405d3 100644
--- a/app/components/Sidebar/components/CollectionLinkChildren.tsx
+++ b/app/components/Sidebar/components/CollectionLinkChildren.tsx
@@ -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 (
- {isDraggingAnyDocument && can.update && manualSort && (
+ {isDraggingAnyDocument && can.createDocument && manualSort && (
)}
- {childDocuments.map((node, index) => (
-
- ))}
- {childDocuments.length === 0 && }
+
+ {!childDocuments && (
+
+
+
+
+
+ )}
+ {childDocuments?.map((node, index) => (
+
+ ))}
+ {childDocuments?.length === 0 && }
+
);
}
+const Loading = styled(PlaceholderCollections)`
+ margin-left: 44px;
+ min-height: 90px;
+`;
+
export default observer(CollectionLinkChildren);
diff --git a/app/components/Sidebar/components/Collections.tsx b/app/components/Sidebar/components/Collections.tsx
index 3ff866957d..8da3ac8158 100644
--- a/app/components/Sidebar/components/Collections.tsx
+++ b/app/components/Sidebar/components/Collections.tsx
@@ -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() {
}
diff --git a/app/components/Sidebar/components/DropToImport.tsx b/app/components/Sidebar/components/DropToImport.tsx
index 66e574b8e4..55bbc6960f 100644
--- a/app/components/Sidebar/components/DropToImport.tsx
+++ b/app/components/Sidebar/components/DropToImport.tsx
@@ -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;
}
diff --git a/app/components/Sidebar/components/PlaceholderCollections.tsx b/app/components/Sidebar/components/PlaceholderCollections.tsx
index 8fe5c46ddd..49c732f59a 100644
--- a/app/components/Sidebar/components/PlaceholderCollections.tsx
+++ b/app/components/Sidebar/components/PlaceholderCollections.tsx
@@ -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) {
return (
-
+
diff --git a/app/components/Sidebar/components/StarredLink.tsx b/app/components/Sidebar/components/StarredLink.tsx
index 30560b34db..250f155921 100644
--- a/app/components/Sidebar/components/StarredLink.tsx
+++ b/app/components/Sidebar/components/StarredLink.tsx
@@ -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)
: [];
diff --git a/app/components/Sidebar/components/useCollectionDocuments.ts b/app/components/Sidebar/components/useCollectionDocuments.ts
index 42af1eedfa..62734ce11d 100644
--- a/app/components/Sidebar/components/useCollectionDocuments.ts
+++ b/app/components/Sidebar/components/useCollectionDocuments.ts
@@ -8,8 +8,8 @@ export default function useCollectionDocuments(
activeDocument: Document | undefined
) {
return React.useMemo(() => {
- if (!collection) {
- return [];
+ if (!collection?.sortedDocuments) {
+ return undefined;
}
const insertDraftDocument =
diff --git a/app/components/TeamContext.ts b/app/components/TeamContext.ts
new file mode 100644
index 0000000000..9133503265
--- /dev/null
+++ b/app/components/TeamContext.ts
@@ -0,0 +1,11 @@
+import * as React from "react";
+import { PublicTeam } from "@shared/types";
+import Team from "~/models/Team";
+
+export const TeamContext = React.createContext(
+ undefined
+);
+
+export function useTeamContext() {
+ return React.useContext(TeamContext);
+}
diff --git a/app/components/UserRoleDialogs.tsx b/app/components/UserDialogs.tsx
similarity index 64%
rename from app/components/UserRoleDialogs.tsx
rename to app/components/UserDialogs.tsx
index 6ead42f0e8..afc283adec 100644
--- a/app/components/UserRoleDialogs.tsx
+++ b/app/components/UserDialogs.tsx
@@ -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 (
+
+ {t(
+ "Are you sure you want to permanently delete {{ userName }}? This operation is unrecoverable, consider suspending the user instead.",
+ {
+ userName: user.name,
+ }
+ )}
+
+ );
+}
+
export function UserChangeToAdminDialog({ user, onSubmit }: Props) {
const { t } = useTranslation();
const { users } = useStores();
@@ -106,3 +132,37 @@ export function UserSuspendDialog({ user, onSubmit }: Props) {
);
}
+
+export function UserChangeNameDialog({ user, onSubmit }: Props) {
+ const { t } = useTranslation();
+ const [name, setName] = React.useState(user.name);
+
+ const handleSubmit = async () => {
+ await user.save({ name });
+ onSubmit();
+ };
+
+ const handleChange = (ev: React.ChangeEvent) => {
+ setName(ev.target.value);
+ };
+
+ return (
+
+
+
+ );
+}
diff --git a/app/components/WebsocketProvider.tsx b/app/components/WebsocketProvider.tsx
index a62274b021..3a1b396329 100644
--- a/app/components/WebsocketProvider.tsx
+++ b/app/components/WebsocketProvider.tsx
@@ -175,7 +175,7 @@ class WebsocketProvider extends React.Component {
id: document.collectionId,
});
- if (!existing) {
+ if (!existing && document.collectionId) {
event.collectionIds.push({
id: document.collectionId,
});
@@ -196,7 +196,7 @@ class WebsocketProvider extends React.Component {
}
try {
- await collections.fetch(collectionId, {
+ await collection?.fetchDocuments({
force: true,
});
} catch (err) {
@@ -293,15 +293,23 @@ class WebsocketProvider extends React.Component {
collections.add(event);
});
+ this.socket.on("collections.update", (event: PartialWithId) => {
+ 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 {
// 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(
diff --git a/app/editor/components/SelectionToolbar.tsx b/app/editor/components/SelectionToolbar.tsx
index 54288b5f4a..c4ed4dd6d1 100644
--- a/app/editor/components/SelectionToolbar.tsx
+++ b/app/editor/components/SelectionToolbar.tsx
@@ -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(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;
}
diff --git a/app/editor/menus/block.tsx b/app/editor/menus/block.tsx
index 3d954b2744..d9404e6ba0 100644
--- a/app/editor/menus/block.tsx
+++ b/app/editor/menus/block.tsx
@@ -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: ,
+ 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: ,
+ keywords: "notice card success",
+ attrs: { style: "success" },
+ },
{
name: "container_notice",
title: dictionary.warningNotice,
diff --git a/app/hooks/useCollectionTrees.ts b/app/hooks/useCollectionTrees.ts
index fe7ea419f4..7d8ed57842 100644
--- a/app/hooks/useCollectionTrees.ts
+++ b/app/hooks/useCollectionTrees.ts
@@ -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;
diff --git a/app/hooks/useDictionary.ts b/app/hooks/useDictionary.ts
index 15dff16fd2..5d359bc0bd 100644
--- a/app/hooks/useDictionary.ts
+++ b/app/hooks/useDictionary.ts
@@ -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"),
diff --git a/app/hooks/useImportDocument.ts b/app/hooks/useImportDocument.ts
index 9e668e77df..ddd1d4d8e4 100644
--- a/app/hooks/useImportDocument.ts
+++ b/app/hooks/useImportDocument.ts
@@ -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;
diff --git a/app/hooks/usePolicy.ts b/app/hooks/usePolicy.ts
index 5e455ab575..996e4ea2cd 100644
--- a/app/hooks/usePolicy.ts
+++ b/app/hooks/usePolicy.ts
@@ -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
diff --git a/app/hooks/useSettingsConfig.ts b/app/hooks/useSettingsConfig.ts
index b1553ef255..c82e47369d 100644
--- a/app/hooks/useSettingsConfig.ts
+++ b/app/hooks/useSettingsConfig.ts
@@ -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;
- component: () => JSX.Element;
+ component: React.ComponentType;
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;
diff --git a/app/menus/CollectionMenu.tsx b/app/menus/CollectionMenu.tsx
index 75a7a6bf77..023e907177 100644
--- a/app/menus/CollectionMenu.tsx
+++ b/app/menus/CollectionMenu.tsx
@@ -200,14 +200,14 @@ function CollectionMenu({
{
type: "button",
title: t("New document"),
- visible: can.update,
+ visible: can.createDocument,
onClick: handleNewDocument,
icon: ,
},
{
type: "button",
title: t("Import document"),
- visible: can.update,
+ visible: can.createDocument,
onClick: handleImportDocument,
icon: ,
},
@@ -239,7 +239,7 @@ function CollectionMenu({
{
type: "button",
title: `${t("Export")}…`,
- visible: !!(collection && canUserInTeam.createExport),
+ visible: !!(collection && canUserInTeam.createExport && can.export),
onClick: handleExport,
icon: ,
},
@@ -261,6 +261,7 @@ function CollectionMenu({
collection,
can.unstar,
can.star,
+ can.createDocument,
can.update,
can.delete,
handleStar,
diff --git a/app/menus/DocumentMenu.tsx b/app/menus/DocumentMenu.tsx
index 0ad7f37cb4..2c6117706a 100644
--- a/app/menus/DocumentMenu.tsx
+++ b/app/menus/DocumentMenu.tsx
@@ -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