From 2bcb4ed2a2cf910cf644806c28dd948a53fa3b3d Mon Sep 17 00:00:00 2001 From: "Hugh A. Miles II" Date: Mon, 9 Oct 2023 20:16:18 +0000 Subject: [PATCH] fix clear on description --- .../src/pages/AllEntities/index.tsx | 31 ++++++++++++------- superset/tags/api.py | 12 ++++--- superset/tags/commands/create.py | 8 +++-- superset/tags/commands/update.py | 6 ++-- 4 files changed, 33 insertions(+), 24 deletions(-) diff --git a/superset-frontend/src/pages/AllEntities/index.tsx b/superset-frontend/src/pages/AllEntities/index.tsx index e131e7e6fb865..25068928b5574 100644 --- a/superset-frontend/src/pages/AllEntities/index.tsx +++ b/superset-frontend/src/pages/AllEntities/index.tsx @@ -164,21 +164,25 @@ function AllEntities() { ); }; + const fetchTag = (tagId: number) => { + fetchSingleTag( + tagId, + (tag: Tag) => { + setTag(tag); + setLoading(false); + }, + (error: Response) => { + addDangerToast(t('Error Fetching Tagged Objects')); + setLoading(false); + }, + ); + }; + useEffect(() => { // fetch single tag met if (tagId) { setLoading(true); - fetchSingleTag( - tagId, - (tag: Tag) => { - setTag(tag); - setLoading(false); - }, - (error: Response) => { - addDangerToast(t('Error Fetching Tagged Objects')); - setLoading(false); - }, - ); + fetchTag(tagId); } }, [tagId]); @@ -197,7 +201,10 @@ function AllEntities() { editTag={tag} addSuccessToast={addSuccessToast} addDangerToast={addDangerToast} - refreshData={fetchTaggedObjects} + refreshData={() => { + fetchTaggedObjects(); + fetchTag(tagId); + }} /> Response: except ValidationError as error: return self.response_400(message=error.messages) try: - all_tagged_objects = [] - all_skipped_tagged_objects = [] + all_tagged_objects: set[tuple[str, int]] = set() + all_skipped_tagged_objects: set[tuple[str, int]] = set() for tag in item.get("tags"): tagged_item: dict[str, Any] = self.add_model_schema.load( { @@ -273,13 +273,15 @@ def bulk_create(self) -> Response: ) = CreateCustomTagWithRelationshipsCommand( tagged_item, bulk_create=True ).run() - all_tagged_objects += objects_tagged - all_skipped_tagged_objects += objects_skipped + all_tagged_objects = all_tagged_objects | objects_tagged + all_skipped_tagged_objects = ( + all_skipped_tagged_objects | objects_skipped + ) return self.response( 200, result={ "objects_tagged": list( - set(all_tagged_objects) - set(all_skipped_tagged_objects) + all_tagged_objects - all_skipped_tagged_objects ), "objects_skipped": list(all_skipped_tagged_objects), }, diff --git a/superset/tags/commands/create.py b/superset/tags/commands/create.py index a9ab34ef5f386..cd3bcc176b2b6 100644 --- a/superset/tags/commands/create.py +++ b/superset/tags/commands/create.py @@ -71,7 +71,7 @@ def __init__(self, data: dict[str, Any], bulk_create: bool = False): self._bulk_create = bulk_create self._skipped_tagged_objects: set[tuple[str, int]] = set() - def run(self) -> tuple[list[tuple[str, int]], list[tuple[str, int]]]: + def run(self) -> tuple[set[tuple[str, int]], set[tuple[str, int]]]: self.validate() try: @@ -87,7 +87,7 @@ def run(self) -> tuple[list[tuple[str, int]], list[tuple[str, int]]]: db.session.commit() - return self._properties["objects_to_tag"], self._skipped_tagged_objects + return set(self._properties["objects_to_tag"]), self._skipped_tagged_objects except DAOCreateFailedError as ex: logger.exception(ex.exception) @@ -114,7 +114,9 @@ def validate(self) -> None: # skip the object if the user doesn't have access self._skipped_tagged_objects.add((obj_type, obj_id)) - self._properties["objects_to_tag"] = set(objects_to_tag) - self._skipped_tagged_objects + self._properties["objects_to_tag"] = ( + set(objects_to_tag) - self._skipped_tagged_objects + ) if exceptions: raise TagInvalidError(exceptions=exceptions) diff --git a/superset/tags/commands/update.py b/superset/tags/commands/update.py index cc1c9a2be788d..182376438b6c5 100644 --- a/superset/tags/commands/update.py +++ b/superset/tags/commands/update.py @@ -38,14 +38,12 @@ def __init__(self, model_id: int, data: dict[str, Any]): def run(self) -> Model: self.validate() if self._model: + self._model.name = self._properties["name"] TagDAO.create_tag_relationship( objects_to_tag=self._properties.get("objects_to_tag", []), tag=self._model, ) - if description := self._properties.get("description"): - self._model.description = description - if tag_name := self._properties.get("name"): - self._model.name = tag_name + self._model.description = self._properties.get("description") db.session.add(self._model) db.session.commit()