Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support link text with boolean config & empty link #352

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,48 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [7.9.0-alpha.3](https://github.com/prismicio/prismic-client/compare/v7.8.1...v7.9.0-alpha.3) (2024-09-10)


### Chore

* **deps:** maintain lock file ([601edd5](https://github.com/prismicio/prismic-client/commit/601edd55ed2594010da740f3f40250a7f517cf5c))

## [7.9.0-alpha.2](https://github.com/prismicio/prismic-client/compare/v7.9.0-alpha.1...v7.9.0-alpha.2) (2024-08-27)


### Chore

* **release:** 7.9.0-alpha.2 ([000f146](https://github.com/prismicio/prismic-client/commit/000f146d25b84b2937c3accaffa54ab936a78de8))
* revert previous changes ([c53de86](https://github.com/prismicio/prismic-client/commit/c53de86a7ed749f0f9d8999b9e58564d9a8efe35))

## [7.9.0-alpha.1](https://github.com/prismicio/prismic-client/compare/v7.9.0-alpha.0...v7.9.0-alpha.1) (2024-08-27)


### Features

* use KeyTextField for link text value definition ([1a4c51a](https://github.com/prismicio/prismic-client/commit/1a4c51a389ed4d06cf69c3edcb215559ba91fe99))


### Chore

* **release:** 7.9.0-alpha.1 ([d940fcd](https://github.com/prismicio/prismic-client/commit/d940fcdb023de34765006607f7f34481de00a6ef))
* remove changelog for alpha ([50fc797](https://github.com/prismicio/prismic-client/commit/50fc797372726c0abc575b9f1b0a56d5db939bb1))

## [7.9.0-alpha.0](https://github.com/prismicio/prismic-client/compare/v7.8.0...v7.9.0-alpha.0) (2024-08-14)


### Features

* add text property to link models ([40d0e0b](https://github.com/prismicio/prismic-client/commit/40d0e0be3ce8038cd36e8cdf3350ffa9893ada98))
* add text to link value models ([8459d75](https://github.com/prismicio/prismic-client/commit/8459d75608c1af8319adafd2b3bf73555569a434))


### Chore

* **release:** 7.9.0-alpha.0 ([f2021c0](https://github.com/prismicio/prismic-client/commit/f2021c053b9aac1c17b7bbd1845c91eab7b0d176))
* update package version ([c06b383](https://github.com/prismicio/prismic-client/commit/c06b383ff41f01e253641c7852a4e9701725bdba))

## [7.9.0-alpha.1](https://github.com/prismicio/prismic-client/compare/v7.9.0-alpha.0...v7.9.0-alpha.1) (2024-08-27)


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@prismicio/client",
"version": "7.9.0-alpha.2",
"version": "7.9.0-alpha.3",
"description": "The official JavaScript + TypeScript client library for Prismic",
"keywords": [
"typescript",
Expand Down
2 changes: 0 additions & 2 deletions src/types/model/contentRelationship.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { CustomTypeModelFieldType } from "./types"

import type { CustomTypeModelKeyTextField } from "./keyText"
import type { CustomTypeModelLinkSelectType } from "./link"

/**
Expand All @@ -19,6 +18,5 @@ export interface CustomTypeModelContentRelationshipField<
select: typeof CustomTypeModelLinkSelectType.Document
customtypes?: readonly CustomTypeIDs[]
tags?: readonly Tags[]
text?: CustomTypeModelKeyTextField
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ #ask: Are we missing an allowText property here, as seen in CustomTypeModelLinkField and CustomTypeModelLinkToMediaField?

Copy link
Member

@angeloashmore angeloashmore Sep 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the idea is that content relationships are not links and thus don't need labels. What happens if someone wants to limit a link to only internal docs, not arbitrary URLs? Wouldn't they need a Content Relationship?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey,

Yes it's the idea, to not have link allow for CR. The fact is, today they are really mixed. In SM UI you cannot select to only link to documents. So that why I did that.

You think we should be more flexible on that?

At the end technically, if you edit manually your slice in SM it will work, custom types API will accept it. I was just thinking on prismic-client to not push for it as it's really name Content Relationship.

Copy link
Member

@angeloashmore angeloashmore Sep 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Things might break if the @prismicio/client types are not 1:1 with what other tools allow. For example, incorrect types might be generated via prismic-ts-codegen, and users won't be able to access myContentRelationship.text without TypeScript complaining.

In SM UI you cannot select to only link to documents.

Today, the content relationship field is used for that purpose. It has to be done that way because the link field does not allow for limiting what is accepted. It's a workaround since, as you said, a link field would be more appropriate if it had the capability of limiting what it accepts.

Since this is a new feature and there's no risk of making a breaking change, let's go with what the team already decided. We can always add text to the content relationship type if we find it is necessary, or even better, enhance link so devs can define what it accepts. 👍

}
}
4 changes: 1 addition & 3 deletions src/types/model/link.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type { CustomTypeModelFieldType } from "./types"

import type { CustomTypeModelKeyTextField } from "./keyText"

/**
* A link custom type field.
*
Expand All @@ -15,7 +13,7 @@ export interface CustomTypeModelLinkField {
select?:
| null
| (typeof CustomTypeModelLinkSelectType)[keyof typeof CustomTypeModelLinkSelectType]
text?: CustomTypeModelKeyTextField
allowText?: boolean
allowTargetBlank?: boolean
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/types/model/linkToMedia.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { CustomTypeModelFieldType } from "./types"

import type { CustomTypeModelKeyTextField } from "./keyText"
import type { CustomTypeModelLinkSelectType } from "./link"

/**
Expand All @@ -14,6 +13,6 @@ export interface CustomTypeModelLinkToMediaField {
label?: string | null
placeholder?: string
select: typeof CustomTypeModelLinkSelectType.Media
text?: CustomTypeModelKeyTextField
allowText?: boolean
}
}
1 change: 1 addition & 0 deletions src/types/value/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type EmptyLinkField<
Type extends (typeof LinkType)[keyof typeof LinkType] = typeof LinkType.Any,
> = {
link_type: Type | string
text?: string
}

/**
Expand Down
3 changes: 0 additions & 3 deletions test/types/customType-contentRelationship.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ expectType<prismic.CustomTypeModelContentRelationshipField>({
config: {
label: "string",
select: prismic.CustomTypeModelLinkSelectType.Document,
text: {
type: prismic.CustomTypeModelFieldType.Text,
},
},
})

Expand Down
4 changes: 1 addition & 3 deletions test/types/customType-link.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ expectType<prismic.CustomTypeModelLinkField>({
type: prismic.CustomTypeModelFieldType.Link,
config: {
label: "string",
text: {
type: prismic.CustomTypeModelFieldType.Text,
},
allowText: true,
},
})

Expand Down
4 changes: 1 addition & 3 deletions test/types/customType-linkToMedia.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ expectType<prismic.CustomTypeModelLinkToMediaField>({
config: {
label: "string",
select: prismic.CustomTypeModelLinkSelectType.Media,
text: {
type: prismic.CustomTypeModelFieldType.Text,
},
allowText: true,
},
})

Expand Down
19 changes: 19 additions & 0 deletions test/types/fields-contentRelationship.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,25 @@ expectType<prismic.ContentRelationshipField<string, string, never, "filled">>(
},
)

/**
* Empty state with text.
*/
expectType<prismic.ContentRelationshipField>({
link_type: prismic.LinkType.Document,
text: "string",
})
expectType<prismic.ContentRelationshipField<string, string, never, "empty">>({
link_type: prismic.LinkType.Document,
text: "string",
})
expectType<prismic.ContentRelationshipField<string, string, never, "filled">>(
// @ts-expect-error - Filled fields cannot contain an empty value.
{
link_type: prismic.LinkType.Document,
text: "string",
},
)

/**
* Supports custom document type.
*/
Expand Down
70 changes: 70 additions & 0 deletions test/types/fields-link.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,82 @@ expectType<prismic.LinkField<string, string, never, "empty">>({
expectType<prismic.LinkField>({
link_type: prismic.LinkType.Any,
})
expectType<prismic.LinkField<string, string, never, "filled">>({
// @ts-expect-error - Filled fields cannot contain an empty value.
link_type: prismic.LinkType.Any,
})
expectType<prismic.LinkField>({
link_type: prismic.LinkType.Web,
})
expectType<prismic.LinkField<string, string, never, "filled">>(
// @ts-expect-error - Filled fields cannot contain an empty value.
{
link_type: prismic.LinkType.Web,
},
)
expectType<prismic.LinkField>({
link_type: prismic.LinkType.Document,
})
expectType<prismic.LinkField<string, string, never, "filled">>(
// @ts-expect-error - Filled fields cannot contain an empty value.
{
link_type: prismic.LinkType.Document,
},
)
expectType<prismic.LinkField>({
link_type: prismic.LinkType.Media,
})
expectType<prismic.LinkField<string, string, never, "filled">>(
// @ts-expect-error - Filled fields cannot contain an empty value.
{
link_type: prismic.LinkType.Media,
},
)

/**
* Empty state with text.
*/
expectType<prismic.LinkField<string, string, never, "empty">>({
link_type: prismic.LinkType.Web,
text: "string",
})
expectType<prismic.LinkField<string, string, never, "filled">>(
// @ts-expect-error - Filled fields cannot contain an empty value.
{
link_type: prismic.LinkType.Web,
text: "string",
},
)
expectType<prismic.LinkField<string, string, never, "empty">>({
link_type: prismic.LinkType.Document,
text: "string",
})
expectType<prismic.LinkField<string, string, never, "filled">>(
// @ts-expect-error - Filled fields cannot contain an empty value.
{
link_type: prismic.LinkType.Document,
text: "string",
},
)
expectType<prismic.LinkField<string, string, never, "empty">>({
link_type: prismic.LinkType.Media,
text: "string",
})
expectType<prismic.LinkField<string, string, never, "filled">>(
// @ts-expect-error - Filled fields cannot contain an empty value.
{
link_type: prismic.LinkType.Media,
text: "string",
},
)
expectType<prismic.LinkField<string, string, never, "empty">>({
link_type: prismic.LinkType.Any,
text: "string",
})
expectType<prismic.LinkField<string, string, never, "filled">>({
// @ts-expect-error - Filled fields cannot contain an empty value.
link_type: prismic.LinkType.Any,
text: "string",
})

/**
Expand Down
19 changes: 19 additions & 0 deletions test/types/fields-linkToMedia.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,22 @@ expectType<prismic.LinkToMediaField<"filled">>(
link_type: prismic.LinkType.Media,
},
)

/**
* Empty state with text.
*/
expectType<prismic.LinkToMediaField>({
link_type: prismic.LinkType.Media,
text: "string",
})
expectType<prismic.LinkToMediaField<"empty">>({
link_type: prismic.LinkType.Media,
text: "string",
})
expectType<prismic.LinkToMediaField<"filled">>(
// @ts-expect-error - Filled fields cannot contain an empty value.
{
link_type: prismic.LinkType.Media,
text: "string",
},
)
Loading