Merge branch 'feature/delete-hook' of https://github.com/faizaand/firecms

This commit is contained in:
francesco
2020-09-18 15:15:40 +02:00
3 changed files with 15 additions and 2 deletions

View File

@@ -14,6 +14,7 @@ export interface DeleteEntityDialogProps<S extends EntitySchema> {
entity?: Entity<S>,
schema: S
open: boolean;
afterDelete?: () => void;
onClose: () => void;
}
@@ -30,7 +31,10 @@ export default function DeleteEntityDialog<S extends EntitySchema>(props: Delete
if (entity) {
setOpenSnackbar(true);
setLoading(true);
deleteEntity(entity).then(_ => setLoading(false));
deleteEntity(entity).then(_ => {
setLoading(false);
if(props.afterDelete) props.afterDelete()
});
onClose();
}
};

View File

@@ -73,6 +73,15 @@ export interface EntityCollectionView<S extends EntitySchema,
* Properties that can be filtered in this view
*/
filterableProperties?: Key[];
/**
* Hook called when the user initiates a delete operation.
* This is called after the entity is deleted in Firestore.
*
* @param collectionPath the Firestore collection path.
* @param entity the entity being deleted.
*/
onEntityDelete?(collectionPath: string, entity: Entity<S>): void;
}
/**
@@ -125,7 +134,6 @@ export interface EntitySchema<Key extends string = string, P extends Properties<
*/
onPreSave?(entitySaveProps: EntitySaveProps<this>)
: Promise<EntityValues<this>> | EntityValues<this>
}
/**

View File

@@ -116,6 +116,7 @@ export function CollectionRoute<S extends EntitySchema>({
<DeleteEntityDialog entity={deleteEntityClicked}
schema={view.schema}
open={!!deleteEntityClicked}
afterDelete={() => view?.onEntityDelete ? view.onEntityDelete(collectionPath, deleteEntityClicked) : undefined}
onClose={() => setDeleteEntityClicked(undefined)}/>}
</React.Fragment>