mirror of
https://github.com/outline/outline.git
synced 2026-11-22 22:02:35 +03:00
wip
This commit is contained in:
1 parent
6f50ea1d60
commit
97f65ae250
11 files changed
+301
-15
No files matched your search
@@ -5,7 +5,7 @@ import { Trans, useTranslation } from "react-i18next";
|
||||
import styled from "styled-components";
|
||||
import Icon from "@shared/components/Icon";
|
||||
import { randomElement } from "@shared/random";
|
||||
import { CollectionPermission } from "@shared/types";
|
||||
import { CollectionDisplay, CollectionPermission } from "@shared/types";
|
||||
import { IconLibrary } from "@shared/utils/IconLibrary";
|
||||
import { colorPalette } from "@shared/utils/collections";
|
||||
import { CollectionValidation } from "@shared/validations";
|
||||
@@ -27,6 +27,7 @@ export interface FormData {
|
||||
icon: string;
|
||||
color: string | null;
|
||||
sharing: boolean;
|
||||
display: CollectionDisplay | undefined;
|
||||
permission: CollectionPermission | undefined;
|
||||
}
|
||||
|
||||
@@ -62,6 +63,7 @@ export const CollectionForm = observer(function CollectionForm_({
|
||||
defaultValues: {
|
||||
name: collection?.name ?? "",
|
||||
icon: collection?.icon,
|
||||
display: collection?.display,
|
||||
sharing: collection?.sharing ?? true,
|
||||
permission: collection?.permission,
|
||||
color: iconColor,
|
||||
|
||||
@@ -0,0 +1,219 @@
|
||||
import {
|
||||
useFocusEffect,
|
||||
useRovingTabIndex,
|
||||
} from "@getoutline/react-roving-tabindex";
|
||||
import { observer } from "mobx-react";
|
||||
import * as React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Link } from "react-router-dom";
|
||||
import styled from "styled-components";
|
||||
import breakpoint from "styled-components-breakpoint";
|
||||
import EventBoundary from "@shared/components/EventBoundary";
|
||||
import Icon from "@shared/components/Icon";
|
||||
import { richExtensions, withComments } from "@shared/editor/nodes";
|
||||
import { s, hover } from "@shared/styles";
|
||||
import Document from "~/models/Document";
|
||||
import Badge from "~/components/Badge";
|
||||
import Flex from "~/components/Flex";
|
||||
import Highlight from "~/components/Highlight";
|
||||
import NudeButton from "~/components/NudeButton";
|
||||
import StarButton from "~/components/Star";
|
||||
import Tooltip from "~/components/Tooltip";
|
||||
import useBoolean from "~/hooks/useBoolean";
|
||||
import useCurrentUser from "~/hooks/useCurrentUser";
|
||||
import { useLocationSidebarContext } from "~/hooks/useLocationSidebarContext";
|
||||
import DocumentMenu from "~/menus/DocumentMenu";
|
||||
import { documentPath } from "~/utils/routeHelpers";
|
||||
import { Avatar, AvatarSize } from "./Avatar";
|
||||
import Editor from "./Editor";
|
||||
import { determineSidebarContext } from "./Sidebar/components/SidebarContext";
|
||||
import Text from "./Text";
|
||||
import Time from "./Time";
|
||||
|
||||
const extensions = withComments(richExtensions);
|
||||
|
||||
type Props = {
|
||||
document: Document;
|
||||
highlight?: string | undefined;
|
||||
context?: string | undefined;
|
||||
showParentDocuments?: boolean;
|
||||
showCollection?: boolean;
|
||||
showPublished?: boolean;
|
||||
showPin?: boolean;
|
||||
showDraft?: boolean;
|
||||
};
|
||||
|
||||
function DocumentPostItem(
|
||||
props: Props,
|
||||
ref: React.RefObject<HTMLAnchorElement>
|
||||
) {
|
||||
const { t } = useTranslation();
|
||||
const user = useCurrentUser();
|
||||
const locationSidebarContext = useLocationSidebarContext();
|
||||
const [menuOpen, handleMenuOpen, handleMenuClose] = useBoolean();
|
||||
|
||||
let itemRef: React.Ref<HTMLAnchorElement> =
|
||||
React.useRef<HTMLAnchorElement>(null);
|
||||
if (ref) {
|
||||
itemRef = ref;
|
||||
}
|
||||
|
||||
const { focused, ...rovingTabIndex } = useRovingTabIndex(itemRef, false);
|
||||
useFocusEffect(focused, itemRef);
|
||||
|
||||
const {
|
||||
document,
|
||||
showParentDocuments,
|
||||
showCollection,
|
||||
showPublished,
|
||||
showPin,
|
||||
showDraft = true,
|
||||
highlight,
|
||||
context,
|
||||
...rest
|
||||
} = props;
|
||||
const canStar = !document.isArchived && !document.isTemplate;
|
||||
|
||||
const sidebarContext = determineSidebarContext({
|
||||
document,
|
||||
user,
|
||||
currentContext: locationSidebarContext,
|
||||
});
|
||||
|
||||
return (
|
||||
<Post
|
||||
ref={itemRef}
|
||||
dir={document.dir}
|
||||
role="menuitem"
|
||||
$isStarred={document.isStarred}
|
||||
$menuOpen={menuOpen}
|
||||
{...rest}
|
||||
{...rovingTabIndex}
|
||||
>
|
||||
<Content>
|
||||
<Heading
|
||||
dir={document.dir}
|
||||
to={{
|
||||
pathname: documentPath(document),
|
||||
state: {
|
||||
title: document.titleWithDefault,
|
||||
sidebarContext,
|
||||
},
|
||||
}}
|
||||
>
|
||||
{document.icon && (
|
||||
<>
|
||||
<Icon value={document.icon} color={document.color ?? undefined} />
|
||||
|
||||
</>
|
||||
)}
|
||||
<Title
|
||||
text={document.titleWithDefault}
|
||||
highlight={highlight}
|
||||
dir={document.dir}
|
||||
/>
|
||||
{document.isBadgedNew && document.createdBy?.id !== user.id && (
|
||||
<Badge yellow>{t("New")}</Badge>
|
||||
)}
|
||||
{document.isDraft && showDraft && (
|
||||
<Tooltip content={t("Only visible to you")} placement="top">
|
||||
<Badge>{t("Draft")}</Badge>
|
||||
</Tooltip>
|
||||
)}
|
||||
{canStar && (
|
||||
<StarPositioner>
|
||||
<StarButton document={document} />
|
||||
</StarPositioner>
|
||||
)}
|
||||
<Actions>
|
||||
<DocumentMenu
|
||||
document={document}
|
||||
showPin={showPin}
|
||||
onOpen={handleMenuOpen}
|
||||
onClose={handleMenuClose}
|
||||
modal={false}
|
||||
/>
|
||||
</Actions>
|
||||
</Heading>
|
||||
|
||||
<Flex justify="space-between" style={{ marginBottom: 8 }}>
|
||||
<Flex gap={6} align="center">
|
||||
<Avatar model={document.createdBy} size={AvatarSize.Medium} />
|
||||
<Text type="secondary" size="small">
|
||||
{t("By {{ author }}", { author: document.createdBy?.name })}{" "}
|
||||
<Time dateTime={document.updatedAt} addSuffix />
|
||||
</Text>
|
||||
</Flex>
|
||||
</Flex>
|
||||
|
||||
<Editor defaultValue={document.data} extensions={extensions} readOnly />
|
||||
</Content>
|
||||
</Post>
|
||||
);
|
||||
}
|
||||
|
||||
const Content = styled.div`
|
||||
flex-grow: 1;
|
||||
flex-shrink: 1;
|
||||
min-width: 0;
|
||||
`;
|
||||
|
||||
const Actions = styled(EventBoundary)`
|
||||
display: none;
|
||||
align-items: center;
|
||||
margin: 8px;
|
||||
flex-shrink: 0;
|
||||
flex-grow: 0;
|
||||
color: ${s("textSecondary")};
|
||||
|
||||
${NudeButton} {
|
||||
&: ${hover}, &[aria-expanded= "true"] {
|
||||
background: ${s("sidebarControlHoverBackground")};
|
||||
}
|
||||
}
|
||||
|
||||
${breakpoint("tablet")`
|
||||
display: flex;
|
||||
`};
|
||||
`;
|
||||
|
||||
const Post = styled.div<{
|
||||
$isStarred?: boolean;
|
||||
$menuOpen?: boolean;
|
||||
}>`
|
||||
position: relative;
|
||||
margin-top: 10px;
|
||||
margin-bottom: 2em;
|
||||
padding: 6px 0;
|
||||
`;
|
||||
|
||||
const Heading = styled(Link)<{ rtl?: boolean }>`
|
||||
display: flex;
|
||||
justify-content: ${(props) => (props.rtl ? "flex-end" : "flex-start")};
|
||||
align-items: center;
|
||||
margin-top: 8px;
|
||||
margin-bottom: -4px;
|
||||
white-space: nowrap;
|
||||
color: ${s("text")};
|
||||
font-size: 20px;
|
||||
font-family: ${s("fontFamily")};
|
||||
font-weight: 500;
|
||||
width: 100%;
|
||||
`;
|
||||
|
||||
const StarPositioner = styled(Flex)`
|
||||
margin-left: 4px;
|
||||
align-items: center;
|
||||
`;
|
||||
|
||||
const Title = styled(Highlight)`
|
||||
max-width: 90%;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
|
||||
&: ${hover} {
|
||||
text-decoration: underline;
|
||||
}
|
||||
`;
|
||||
|
||||
export default observer(React.forwardRef(DocumentPostItem));
|
||||
@@ -1,9 +1,11 @@
|
||||
import * as React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { CollectionDisplay } from "@shared/types";
|
||||
import Document from "~/models/Document";
|
||||
import DocumentListItem from "~/components/DocumentListItem";
|
||||
import Error from "~/components/List/Error";
|
||||
import PaginatedList from "~/components/PaginatedList";
|
||||
import DocumentPostItem from "./DocumentPostItem";
|
||||
|
||||
type Props = {
|
||||
documents: Document[];
|
||||
@@ -11,6 +13,7 @@ type Props = {
|
||||
options?: Record<string, any>;
|
||||
heading?: React.ReactNode;
|
||||
empty?: React.ReactNode;
|
||||
display?: CollectionDisplay;
|
||||
showParentDocuments?: boolean;
|
||||
showCollection?: boolean;
|
||||
showPublished?: boolean;
|
||||
@@ -24,6 +27,7 @@ const PaginatedDocumentList = React.memo<Props>(function PaginatedDocumentList({
|
||||
documents,
|
||||
fetch,
|
||||
options,
|
||||
display,
|
||||
showParentDocuments,
|
||||
showCollection,
|
||||
showPublished,
|
||||
@@ -42,18 +46,30 @@ const PaginatedDocumentList = React.memo<Props>(function PaginatedDocumentList({
|
||||
fetch={fetch}
|
||||
options={options}
|
||||
renderError={(props) => <Error {...props} />}
|
||||
renderItem={(item: Document, _index) => (
|
||||
<DocumentListItem
|
||||
key={item.id}
|
||||
document={item}
|
||||
showPin={!!options?.collectionId}
|
||||
showParentDocuments={showParentDocuments}
|
||||
showCollection={showCollection}
|
||||
showPublished={showPublished}
|
||||
showTemplate={showTemplate}
|
||||
showDraft={showDraft}
|
||||
/>
|
||||
)}
|
||||
renderItem={(item: Document, _index) =>
|
||||
display === CollectionDisplay.List ? (
|
||||
<DocumentListItem
|
||||
key={item.id}
|
||||
document={item}
|
||||
showPin={!!options?.collectionId}
|
||||
showParentDocuments={showParentDocuments}
|
||||
showCollection={showCollection}
|
||||
showPublished={showPublished}
|
||||
showTemplate={showTemplate}
|
||||
showDraft={showDraft}
|
||||
/>
|
||||
) : (
|
||||
<DocumentPostItem
|
||||
key={item.id}
|
||||
document={item}
|
||||
showPin={!!options?.collectionId}
|
||||
showParentDocuments={showParentDocuments}
|
||||
showCollection={showCollection}
|
||||
showPublished={showPublished}
|
||||
showDraft={showDraft}
|
||||
/>
|
||||
)
|
||||
}
|
||||
{...rest}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import invariant from "invariant";
|
||||
import { action, computed, observable, runInAction } from "mobx";
|
||||
import {
|
||||
CollectionDisplay,
|
||||
CollectionPermission,
|
||||
FileOperationFormat,
|
||||
type NavigationNode,
|
||||
@@ -42,6 +43,11 @@ export default class Collection extends ParanoidModel {
|
||||
@observable
|
||||
color?: string | null;
|
||||
|
||||
/** The display mode of the collection index. */
|
||||
@Field
|
||||
@observable
|
||||
display: CollectionDisplay;
|
||||
|
||||
/** The default permission for workspace users. */
|
||||
@Field
|
||||
@observable
|
||||
|
||||
@@ -353,6 +353,7 @@ const CollectionScene = observer(function _CollectionScene() {
|
||||
exact
|
||||
>
|
||||
<PaginatedDocumentList
|
||||
display={collection.display}
|
||||
documents={documents.rootInCollection(collection.id)}
|
||||
fetch={documents.fetchPage}
|
||||
options={{
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
|
||||
/** @type {import('sequelize-cli').Migration} */
|
||||
module.exports = {
|
||||
async up(queryInterface, Sequelize) {
|
||||
await queryInterface.sequelize.transaction(async transaction => {
|
||||
await queryInterface.addColumn("collections", "display", {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: "list",
|
||||
}, { transaction });
|
||||
});
|
||||
},
|
||||
|
||||
async down(queryInterface) {
|
||||
await queryInterface.sequelize.transaction(async transaction => {
|
||||
await queryInterface.removeColumn("collections", "display", { transaction });
|
||||
});
|
||||
},
|
||||
};
|
||||
@@ -35,7 +35,11 @@ import {
|
||||
} from "sequelize-typescript";
|
||||
import isUUID from "validator/lib/isUUID";
|
||||
import type { CollectionSort, ProsemirrorData } from "@shared/types";
|
||||
import { CollectionPermission, NavigationNode } from "@shared/types";
|
||||
import {
|
||||
CollectionDisplay,
|
||||
CollectionPermission,
|
||||
NavigationNode,
|
||||
} from "@shared/types";
|
||||
import { UrlHelper } from "@shared/utils/UrlHelper";
|
||||
import { sortNavigationNodes } from "@shared/utils/collections";
|
||||
import slugify from "@shared/utils/slugify";
|
||||
@@ -210,6 +214,10 @@ class Collection extends ParanoidModel<
|
||||
@Column
|
||||
icon: string | null;
|
||||
|
||||
/** The display mode of the collection index. */
|
||||
@Column(DataType.STRING)
|
||||
display: CollectionDisplay;
|
||||
|
||||
/** The color of the icon. */
|
||||
@IsHexColor
|
||||
@Column
|
||||
|
||||
@@ -20,6 +20,7 @@ export default async function presentCollection(
|
||||
icon: collection.icon,
|
||||
index: collection.index,
|
||||
color: collection.color,
|
||||
display: collection.display,
|
||||
permission: collection.permission,
|
||||
sharing: collection.sharing,
|
||||
createdAt: collection.createdAt,
|
||||
|
||||
@@ -55,7 +55,7 @@ router.post(
|
||||
transaction(),
|
||||
async (ctx: APIContext<T.CollectionsCreateReq>) => {
|
||||
const { transaction } = ctx.state;
|
||||
const { name, color, description, data, permission, sharing, icon, sort } =
|
||||
const { name, color, description, data, display, permission, sharing, icon, sort } =
|
||||
ctx.input.body;
|
||||
let { index } = ctx.input.body;
|
||||
|
||||
@@ -80,6 +80,7 @@ router.post(
|
||||
color,
|
||||
teamId: user.teamId,
|
||||
createdById: user.id,
|
||||
display,
|
||||
permission,
|
||||
sharing,
|
||||
sort,
|
||||
@@ -570,6 +571,7 @@ router.post(
|
||||
name,
|
||||
description,
|
||||
data,
|
||||
display,
|
||||
icon,
|
||||
permission,
|
||||
color,
|
||||
@@ -623,6 +625,10 @@ router.post(
|
||||
collection.description = DocumentHelper.toMarkdown(collection);
|
||||
}
|
||||
|
||||
if (display !== undefined) {
|
||||
collection.display = display;
|
||||
}
|
||||
|
||||
if (icon !== undefined) {
|
||||
collection.icon = icon;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import isUndefined from "lodash/isUndefined";
|
||||
import { z } from "zod";
|
||||
import {
|
||||
CollectionDisplay,
|
||||
CollectionPermission,
|
||||
CollectionStatusFilter,
|
||||
FileOperationFormat,
|
||||
@@ -24,6 +25,7 @@ export const CollectionsCreateSchema = BaseSchema.extend({
|
||||
.nullish(),
|
||||
description: z.string().nullish(),
|
||||
data: ProsemirrorSchema({ allowEmpty: true }).nullish(),
|
||||
display: z.nativeEnum(CollectionDisplay).nullish(),
|
||||
permission: z
|
||||
.nativeEnum(CollectionPermission)
|
||||
.nullish()
|
||||
@@ -159,6 +161,7 @@ export const CollectionsUpdateSchema = BaseSchema.extend({
|
||||
data: ProsemirrorSchema({ allowEmpty: true }).nullish(),
|
||||
icon: zodIconType().nullish(),
|
||||
permission: z.nativeEnum(CollectionPermission).nullish(),
|
||||
display: z.nativeEnum(CollectionDisplay).nullish(),
|
||||
color: z
|
||||
.string()
|
||||
.regex(ValidateColor.regex, { message: ValidateColor.message })
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
export enum CollectionDisplay {
|
||||
List = "list",
|
||||
Post = "post",
|
||||
}
|
||||
|
||||
export enum UserRole {
|
||||
Admin = "admin",
|
||||
Member = "member",
|
||||
|
||||
Reference in new issue
Block a user