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

Fix multi-dropdown field can't have no options selected #8391

Merged
merged 1 commit into from
Nov 8, 2024

Conversation

khuddite
Copy link
Contributor

@khuddite khuddite commented Nov 7, 2024

Fixes: #8224

  1. Summary
    All multi-dropdowns across the application don't accept empty options because emptiness is perceived as an invalid state.

  2. Solution
    The issue came down to the back-end and the specific string utility function that converts a string separated by , to an array of options. But the problem with it is that it returns [''] for an empty string representing an emptiness. And then [''] fails on the parser because simply '' is not a valid option the user selected for the dropdown. So I updated the string utility function to return an empty array for cases like '', '{}', '{ }', etc

  3. Recording

CleanShot.2024-11-07.at.13.43.46.mp4

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This change fixes multi-dropdown fields not accepting empty options by modifying how empty string values are handled in the backend formatting logic.

  • Modified format-result.util.ts to return empty array [] instead of [''] for empty multi-select values
  • Updated string parsing to properly handle empty strings, '{}', and '{ }' patterns
  • Fixed validation error that occurred when trying to unselect all options in multi-select fields
  • Ensures consistent empty state handling across all multi-dropdown fields in the application

1 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile

@@ -148,7 +148,9 @@ function formatFieldMetadataValue(
(fieldMetadata.type === FieldMetadataType.MULTI_SELECT ||
fieldMetadata.type === FieldMetadataType.ARRAY)
) {
return value.replace(/{|}/g, '').split(',');
const cleanedValue = value.replace(/{|}/g, '').trim();
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider handling null/undefined values explicitly before the string check to prevent potential runtime errors

Copy link
Member

@FelixMalfait FelixMalfait left a comment

Choose a reason for hiding this comment

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

Great work thank you!

@FelixMalfait FelixMalfait merged commit 0bf2cb6 into twentyhq:main Nov 8, 2024
17 checks passed
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.

Multi-select field can't have no options selected
2 participants