Skip to content

Commit 657a16c

Browse files
authored
chore(): Remove lodash.set entirely (#14041)
* chore(): Remove lodash.set entirely * Create dull-balloons-sneeze.md * chore(): Remove lodash.set entirely * chore(): Remove lodash.set entirely
1 parent b49a445 commit 657a16c

File tree

4 files changed

+26
-18
lines changed

4 files changed

+26
-18
lines changed

.changeset/dull-balloons-sneeze.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@medusajs/dashboard": patch
3+
---
4+
5+
chore(): Remove lodash.set entirely

packages/admin/dashboard/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
"i18next-http-backend": "2.4.2",
6565
"lodash.debounce": "^4.0.8",
6666
"lodash.isequal": "^4.5.0",
67-
"lodash.set": "^4.3.2",
6867
"match-sorter": "^6.3.4",
6968
"motion": "^11.15.0",
7069
"qs": "^6.12.1",

packages/admin/dashboard/src/components/data-grid/hooks/use-data-grid-form-handlers.tsx

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import set from "lodash.set"
21
import { useCallback } from "react"
32
import { FieldValues, Path, PathValue, UseFormReturn } from "react-hook-form"
43

@@ -17,7 +16,7 @@ type UseDataGridFormHandlersOptions<TData, TFieldValues extends FieldValues> = {
1716

1817
export const useDataGridFormHandlers = <
1918
TData,
20-
TFieldValues extends FieldValues,
19+
TFieldValues extends FieldValues
2120
>({
2221
matrix,
2322
form,
@@ -139,7 +138,7 @@ function convertToggleableNumber(value: any): {
139138
}
140139

141140
function setValue<
142-
T extends DataGridToggleableNumber = DataGridToggleableNumber,
141+
T extends DataGridToggleableNumber = DataGridToggleableNumber
143142
>(
144143
currentValues: any,
145144
field: string,
@@ -148,7 +147,13 @@ function setValue<
148147
isHistory?: boolean
149148
) {
150149
if (type !== "togglable-number") {
151-
set(currentValues, field, newValue)
150+
field.split(".").reduce((curr, key, index) => {
151+
if (index === field.split(".").length - 1) {
152+
curr[key] = newValue
153+
}
154+
curr[key] ??= {}
155+
return curr[key]
156+
}, currentValues)
152157
return
153158
}
154159

@@ -187,11 +192,18 @@ function setValueToggleableNumber(
187192
: newValue.checked
188193
: determineChecked(quantity)
189194

190-
set(currentValues, field, {
191-
...currentValue,
192-
quantity,
193-
checked,
194-
})
195+
const fieldParts = field.split(".")
196+
fieldParts.reduce((curr, key: string, index) => {
197+
if (index === fieldParts.length - 1) {
198+
curr[key] = {
199+
...currentValues,
200+
quantity,
201+
checked,
202+
}
203+
}
204+
curr[key] ??= {}
205+
return curr[key]
206+
}, currentValues)
195207
}
196208

197209
export function convertArrayToPrimitive(

yarn.lock

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3423,7 +3423,6 @@ __metadata:
34233423
i18next-http-backend: 2.4.2
34243424
lodash.debounce: ^4.0.8
34253425
lodash.isequal: ^4.5.0
3426-
lodash.set: ^4.3.2
34273426
match-sorter: ^6.3.4
34283427
motion: ^11.15.0
34293428
qs: ^6.12.1
@@ -20385,13 +20384,6 @@ __metadata:
2038520384
languageName: node
2038620385
linkType: hard
2038720386

20388-
"lodash.set@npm:^4.3.2":
20389-
version: 4.3.2
20390-
resolution: "lodash.set@npm:4.3.2"
20391-
checksum: c641d31905e51df43170dce8a1d11a1cff11356e2e2e75fe2615995408e9687d58c3e1d64c3c284c2df2bc519f79a98af737d2944d382ff82ffd244ff6075c29
20392-
languageName: node
20393-
linkType: hard
20394-
2039520387
"lodash.sortby@npm:^4.7.0":
2039620388
version: 4.7.0
2039720389
resolution: "lodash.sortby@npm:4.7.0"

0 commit comments

Comments
 (0)