mirror of
https://github.com/outline/outline.git
synced 2025-12-30 15:30:12 -06:00
fix: Cannot unset collection description, closes #7553
This commit is contained in:
@@ -19,7 +19,7 @@ export const CollectionsCreateSchema = BaseSchema.extend({
|
||||
.regex(ValidateColor.regex, { message: ValidateColor.message })
|
||||
.nullish(),
|
||||
description: z.string().nullish(),
|
||||
data: ProsemirrorSchema.nullish(),
|
||||
data: ProsemirrorSchema({ allowEmpty: true }).nullish(),
|
||||
permission: z
|
||||
.nativeEnum(CollectionPermission)
|
||||
.nullish()
|
||||
@@ -152,7 +152,7 @@ export const CollectionsUpdateSchema = BaseSchema.extend({
|
||||
body: BaseIdSchema.extend({
|
||||
name: z.string().optional(),
|
||||
description: z.string().nullish(),
|
||||
data: ProsemirrorSchema.nullish(),
|
||||
data: ProsemirrorSchema({ allowEmpty: true }).nullish(),
|
||||
icon: zodIconType().nullish(),
|
||||
permission: z.nativeEnum(CollectionPermission).nullish(),
|
||||
color: z
|
||||
|
||||
@@ -33,7 +33,7 @@ export const CommentsCreateSchema = BaseSchema.extend({
|
||||
parentCommentId: z.string().uuid().optional(),
|
||||
|
||||
/** Create comment with this data */
|
||||
data: ProsemirrorSchema,
|
||||
data: ProsemirrorSchema(),
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -42,7 +42,7 @@ export type CommentsCreateReq = z.infer<typeof CommentsCreateSchema>;
|
||||
export const CommentsUpdateSchema = BaseSchema.extend({
|
||||
body: BaseIdSchema.extend({
|
||||
/** Update comment with this data */
|
||||
data: ProsemirrorSchema,
|
||||
data: ProsemirrorSchema(),
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
@@ -11,12 +11,20 @@ export const BaseSchema = z.object({
|
||||
file: z.custom<formidable.File>().optional(),
|
||||
});
|
||||
|
||||
export const ProsemirrorSchema = z.custom<TProsemirrorData>((val) => {
|
||||
try {
|
||||
const node = Node.fromJSON(schema, val);
|
||||
node.check();
|
||||
return !ProsemirrorHelper.isEmpty(node, schema);
|
||||
} catch (_e) {
|
||||
return false;
|
||||
}
|
||||
}, "not valid data");
|
||||
/**
|
||||
* Returns a Zod schema for validating a Prosemirror document.
|
||||
*
|
||||
* @param allowEmpty - Whether to allow an empty document.
|
||||
*/
|
||||
export const ProsemirrorSchema = (options?: { allowEmpty: boolean }) =>
|
||||
z.custom<TProsemirrorData>((val) => {
|
||||
try {
|
||||
const node = Node.fromJSON(schema, val);
|
||||
node.check();
|
||||
return options?.allowEmpty
|
||||
? true
|
||||
: !ProsemirrorHelper.isEmpty(node, schema);
|
||||
} catch (_e) {
|
||||
return false;
|
||||
}
|
||||
}, "Invalid data");
|
||||
|
||||
Reference in New Issue
Block a user