Skip to content

Commit

Permalink
fix clear on description
Browse files Browse the repository at this point in the history
  • Loading branch information
hughhhh committed Oct 9, 2023
1 parent 724bb74 commit 2bcb4ed
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 24 deletions.
31 changes: 19 additions & 12 deletions superset-frontend/src/pages/AllEntities/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand All @@ -197,7 +201,10 @@ function AllEntities() {
editTag={tag}
addSuccessToast={addSuccessToast}
addDangerToast={addDangerToast}
refreshData={fetchTaggedObjects}
refreshData={() => {
fetchTaggedObjects();
fetchTag(tagId);
}}
/>
<AllEntitiesNav>
<PageHeaderWithActions
Expand Down
12 changes: 7 additions & 5 deletions superset/tags/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ def bulk_create(self) -> 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(
{
Expand All @@ -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),
},
Expand Down
8 changes: 5 additions & 3 deletions superset/tags/commands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -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)
6 changes: 2 additions & 4 deletions superset/tags/commands/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 2bcb4ed

Please sign in to comment.