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: introduce link custom renderer #292

Merged
merged 6 commits into from
Jul 26, 2024
Merged

Conversation

dcshzj
Copy link
Contributor

@dcshzj dcshzj commented Jul 10, 2024

Problem

We need a custom renderer to insert links.

Solution

Breaking Changes

  • Yes - this PR contains breaking changes
  • No - this PR is backwards compatible

Features:

  • Adds a new custom renderer for adding links.
    • Full functionality is not available yet pending design, mainly on getting the page permalink for internal links.
    • Only functionality added was adding email links.

Before & After Screenshots

BEFORE:

Screenshot 2024-07-10 at 17 38 49

AFTER:

Screenshot 2024-07-10 at 17 38 29

@dcshzj dcshzj requested a review from a team as a code owner July 10, 2024 09:39
Copy link

vercel bot commented Jul 10, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
isomer-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 25, 2024 5:55am

Copy link
Contributor

@seaerchin seaerchin left a comment

Choose a reason for hiding this comment

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

lgtm code-wise, some follow-up questions below

  1. we haven't actually used this anywhere? the PR to use this will be done in a follow-up?
  2. have we done validation here? i think the bare minimum is to just conform to the URL format right?

packages/components/src/interfaces/complex/Hero.ts Outdated Show resolved Hide resolved
@dcshzj
Copy link
Contributor Author

dcshzj commented Jul 11, 2024

  1. we haven't actually used this anywhere? the PR to use this will be done in a follow-up?

This is being used in components like Button, InfoCols, etc. The follow-up is just adding the full functionality to support adding internal links, external links, selecting files and adding validation.

  1. have we done validation here? i think the bare minimum is to just conform to the URL format right?

Full validation not available yet, but it would not just be the URL format. We have internal links that we store as references rather than as URLs.

<FormControl isRequired={required}>
<FormLabel description={description}>{label}</FormLabel>

<Tabs variant="group" onChange={() => handleChange(path, "")}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Not really an issue, but does this mean that if I had data in a tab, and I clicked on another type of link(maybe to check if this suits the purpose better), and I clicked back my previous data will be lost?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, the 4 types are mutually exclusive so the content of one type would not be transferrable to another, hence opted to clear the value to force the user to make the selection first.

Comment on lines 75 to 80
<Input
type="text"
value={dataString}
onChange={(e) => handleChange(path, e.target.value)}
placeholder="Page permalink"
/>
Copy link
Contributor

Choose a reason for hiding this comment

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

this however is the bigger issue (and thus i'd recommend dynamic state based on selected radio value instead), as the tab panels can desynchronise with LINK_TYPES and a specific order is required, which is not obvious if LINK_TYPE is ever modified.

might be safer to not use tabs and just render a specific input depending on the selected radio option. to that end, you can rely on compile time typechecking to ensure something is rendered accordingly to the option.

UNLESS the value of the current tab does not matter to you, and only the input value does. then maybe tab can be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in 950c8ed, agreed that it would better with a more explicit mapping of the link type to the actual rendering.

The value of the current tab would not matter because the 4 link types are mutually exclusive, so it is not possible to translate from one to another. Opted to clear out the value of the input to avoid confusing the user.

/>
)
default:
return <></>
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: might want to skip default case, or assert never for compile-time typecheck

see knowledge base


const handleLinkTypeChange = (value: string) => {
setSelectedLinkType(value)
handleChange(path, "")
Copy link
Contributor

Choose a reason for hiding this comment

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

does this actually do anything? are you supposed to pass in the change into handleChange too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm yeah it is supposed to reset the input field to empty when they change the selected link type. This is because all 4 link types are mutually exclusive of one another, so the input from one does not translate to another, so opted to clear the input field to prevent user confusion.

Copy link
Contributor

@karrui karrui left a comment

Choose a reason for hiding this comment

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

lgtm

@dcshzj dcshzj merged commit 38af9e1 into main Jul 26, 2024
19 checks passed
@dcshzj dcshzj deleted the feat/link-custom-renderer branch July 26, 2024 02:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants