-
Notifications
You must be signed in to change notification settings - Fork 20
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
Add unique key to transporter array elements #718
Add unique key to transporter array elements #718
Conversation
…ach Transporter by combining the EPAID and array index. I also found a bug where the tooltips in the Transporter list displayed the zero-index value, i.e. 'view transporter 0 details' for transporter 1. I corrected the tests to reflect this change in tooltip labels. Also added a test to ensure that only one accordion expands when the same Transporter appears in the manifest and 'Details' is clicked.
@sheckathorne Thanks for the PR, I should have time to look at it this week. |
@sheckathorne Thanks for getting the ball rolling on this and submitting the PR. I've added a This was the only way I could think to fix the original bug while playing nice with react and not relying on the order/index of the transporter instance. |
client/src/components/Manifest/Transporter/TransporterTable.tsx
Outdated
Show resolved
Hide resolved
After this commit I'm no longer able to add transporters to a manifest unless I change:
to
however this re-introduces the problem of React re-rendering the entire table every time the transporters array is modified. |
Ah geez, here's the quick fix. export function TransporterSection({ setupSign }: TransporterSectionProps) {
const [, setSearchConfigs] = useHandlerSearchConfig();
const [readOnly] = useReadOnly();
const manifestForm = useFormContext<Manifest>();
const { errors } = manifestForm.formState;
const transporterForm = useFieldArray<Manifest, 'transporters'>({
control: manifestForm.control,
name: 'transporters',
});
const transporters = manifestForm.watch('transporters');
transporters.forEach((transporter, index) => {
if (!transporter.clientKey) {
// @ts-ignore
manifestForm.setValue(`transporters[${index}].clientKey`, uuidv4());
}
});
return ... The difference is the change from @sheckathorne Do you want to submit a PR for this? I've started looking at the react-hook-form useFieldArray documentation more, turns out the |
Sure, I'll take a look at it today |
Description
Created a unique key for each Transporter by combining the EPAID and array index. This allows the user to apply all actions in the transporter drop-down menu without side-effects.
I found a bug where the tool-tips in the Transporter list displayed the zero-index value, i.e. 'view transporter 0 details' for transporter 1. I corrected the tests to reflect this change in tool-tip labels since the selectors are based on the index value.
Added a test to ensure that only one accordion expands when the same Transporter appears in the manifest and 'Details' is clicked.
Issue ticket number and link
Closes issue #620 [https://github.com//issues/620]
Checklist