diff --git a/src/myfasthtml/controls/DataGridsManager.py b/src/myfasthtml/controls/DataGridsManager.py
index fc5efa7..19d41fc 100644
--- a/src/myfasthtml/controls/DataGridsManager.py
+++ b/src/myfasthtml/controls/DataGridsManager.py
@@ -72,7 +72,7 @@ class Commands(BaseCommands):
self._owner,
self._owner.select_document,
key="SelectNode")
-
+
def delete_grid(self):
return Command("DeleteGrid",
"Delete grid",
@@ -248,7 +248,7 @@ class DataGridsManager(SingleInstance, DatagridMetadataProvider):
except StopIteration:
# the selected node is not a document (it's a folder)
return None
-
+
def delete_grid(self, node_id):
"""
Delete a grid and all its associated resources.
@@ -266,37 +266,37 @@ class DataGridsManager(SingleInstance, DatagridMetadataProvider):
if document_id is None:
# Node is a folder, not a document - nothing to clean up
return None
-
+
+ res = []
try:
# Find the document
document = next(filter(lambda x: x.document_id == document_id, self._state.elements))
-
+
# Get the DataGrid instance
dg = DataGrid(self, _id=document.datagrid_id)
-
+
# Close the tab
- self._tabs_manager.close_tab(document.tab_id)
-
+ close_tab_res = self._tabs_manager.close_tab(document.tab_id)
+ res.append(close_tab_res)
+
# Remove from registry
self._registry.remove(document.datagrid_id)
-
+
# Clean up DataGrid (delete DBEngine entries)
dg.delete()
-
+
# Remove from InstancesManager
InstancesManager.remove(self._session, document.datagrid_id)
-
+
# Remove DocumentDefinition from state
self._state.elements = [d for d in self._state.elements if d.document_id != document_id]
self._state.save()
-
+
except StopIteration:
# Document not found - already deleted or invalid state
pass
-
- # Note: We do NOT call tree._delete_node() here because TreeView will do it
- # automatically after this "before" bound command completes
- return None
+
+ return res
def create_tab_content(self, tab_id):
"""
diff --git a/src/myfasthtml/core/dbmanager.py b/src/myfasthtml/core/dbmanager.py
index e52d0e7..2a7a603 100644
--- a/src/myfasthtml/core/dbmanager.py
+++ b/src/myfasthtml/core/dbmanager.py
@@ -23,6 +23,9 @@ class DbManager(SingleInstance):
def load(self, entry):
return self.db.load(self.get_tenant(), entry)
+ def delete(self, entry):
+ self.db.delete(self.get_tenant(), self.get_user(), entry)
+
def exists_entry(self, entry):
return self.db.exists(self.get_tenant(), entry)
@@ -171,6 +174,9 @@ class DbObject:
def save(self):
self._save_self()
+ def delete(self):
+ self._db_manager.delete(self._name)
+
def reload(self):
self._reload_self()
diff --git a/src/myfasthtml/core/instances.py b/src/myfasthtml/core/instances.py
index 6804c86..170736e 100644
--- a/src/myfasthtml/core/instances.py
+++ b/src/myfasthtml/core/instances.py
@@ -260,6 +260,16 @@ class InstancesManager:
logger.debug(f"Creating new component {component_id} of type {real_component_type}")
return cls(parent, _id=component_id)
+ @staticmethod
+ def remove(session, component_id: str):
+ session_id = InstancesManager.get_session_id(session)
+ key = (session_id, component_id)
+ if key not in InstancesManager.instances:
+ return False
+
+ del InstancesManager.instances[key]
+ return True
+
@staticmethod
def get_session_id(session):
if isinstance(session, str):