From 5f00e1394d52c766702831c9182dbad464b914bd Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sun, 31 Oct 2021 18:36:16 -0700 Subject: [PATCH 1/6] fix: Move notifications to be revision driven (#2709) --- server/queues/processors/notifications.js | 22 ++++---- .../queues/processors/notifications.test.js | 10 ++-- server/queues/processors/slack.js | 19 ++++--- server/routes/api/documents.js | 51 ++++++++++--------- 4 files changed, 58 insertions(+), 44 deletions(-) diff --git a/server/queues/processors/notifications.js b/server/queues/processors/notifications.js index 1a52ba4aa4..3859bf8a4d 100644 --- a/server/queues/processors/notifications.js +++ b/server/queues/processors/notifications.js @@ -10,13 +10,18 @@ import { NotificationSetting, } from "../../models"; import { Op } from "../../sequelize"; -import type { DocumentEvent, CollectionEvent, Event } from "../../types"; +import type { + DocumentEvent, + CollectionEvent, + RevisionEvent, + Event, +} from "../../types"; export default class NotificationsProcessor { async on(event: Event) { switch (event.name) { case "documents.publish": - case "documents.update.debounced": + case "revisions.create": return this.documentUpdated(event); case "collections.create": return this.collectionCreated(event); @@ -24,18 +29,17 @@ export default class NotificationsProcessor { } } - async documentUpdated(event: DocumentEvent) { + async documentUpdated(event: DocumentEvent | RevisionEvent) { // never send notifications when batch importing documents if (event.data && event.data.source === "import") return; - const document = await Document.findByPk(event.documentId); - if (!document) return; + const [document, team] = await Promise.all([ + Document.findByPk(event.documentId), + Team.findByPk(event.teamId), + ]); + if (!document || !team || !document.collection) return; const { collection } = document; - if (!collection) return; - - const team = await Team.findByPk(document.teamId); - if (!team) return; const notificationSettings = await NotificationSetting.findAll({ where: { diff --git a/server/queues/processors/notifications.test.js b/server/queues/processors/notifications.test.js index 0cdfcc54b9..c3e2991dc5 100644 --- a/server/queues/processors/notifications.test.js +++ b/server/queues/processors/notifications.test.js @@ -93,8 +93,8 @@ describe("documents.publish", () => { }); }); -describe("documents.update.debounced", () => { - test("should send a notification to other collaborator", async () => { +describe("revisions.create", () => { + test("should send a notification to other collaborators", async () => { const document = await buildDocument(); const collaborator = await buildUser({ teamId: document.teamId }); document.collaboratorIds = [collaborator.id]; @@ -107,7 +107,7 @@ describe("documents.update.debounced", () => { }); await Notifications.on({ - name: "documents.update.debounced", + name: "revisions.create", documentId: document.id, collectionId: document.collectionId, teamId: document.teamId, @@ -132,7 +132,7 @@ describe("documents.update.debounced", () => { await View.touch(document.id, collaborator.id, true); await Notifications.on({ - name: "documents.update.debounced", + name: "revisions.create", documentId: document.id, collectionId: document.collectionId, teamId: document.teamId, @@ -156,7 +156,7 @@ describe("documents.update.debounced", () => { }); await Notifications.on({ - name: "documents.update.debounced", + name: "revisions.create", documentId: document.id, collectionId: document.collectionId, teamId: document.teamId, diff --git a/server/queues/processors/slack.js b/server/queues/processors/slack.js index daa6b7eca7..5b3b31f795 100644 --- a/server/queues/processors/slack.js +++ b/server/queues/processors/slack.js @@ -2,13 +2,18 @@ import fetch from "fetch-with-proxy"; import { Document, Integration, Collection, Team } from "../../models"; import { presentSlackAttachment } from "../../presenters"; -import type { DocumentEvent, IntegrationEvent, Event } from "../../types"; +import type { + DocumentEvent, + IntegrationEvent, + RevisionEvent, + Event, +} from "../../types"; export default class SlackProcessor { async on(event: Event) { switch (event.name) { case "documents.publish": - case "documents.update.debounced": + case "revisions.create": return this.documentUpdated(event); case "integrations.create": return this.integrationCreated(event); @@ -55,11 +60,15 @@ export default class SlackProcessor { }); } - async documentUpdated(event: DocumentEvent) { + async documentUpdated(event: DocumentEvent | RevisionEvent) { // never send notifications when batch importing documents if (event.data && event.data.source === "import") return; - const document = await Document.findByPk(event.documentId); + const [document, team] = await Promise.all([ + Document.findByPk(event.documentId), + Team.findByPk(event.teamId), + ]); + if (!document) return; // never send notifications for draft documents @@ -75,8 +84,6 @@ export default class SlackProcessor { }); if (!integration) return; - const team = await Team.findByPk(document.teamId); - let text = `${document.updatedBy.name} updated a document`; if (event.name === "documents.publish") { diff --git a/server/routes/api/documents.js b/server/routes/api/documents.js index a10dc7eebf..4580044ddf 100644 --- a/server/routes/api/documents.js +++ b/server/routes/api/documents.js @@ -1048,6 +1048,7 @@ router.post("documents.update", auth(), async (ctx) => { document.lastModifiedById = user.id; const { collection } = document; + const changed = document.changed(); let transaction; try { @@ -1066,30 +1067,32 @@ router.post("documents.update", auth(), async (ctx) => { throw err; } - if (publish) { - await Event.create({ - name: "documents.publish", - documentId: document.id, - collectionId: document.collectionId, - teamId: document.teamId, - actorId: user.id, - data: { title: document.title }, - ip: ctx.request.ip, - }); - } else { - await Event.create({ - name: "documents.update", - documentId: document.id, - collectionId: document.collectionId, - teamId: document.teamId, - actorId: user.id, - data: { - autosave, - done, - title: document.title, - }, - ip: ctx.request.ip, - }); + if (changed) { + if (publish) { + await Event.create({ + name: "documents.publish", + documentId: document.id, + collectionId: document.collectionId, + teamId: document.teamId, + actorId: user.id, + data: { title: document.title }, + ip: ctx.request.ip, + }); + } else { + await Event.create({ + name: "documents.update", + documentId: document.id, + collectionId: document.collectionId, + teamId: document.teamId, + actorId: user.id, + data: { + autosave, + done, + title: document.title, + }, + ip: ctx.request.ip, + }); + } } if (document.title !== previousTitle) { From 57fa1305a609bc7605dc6e640a35ba85e4fd4201 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 1 Nov 2021 19:52:04 -0700 Subject: [PATCH 2/6] chore: Remove `react-keydown` (#2713) * First steps of remove react-keydown, replace with hook * RegisterKeyDown component to aid transition away from react-keydown --- app/components/InputSearchPage.js | 138 +++---- app/components/Layout.js | 30 +- app/components/RegisterKeyDown.js | 17 + app/hooks/useKeyDown.js | 67 +++ app/hooks/usePrevious.js | 2 +- app/scenes/Document/components/Document.js | 54 ++- app/scenes/Search/Search.js | 8 +- app/utils/isTextInput.js | 12 + flow-typed/npm/react-keydown_vx.x.x.js | 447 --------------------- package.json | 1 - yarn.lock | 9 +- 11 files changed, 220 insertions(+), 565 deletions(-) create mode 100644 app/components/RegisterKeyDown.js create mode 100644 app/hooks/useKeyDown.js create mode 100644 app/utils/isTextInput.js delete mode 100644 flow-typed/npm/react-keydown_vx.x.x.js diff --git a/app/components/InputSearchPage.js b/app/components/InputSearchPage.js index 872d81131c..52a5a9fa29 100644 --- a/app/components/InputSearchPage.js +++ b/app/components/InputSearchPage.js @@ -1,20 +1,17 @@ // @flow -import { observable } from "mobx"; import { observer } from "mobx-react"; import { SearchIcon } from "outline-icons"; import * as React from "react"; -import { withTranslation, type TFunction } from "react-i18next"; -import keydown from "react-keydown"; -import { withRouter, type RouterHistory } from "react-router-dom"; -import styled, { withTheme } from "styled-components"; +import { useTranslation } from "react-i18next"; +import { useHistory } from "react-router-dom"; +import styled, { useTheme } from "styled-components"; import Input from "./Input"; -import { type Theme } from "types"; -import { meta } from "utils/keyboard"; +import useBoolean from "hooks/useBoolean"; +import useKeyDown from "hooks/useKeyDown"; +import { isModKey } from "utils/keyboard"; import { searchUrl } from "utils/routeHelpers"; -type Props = { - history: RouterHistory, - theme: Theme, +type Props = {| source: string, placeholder?: string, label?: string, @@ -23,78 +20,77 @@ type Props = { value: string, onChange: (event: SyntheticInputEvent<>) => mixed, onKeyDown: (event: SyntheticKeyboardEvent) => mixed, - t: TFunction, -}; +|}; -@observer -class InputSearchPage extends React.Component { - input: ?Input; - @observable focused: boolean = false; +function InputSearchPage({ + onKeyDown, + value, + onChange, + placeholder, + label, + collectionId, + source, +}: Props) { + const inputRef = React.useRef(); + const theme = useTheme(); + const history = useHistory(); + const { t } = useTranslation(); + const [isFocused, setFocused, setUnfocused] = useBoolean(false); - @keydown(`${meta}+f`) - focus(ev: SyntheticEvent<>) { - ev.preventDefault(); + const focus = React.useCallback(() => { + inputRef.current?.focus(); + }, []); - if (this.input) { - this.input.focus(); - } - } - - handleKeyDown = (ev: SyntheticKeyboardEvent) => { - if (ev.key === "Enter") { + useKeyDown("f", (ev: KeyboardEvent) => { + if (isModKey(ev)) { ev.preventDefault(); - this.props.history.push( - searchUrl(ev.currentTarget.value, { - collectionId: this.props.collectionId, - ref: this.props.source, - }) - ); + focus(); } + }); - if (this.props.onKeyDown) { - this.props.onKeyDown(ev); - } - }; + const handleKeyDown = React.useCallback( + (ev: SyntheticKeyboardEvent) => { + if (ev.key === "Enter") { + ev.preventDefault(); + history.push( + searchUrl(ev.currentTarget.value, { + collectionId, + ref: source, + }) + ); + } - handleFocus = () => { - this.focused = true; - }; + if (onKeyDown) { + onKeyDown(ev); + } + }, + [history, collectionId, source, onKeyDown] + ); - handleBlur = () => { - this.focused = false; - }; - - render() { - const { t, value, onChange } = this.props; - const { theme, placeholder = `${t("Search")}…` } = this.props; - - return ( - (this.input = ref)} - type="search" - placeholder={placeholder} - value={value} - onChange={onChange} - onKeyDown={this.handleKeyDown} - icon={ - - } - label={this.props.label} - onFocus={this.handleFocus} - onBlur={this.handleBlur} - margin={0} - labelHidden - /> - ); - } + return ( + + } + label={label} + onFocus={setFocused} + onBlur={setUnfocused} + margin={0} + labelHidden + /> + ); } const InputMaxWidth = styled(Input)` max-width: 30vw; `; -export default withTranslation()( - withTheme(withRouter(InputSearchPage)) -); +export default observer(InputSearchPage); diff --git a/app/components/Layout.js b/app/components/Layout.js index 6f86685ae4..40d019596e 100644 --- a/app/components/Layout.js +++ b/app/components/Layout.js @@ -5,7 +5,6 @@ import { MenuIcon } from "outline-icons"; import * as React from "react"; import { Helmet } from "react-helmet"; import { withTranslation } from "react-i18next"; -import keydown from "react-keydown"; import { Switch, Route, @@ -22,11 +21,12 @@ import ErrorSuspended from "scenes/ErrorSuspended"; import Button from "components/Button"; import Flex from "components/Flex"; import { LoadingIndicatorBar } from "components/LoadingIndicator"; +import RegisterKeyDown from "components/RegisterKeyDown"; import Sidebar from "components/Sidebar"; import SettingsSidebar from "components/Sidebar/Settings"; import SkipNavContent from "components/SkipNavContent"; import SkipNavLink from "components/SkipNavLink"; -import { meta } from "utils/keyboard"; +import { isModKey } from "utils/keyboard"; import { searchUrl, matchDocumentSlug as slug, @@ -64,20 +64,13 @@ class Layout extends React.Component { scrollable: ?HTMLDivElement; @observable keyboardShortcutsOpen: boolean = false; - @keydown(`${meta}+.`) - handleToggleSidebar() { - this.props.ui.toggleCollapsedSidebar(); - } - - @keydown(["t", "/"]) - goToSearch(ev: SyntheticEvent<>) { + goToSearch = (ev: KeyboardEvent) => { ev.preventDefault(); ev.stopPropagation(); this.props.history.push(searchUrl()); - } + }; - @keydown("n") - goToNewDocument() { + goToNewDocument = () => { const { activeCollectionId } = this.props.ui; if (!activeCollectionId) return; @@ -85,7 +78,7 @@ class Layout extends React.Component { if (!can.update) return; this.props.history.push(newDocumentPath(activeCollectionId)); - } + }; render() { const { auth, ui } = this.props; @@ -97,6 +90,17 @@ class Layout extends React.Component { return ( + + + + { + if (isModKey(event)) { + ui.toggleCollapsedSidebar(); + } + }} + /> {team && team.name ? team.name : "Outline"} void, +}; + +/** + * This method is a wrapper around the useKeyDown hook to allow easier use in + * class components that have not yet been converted to functions. Do not use + * this method in functional components. + */ +export default function RegisterKeyDown({ trigger, handler }: Props) { + useKeyDown(trigger, handler); + return null; +} diff --git a/app/hooks/useKeyDown.js b/app/hooks/useKeyDown.js new file mode 100644 index 0000000000..ed95858351 --- /dev/null +++ b/app/hooks/useKeyDown.js @@ -0,0 +1,67 @@ +// @flow +import * as React from "react"; +import isTextInput from "utils/isTextInput"; + +export type KeyFilter = ((event: KeyboardEvent) => boolean) | string; + +// Registered keyboard event callbacks +let callbacks = []; + +// Track if IME input suggestions are open so we can ignore keydown shortcuts +// in this case, they should never be triggered from mobile keyboards. +let imeOpen = false; + +// Based on implementation in react-use +// https://github.com/streamich/react-use/blob/master/src/useKey.ts#L15-L22 +const createKeyPredicate = (keyFilter: KeyFilter) => + typeof keyFilter === "function" + ? keyFilter + : typeof keyFilter === "string" + ? (event: KeyboardEvent) => event.key === keyFilter + : keyFilter + ? (_event) => true + : (_event) => false; + +export default function useKeyDown( + key: KeyFilter, + fn: (event: KeyboardEvent) => void +): void { + const predicate = createKeyPredicate(key); + + React.useEffect(() => { + const handler = (event: KeyboardEvent) => { + if (predicate(event)) { + fn(event); + } + }; + + callbacks.push(handler); + + return () => { + callbacks = callbacks.filter((cb) => cb !== handler); + }; + }, []); +} + +window.addEventListener("keydown", (event) => { + if (imeOpen) { + return; + } + + // reverse so that the last registered callbacks get executed first + for (const callback of callbacks.reverse()) { + if (event.defaultPrevented === true) { + break; + } + if (!isTextInput(event.target) || event.ctrlKey || event.metaKey) { + callback(event); + } + } +}); + +window.addEventListener("compositionstart", () => { + imeOpen = true; +}); +window.addEventListener("compositionend", () => { + imeOpen = false; +}); diff --git a/app/hooks/usePrevious.js b/app/hooks/usePrevious.js index 501ef32ef7..0ddfcb450b 100644 --- a/app/hooks/usePrevious.js +++ b/app/hooks/usePrevious.js @@ -1,7 +1,7 @@ // @flow import * as React from "react"; -export default function usePrevious(value: any) { +export default function usePrevious(value: T): T | void { const ref = React.useRef(); React.useEffect(() => { ref.current = value; diff --git a/app/scenes/Document/components/Document.js b/app/scenes/Document/components/Document.js index e9fb85e2db..77c92a1c9c 100644 --- a/app/scenes/Document/components/Document.js +++ b/app/scenes/Document/components/Document.js @@ -6,7 +6,6 @@ import { InputIcon } from "outline-icons"; import { AllSelection } from "prosemirror-state"; import * as React from "react"; import { type TFunction, Trans, withTranslation } from "react-i18next"; -import keydown from "react-keydown"; import { Prompt, Route, withRouter } from "react-router-dom"; import type { RouterHistory, Match } from "react-router-dom"; import styled from "styled-components"; @@ -27,6 +26,7 @@ import Modal from "components/Modal"; import Notice from "components/Notice"; import PageTitle from "components/PageTitle"; import PlaceholderDocument from "components/PlaceholderDocument"; +import RegisterKeyDown from "components/RegisterKeyDown"; import Time from "components/Time"; import Container from "./Container"; import Contents from "./Contents"; @@ -39,7 +39,7 @@ import References from "./References"; import { type LocationWithState, type NavigationNode, type Theme } from "types"; import { isCustomDomain } from "utils/domains"; import { emojiToUrl } from "utils/emoji"; -import { meta } from "utils/keyboard"; +import { isModKey } from "utils/keyboard"; import { documentMoveUrl, documentHistoryUrl, @@ -148,8 +148,7 @@ class DocumentScene extends React.Component { this.updateIsDirty(); }; - @keydown("m") - goToMove(ev) { + goToMove = (ev) => { if (!this.props.readOnly) return; ev.preventDefault(); @@ -158,10 +157,9 @@ class DocumentScene extends React.Component { if (abilities.move) { this.props.history.push(documentMoveUrl(document)); } - } + }; - @keydown("e") - goToEdit(ev) { + goToEdit = (ev) => { if (!this.props.readOnly) return; ev.preventDefault(); @@ -170,18 +168,16 @@ class DocumentScene extends React.Component { if (abilities.update) { this.props.history.push(editDocumentUrl(document)); } - } + }; - @keydown("esc") - goBack(ev) { + goBack = (ev) => { if (this.props.readOnly) return; ev.preventDefault(); this.props.history.goBack(); - } + }; - @keydown("h") - goToHistory(ev) { + goToHistory = (ev) => { if (!this.props.readOnly) return; ev.preventDefault(); @@ -192,18 +188,16 @@ class DocumentScene extends React.Component { } else { this.props.history.push(documentHistoryUrl(document)); } - } + }; - @keydown(`${meta}+shift+p`) - onPublish(ev) { + onPublish = (ev) => { ev.preventDefault(); const { document } = this.props; if (document.publishedAt) return; this.onSave({ publish: true, done: true }); - } + }; - @keydown("ctrl+alt+h") - onToggleTableOfContents(ev) { + onToggleTableOfContents = (ev) => { if (!this.props.readOnly) return; ev.preventDefault(); @@ -214,7 +208,7 @@ class DocumentScene extends React.Component { } else { ui.showTableOfContents(); } - } + }; onSave = async ( options: { @@ -381,6 +375,26 @@ class DocumentScene extends React.Component { return ( + + + + + { + if (isModKey(event) && event.shiftKey) { + this.onPublish(event); + } + }} + /> + { + if (event.ctrlKey && event.altKey) { + this.onToggleTableOfContents(event); + } + }} + /> { } } - @keydown("esc") - goBack() { + goBack = () => { this.props.history.goBack(); - } + }; handleKeyDown = (ev: SyntheticKeyboardEvent) => { if (ev.key === "Enter") { @@ -269,6 +268,7 @@ class Search extends React.Component { return ( + {this.isLoading && } {notFound && (
diff --git a/app/utils/isTextInput.js b/app/utils/isTextInput.js new file mode 100644 index 0000000000..04e9ebcafe --- /dev/null +++ b/app/utils/isTextInput.js @@ -0,0 +1,12 @@ +// @flow +const inputs = ["input", "select", "button", "textarea"]; + +// detect if node is a text input element +export default function isTextInput(element: HTMLElement): boolean { + return ( + element && + (inputs.indexOf(element.tagName.toLowerCase()) !== -1 || + element.attributes.getNamedItem("role")?.value === "textbox" || + element.attributes.getNamedItem("contenteditable")?.value === "true") + ); +} diff --git a/flow-typed/npm/react-keydown_vx.x.x.js b/flow-typed/npm/react-keydown_vx.x.x.js deleted file mode 100644 index f62bef0b12..0000000000 --- a/flow-typed/npm/react-keydown_vx.x.x.js +++ /dev/null @@ -1,447 +0,0 @@ -// flow-typed signature: 83d11d74aafca79519887b934bf9ec86 -// flow-typed version: <>/react-keydown_v^1.7.3/flow_v0.104.0 - -/** - * This is an autogenerated libdef stub for: - * - * 'react-keydown' - * - * Fill this stub out by replacing all the `any` types. - * - * Once filled out, we encourage you to share your work with the - * community by sending a pull request to: - * https://github.com/flowtype/flow-typed - */ - -declare module 'react-keydown' { - declare module.exports: any; -} - -/** - * We include stubs for each file inside this npm package in case you need to - * require those files directly. Feel free to delete any files that aren't - * needed. - */ -declare module 'react-keydown/dist/decorators/class_decorator' { - declare module.exports: any; -} - -declare module 'react-keydown/dist/decorators' { - declare module.exports: any; -} - -declare module 'react-keydown/dist/decorators/method_decorator_scoped' { - declare module.exports: any; -} - -declare module 'react-keydown/dist/decorators/method_decorator' { - declare module.exports: any; -} - -declare module 'react-keydown/dist/event_handlers' { - declare module.exports: any; -} - -declare module 'react-keydown/dist' { - declare module.exports: any; -} - -declare module 'react-keydown/dist/lib/array.from' { - declare module.exports: any; -} - -declare module 'react-keydown/dist/lib/dom_helpers' { - declare module.exports: any; -} - -declare module 'react-keydown/dist/lib/keys' { - declare module.exports: any; -} - -declare module 'react-keydown/dist/lib/listeners' { - declare module.exports: any; -} - -declare module 'react-keydown/dist/lib/match_keys' { - declare module.exports: any; -} - -declare module 'react-keydown/dist/lib/parse_keys' { - declare module.exports: any; -} - -declare module 'react-keydown/dist/lib/uuid' { - declare module.exports: any; -} - -declare module 'react-keydown/dist/store' { - declare module.exports: any; -} - -declare module 'react-keydown/es/decorators/class_decorator' { - declare module.exports: any; -} - -declare module 'react-keydown/es/decorators' { - declare module.exports: any; -} - -declare module 'react-keydown/es/decorators/method_decorator_scoped' { - declare module.exports: any; -} - -declare module 'react-keydown/es/decorators/method_decorator' { - declare module.exports: any; -} - -declare module 'react-keydown/es/event_handlers' { - declare module.exports: any; -} - -declare module 'react-keydown/es' { - declare module.exports: any; -} - -declare module 'react-keydown/es/lib/array.from' { - declare module.exports: any; -} - -declare module 'react-keydown/es/lib/dom_helpers' { - declare module.exports: any; -} - -declare module 'react-keydown/es/lib/keys' { - declare module.exports: any; -} - -declare module 'react-keydown/es/lib/listeners' { - declare module.exports: any; -} - -declare module 'react-keydown/es/lib/match_keys' { - declare module.exports: any; -} - -declare module 'react-keydown/es/lib/parse_keys' { - declare module.exports: any; -} - -declare module 'react-keydown/es/lib/uuid' { - declare module.exports: any; -} - -declare module 'react-keydown/es/store' { - declare module.exports: any; -} - -declare module 'react-keydown/example/public/js/app' { - declare module.exports: any; -} - -declare module 'react-keydown/example/public/prism' { - declare module.exports: any; -} - -declare module 'react-keydown/example/src/app/class_decorator/code' { - declare module.exports: any; -} - -declare module 'react-keydown/example/src/app/class_decorator' { - declare module.exports: any; -} - -declare module 'react-keydown/example/src/app' { - declare module.exports: any; -} - -declare module 'react-keydown/example/src/app/method_decorator/code' { - declare module.exports: any; -} - -declare module 'react-keydown/example/src/app/method_decorator' { - declare module.exports: any; -} - -declare module 'react-keydown/example/src' { - declare module.exports: any; -} - -declare module 'react-keydown/src/decorators/class_decorator' { - declare module.exports: any; -} - -declare module 'react-keydown/src/decorators' { - declare module.exports: any; -} - -declare module 'react-keydown/src/decorators/method_decorator_scoped' { - declare module.exports: any; -} - -declare module 'react-keydown/src/decorators/method_decorator' { - declare module.exports: any; -} - -declare module 'react-keydown/src/event_handlers' { - declare module.exports: any; -} - -declare module 'react-keydown/src' { - declare module.exports: any; -} - -declare module 'react-keydown/src/lib/array.from' { - declare module.exports: any; -} - -declare module 'react-keydown/src/lib/dom_helpers' { - declare module.exports: any; -} - -declare module 'react-keydown/src/lib/keys' { - declare module.exports: any; -} - -declare module 'react-keydown/src/lib/listeners' { - declare module.exports: any; -} - -declare module 'react-keydown/src/lib/match_keys' { - declare module.exports: any; -} - -declare module 'react-keydown/src/lib/parse_keys' { - declare module.exports: any; -} - -declare module 'react-keydown/src/lib/uuid' { - declare module.exports: any; -} - -declare module 'react-keydown/src/store' { - declare module.exports: any; -} - -declare module 'react-keydown/tests/event_handlers-test' { - declare module.exports: any; -} - -declare module 'react-keydown/tests/fixtures/event' { - declare module.exports: any; -} - -declare module 'react-keydown/tests/match_keys-test' { - declare module.exports: any; -} - -declare module 'react-keydown/tests/parse_keys-test' { - declare module.exports: any; -} - -declare module 'react-keydown/tests/store-test' { - declare module.exports: any; -} - -declare module 'react-keydown/webpack.config' { - declare module.exports: any; -} - -// Filename aliases -declare module 'react-keydown/dist/decorators/class_decorator.js' { - declare module.exports: $Exports<'react-keydown/dist/decorators/class_decorator'>; -} -declare module 'react-keydown/dist/decorators/index' { - declare module.exports: $Exports<'react-keydown/dist/decorators'>; -} -declare module 'react-keydown/dist/decorators/index.js' { - declare module.exports: $Exports<'react-keydown/dist/decorators'>; -} -declare module 'react-keydown/dist/decorators/method_decorator_scoped.js' { - declare module.exports: $Exports<'react-keydown/dist/decorators/method_decorator_scoped'>; -} -declare module 'react-keydown/dist/decorators/method_decorator.js' { - declare module.exports: $Exports<'react-keydown/dist/decorators/method_decorator'>; -} -declare module 'react-keydown/dist/event_handlers.js' { - declare module.exports: $Exports<'react-keydown/dist/event_handlers'>; -} -declare module 'react-keydown/dist/index' { - declare module.exports: $Exports<'react-keydown/dist'>; -} -declare module 'react-keydown/dist/index.js' { - declare module.exports: $Exports<'react-keydown/dist'>; -} -declare module 'react-keydown/dist/lib/array.from.js' { - declare module.exports: $Exports<'react-keydown/dist/lib/array.from'>; -} -declare module 'react-keydown/dist/lib/dom_helpers.js' { - declare module.exports: $Exports<'react-keydown/dist/lib/dom_helpers'>; -} -declare module 'react-keydown/dist/lib/keys.js' { - declare module.exports: $Exports<'react-keydown/dist/lib/keys'>; -} -declare module 'react-keydown/dist/lib/listeners.js' { - declare module.exports: $Exports<'react-keydown/dist/lib/listeners'>; -} -declare module 'react-keydown/dist/lib/match_keys.js' { - declare module.exports: $Exports<'react-keydown/dist/lib/match_keys'>; -} -declare module 'react-keydown/dist/lib/parse_keys.js' { - declare module.exports: $Exports<'react-keydown/dist/lib/parse_keys'>; -} -declare module 'react-keydown/dist/lib/uuid.js' { - declare module.exports: $Exports<'react-keydown/dist/lib/uuid'>; -} -declare module 'react-keydown/dist/store.js' { - declare module.exports: $Exports<'react-keydown/dist/store'>; -} -declare module 'react-keydown/es/decorators/class_decorator.js' { - declare module.exports: $Exports<'react-keydown/es/decorators/class_decorator'>; -} -declare module 'react-keydown/es/decorators/index' { - declare module.exports: $Exports<'react-keydown/es/decorators'>; -} -declare module 'react-keydown/es/decorators/index.js' { - declare module.exports: $Exports<'react-keydown/es/decorators'>; -} -declare module 'react-keydown/es/decorators/method_decorator_scoped.js' { - declare module.exports: $Exports<'react-keydown/es/decorators/method_decorator_scoped'>; -} -declare module 'react-keydown/es/decorators/method_decorator.js' { - declare module.exports: $Exports<'react-keydown/es/decorators/method_decorator'>; -} -declare module 'react-keydown/es/event_handlers.js' { - declare module.exports: $Exports<'react-keydown/es/event_handlers'>; -} -declare module 'react-keydown/es/index' { - declare module.exports: $Exports<'react-keydown/es'>; -} -declare module 'react-keydown/es/index.js' { - declare module.exports: $Exports<'react-keydown/es'>; -} -declare module 'react-keydown/es/lib/array.from.js' { - declare module.exports: $Exports<'react-keydown/es/lib/array.from'>; -} -declare module 'react-keydown/es/lib/dom_helpers.js' { - declare module.exports: $Exports<'react-keydown/es/lib/dom_helpers'>; -} -declare module 'react-keydown/es/lib/keys.js' { - declare module.exports: $Exports<'react-keydown/es/lib/keys'>; -} -declare module 'react-keydown/es/lib/listeners.js' { - declare module.exports: $Exports<'react-keydown/es/lib/listeners'>; -} -declare module 'react-keydown/es/lib/match_keys.js' { - declare module.exports: $Exports<'react-keydown/es/lib/match_keys'>; -} -declare module 'react-keydown/es/lib/parse_keys.js' { - declare module.exports: $Exports<'react-keydown/es/lib/parse_keys'>; -} -declare module 'react-keydown/es/lib/uuid.js' { - declare module.exports: $Exports<'react-keydown/es/lib/uuid'>; -} -declare module 'react-keydown/es/store.js' { - declare module.exports: $Exports<'react-keydown/es/store'>; -} -declare module 'react-keydown/example/public/js/app.js' { - declare module.exports: $Exports<'react-keydown/example/public/js/app'>; -} -declare module 'react-keydown/example/public/prism.js' { - declare module.exports: $Exports<'react-keydown/example/public/prism'>; -} -declare module 'react-keydown/example/src/app/class_decorator/code.js' { - declare module.exports: $Exports<'react-keydown/example/src/app/class_decorator/code'>; -} -declare module 'react-keydown/example/src/app/class_decorator/index' { - declare module.exports: $Exports<'react-keydown/example/src/app/class_decorator'>; -} -declare module 'react-keydown/example/src/app/class_decorator/index.js' { - declare module.exports: $Exports<'react-keydown/example/src/app/class_decorator'>; -} -declare module 'react-keydown/example/src/app/index' { - declare module.exports: $Exports<'react-keydown/example/src/app'>; -} -declare module 'react-keydown/example/src/app/index.js' { - declare module.exports: $Exports<'react-keydown/example/src/app'>; -} -declare module 'react-keydown/example/src/app/method_decorator/code.js' { - declare module.exports: $Exports<'react-keydown/example/src/app/method_decorator/code'>; -} -declare module 'react-keydown/example/src/app/method_decorator/index' { - declare module.exports: $Exports<'react-keydown/example/src/app/method_decorator'>; -} -declare module 'react-keydown/example/src/app/method_decorator/index.js' { - declare module.exports: $Exports<'react-keydown/example/src/app/method_decorator'>; -} -declare module 'react-keydown/example/src/index' { - declare module.exports: $Exports<'react-keydown/example/src'>; -} -declare module 'react-keydown/example/src/index.js' { - declare module.exports: $Exports<'react-keydown/example/src'>; -} -declare module 'react-keydown/src/decorators/class_decorator.js' { - declare module.exports: $Exports<'react-keydown/src/decorators/class_decorator'>; -} -declare module 'react-keydown/src/decorators/index' { - declare module.exports: $Exports<'react-keydown/src/decorators'>; -} -declare module 'react-keydown/src/decorators/index.js' { - declare module.exports: $Exports<'react-keydown/src/decorators'>; -} -declare module 'react-keydown/src/decorators/method_decorator_scoped.js' { - declare module.exports: $Exports<'react-keydown/src/decorators/method_decorator_scoped'>; -} -declare module 'react-keydown/src/decorators/method_decorator.js' { - declare module.exports: $Exports<'react-keydown/src/decorators/method_decorator'>; -} -declare module 'react-keydown/src/event_handlers.js' { - declare module.exports: $Exports<'react-keydown/src/event_handlers'>; -} -declare module 'react-keydown/src/index' { - declare module.exports: $Exports<'react-keydown/src'>; -} -declare module 'react-keydown/src/index.js' { - declare module.exports: $Exports<'react-keydown/src'>; -} -declare module 'react-keydown/src/lib/array.from.js' { - declare module.exports: $Exports<'react-keydown/src/lib/array.from'>; -} -declare module 'react-keydown/src/lib/dom_helpers.js' { - declare module.exports: $Exports<'react-keydown/src/lib/dom_helpers'>; -} -declare module 'react-keydown/src/lib/keys.js' { - declare module.exports: $Exports<'react-keydown/src/lib/keys'>; -} -declare module 'react-keydown/src/lib/listeners.js' { - declare module.exports: $Exports<'react-keydown/src/lib/listeners'>; -} -declare module 'react-keydown/src/lib/match_keys.js' { - declare module.exports: $Exports<'react-keydown/src/lib/match_keys'>; -} -declare module 'react-keydown/src/lib/parse_keys.js' { - declare module.exports: $Exports<'react-keydown/src/lib/parse_keys'>; -} -declare module 'react-keydown/src/lib/uuid.js' { - declare module.exports: $Exports<'react-keydown/src/lib/uuid'>; -} -declare module 'react-keydown/src/store.js' { - declare module.exports: $Exports<'react-keydown/src/store'>; -} -declare module 'react-keydown/tests/event_handlers-test.js' { - declare module.exports: $Exports<'react-keydown/tests/event_handlers-test'>; -} -declare module 'react-keydown/tests/fixtures/event.js' { - declare module.exports: $Exports<'react-keydown/tests/fixtures/event'>; -} -declare module 'react-keydown/tests/match_keys-test.js' { - declare module.exports: $Exports<'react-keydown/tests/match_keys-test'>; -} -declare module 'react-keydown/tests/parse_keys-test.js' { - declare module.exports: $Exports<'react-keydown/tests/parse_keys-test'>; -} -declare module 'react-keydown/tests/store-test.js' { - declare module.exports: $Exports<'react-keydown/tests/store-test'>; -} -declare module 'react-keydown/webpack.config.js' { - declare module.exports: $Exports<'react-keydown/webpack.config'>; -} diff --git a/package.json b/package.json index 7e8a6196ac..a8acd93d23 100644 --- a/package.json +++ b/package.json @@ -141,7 +141,6 @@ "react-helmet": "^6.1.0", "react-i18next": "^11.7.3", "react-is": "^17.0.2", - "react-keydown": "^1.7.3", "react-portal": "^4.2.0", "react-router-dom": "^5.2.0", "react-table": "^7.7.0", diff --git a/yarn.lock b/yarn.lock index 8824d9545f..2a450e0467 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5090,7 +5090,7 @@ core-js@^2.4.0: resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.6.11.tgz#38831469f9922bded8ee21c9dc46985e0399308c" integrity sha512-5wjnpaT/3dV+XB4borEsnAYQchn00XSgTAWKDkEqv+K8KevjbzmofK6hfJ9TZIlpj2N0xQpazy7PiRQiWHqzWg== -core-js@^3.1.2, core-js@^3.10.2, core-js@^3.6.4: +core-js@^3.10.2, core-js@^3.6.4: version "3.10.2" resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.10.2.tgz#17cb038ce084522a717d873b63f2b3ee532e2cd5" integrity sha512-W+2oVYeNghuBr3yTzZFQ5rfmjZtYB/Ubg87R5YOmlGrIb+Uw9f7qjUbhsj+/EkXhcV7eOD3jiM4+sgraX3FZUw== @@ -12144,13 +12144,6 @@ react-is@^17.0.1, react-is@^17.0.2: resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0" integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w== -react-keydown@^1.7.3: - version "1.9.12" - resolved "https://registry.yarnpkg.com/react-keydown/-/react-keydown-1.9.12.tgz#9e10157775c9e3f21e124987e14af45a2ed52384" - integrity sha512-KnQdVCTlPeJJ5FcnaqT4LJFHFUWbr/P+KnUtKA3xOc2JuJy738LyNM8jdnkWNkexHWEXt/021ufR5l9e3fzUCQ== - dependencies: - core-js "^3.1.2" - react-medium-image-zoom@^3.1.3: version "3.1.3" resolved "https://registry.yarnpkg.com/react-medium-image-zoom/-/react-medium-image-zoom-3.1.3.tgz#b1470abc5a342d65c23021c01bafa8c731821478" From ea12ebea0e1a85e133aadbc3c1a52c23c95f7ecc Mon Sep 17 00:00:00 2001 From: Nan Yu Date: Tue, 2 Nov 2021 18:30:37 -0700 Subject: [PATCH 3/6] Fix: increase left gutter spacing on mobile edit mode (#2720) * fix: adds space to the left gutter in edit mode so heading annotations have room on mobile --- app/scenes/Document/components/Document.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/scenes/Document/components/Document.js b/app/scenes/Document/components/Document.js index 77c92a1c9c..5f0f348ad8 100644 --- a/app/scenes/Document/components/Document.js +++ b/app/scenes/Document/components/Document.js @@ -464,6 +464,7 @@ class DocumentScene extends React.Component { @@ -600,11 +601,15 @@ const ReferencesWrapper = styled("div")` const MaxWidth = styled(Flex)` ${(props) => props.archived && `* { color: ${props.theme.textSecondary} !important; } `}; - padding: 0 12px; + + // Adds space to the left gutter to make room for heading annotations on mobile + padding: ${(props) => (props.isEditing ? "0 12px 0 32px" : "0 12px")}; + transition: padding 100ms; + max-width: 100vw; width: 100%; - ${breakpoint("tablet")` + ${breakpoint("tablet")` padding: 0 24px; margin: 4px auto 12px; max-width: calc(48px + ${(props) => From a839f2ed5b31d5c38c9a8d96daf3f7eb4cd5ef30 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 3 Nov 2021 11:08:01 -0700 Subject: [PATCH 4/6] chore(deps): bump validator from 5.2.0 to 13.7.0 (#2726) Bumps [validator](https://github.com/validatorjs/validator.js) from 5.2.0 to 13.7.0. - [Release notes](https://github.com/validatorjs/validator.js/releases) - [Changelog](https://github.com/validatorjs/validator.js/blob/master/CHANGELOG.md) - [Commits](https://github.com/validatorjs/validator.js/compare/5.2.0...13.7.0) --- updated-dependencies: - dependency-name: validator dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index a8acd93d23..7a0aa9b236 100644 --- a/package.json +++ b/package.json @@ -173,7 +173,7 @@ "turndown": "^7.1.1", "utf8": "^3.0.0", "uuid": "^8.3.2", - "validator": "5.2.0", + "validator": "13.7.0", "winston": "^3.3.3", "ws": "^7.5.3", "y-indexeddb": "^9.0.6", diff --git a/yarn.lock b/yarn.lock index 2a450e0467..96fc4fa9ea 100644 --- a/yarn.lock +++ b/yarn.lock @@ -14914,10 +14914,10 @@ validate-npm-package-license@^3.0.1: spdx-correct "^3.0.0" spdx-expression-parse "^3.0.0" -validator@5.2.0: - version "5.2.0" - resolved "https://registry.yarnpkg.com/validator/-/validator-5.2.0.tgz#e66fb3ec352348c1f7232512328738d8d66a9689" - integrity sha1-5m+z7DUjSMH3IyUSMoc42NZqlok= +validator@13.7.0: + version "13.7.0" + resolved "https://registry.yarnpkg.com/validator/-/validator-13.7.0.tgz#4f9658ba13ba8f3d82ee881d3516489ea85c0857" + integrity sha512-nYXQLCBkpJ8X6ltALua9dRrZDHVYxjJ1wgskNt1lH9fzGjs3tgojGSCBjmEPwkWS1y29+DrizMTW19Pr9uB2nw== validator@^10.11.0: version "10.11.0" From ad3bb9808790ae2d1280651d0338dd23db6ee514 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Wed, 3 Nov 2021 17:51:51 -0700 Subject: [PATCH 5/6] fix: Various collab cursor issues (#2727) --- app/components/Editor.js | 10 +++++++--- package.json | 4 ++-- yarn.lock | 26 +++++++++++++------------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/app/components/Editor.js b/app/components/Editor.js index 98eb060c19..b349938a7e 100644 --- a/app/components/Editor.js +++ b/app/components/Editor.js @@ -12,7 +12,6 @@ import ErrorBoundary from "components/ErrorBoundary"; import Tooltip from "components/Tooltip"; import useMediaQuery from "hooks/useMediaQuery"; import useToasts from "hooks/useToasts"; -import { fadeOutCursor } from "styles/animations"; import { type Theme } from "types"; import { isModKey } from "utils/keyboard"; import { uploadFile } from "utils/uploadFile"; @@ -228,7 +227,8 @@ const StyledEditor = styled(RichMarkdownEditor)` visibility: hidden; } - .heading-name:first-child { + .heading-name:first-child, + .heading-name:first-child + .ProseMirror-yjs-cursor { & + h1, & + h2, & + h3, @@ -252,6 +252,10 @@ const StyledEditor = styled(RichMarkdownEditor)` } .ProseMirror { + & > .ProseMirror-yjs-cursor { + display: none; + } + .ProseMirror-yjs-cursor { position: relative; margin-left: -1px; @@ -260,6 +264,7 @@ const StyledEditor = styled(RichMarkdownEditor)` border-right: 1px solid black; height: 1em; word-break: normal; + &:after { content: ""; display: block; @@ -270,7 +275,6 @@ const StyledEditor = styled(RichMarkdownEditor)` bottom: 0; } > div { - animation: ${fadeOutCursor} 2000ms ease-out; opacity: 0; position: absolute; top: -1.8em; diff --git a/package.json b/package.json index 7a0aa9b236..29c66d14c5 100644 --- a/package.json +++ b/package.json @@ -150,7 +150,7 @@ "react-window": "^1.8.6", "reakit": "^1.3.10", "regenerator-runtime": "^0.13.7", - "rich-markdown-editor": "^11.18.12", + "rich-markdown-editor": "^11.18.17", "semver": "^7.3.2", "sequelize": "^6.3.4", "sequelize-cli": "^6.2.0", @@ -221,7 +221,7 @@ "yarn-deduplicate": "^3.1.0" }, "resolutions": { - "prosemirror-view": "1.18.1", + "prosemirror-view": "1.21.0", "dot-prop": "^5.2.0", "js-yaml": "^3.13.1" }, diff --git a/yarn.lock b/yarn.lock index 96fc4fa9ea..b2cef7fda6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11765,10 +11765,10 @@ prosemirror-markdown@^1.5.2: markdown-it "^10.0.0" prosemirror-model "^1.0.0" -prosemirror-model@^1.0.0, prosemirror-model@^1.1.0, prosemirror-model@^1.13.3, prosemirror-model@^1.8.1: - version "1.13.3" - resolved "https://registry.yarnpkg.com/prosemirror-model/-/prosemirror-model-1.13.3.tgz#3ccfde73b9c9e706933c72bdf7462906509ff1c9" - integrity sha512-wujIYYQEcxdkbKmIJiekVjqtylKxuoEcc+w2PnN7Itc58m/75J4rCUz2dibygVQJFi3gZrD2DNFLjOS6LP4w1g== +prosemirror-model@^1.0.0, prosemirror-model@^1.13.3, prosemirror-model@^1.14.3, prosemirror-model@^1.8.1: + version "1.15.0" + resolved "https://registry.yarnpkg.com/prosemirror-model/-/prosemirror-model-1.15.0.tgz#23bc09098daa7c309dba90a76a1b989ce6f61405" + integrity sha512-hQJv7SnIhlAy9ga3lhPPgaufhvCbQB9tHwscJ9E1H1pPHmN8w5V/lURueoYv9Kc3/bpNWoyHa8r3g//m7N0ChQ== dependencies: orderedmap "^1.1.0" @@ -11811,12 +11811,12 @@ prosemirror-utils@^0.9.6: resolved "https://registry.yarnpkg.com/prosemirror-utils/-/prosemirror-utils-0.9.6.tgz#3d97bd85897e3b535555867dc95a51399116a973" integrity sha512-UC+j9hQQ1POYfMc5p7UFxBTptRiGPR7Kkmbl3jVvU8VgQbkI89tR/GK+3QYC8n+VvBZrtAoCrJItNhWSxX3slA== -prosemirror-view@1.18.1, prosemirror-view@^1.0.0, prosemirror-view@^1.1.0, prosemirror-view@^1.13.3: - version "1.18.1" - resolved "https://registry.yarnpkg.com/prosemirror-view/-/prosemirror-view-1.18.1.tgz#52ad1c67f51144e27e368bba129142ce87c7791e" - integrity sha512-TZd8byDRfdopLiokBY7T27msCSfWqqRxWs/LnBbdI030F+iI2kS+tO59/XFnpZxMLFKlJgOgGGhM9SzD1Nwdxw== +prosemirror-view@1.18.1, prosemirror-view@1.21.0, prosemirror-view@^1.0.0, prosemirror-view@^1.1.0, prosemirror-view@^1.13.3: + version "1.21.0" + resolved "https://registry.yarnpkg.com/prosemirror-view/-/prosemirror-view-1.21.0.tgz#d793cd338eda224026b8fe18a4f3163204963b8b" + integrity sha512-Pjh0vXw/l2Ifc3QcBVKJ/qHej33MX4sdq4/uAVqkSmHLf//bVWTYSZibihMya3lsIxTbDzNl/Z03KrhXWMHaoA== dependencies: - prosemirror-model "^1.1.0" + prosemirror-model "^1.14.3" prosemirror-state "^1.0.0" prosemirror-transform "^1.1.0" @@ -12776,10 +12776,10 @@ retry-as-promised@^3.2.0: dependencies: any-promise "^1.3.0" -rich-markdown-editor@^11.18.12: - version "11.18.12" - resolved "https://registry.yarnpkg.com/rich-markdown-editor/-/rich-markdown-editor-11.18.12.tgz#389ac35bda688acc1d60e30db36698f93409c5a5" - integrity sha512-NWgV1qqV6xu//FE3aQJq7PVlsJH3HxF6B9F2UVgYYBO3AUU/Ld5z6EhbJ5EnTw3/16JG/hc38t1yvmcjd9BypQ== +rich-markdown-editor@^11.18.17: + version "11.18.17" + resolved "https://registry.yarnpkg.com/rich-markdown-editor/-/rich-markdown-editor-11.18.17.tgz#bab7f14708e61d4baaf1173892ada06844390a35" + integrity sha512-0NJ08igupcoI/DsxkuivAi9ouKIGzmZdGv2L2W4jz/M0Z8p7SaW4vnTJ1Kk8cT9ryPF/Hvbuimnco5xaqiCCHg== dependencies: copy-to-clipboard "^3.0.8" fuzzy-search "^3.2.1" From 89115a53ca7c97aa1719781209bc90c079ac376b Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Wed, 3 Nov 2021 18:43:01 -0700 Subject: [PATCH 6/6] fix: documents.publish event not triggered if nothing else changed in doc (#2728) --- server/routes/api/documents.js | 50 ++++++++++++++--------------- server/routes/api/documents.test.js | 25 +++++++++++++++ 2 files changed, 49 insertions(+), 26 deletions(-) diff --git a/server/routes/api/documents.js b/server/routes/api/documents.js index 4580044ddf..1c1f26c5a1 100644 --- a/server/routes/api/documents.js +++ b/server/routes/api/documents.js @@ -1067,32 +1067,30 @@ router.post("documents.update", auth(), async (ctx) => { throw err; } - if (changed) { - if (publish) { - await Event.create({ - name: "documents.publish", - documentId: document.id, - collectionId: document.collectionId, - teamId: document.teamId, - actorId: user.id, - data: { title: document.title }, - ip: ctx.request.ip, - }); - } else { - await Event.create({ - name: "documents.update", - documentId: document.id, - collectionId: document.collectionId, - teamId: document.teamId, - actorId: user.id, - data: { - autosave, - done, - title: document.title, - }, - ip: ctx.request.ip, - }); - } + if (publish) { + await Event.create({ + name: "documents.publish", + documentId: document.id, + collectionId: document.collectionId, + teamId: document.teamId, + actorId: user.id, + data: { title: document.title }, + ip: ctx.request.ip, + }); + } else if (changed) { + await Event.create({ + name: "documents.update", + documentId: document.id, + collectionId: document.collectionId, + teamId: document.teamId, + actorId: user.id, + data: { + autosave, + done, + title: document.title, + }, + ip: ctx.request.ip, + }); } if (document.title !== previousTitle) { diff --git a/server/routes/api/documents.test.js b/server/routes/api/documents.test.js index 11ec9f6a53..561d62983d 100644 --- a/server/routes/api/documents.test.js +++ b/server/routes/api/documents.test.js @@ -8,6 +8,7 @@ import { Backlink, CollectionUser, SearchQuery, + Event, } from "../../models"; import webService from "../../services/web"; import { @@ -2005,6 +2006,9 @@ describe("#documents.update", () => { expect(res.status).toEqual(200); expect(body.data.title).toBe("Updated title"); expect(body.data.text).toBe("Updated text"); + + const events = await Event.findAll(); + expect(events.length).toEqual(1); }); it("should not add template to collection structure when publishing", async () => { @@ -2068,6 +2072,9 @@ describe("#documents.update", () => { expect(res.status).toEqual(200); expect(body.data.publishedAt).toBeTruthy(); expect(body.policies[0].abilities.update).toEqual(true); + + const events = await Event.findAll(); + expect(events.length).toEqual(1); }); it("should not edit archived document", async () => { @@ -2260,6 +2267,24 @@ describe("#documents.update", () => { expect(body.data.text).toBe(""); }); + it("should not produce event if nothing changes", async () => { + const { user, document } = await seed(); + + const res = await server.post("/api/documents.update", { + body: { + token: user.getJwtToken(), + id: document.id, + lastRevision: document.revision, + title: document.title, + text: document.text, + }, + }); + expect(res.status).toEqual(200); + + const events = await Event.findAll(); + expect(events.length).toEqual(0); + }); + it("should require authentication", async () => { const { document } = await seed(); const res = await server.post("/api/documents.update", {