Discard empty and null links in Links fields (#12188)

This PR has several objectives:

- Ignore invalid and empty links in the frontend
- Ignore empty links when creating or updating a link field in the
backend
- Throw an error when trying to create or update a link field with an
invalid link

The logic is mostly the same in the frontend and the backend: we take
the initial primaryLink and the secondaryLinks, we discard all the empty
links (with `url === '' || url === null`), and the primaryLink becomes
the first remaining link.

## Frontend

There are three parts in the frontend where we have to remove the empty
links:

- LinksDisplay
- LinksFieldInput
- isFieldValueEmpty; used in RecordInlineCell

## Backend

I put the logic in
`packages/twenty-server/src/engine/core-modules/record-transformer/services/record-input-transformer.service.ts`
as it's used by the REST API, the GraphQL API, and by Create Record and
Update Record actions in the workflows.
This commit is contained in:
Baptiste Devessier
2025-05-23 11:13:10 +02:00
committed by GitHub
parent 75e4a5d19b
commit ec9d8e4e95
17 changed files with 544 additions and 31 deletions

View File

@ -180,3 +180,25 @@ export const AutomaticLabelFromURL: Story = {
expect(secondaryLink).toHaveAttribute('href', 'https://test.example.com');
},
};
export const InvalidLinks: Story = {
args: {
value: {
primaryLinkUrl: 'wikipedia',
primaryLinkLabel: 'Invalid URL',
secondaryLinks: [{ url: 'lydia,com', label: 'Invalid URL with comma' }],
},
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
await waitFor(() => {
expect(canvas.queryByRole('link')).toBeNull();
});
expect(canvas.queryByText('Invalid URL')).not.toBeInTheDocument();
expect(
canvas.queryByText('Invalid URL with comma'),
).not.toBeInTheDocument();
},
};