Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add validation on tag name to have name + onDelete refresh list view #25831

Merged
merged 8 commits into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions superset-frontend/src/features/tags/TagModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,14 @@ const TagModal: React.FC<TagModalProps> = ({
name: tagName,
objects_to_tag: [...dashboards, ...charts, ...savedQueries],
},
}).then(({ json = {} }) => {
refreshData();
addSuccessToast(t('Tag updated'));
});
})
.then(({ json = {} }) => {
refreshData();
addSuccessToast(t('Tag updated'));
})
.catch(err => {
addDangerToast(err.message ? err.message : 'Error Updating Tag');
hughhhh marked this conversation as resolved.
Show resolved Hide resolved
});
} else {
SupersetClient.post({
endpoint: `/api/v1/tag/`,
Expand All @@ -234,10 +238,14 @@ const TagModal: React.FC<TagModalProps> = ({
name: tagName,
objects_to_tag: [...dashboards, ...charts, ...savedQueries],
},
}).then(({ json = {} }) => {
refreshData();
addSuccessToast(t('Tag created'));
});
})
.then(({ json = {} }) => {
refreshData();
addSuccessToast(t('Tag created'));
})
.catch(err =>
addDangerToast(err.message ? err.message : 'Error Creating Tag'),
hughhhh marked this conversation as resolved.
Show resolved Hide resolved
);
}
onHide();
};
Expand Down
26 changes: 14 additions & 12 deletions superset-frontend/src/pages/Tags/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,18 @@ function TagList(props: TagListProps) {

const initialSort = [{ id: 'changed_on_delta_humanized', desc: true }];

function handleTagsDelete(
tags: Tag[],
callback: (text: string) => void,
error: (text: string) => void,
) {
// TODO what permissions need to be checked here?
deleteTags(tags, callback, error);
refreshData();
function handleTagsDelete(tags: Tag[]) {
deleteTags(
tags,
(msg: string) => {
addSuccessToast(msg);
refreshData();
},
msg => {
addDangerToast(msg);
refreshData();
},
);
}

const handleTagEdit = (tag: Tag) => {
Expand Down Expand Up @@ -178,8 +182,6 @@ function TagList(props: TagListProps) {
},
{
Cell: ({ row: { original } }: any) => {
const handleDelete = () =>
handleTagsDelete([original], addSuccessToast, addDangerToast);
const handleEdit = () => handleTagEdit(original);
return (
<Actions className="actions">
Expand All @@ -192,7 +194,7 @@ function TagList(props: TagListProps) {
<b>{original.dashboard_title}</b>?
</>
}
onConfirm={handleDelete}
onConfirm={() => handleTagsDelete([original])}
>
{confirmDelete => (
<Tooltip
Expand Down Expand Up @@ -318,7 +320,7 @@ function TagList(props: TagListProps) {
});

const handleBulkDelete = (tagsToDelete: Tag[]) =>
handleTagsDelete(tagsToDelete, addSuccessToast, addDangerToast);
handleTagsDelete(tagsToDelete);

return (
<>
Expand Down
4 changes: 2 additions & 2 deletions superset/tags/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.
from marshmallow import fields, Schema
from marshmallow.validate import Range
from marshmallow.validate import Length, Range

from superset.dashboards.schemas import UserSchema

Expand Down Expand Up @@ -58,7 +58,7 @@ class TaggedObjectEntityResponseSchema(Schema):


class TagObjectSchema(Schema):
name = fields.String()
name = fields.String(validate=Length(min=1))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this logic also need to reside within the Command or DAO? Additionally do we have any tests for schema validation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it lies in the API, I'm working on a test now to validate

description = fields.String(required=False, allow_none=True)
objects_to_tag = fields.List(
fields.Tuple((fields.String(), fields.Int(validate=Range(min=1)))),
Expand Down