From 657a16c4622d1c075e9e40cb9babbf15f04a3aa7 Mon Sep 17 00:00:00 2001 From: Adrien de Peretti Date: Thu, 13 Nov 2025 09:18:43 +0100 Subject: [PATCH] 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 --- .changeset/dull-balloons-sneeze.md | 5 ++++ packages/admin/dashboard/package.json | 1 - .../hooks/use-data-grid-form-handlers.tsx | 30 +++++++++++++------ yarn.lock | 8 ----- 4 files changed, 26 insertions(+), 18 deletions(-) create mode 100644 .changeset/dull-balloons-sneeze.md diff --git a/.changeset/dull-balloons-sneeze.md b/.changeset/dull-balloons-sneeze.md new file mode 100644 index 0000000000..bd3c0915c8 --- /dev/null +++ b/.changeset/dull-balloons-sneeze.md @@ -0,0 +1,5 @@ +--- +"@medusajs/dashboard": patch +--- + +chore(): Remove lodash.set entirely diff --git a/packages/admin/dashboard/package.json b/packages/admin/dashboard/package.json index 49d4a0e768..349eae20fa 100644 --- a/packages/admin/dashboard/package.json +++ b/packages/admin/dashboard/package.json @@ -64,7 +64,6 @@ "i18next-http-backend": "2.4.2", "lodash.debounce": "^4.0.8", "lodash.isequal": "^4.5.0", - "lodash.set": "^4.3.2", "match-sorter": "^6.3.4", "motion": "^11.15.0", "qs": "^6.12.1", diff --git a/packages/admin/dashboard/src/components/data-grid/hooks/use-data-grid-form-handlers.tsx b/packages/admin/dashboard/src/components/data-grid/hooks/use-data-grid-form-handlers.tsx index abb0e60416..805beba6cc 100644 --- a/packages/admin/dashboard/src/components/data-grid/hooks/use-data-grid-form-handlers.tsx +++ b/packages/admin/dashboard/src/components/data-grid/hooks/use-data-grid-form-handlers.tsx @@ -1,4 +1,3 @@ -import set from "lodash.set" import { useCallback } from "react" import { FieldValues, Path, PathValue, UseFormReturn } from "react-hook-form" @@ -17,7 +16,7 @@ type UseDataGridFormHandlersOptions = { export const useDataGridFormHandlers = < TData, - TFieldValues extends FieldValues, + TFieldValues extends FieldValues >({ matrix, form, @@ -139,7 +138,7 @@ function convertToggleableNumber(value: any): { } function setValue< - T extends DataGridToggleableNumber = DataGridToggleableNumber, + T extends DataGridToggleableNumber = DataGridToggleableNumber >( currentValues: any, field: string, @@ -148,7 +147,13 @@ function setValue< isHistory?: boolean ) { if (type !== "togglable-number") { - set(currentValues, field, newValue) + field.split(".").reduce((curr, key, index) => { + if (index === field.split(".").length - 1) { + curr[key] = newValue + } + curr[key] ??= {} + return curr[key] + }, currentValues) return } @@ -187,11 +192,18 @@ function setValueToggleableNumber( : newValue.checked : determineChecked(quantity) - set(currentValues, field, { - ...currentValue, - quantity, - checked, - }) + const fieldParts = field.split(".") + fieldParts.reduce((curr, key: string, index) => { + if (index === fieldParts.length - 1) { + curr[key] = { + ...currentValues, + quantity, + checked, + } + } + curr[key] ??= {} + return curr[key] + }, currentValues) } export function convertArrayToPrimitive( diff --git a/yarn.lock b/yarn.lock index 515edf64cd..02121eac09 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3423,7 +3423,6 @@ __metadata: i18next-http-backend: 2.4.2 lodash.debounce: ^4.0.8 lodash.isequal: ^4.5.0 - lodash.set: ^4.3.2 match-sorter: ^6.3.4 motion: ^11.15.0 qs: ^6.12.1 @@ -20385,13 +20384,6 @@ __metadata: languageName: node linkType: hard -"lodash.set@npm:^4.3.2": - version: 4.3.2 - resolution: "lodash.set@npm:4.3.2" - checksum: c641d31905e51df43170dce8a1d11a1cff11356e2e2e75fe2615995408e9687d58c3e1d64c3c284c2df2bc519f79a98af737d2944d382ff82ffd244ff6075c29 - languageName: node - linkType: hard - "lodash.sortby@npm:^4.7.0": version: 4.7.0 resolution: "lodash.sortby@npm:4.7.0"