-
Notifications
You must be signed in to change notification settings - Fork 1
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
Don't allow duplicate column names #307
Conversation
Signed-off-by: Aaron Sutula <asutula@users.noreply.github.com>
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
function columnsNameUnique<T extends { name: string }>(columns: T[]) { | ||
const columnNames = columns.map((column) => column.name); | ||
const uniqueColumnNames = new Set(columnNames); | ||
return columnNames.length === uniqueColumnNames.size; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this helper function that checks that column names are unique. It's generic because we have two different flavors of column data depending on if it's the Zod schema used on the client side form or the server side API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is used below.
React.HTMLAttributes<HTMLParagraphElement> | ||
>(({ className, children, ...props }, ref) => { | ||
const { error, formMessageId } = useFormField(); | ||
const body = error?.root?.message ?? error?.message ?? children; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FormMessage
is used to display the error message for a FormField
. I copied and modified the code provided by Shadcn because it only displays the error message at error?.message
, but react-hook-form sometimes sets the error message at error?.root?.message
in the case of form fields defined by useFieldArray
(https://react-hook-form.com/docs/usefieldarray). This handles both cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In investigating all this, I upgraded react-hook-form
and @hookform/resolvers
in hopes it would fix the weird behavior of the error message being set in different places. It didn't help, but figured we might as well keep these version updates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤘
When creating a definition, validate there are no duplicate column names.
Closes ENG-850