add callback when in right drawer

This commit is contained in:
bosiraphael
2024-10-23 15:14:55 +02:00
parent 53d5d609da
commit 33117dd154
4 changed files with 45 additions and 11 deletions

View File

@@ -2,7 +2,16 @@ import { DeleteRecordsActionEffect } from '@/action-menu/actions/record-actions/
import { ExportRecordsActionEffect } from '@/action-menu/actions/record-actions/components/ExportRecordsActionEffect';
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
const actionEffects = [ExportRecordsActionEffect, DeleteRecordsActionEffect];
const actions = [
{
ActionEffect: ExportRecordsActionEffect,
onActionExecutedCallback: () => {},
},
{
ActionEffect: DeleteRecordsActionEffect,
onActionExecutedCallback: () => {},
},
];
export const MultipleRecordsActionMenuEntriesSetter = ({
objectMetadataItem,
@@ -11,11 +20,12 @@ export const MultipleRecordsActionMenuEntriesSetter = ({
}) => {
return (
<>
{actionEffects.map((ActionEffect, index) => (
{actions.map(({ ActionEffect, onActionExecutedCallback }, index) => (
<ActionEffect
key={index}
position={index}
objectMetadataItem={objectMetadataItem}
onActionExecutedCallback={onActionExecutedCallback}
/>
))}
</>

View File

@@ -5,7 +5,11 @@ import { contextStoreNumberOfSelectedRecordsComponentState } from '@/context-sto
import { useObjectMetadataItemById } from '@/object-metadata/hooks/useObjectMetadataItemById';
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2';
export const RecordActionMenuEntriesSetter = () => {
export const RecordActionMenuEntriesSetter = ({
isInRightDrawer = false,
}: {
isInRightDrawer?: boolean;
}) => {
const contextStoreNumberOfSelectedRecords = useRecoilComponentValueV2(
contextStoreNumberOfSelectedRecordsComponentState,
);
@@ -32,6 +36,7 @@ export const RecordActionMenuEntriesSetter = () => {
return (
<SingleRecordActionMenuEntriesSetter
objectMetadataItem={objectMetadataItem}
isInRightDrawer={isInRightDrawer}
/>
);
}

View File

@@ -1,25 +1,44 @@
import { DeleteRecordsActionEffect } from '@/action-menu/actions/record-actions/components/DeleteRecordsActionEffect';
import { ExportRecordsActionEffect } from '@/action-menu/actions/record-actions/components/ExportRecordsActionEffect';
import { ManageFavoritesActionEffect } from '@/action-menu/actions/record-actions/components/ManageFavoritesActionEffect';
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
import { useRightDrawer } from '@/ui/layout/right-drawer/hooks/useRightDrawer';
import { useMemo } from 'react';
export const SingleRecordActionMenuEntriesSetter = ({
objectMetadataItem,
isInRightDrawer = false,
}: {
objectMetadataItem: ObjectMetadataItem;
isInRightDrawer?: boolean;
}) => {
const actionEffects = [
ManageFavoritesActionEffect,
ExportRecordsActionEffect,
DeleteRecordsActionEffect,
];
const { closeRightDrawer } = useRightDrawer();
const actions = useMemo(
() => [
{
ActionEffect: ExportRecordsActionEffect,
onActionExecutedCallback: isInRightDrawer
? closeRightDrawer
: undefined,
},
{
ActionEffect: DeleteRecordsActionEffect,
onActionExecutedCallback: isInRightDrawer
? closeRightDrawer
: undefined,
},
],
[isInRightDrawer, closeRightDrawer],
);
return (
<>
{actionEffects.map((ActionEffect, index) => (
{actions.map(({ ActionEffect, onActionExecutedCallback }, index) => (
<ActionEffect
key={index}
position={index}
objectMetadataItem={objectMetadataItem}
onActionExecutedCallback={onActionExecutedCallback}
/>
))}
</>

View File

@@ -69,7 +69,7 @@ export const RecordShowContainer = ({
{contextStoreCurrentObjectMetadataId && (
<>
<ActionMenuConfirmationModals />
<RecordActionMenuEntriesSetter />
<RecordActionMenuEntriesSetter isInRightDrawer={isInRightDrawer} />
</>
)}
{recordFromStore && recordFromStore.deletedAt && (