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

feat: add support for display text in links #1431

Merged
merged 40 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
eab4337
chore: update packages
levimykel Aug 20, 2024
e228b6b
feat: add support for text in links
levimykel Aug 20, 2024
eb32bfe
feat: add display text tooltip
levimykel Aug 22, 2024
dcf5a94
chore: update form layout
levimykel Aug 26, 2024
2f7ce28
fix: minor PR review updates
levimykel Aug 27, 2024
2dccd93
feat: add link text by default
levimykel Aug 27, 2024
18cea8b
fix: minor update from PR review
levimykel Aug 27, 2024
f2b3b2a
fix: set the field value on checkbox change
levimykel Aug 27, 2024
6a704f8
Merge branch 'main' into lg/text-in-links
levimykel Aug 28, 2024
15a73e3
Use link text in next adapter slice templates
dani-mp Aug 29, 2024
a0a4356
Use link text in nuxt adapter slice templates
dani-mp Aug 29, 2024
be7898f
Use link text in sveltekit adapter slice templates
dani-mp Aug 29, 2024
256833b
fix: display text deactivated by default for content relationship fields
levimykel Aug 29, 2024
83a9318
support link text with boolean config
xrutayisire Sep 9, 2024
65d22b0
update prismic-types-internal
xrutayisire Sep 10, 2024
a178ad0
Merge branch 'main' into lg/text-in-links
xrutayisire Sep 13, 2024
e69de41
Merge branch 'lg/text-in-links' into xru/support-link-text-boolean
xrutayisire Sep 13, 2024
c0d0e5e
Merge pull request #1454 from prismicio/xru/support-link-text-boolean
dani-mp Sep 16, 2024
20bb674
Fix slice templates
dani-mp Sep 16, 2024
b86e35b
Merge branch 'lg/text-in-links' into dani/link-text-templates
dani-mp Sep 16, 2024
2453429
Merge pull request #1449 from prismicio/dani/link-text-templates
dani-mp Sep 16, 2024
85c2ad8
chore: update prismic-types-internal
levimykel Sep 17, 2024
f6b88c0
chore: update prismic-client
levimykel Sep 17, 2024
d93c192
chore: update prismic-client
levimykel Sep 17, 2024
0b4cb36
Upgrade deps
dani-mp Sep 26, 2024
9beb1be
temp add correct snipet for Next (to finish)
xrutayisire Sep 27, 2024
111bd30
Remove children from link snippets that allow text
dani-mp Sep 30, 2024
265c488
Merge pull request #1458 from prismicio/dani/link-snippets
dani-mp Sep 30, 2024
8f1868b
Add allowText to field added analytics event
dani-mp Sep 30, 2024
e043f69
Merge pull request #1459 from prismicio/dani/track-allow-text
dani-mp Sep 30, 2024
a1578a4
Make allow target blank true by default
dani-mp Sep 30, 2024
72a2cc0
Merge pull request #1460 from prismicio/dani/target-blank
dani-mp Sep 30, 2024
0e59978
update all deps
xrutayisire Oct 3, 2024
16eb39b
revert prismic-mock update
xrutayisire Oct 3, 2024
561d5f7
update editor packages
xrutayisire Oct 3, 2024
747d922
wrong update
xrutayisire Oct 3, 2024
4a3ded4
fix Text props
xrutayisire Oct 3, 2024
e4b1d6a
fix problems following braking changes in editor-ui
xrutayisire Oct 3, 2024
0f558cc
fix problems following breaking changes in editor-ui 2
xrutayisire Oct 3, 2024
1919187
try editor 0.4.48
xrutayisire Oct 3, 2024
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"resolutions": {
"connected-next-router/react-redux": "8.0.7",
"react-beautiful-dnd/react-redux": "8.0.7",
"@prismicio/types-internal": "2.5.0"
"@prismicio/types-internal": "2.7.0-alpha.1"
},
"workspaces": [
"e2e-projects/next",
Expand Down
4 changes: 2 additions & 2 deletions packages/slice-machine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@
"devDependencies": {
"@emotion/react": "11.11.1",
"@extractus/oembed-extractor": "3.1.8",
"@prismicio/client": "7.6.0",
"@prismicio/client": "7.9.0-alpha.0",
"@prismicio/editor-fields": "0.4.40",
"@prismicio/editor-support": "0.4.40",
"@prismicio/editor-ui": "0.4.40",
"@prismicio/mock": "0.3.3",
"@prismicio/mocks": "2.3.3",
"@prismicio/simulator": "0.1.4",
"@prismicio/types-internal": "2.5.0",
"@prismicio/types-internal": "2.7.0-alpha.1",
"@radix-ui/react-hover-card": "1.0.6",
"@radix-ui/react-tabs": "1.0.4",
"@reach/menu-button": "0.18.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { DefaultFields } from "@/legacy/lib/forms/defaults";
import { selectAllCustomTypes } from "@/modules/availableCustomTypes";

import { hasLocal } from "../../ModelData";
import { DisplayTextCheckbox } from "../Link/components";

const FormFields = {
label: DefaultFields.label,
Expand All @@ -21,7 +22,12 @@ const FormFields = {
};

type FormProps = {
config: { label: string; select: string; customtypes?: string[] };
config: {
label: string;
select: string;
customtypes?: string[];
text?: { type: "Text" };
};
id: string;
// type: string; // TODO: this exists in the yup schema but this doesn't seem to be validated by formik
};
Expand All @@ -48,6 +54,10 @@ const WidgetForm = ({
})
: null;

const {
config: { text },
} = formValues;

return (
<FlexGrid>
{Object.entries(FormFields)
Expand Down Expand Up @@ -99,6 +109,7 @@ const WidgetForm = ({
/>
</Box>
</Col>
<DisplayTextCheckbox text={text} setFieldValue={setFieldValue} />
</FlexGrid>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import Form, { FormFields } from "./Form";
"customtypes": [
"page"
],
"label": "relationship"
"label": "relationship",
"text": {
"type": "Text"
}
}
}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { createFieldNameFromKey } from "@/legacy/lib/forms";
import { DefaultFields } from "@/legacy/lib/forms/defaults";
import { CheckBox } from "@/legacy/lib/forms/fields";

import { DisplayTextCheckbox } from "./components";

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const FormFields = {
...DefaultFields,
Expand All @@ -12,7 +14,12 @@ const FormFields = {

const Form = (props) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const { initialValues, fields } = props;
const { initialValues, values: formValues, fields, setFieldValue } = props;

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const {
config: { text },
} = formValues;

return (
<FlexGrid>
Expand All @@ -32,6 +39,8 @@ const Form = (props) => {
</Col>
))
}
{/* eslint-disable-next-line @typescript-eslint/no-unsafe-assignment */}
<DisplayTextCheckbox text={text} setFieldValue={setFieldValue} />
</FlexGrid>
);
};
Expand Down
dani-mp marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { Box, Icon, Tooltip } from "@prismicio/editor-ui";
import React, { useEffect, useState } from "react";
import { Checkbox, Flex, Label } from "theme-ui";

import { Col } from "@/legacy/components/Flex";

type DisplayTextModel = { type: string };
levimykel marked this conversation as resolved.
Show resolved Hide resolved

interface DisplayTextCheckboxProps {
text?: DisplayTextModel;
setFieldValue: (
a: string,
b?: DisplayTextModel,
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents, @typescript-eslint/no-explicit-any
) => void | Promise<void | any>;
levimykel marked this conversation as resolved.
Show resolved Hide resolved
}

export function DisplayTextCheckbox(props: DisplayTextCheckboxProps) {
const { text, setFieldValue } = props;

const [allowDisplayText, setAllowDisplayText] = useState(Boolean(text));

useEffect(() => {
void setFieldValue(
"config.text",
allowDisplayText ? { type: "Text" } : undefined,
);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [allowDisplayText]);
levimykel marked this conversation as resolved.
Show resolved Hide resolved

return (
<Col>
<Flex
sx={{
mt: 2,
levimykel marked this conversation as resolved.
Show resolved Hide resolved
alignItems: "center",
height: "130%",
}}
>
<Label variant="label.border">
<Box
display="flex"
justifyContent="space-between"
alignItems="center"
width="100%"
>
<Flex>
<Checkbox
checked={allowDisplayText}
onChange={() => setAllowDisplayText(!allowDisplayText)}
levimykel marked this conversation as resolved.
Show resolved Hide resolved
/>
Allow display text
</Flex>
<Tooltip
content="Allow editors to customize the link display text"
align="end"
zIndexHack
>
<Icon name="alert" size="medium" color="grey11" />
</Tooltip>
</Box>
</Label>
</Flex>
</Col>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import Form, { FormFields } from "./Form";
"config": {
"label": "link",
"placeholder": "Could be a link to use case, press article, signup...",
"allowTargetBlank": true
"allowTargetBlank": true,
"text": {
"type": "Text"
}
}
}
*/
Expand All @@ -23,7 +26,10 @@ import Form, { FormFields } from "./Form";
"select": "document",
"customtypes": ["homepage"],
"label": "contentrrrrr",
"placeholder": "dsfdsfsdf"
"placeholder": "dsfdsfsdf",
"text": {
"type": "Text"
}
}
}
*/
Expand All @@ -33,7 +39,10 @@ import Form, { FormFields } from "./Form";
"config" : {
"select" : "media",
"label" : "tomedia",
"placeholder" : "qsdqsdqsd"
"placeholder" : "qsdqsdqsd",
"text": {
"type": "Text"
}
}
} */

Expand Down Expand Up @@ -70,6 +79,14 @@ export const linkConfigSchema = yup
masks: yup.array(yup.string()).optional(),
tags: yup.array(yup.string()).optional(),
allowTargetBlank: yup.boolean().strict().optional(),
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
text: yup
.object()
.shape({
type: yup.string().matches(/^Text$/, { excludeEmptyString: true }),
})
.strict()
.optional(),
})
.required()
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@ import WidgetFormField from "@/legacy/lib/builders/common/EditModal/Field";
import { createFieldNameFromKey } from "@/legacy/lib/forms";
import { DefaultFields } from "@/legacy/lib/forms/defaults";

import { DisplayTextCheckbox } from "../Link/components";

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const FormFields = {
...DefaultFields,
};

const Form = (props) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const { initialValues, fields } = props;
const { initialValues, values: formValues, fields, setFieldValue } = props;

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const {
config: { text },
} = formValues;

return (
<FlexGrid>
Expand All @@ -30,6 +37,8 @@ const Form = (props) => {
</Col>
))
}
{/* eslint-disable-next-line @typescript-eslint/no-unsafe-assignment */}
<DisplayTextCheckbox text={text} setFieldValue={setFieldValue} />
</FlexGrid>
);
};
Expand Down
38 changes: 27 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5978,12 +5978,12 @@ __metadata:
languageName: node
linkType: hard

"@prismicio/client@npm:7.6.0, @prismicio/client@npm:^7.1.0, @prismicio/client@npm:^7.5.0, @prismicio/client@npm:^7.6.0":
version: 7.6.0
resolution: "@prismicio/client@npm:7.6.0"
"@prismicio/client@npm:7.9.0-alpha.0":
version: 7.9.0-alpha.0
resolution: "@prismicio/client@npm:7.9.0-alpha.0"
dependencies:
imgix-url-builder: ^0.0.4
checksum: 716d9d3f0d920c58d3af74a3558886a090dc12d7ec190761d296bcfb8beda1dd47806681eeebf6543f1fdb24c92411939554517d74c9ac3120c84755b2dd14ad
imgix-url-builder: ^0.0.5
checksum: ab970d7bcf7c876c4b22222828491709080823b8e03e7200ce26ed42f5b82e4fb5160338036f95deac0784b1205ae3674f8012903344466035d77d3848cc927a
languageName: node
linkType: hard

Expand All @@ -5997,6 +5997,15 @@ __metadata:
languageName: node
linkType: hard

"@prismicio/client@npm:^7.1.0, @prismicio/client@npm:^7.5.0, @prismicio/client@npm:^7.6.0":
version: 7.6.0
resolution: "@prismicio/client@npm:7.6.0"
dependencies:
imgix-url-builder: ^0.0.4
checksum: 716d9d3f0d920c58d3af74a3558886a090dc12d7ec190761d296bcfb8beda1dd47806681eeebf6543f1fdb24c92411939554517d74c9ac3120c84755b2dd14ad
languageName: node
linkType: hard

"@prismicio/custom-types-client@npm:2.1.0":
version: 2.1.0
resolution: "@prismicio/custom-types-client@npm:2.1.0"
Expand Down Expand Up @@ -6300,9 +6309,9 @@ __metadata:
languageName: node
linkType: hard

"@prismicio/types-internal@npm:2.5.0":
version: 2.5.0
resolution: "@prismicio/types-internal@npm:2.5.0"
"@prismicio/types-internal@npm:2.7.0-alpha.1":
version: 2.7.0-alpha.1
resolution: "@prismicio/types-internal@npm:2.7.0-alpha.1"
dependencies:
monocle-ts: ^2.3.11
newtype-ts: ^0.3.5
Expand All @@ -6313,7 +6322,7 @@ __metadata:
io-ts: ^2.2.16
io-ts-types: ^0.5.16
uuid: ^9.0.0
checksum: 4cdb6f69cdeb1b197d125c281ffa79c86f4351ef355ebf1ee4d3b066eda49e5092288cccc00b8744f85fcaa30504e6be21fc3eee220a956840ae89e815b0f727
checksum: 7d642f2bb27c3ccc414298bad65ed7e0bf3ca1c788dcfcfafe6232d1c38f6a43a40af92bc06791728db4cd44e42e2caa46758266079d5de2b359fdc6a05a778e
languageName: node
linkType: hard

Expand Down Expand Up @@ -21083,6 +21092,13 @@ __metadata:
languageName: node
linkType: hard

"imgix-url-builder@npm:^0.0.5":
version: 0.0.5
resolution: "imgix-url-builder@npm:0.0.5"
checksum: 5bdb9c8df1ef6eff7f53cb8f84dfc33c4862bb3542d557ee083a1cb213c3acb9464f0216ade00a5ed5d79403d58bb2169a537bb24e705ed05b8c3606902435d7
languageName: node
linkType: hard

"immediate@npm:~3.0.5":
version: 3.0.6
resolution: "immediate@npm:3.0.6"
Expand Down Expand Up @@ -31424,14 +31440,14 @@ __metadata:
dependencies:
"@emotion/react": 11.11.1
"@extractus/oembed-extractor": 3.1.8
"@prismicio/client": 7.6.0
"@prismicio/client": 7.9.0-alpha.0
"@prismicio/editor-fields": 0.4.40
"@prismicio/editor-support": 0.4.40
"@prismicio/editor-ui": 0.4.40
"@prismicio/mock": 0.3.3
"@prismicio/mocks": 2.3.3
"@prismicio/simulator": 0.1.4
"@prismicio/types-internal": 2.5.0
"@prismicio/types-internal": 2.7.0-alpha.1
"@radix-ui/react-hover-card": 1.0.6
"@radix-ui/react-tabs": 1.0.4
"@radix-ui/react-visually-hidden": 1.0.3
Expand Down
Loading