-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
9260 refactor multiple record actions and no selection actions (#9314)
Closes #9260 - Refactored multiple record actions and no selection record actions to use config file - Simplified actions registration logic - Updated tests
- Loading branch information
1 parent
306b45a
commit e3f7a05
Showing
52 changed files
with
871 additions
and
1,123 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
55 changes: 55 additions & 0 deletions
55
.../src/modules/action-menu/actions/record-actions/components/RegisterRecordActionEffect.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,55 @@ | ||
import { ActionHook } from '@/action-menu/actions/types/ActionHook'; | ||
import { wrapActionInCallbacks } from '@/action-menu/actions/utils/wrapActionInCallbacks'; | ||
import { ActionMenuContext } from '@/action-menu/contexts/ActionMenuContext'; | ||
import { useActionMenuEntries } from '@/action-menu/hooks/useActionMenuEntries'; | ||
import { ActionMenuEntry } from '@/action-menu/types/ActionMenuEntry'; | ||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem'; | ||
import { useContext, useEffect } from 'react'; | ||
|
||
type RegisterRecordActionEffectProps = { | ||
action: ActionMenuEntry & { | ||
actionHook: ActionHook; | ||
}; | ||
objectMetadataItem: ObjectMetadataItem; | ||
}; | ||
|
||
export const RegisterRecordActionEffect = ({ | ||
action, | ||
objectMetadataItem, | ||
}: RegisterRecordActionEffectProps) => { | ||
const { shouldBeRegistered, onClick, ConfirmationModal } = action.actionHook({ | ||
objectMetadataItem, | ||
}); | ||
|
||
const { onActionStartedCallback, onActionExecutedCallback } = | ||
useContext(ActionMenuContext); | ||
|
||
const { addActionMenuEntry, removeActionMenuEntry } = useActionMenuEntries(); | ||
|
||
const wrappedAction = wrapActionInCallbacks({ | ||
action: { | ||
...action, | ||
onClick, | ||
ConfirmationModal, | ||
}, | ||
onActionStartedCallback, | ||
onActionExecutedCallback, | ||
}); | ||
|
||
useEffect(() => { | ||
if (shouldBeRegistered) { | ||
addActionMenuEntry(wrappedAction); | ||
} | ||
|
||
return () => { | ||
removeActionMenuEntry(wrappedAction.key); | ||
}; | ||
}, [ | ||
addActionMenuEntry, | ||
removeActionMenuEntry, | ||
shouldBeRegistered, | ||
wrappedAction, | ||
]); | ||
|
||
return null; | ||
}; |
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
Oops, something went wrong.