Skip to content

Commit

Permalink
feat: update Multilink type
Browse files Browse the repository at this point in the history
  • Loading branch information
Edo-San committed Sep 26, 2024
1 parent 4ec6d51 commit 7562c03
Showing 1 changed file with 63 additions and 18 deletions.
81 changes: 63 additions & 18 deletions src/utils/typescript/storyblokProvidedPropertyTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -248,39 +262,70 @@ 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",
},
linktype: {
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"],
},
},
},
Expand Down

0 comments on commit 7562c03

Please sign in to comment.