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

I should be able to reset the primary link of a Links field #6041

Open
FelixMalfait opened this issue Jun 26, 2024 · 1 comment
Open

I should be able to reset the primary link of a Links field #6041

FelixMalfait opened this issue Jun 26, 2024 · 1 comment
Labels

Comments

@FelixMalfait
Copy link
Member

I've created a custom field of type Links:

Screenshot 2024-06-26 at 15 52 20

I can remove the second option:
Screenshot 2024-06-26 at 15 52 48

But I cannot remove this first:
Screenshot 2024-06-26 at 15 53 11

I get why we didn't do it in v1 (because it's not just about deleting the primary link, it's also about moving the first element of secondary links into the primary link it there are any secondary link). But we should prioritize it

@FelixMalfait FelixMalfait added the T label Jun 26, 2024
Copy link

greptile-apps bot commented Jun 26, 2024

To implement the ability to reset the primary link of a Links field, follow these steps:

  1. Modify LinksFieldInput Component:

    • File: frontend/components/LinksFieldInput.tsx
    • Update the logic to handle the removal of the primary link and promote a secondary link if available.
    const handleRemovePrimaryLink = () => {
      if (links.length > 1) {
        const newPrimaryLink = links[1];
        setLinks([newPrimaryLink, ...links.slice(2)]);
      } else {
        setLinks([]);
      }
    };
  2. Update the isFieldLinksValue Guard:

    • File: frontend/guards/isFieldLinksValue.ts
    • Ensure the guard correctly validates the updated structure of the Links field.
    export const isFieldLinksValue = (value: any): value is FieldLinksValue => {
      return Array.isArray(value) && value.every(link => typeof link === 'string');
    };
  3. Integrate the New Logic:

    • Ensure the handleRemovePrimaryLink function is called appropriately within the LinksFieldInput component's event handlers.
    <button onClick={handleRemovePrimaryLink}>Remove Primary Link</button>

References

Edit Issue Bot Settings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: 🆕 New
Development

No branches or pull requests

1 participant