From 7562c037d2ad84b0c0a925f88908bc5b7fcf637b Mon Sep 17 00:00:00 2001 From: Edoardo Sandon Date: Thu, 26 Sep 2024 16:23:49 +0200 Subject: [PATCH] feat: update Multilink type --- .../storyblokProvidedPropertyTypes.ts | 81 ++++++++++++++----- 1 file changed, 63 insertions(+), 18 deletions(-) diff --git a/src/utils/typescript/storyblokProvidedPropertyTypes.ts b/src/utils/typescript/storyblokProvidedPropertyTypes.ts index 176e27f1..21f5b139 100644 --- a/src/utils/typescript/storyblokProvidedPropertyTypes.ts +++ b/src/utils/typescript/storyblokProvidedPropertyTypes.ts @@ -139,29 +139,43 @@ export const getMultiassetJSONSchema = (title: string): JSONSchema => ({ }, }); +// TODO: find a reliable way to share props among different Link Types to increase maintainability +// Currently not possible because of JSONSchema4 complaining +const multilinkSharedRequiredProps = ["fieldtype", "id", "url", "cached_url", "linktype"]; + export const getMultilinkJSONSchema = (title: string): JSONSchema => ({ $id: "#/multilink", title, oneOf: [ { type: "object", + required: multilinkSharedRequiredProps, properties: { - id: { + // Shared props + fieldtype: { type: "string", + enum: ["multilink"], }, - cached_url: { + id: { type: "string" }, + url: { type: "string" }, + cached_url: { type: "string" }, + target: { type: "string", enum: ["_blank", "_self"] }, + // Custom props + anchor: { type: "string", }, - anchor: { + rel: { type: "string", }, - linktype: { + title: { + type: "string", + }, + prep: { type: "string", - enum: ["story"], }, - target: { + linktype: { type: "string", - enum: ["_self", "_blank"], + enum: ["story"], }, story: { type: "object", @@ -248,29 +262,44 @@ export const getMultilinkJSONSchema = (title: string): JSONSchema => ({ }, { type: "object", + required: multilinkSharedRequiredProps, properties: { - url: { + // Shared props + fieldtype: { type: "string", + enum: ["multilink"], }, - cached_url: { - type: "string", - }, - anchor: { + id: { type: "string" }, + url: { type: "string" }, + cached_url: { type: "string" }, + target: { type: "string", enum: ["_blank", "_self"] }, + // Custom props + linktype: { type: "string", + enum: ["url"], }, - linktype: { + rel: { type: "string", - enum: ["asset", "url"], }, - target: { + title: { type: "string", - enum: ["_self", "_blank"], }, }, }, { type: "object", + required: multilinkSharedRequiredProps, properties: { + // Shared props + fieldtype: { + type: "string", + enum: ["multilink"], + }, + id: { type: "string" }, + url: { type: "string" }, + cached_url: { type: "string" }, + target: { type: "string", enum: ["_blank", "_self"] }, + // Custom props email: { type: "string", }, @@ -278,9 +307,25 @@ export const getMultilinkJSONSchema = (title: string): JSONSchema => ({ type: "string", enum: ["email"], }, - target: { + }, + }, + { + type: "object", + required: multilinkSharedRequiredProps, + properties: { + // Shared props + fieldtype: { + type: "string", + enum: ["multilink"], + }, + id: { type: "string" }, + url: { type: "string" }, + cached_url: { type: "string" }, + target: { type: "string", enum: ["_blank", "_self"] }, + // Custom props + linktype: { type: "string", - enum: ["_self", "_blank"], + enum: ["asset"], }, }, },