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

Don't allow duplicate column names #307

Merged
merged 1 commit into from
Aug 12, 2024
Merged

Conversation

asutula
Copy link
Contributor

@asutula asutula commented Aug 8, 2024

When creating a definition, validate there are no duplicate column names.

Screenshot 2024-08-08 at 4 02 45 PM

Closes ENG-850

Signed-off-by: Aaron Sutula <asutula@users.noreply.github.com>
Copy link

linear bot commented Aug 8, 2024

Copy link

vercel bot commented Aug 8, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 8, 2024 9:55pm

Comment on lines +16 to +21
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;
}

Copy link
Contributor Author

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.

Copy link
Contributor Author

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;
Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@asutula asutula requested review from joewagner and dtbuchholz August 8, 2024 22:00
Copy link
Contributor

@dtbuchholz dtbuchholz left a comment

Choose a reason for hiding this comment

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

🤘

@asutula asutula merged commit 54e2ab1 into main Aug 12, 2024
4 checks passed
@asutula asutula deleted the asutula/no-dup-column-names branch August 12, 2024 00:55
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.

2 participants