Home / Function/ link() — supabase Function Reference

link() — supabase Function Reference

Architecture documentation for the link() function in link.ts from the supabase codebase.

Entity Profile

Dependency Diagram

graph TD
  092e07cb_1d6d_aac1_850c_58b0cedc25f8["link()"]
  80956428_d9d0_1b2c_fb8c_db56ae88cfb0["linkGroup()"]
  80956428_d9d0_1b2c_fb8c_db56ae88cfb0 -->|calls| 092e07cb_1d6d_aac1_850c_58b0cedc25f8
  a1909c53_6c6a_4807_4c44_fcea7b64381a["deepMerge()"]
  092e07cb_1d6d_aac1_850c_58b0cedc25f8 -->|calls| a1909c53_6c6a_4807_4c44_fcea7b64381a
  style 092e07cb_1d6d_aac1_850c_58b0cedc25f8 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

apps/cms/src/fields/link.ts lines 24–139

export const link: LinkType = ({ appearances, disableLabel = false, overrides = {} } = {}) => {
  const linkResult: GroupField = {
    name: 'link',
    type: 'group',
    admin: {
      hideGutter: true,
    },
    fields: [
      {
        type: 'row',
        fields: [
          {
            name: 'type',
            type: 'radio',
            admin: {
              layout: 'horizontal',
              width: '50%',
            },
            defaultValue: 'reference',
            options: [
              {
                label: 'Internal link',
                value: 'reference',
              },
              {
                label: 'Custom URL',
                value: 'custom',
              },
            ],
          },
          {
            name: 'newTab',
            type: 'checkbox',
            admin: {
              style: {
                alignSelf: 'flex-end',
              },
              width: '50%',
            },
            label: 'Open in new tab',
          },
        ],
      },
    ],
  }

  const linkTypes: Field[] = [
    {
      name: 'reference',
      type: 'relationship',
      admin: {
        condition: (_, siblingData) => siblingData?.type === 'reference',
      },
      label: 'Document to link to',
      relationTo: ['posts'],
      required: true,
    },
    {
      name: 'url',
      type: 'text',
      admin: {
        condition: (_, siblingData) => siblingData?.type === 'custom',
      },
      label: 'Custom URL',
      required: true,
    },
  ]

  if (!disableLabel) {
    linkTypes.map((linkType) => ({
      ...linkType,
      admin: {
        ...linkType.admin,
        width: '50%',
      },
    }))

    linkResult.fields.push({
      type: 'row',
      fields: [
        ...linkTypes,
        {
          name: 'label',
          type: 'text',
          admin: {
            width: '50%',
          },
          label: 'Label',
          required: true,
        },
      ],
    })
  } else {
    linkResult.fields = [...linkResult.fields, ...linkTypes]
  }

  if (appearances !== false) {
    let appearanceOptionsToUse = [appearanceOptions.default, appearanceOptions.outline]

    if (appearances) {
      appearanceOptionsToUse = appearances.map((appearance) => appearanceOptions[appearance])
    }

    linkResult.fields.push({
      name: 'appearance',
      type: 'select',
      admin: {
        description: 'Choose how the link should be rendered.',
      },
      defaultValue: 'default',
      options: appearanceOptionsToUse,
    })
  }

  return deepMerge(linkResult, overrides)
}

Subdomains

Calls

Called By

Frequently Asked Questions

What does link() do?
link() is a function in the supabase codebase.
What does link() call?
link() calls 1 function(s): deepMerge.
What calls link()?
link() is called by 1 function(s): linkGroup.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free