MPDX-6917-Remove-Lodash#8
Conversation
|
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/cru/mpdx-react/h9xpzaxts |
| @@ -0,0 +1,5 @@ | |||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | |||
| const omit = (keysToOmit: string[], originalObj = {}): any => | |||
There was a problem hiding this comment.
I had the type for this as Record<string, unknown> and it worked everywhere except for one spot that was using a generated type that was expecting subject. Switched to any for now until I could figure out how to resolve it.
There was a problem hiding this comment.
It probably should use generics. I can help play with it if you want.
Or we could remove this helper function completely and use destructuring to pull out keys we want to ignore.
There was a problem hiding this comment.
Yeah I started to go the descructuring route but was unsure what to do with the values we omitted(since they aren't going to be used in most cases). I believe there's a lint rule we could throw in to ignore unused values but wanted to get your opinion on that?
There was a problem hiding this comment.
I think a naming convention is to prefix them with an _. I assume there's a lint rule to allow that. Although that's a little odd in destructuring cuz you have to rename them probably const { key: _key } = ...;. Idk what's nicest...
There was a problem hiding this comment.
We could keep lodash or something similar for this or other use cases, it just seemed a little overused.
There was a problem hiding this comment.
https://stackoverflow.com/a/56157826/665224 suggests varsIgnorePattern (and ignoreRestSiblingsbut that seems like the less strict option).
There was a problem hiding this comment.
Yeah, varsIgnorePattern worked so I went for the destructuring route!
|
@OzzieOrca I ran into some issues with the |
|
|
||
| return initialFilter; | ||
| const { userIds, tags, contactIds, activityType, completed, wildcardSearch, startAt } = initialFilter; | ||
| const finalInitalFilter = { userIds, tags, contactIds, activityType, completed, wildcardSearch, startAt }; |
There was a problem hiding this comment.
Seems like this const is unnecessary? Couldn't we just return this?
There was a problem hiding this comment.
Yep, will change!
|
Ya that test has issues... That's the one I increased timeouts on. You could increase the timeout more or just hope it finishes on CI. We probably need to spend some time on that one... |
|
@OzzieOrca So I removed the majority of the lodash functions I believe could be easily replaced with native options. It definitely brought the number of lodash usages down. I left things like I also tried replacing the lodash |
# Conflicts: # .eslintrc.js # pages/accountLists/[accountListId]/tasks.tsx # src/components/App/Provider.tsx # src/components/Layouts/Primary/TopBar/NotificationMenu/Item/Item.tsx # src/components/Layouts/Primary/TopBar/TopBar.tsx # src/components/Task/Drawer/CommentList/CommentList.tsx # src/components/Task/Drawer/CommentList/Item/Item.tsx # src/components/Task/Drawer/ContactList/ContactList.tsx # src/components/Task/Drawer/ContactList/Item/Item.tsx # src/components/Task/Drawer/Form/Form.mock.tsx # src/components/Task/Drawer/Form/Form.tsx # src/components/Task/List/List.tsx # src/components/Task/Status/Status.tsx # src/lib/intlFormat/intlFormat.ts # src/lib/reduceObject/reduceObject.test.ts
OzzieOrca
left a comment
There was a problem hiding this comment.
I'm ok with leaving some lodash usage if it seems to really provide value but I don't think we should be reaching for it all the time...
- Those
cloneDeeps could probably be replaced by lots of spreads... We've done that in MissionHub for Apollo cache updates... Apollo might have a better way to do that now. rejectshould be a `filter with the opposite condition right?- With
uniqBymaybe we could do something with JS Sets but that might be more complicated. Maybe that could live in a helper file...
Lodash should be able to support tree shaking... Maybe we need a babel or webpack plugin... Something is still including the big lodash bundle...


(I've been meaning to add a build:analyze npm script for this but I got this from running ANALYZE=true yarn build)
| break; | ||
| default: | ||
| result[key.replace('[]', '')] = castArray(value); | ||
| result[key.replace('[]', '')] = Array.isArray(value) |
There was a problem hiding this comment.
I know you didn't write any of this but it's some weird code...
The reduceObject around this is the only usage of reduceObject... And the current implementation throws away all types with the cast to any. Maybe we should just remove it?
We could probably use an Object.entries(filter).reduce((result, [key, value]) => {...}, {}).
I'm not sure I understand this default case... I think using the bracket arrayFormat on the parse https://github.com/sindresorhus/query-string#arrayformat might clean up the [] in the key but looks like it although it always returns an array, the types don't know that...
| { user: { id } }, | ||
| filterData.accountListUsers.nodes, | ||
| const accountListUser = filterData.accountListUsers.nodes.find( | ||
| ({ user: { id: accountListUserId } }) => |
There was a problem hiding this comment.
Are we sure these objects are defined? Maybe the types say so... Lodash usually swallows undefined errors in cases like this.
There was a problem hiding this comment.
Yeah, based on the generated type user should always be defined and same with id. However, the user firstName and lastName could be null. Should we have it check that the name(at least the firstName) is a non-null value as well?
There was a problem hiding this comment.
Sounds like it's not going to throw a can't read property of undefined error then. I think the names are ok unless we really need a perfectly empty string if there are no names.
There was a problem hiding this comment.
So it uses the firstName and lastName to render the filter:
return `${accountListUser.user.firstName} ${accountListUser.user.lastName}`
So if those are both null it would just render a string of null null... but at the same time, it would be very unlikely an account wouldn't have a first and last name right?
There was a problem hiding this comment.
Oh ya for some reason I thought the null would turn into an empty string but it doesn't. I have no idea what the DB constraints are...
|
For the |
…leCompare, switch to nullish coalescing operator
| ...reject( | ||
| ({ id: commentId }) => id === commentId, | ||
| dataFromCache.task.comments.nodes, | ||
| ), |
There was a problem hiding this comment.
Still couldn't get the filter method I created to replace this reject to not break the test suite. It works fine in the browser but not in the tests for some reason.
- Avoid importing the big lodash.min.js
OzzieOrca
left a comment
There was a problem hiding this comment.
I think this is pretty good for now. Thanks for cleaning stuff up :) Maybe we can tackle some of the weirder ones eventually.
I added a commit to import from lodash/fp/<function name> instead of all of lodash/fp since that seemed to remove the big lodash.min.js file and save 17.77KB (gzipped). So now lodash is just using 16.43KB. We could go back to the big import if we configure some lodash tree shaking plugin for webpack or babel but I think this is good for now.
|
@OzzieOrca Sounds good, thanks for the help 🙂 I also made a new ticket of a bug I discovered while working on this. I was going to include it here but figured it would be better to be in a separate pr. |
Flows columns min-width is 300px. Adding/Removing columns now updates local as well as server. Unused Statuses now sticks to the right-hand-side, to make it easier for users to move statuses around. Fixed :hover of the coloured circles. useDrops and useCallbacks to include flowOptions as a dependency. add column button loading for UX as sometimes it would take a while to add a new column. Added Tests MPDX-7614-MPDX-7615 p# This is the commit message #8:

No description provided.