Document emoji picker (#4338)
Co-authored-by: Tom Moor <tom.moor@gmail.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import compact from "lodash/compact";
|
||||
import isNil from "lodash/isNil";
|
||||
import uniq from "lodash/uniq";
|
||||
import randomstring from "randomstring";
|
||||
import type { SaveOptions } from "sequelize";
|
||||
@@ -33,7 +34,6 @@ import {
|
||||
import isUUID from "validator/lib/isUUID";
|
||||
import type { NavigationNode } from "@shared/types";
|
||||
import getTasks from "@shared/utils/getTasks";
|
||||
import parseTitle from "@shared/utils/parseTitle";
|
||||
import { SLUG_URL_REGEX } from "@shared/utils/urlHelpers";
|
||||
import { DocumentValidation } from "@shared/validations";
|
||||
import slugify from "@server/utils/slugify";
|
||||
@@ -261,7 +261,7 @@ class Document extends ParanoidModel {
|
||||
// hooks
|
||||
|
||||
@BeforeSave
|
||||
static async updateTitleInCollectionStructure(
|
||||
static async updateCollectionStructure(
|
||||
model: Document,
|
||||
{ transaction }: SaveOptions<Document>
|
||||
) {
|
||||
@@ -271,7 +271,7 @@ class Document extends ParanoidModel {
|
||||
model.archivedAt ||
|
||||
model.template ||
|
||||
!model.publishedAt ||
|
||||
!model.changed("title") ||
|
||||
!(model.changed("title") || model.changed("emoji")) ||
|
||||
!model.collectionId
|
||||
) {
|
||||
return;
|
||||
@@ -330,10 +330,6 @@ class Document extends ParanoidModel {
|
||||
|
||||
@BeforeUpdate
|
||||
static processUpdate(model: Document) {
|
||||
const { emoji } = parseTitle(model.title);
|
||||
// emoji in the title is split out for easier display
|
||||
model.emoji = emoji || null;
|
||||
|
||||
// ensure documents have a title
|
||||
model.title = model.title || "";
|
||||
|
||||
@@ -795,6 +791,7 @@ class Document extends ParanoidModel {
|
||||
id: this.id,
|
||||
title: this.title,
|
||||
url: this.url,
|
||||
emoji: isNil(this.emoji) ? undefined : this.emoji,
|
||||
children,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -49,6 +49,13 @@ class Revision extends IdModel {
|
||||
@Column(DataType.TEXT)
|
||||
text: string;
|
||||
|
||||
@Length({
|
||||
max: 1,
|
||||
msg: `Emoji must be a single character`,
|
||||
})
|
||||
@Column
|
||||
emoji: string | null;
|
||||
|
||||
// associations
|
||||
|
||||
@BelongsTo(() => Document, "documentId")
|
||||
@@ -65,6 +72,14 @@ class Revision extends IdModel {
|
||||
@Column(DataType.UUID)
|
||||
userId: string;
|
||||
|
||||
// static methods
|
||||
|
||||
/**
|
||||
* Find the latest revision for a given document
|
||||
*
|
||||
* @param documentId The document id to find the latest revision for
|
||||
* @returns A Promise that resolves to a Revision model
|
||||
*/
|
||||
static findLatest(documentId: string) {
|
||||
return this.findOne({
|
||||
where: {
|
||||
@@ -74,10 +89,17 @@ class Revision extends IdModel {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a Revision model from a Document model
|
||||
*
|
||||
* @param document The document to build from
|
||||
* @returns A Revision model
|
||||
*/
|
||||
static buildFromDocument(document: Document) {
|
||||
return this.build({
|
||||
title: document.title,
|
||||
text: document.text,
|
||||
emoji: document.emoji,
|
||||
userId: document.lastModifiedById,
|
||||
editorVersion: document.editorVersion,
|
||||
version: document.version,
|
||||
@@ -88,6 +110,13 @@ class Revision extends IdModel {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Revision model from a Document model and save it to the database
|
||||
*
|
||||
* @param document The document to create from
|
||||
* @param options Options passed to the save method
|
||||
* @returns A Promise that resolves when saved
|
||||
*/
|
||||
static createFromDocument(
|
||||
document: Document,
|
||||
options?: SaveOptions<Revision>
|
||||
|
||||
Reference in New Issue
Block a user