form icon indicating copy to clipboard operation
form copied to clipboard

feat: support escaped paths in field name

Open chrisirhc opened this issue 1 year ago • 6 comments

Attempts to address https://github.com/TanStack/form/discussions/532 .

This is a sketch implementation for feedback, using lodash's internals for get. Happy to roll a custom implementation but I thought of using an existing battle-tested implementation.

This implementation handles some of the cases in https://github.com/lodash/lodash/blob/main/test/toPath.spec.js .

chrisirhc avatar Jan 04 '24 07:01 chrisirhc

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

codesandbox-ci[bot] avatar Jan 04 '24 07:01 codesandbox-ci[bot]

This looks good overall! The only concern I have now is typings. We'll want a way to merge the types from string[] to string. This can be done like so:

https://github.com/crutchcorn/ts-util-helpers/blob/main/src/concat-string.ts#L1-L7

But then the question becomes "how do we get TName inference working for this?

crutchcorn avatar Jan 08 '24 17:01 crutchcorn

This looks good overall! The only concern I have now is typings. We'll want a way to merge the types from string[] to string.

Not sure I get this part of your comment. Where are you referring to the string[] type? Is it the makePathArray?

But then the question becomes "how do we get TName inference working for this?

Just to make sure I get what you're referring to. You're referring to making sure that the DeepKeys https://github.com/TanStack/form/blob/77f119b0a6e6caccb8fdc3d3cdeda97b3560d1e5/packages/form-core/src/utils.ts#L299 can work for the [''] syntax, right? I'll look in this.

chrisirhc avatar Jan 11 '24 02:01 chrisirhc

I wouldn't modify DeepKeys. I would modify the instance where TName is being passed and introduce a new utility type of some kind.

crutchcorn avatar Jan 11 '24 19:01 crutchcorn

Added spec updates and also utilities as discussed. Ready for comment/review.

chrisirhc avatar Jan 22 '24 08:01 chrisirhc

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (08ad74d) 87.78% compared to head (92bc078) 87.65%.

Files Patch % Lines
packages/form-core/src/utils.ts 89.47% 2 Missing :warning:
packages/react-form/src/useField.tsx 0.00% 1 Missing :warning:

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #551      +/-   ##
==========================================
- Coverage   87.78%   87.65%   -0.14%     
==========================================
  Files          31       31              
  Lines         819      826       +7     
  Branches      184      187       +3     
==========================================
+ Hits          719      724       +5     
- Misses         95       97       +2     
  Partials        5        5              

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter avatar Jan 22 '24 08:01 codecov-commenter

Hey, I am super sorry - but we've made drastic changes to the internals of these files. It's honestly better to close out this PR and revisit them. I think our types support this now, but our logic certainly doesn't.

Let's track the progress of this in: #639

Feel free to open a new PR with the conflicts resolved if you're up for the task. I'll make sure we review it much sooner - I apologize for the crossed wires here. Arrays were in a really bad spot anyway

crutchcorn avatar Mar 23 '24 04:03 crutchcorn