From cc0af155e0f159a11f8fd5793d46bba09790bd83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20DOREAU?= Date: Wed, 16 Sep 2020 16:28:41 +0200 Subject: [PATCH] refactor(core): add immer + action renaming --- packages/core/package.json | 1 + .../components/CheckboxTree/CheckboxTree.tsx | 79 ++++++------------- yarn.lock | 5 ++ 3 files changed, 31 insertions(+), 54 deletions(-) diff --git a/packages/core/package.json b/packages/core/package.json index 7e9932bdc1..b2d55bc6fe 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -39,6 +39,7 @@ "@types/react-sparklines": "^1.7.0", "classnames": "^2.2.6", "clsx": "^1.1.0", + "immer": "^7.0.9", "lodash": "^4.17.15", "material-table": "1.68.0", "prop-types": "^15.7.2", diff --git a/packages/core/src/components/CheckboxTree/CheckboxTree.tsx b/packages/core/src/components/CheckboxTree/CheckboxTree.tsx index 31fefda204..ed0da051c5 100644 --- a/packages/core/src/components/CheckboxTree/CheckboxTree.tsx +++ b/packages/core/src/components/CheckboxTree/CheckboxTree.tsx @@ -26,6 +26,7 @@ import { } from '@material-ui/core'; import ExpandLess from '@material-ui/icons/ExpandLess'; import ExpandMore from '@material-ui/icons/ExpandMore'; +import produce from 'immer'; type IndexedObject = { [key: string]: T; @@ -110,18 +111,7 @@ type checkOptionPayload = { type Action = | { type: 'checkOption'; payload: checkOptionPayload } | { type: 'checkCategory'; payload: string } - | { type: 'openCategory'; payload: string }; - -const checkAllOptions = ( - arr: Option[], - isChecked: boolean, -): IndexedObject