-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(reports): add indeterminate state for S-21 export checkboxes
- Loading branch information
1 parent
9c5efc6
commit 569ad6e
Showing
4 changed files
with
76 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...eatures/reports/publisher_records/export_S21/specific_records/useParentUncheckHandler.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { TreeViewBaseItem } from '@mui/x-tree-view'; | ||
|
||
const useParentUncheckHandler = () => { | ||
const findParentIdByItem = ( | ||
dataSource: TreeViewBaseItem[], | ||
itemId: string, | ||
parentId: string = null | ||
) => { | ||
for (const item of dataSource) { | ||
if (item.id === itemId) { | ||
return parentId; | ||
} | ||
if (item.children) { | ||
const found = findParentIdByItem(item.children, itemId, item.id); | ||
if (found) { | ||
return found; | ||
} | ||
} | ||
} | ||
return null; | ||
}; | ||
|
||
const deleteSelectionFromParentItem = ( | ||
oldSelectedList: string[], | ||
groups: TreeViewBaseItem[], | ||
selected: string[] | ||
) => { | ||
const missedItem = selected.filter( | ||
(item) => !oldSelectedList.includes(item) | ||
)[0]; | ||
|
||
if (!missedItem) { | ||
return oldSelectedList; | ||
} | ||
|
||
const missedItemParent = findParentIdByItem(groups, missedItem); | ||
|
||
return oldSelectedList.filter((item) => item !== missedItemParent); | ||
}; | ||
|
||
return { | ||
deleteSelectionFromParentItem, | ||
}; | ||
}; | ||
|
||
export default useParentUncheckHandler; |