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: Tags Page Polish #25403

Merged
merged 6 commits into from
Sep 30, 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
110 changes: 92 additions & 18 deletions superset-frontend/src/features/allEntities/AllEntitiesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,31 @@ import { t, styled, logging } from '@superset-ui/core';
import TableView, { EmptyWrapperType } from 'src/components/TableView';
import { addDangerToast } from 'src/components/MessageToasts/actions';
import Loading from 'src/components/Loading';
import { TagsList } from 'src/components/Tags';
import FacePile from 'src/components/FacePile';
import Tag from 'src/types/TagType';
import Owner from 'src/types/Owner';
import { EmptyStateBig } from 'src/components/EmptyState';
import { fetchObjects } from '../tags/tags';

const AllEntitiesTableContainer = styled.div`
text-align: left;
border-radius: ${({ theme }) => theme.gridUnit * 1}px 0;
margin: 0 ${({ theme }) => theme.gridUnit * 4}px;
.table {
table-layout: fixed;
}
.td {
width: 33%;
}
.entity-title {
font-family: Inter;
font-size: 14px;
font-weight: 500;
hughhhh marked this conversation as resolved.
Show resolved Hide resolved
line-height: 17px;
letter-spacing: 0px;
text-align: left;
margin: ${({ theme }) => theme.gridUnit * 4}px 0;
}
`;

interface TaggedObject {
Expand All @@ -44,6 +57,8 @@ interface TaggedObject {
changed_on: moment.MomentInput;
created_by: number | undefined;
creator: string;
owners: Owner[];
tags: Tag[];
}

interface TaggedObjects {
Expand All @@ -54,10 +69,12 @@ interface TaggedObjects {

interface AllEntitiesTableProps {
search?: string;
setShowTagModal: (show: boolean) => void;
}

export default function AllEntitiesTable({
search = '',
setShowTagModal,
}: AllEntitiesTableProps) {
type objectType = 'dashboard' | 'chart' | 'query';

Expand All @@ -66,8 +83,19 @@ export default function AllEntitiesTable({
chart: [],
query: [],
});
const [isLoading, setLoading] = useState<boolean>(true);
const showListViewObjs =
objects.dashboard.length > 0 ||
objects.chart.length > 0 ||
objects.query.length > 0;

useEffect(() => {
if (search === '') {
return;
}

setLoading(true);

fetchObjects(
{ tags: search, types: null },
(data: TaggedObject[]) => {
Expand All @@ -77,6 +105,7 @@ export default function AllEntitiesTable({
objects[object_type].push(object);
});
setObjects(objects);
setLoading(false);
},
(error: Response) => {
addDangerToast('Error Fetching Tagged Objects');
Expand All @@ -89,7 +118,10 @@ export default function AllEntitiesTable({
const data = objects[type].map((o: TaggedObject) => ({
[type]: <a href={o.url}>{o.name}</a>,
modified: moment.utc(o.changed_on).fromNow(),
tags: o.tags,
owners: o.owners,
}));

return (
<TableView
className="table-condensed"
Expand All @@ -99,27 +131,69 @@ export default function AllEntitiesTable({
columns={[
{
accessor: type,
Header: type.charAt(0).toUpperCase() + type.slice(1),
Header: 'Title',
},
{
Cell: ({
row: {
original: { tags = [] },
},
}: {
row: {
original: {
tags: Tag[];
};
};
}) => (
// Only show custom type tags
<TagsList
tags={tags.filter(
(tag: Tag) =>
tag.type === 'TagTypes.custom' || tag.type === 1,
)}
maxTags={3}
Copy link
Member

Choose a reason for hiding this comment

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

Can this number be a constant on top of the file?

/>
),
Header: t('Tags'),
accessor: 'tags',
disableSortBy: true,
},
{
Cell: ({
row: {
original: { owners = [] },
},
}: any) => <FacePile users={owners} />,
Header: t('Owners'),
accessor: 'owners',
disableSortBy: true,
size: 'xl',
},
{ accessor: 'modified', Header: 'Modified' },
]}
/>
);
};

if (objects) {
return (
<AllEntitiesTableContainer>
<h3>{t('Dashboards')}</h3>
{renderTable('dashboard')}
<hr />
<h3>{t('Charts')}</h3>
{renderTable('chart')}
<hr />
<h3>{t('Queries')}</h3>
{renderTable('query')}
</AllEntitiesTableContainer>
);
}
return <Loading />;
if (isLoading) return <Loading />;
return (
<AllEntitiesTableContainer>
{showListViewObjs ? (
<>
<div className="entity-title">{t('Dashboards')}</div>
{renderTable('dashboard')}
<div className="entity-title">{t('Charts')}</div>
{renderTable('chart')}
<div className="entity-title">{t('Queries')}</div>
{renderTable('query')}
</>
) : (
<EmptyStateBig
image="dashboard.svg"
title={t('No entities have this tag currently assigned')}
buttonAction={() => setShowTagModal(true)}
buttonText={t('Add tag to entities')}
/>
)}
</AllEntitiesTableContainer>
);
}
9 changes: 7 additions & 2 deletions superset-frontend/src/pages/AllEntities/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const AllEntitiesContainer = styled.div`
margin-bottom: ${theme.gridUnit * 1}px;
}
.entities {
margin: ${theme.gridUnit * 7.5}px; 0px;
margin: ${theme.gridUnit * 6}px; 0px;
}
`}
`;
Expand Down Expand Up @@ -88,6 +88,7 @@ function AllEntities() {
const [tag, setTag] = useState<Tag | null>(null);
const [showTagModal, setShowTagModal] = useState<boolean>(false);
const { addSuccessToast, addDangerToast } = useToasts();

const editableTitleProps = {
title: tag?.name || '',
placeholder: 'testing',
Expand Down Expand Up @@ -166,10 +167,14 @@ function AllEntities() {
menuDropdownProps={{
disabled: true,
}}
showMenuDropdown={false}
/>
</AllEntitiesNav>
<div className="entities">
<AllEntitiesTable search={tag?.name || ''} />
<AllEntitiesTable
search={tag?.name || ''}
setShowTagModal={setShowTagModal}
/>
</div>
</AllEntitiesContainer>
);
Expand Down
2 changes: 1 addition & 1 deletion superset-frontend/src/pages/DashboardList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ interface DashboardListProps {
};
}

interface Dashboard {
export interface Dashboard {
changed_by_name: string;
changed_on_delta_humanized: string;
changed_by: string;
Expand Down
16 changes: 6 additions & 10 deletions superset/daos/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,6 @@ def get_tagged_objects_for_tags(
returns a list of tagged objects filtered by tag names and object types
if no filters applied returns all tagged objects
"""
# id = fields.Int()
# type = fields.String()
# name = fields.String()
# url = fields.String()
# changed_on = fields.DateTime()
# created_by = fields.Nested(UserSchema)
# creator = fields.String(

# filter types

results: list[dict[str, Any]] = []

# dashboards
Expand All @@ -211,6 +201,8 @@ def get_tagged_objects_for_tags(
"changed_on": obj.changed_on,
"created_by": obj.created_by_fk,
"creator": obj.creator(),
"tags": obj.tags,
"owners": obj.owners,
}
for obj in dashboards
)
Expand Down Expand Up @@ -238,6 +230,8 @@ def get_tagged_objects_for_tags(
"changed_on": obj.changed_on,
"created_by": obj.created_by_fk,
"creator": obj.creator(),
"tags": obj.tags,
"owners": obj.owners,
}
for obj in charts
)
Expand Down Expand Up @@ -265,6 +259,8 @@ def get_tagged_objects_for_tags(
"changed_on": obj.changed_on,
"created_by": obj.created_by_fk,
"creator": obj.creator(),
"tags": obj.tags,
"owners": [obj.creator()],
}
for obj in saved_queries
)
Expand Down
14 changes: 8 additions & 6 deletions superset/tags/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
}


class TagGetResponseSchema(Schema):
id = fields.Int()
name = fields.String()
type = fields.String()


class TaggedObjectEntityResponseSchema(Schema):
id = fields.Int()
type = fields.String()
Expand All @@ -46,12 +52,8 @@ class TaggedObjectEntityResponseSchema(Schema):
changed_on = fields.DateTime()
created_by = fields.Nested(UserSchema(exclude=["username"]))
creator = fields.String()


class TagGetResponseSchema(Schema):
id = fields.Int()
name = fields.String()
type = fields.String()
tags = fields.List(fields.Nested(TagGetResponseSchema))
owners = fields.List(fields.Nested(UserSchema))


class TagObjectSchema(Schema):
Expand Down
Loading