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

feat: Tags ListView Page #24964

Merged
merged 58 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
0e099cc
add create relationship dao + test
hughhhh Jul 27, 2023
9ffd7c7
aadd create command for relationships
hughhhh Jul 28, 2023
6b75e34
add api + test
hughhhh Jul 30, 2023
98ecc81
create tags modal
hughhhh Jul 31, 2023
c9ecff7
save for now
hughhhh Aug 1, 2023
93dc089
Merge branch 'master' of https://github.com/preset-io/superset into t…
hughhhh Aug 9, 2023
68d8ebf
remove unneeded migration
hughhhh Aug 9, 2023
815fe05
Merge branch 'master' of https://github.com/preset-io/superset into t…
hughhhh Aug 11, 2023
b6da96f
fix fe linting
hughhhh Aug 14, 2023
55d2e12
update test
hughhhh Aug 14, 2023
b474daf
fix test
hughhhh Aug 14, 2023
80d6090
added test
hughhhh Aug 15, 2023
423b069
fixed python test
hughhhh Aug 15, 2023
53c4590
fix linting
hughhhh Aug 17, 2023
da3a783
Update superset-frontend/src/features/tags/TagModal.tsx
hughhhh Aug 21, 2023
18a81d1
refactory
hughhhh Aug 21, 2023
417fae1
update exception
hughhhh Aug 21, 2023
c2e069d
fix update test
hughhhh Aug 22, 2023
b7cfbc6
ok
hughhhh Aug 22, 2023
748d0cb
updating status codes
hughhhh Aug 22, 2023
910656a
fix: remove unused file (#24946)
mdeshmu Aug 10, 2023
e30746d
save
hughhhh Aug 15, 2023
4d68c24
save
hughhhh Aug 17, 2023
881712e
saving
hughhhh Aug 18, 2023
0719bde
add validation test
hughhhh Aug 21, 2023
85ff144
save
hughhhh Aug 22, 2023
29ff60a
add api
hughhhh Aug 23, 2023
9c5977d
update bulk test
hughhhh Aug 24, 2023
fd6f2ee
add refresh data
hughhhh Aug 24, 2023
a2f0187
Merge branch 'master' of https://github.com/preset-io/superset into t…
hughhhh Aug 28, 2023
58409d1
fix PageHeaderWithActions not showing dropdown
hughhhh Aug 28, 2023
2bb4640
fix styling on metadata bar
hughhhh Aug 28, 2023
f0a0070
fix more bugs
hughhhh Aug 29, 2023
1e8766f
add bulk to queries
hughhhh Aug 29, 2023
27f6d37
add + button
hughhhh Aug 30, 2023
d98a37f
Merge branch 'master' of https://github.com/preset-io/superset into t…
hughhhh Sep 5, 2023
0b366af
linting
hughhhh Sep 5, 2023
712d3bd
fix linting
hughhhh Sep 6, 2023
9659dce
fixing test part 2
hughhhh Sep 6, 2023
2453c4a
fixed metadata bar owner items and added created_on_delta_humanized t…
fisjac Sep 6, 2023
5eac9c4
fix open api spec
hughhhh Sep 7, 2023
2cfa65a
Merge pull request #604 from fisjac/tags-hover-bugfix
hughhhh Sep 8, 2023
7a09338
Merge branch 'master' of https://github.com/preset-io/superset into t…
hughhhh Sep 9, 2023
4805e5f
opps
hughhhh Sep 9, 2023
4dab0c4
rename var
hughhhh Sep 9, 2023
2400b7d
Update superset-frontend/src/components/ListView/ListView.tsx
hughhhh Sep 9, 2023
9be61e1
fix test
hughhhh Sep 9, 2023
94be254
first set of bug fixes
hughhhh Sep 10, 2023
93bdc9e
fix update list
hughhhh Sep 11, 2023
84d3cfd
add bulk_create setting for keeping state on create functions
hughhhh Sep 11, 2023
790511b
set bulk tagging to false
hughhhh Sep 11, 2023
fddf9b1
set showMenuDropdown to true
hughhhh Sep 11, 2023
4137e28
fix linting
hughhhh Sep 11, 2023
564fa06
Merge branch 'master' of https://github.com/preset-io/superset into t…
hughhhh Sep 11, 2023
737eaca
update classname for tag button
hughhhh Sep 11, 2023
b7aec35
update default value for test
hughhhh Sep 11, 2023
9a5ede4
ok ok ok
hughhhh Sep 12, 2023
43eb5dd
address kamil concernes
hughhhh Sep 12, 2023
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
40 changes: 37 additions & 3 deletions superset-frontend/src/components/ListView/ListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
* under the License.
*/
import { t, styled } from '@superset-ui/core';
import React, { useCallback, useEffect, useRef } from 'react';
import React, { useCallback, useEffect, useRef, useState } from 'react';
import Alert from 'src/components/Alert';
import cx from 'classnames';
import Button from 'src/components/Button';
import Icons from 'src/components/Icons';
import IndeterminateCheckbox from 'src/components/IndeterminateCheckbox';
import Pagination from 'src/components/Pagination';
import TableCollection from 'src/components/TableCollection';
import BulkTagModal from 'src/features/tags/BulkTagModal';
import CardCollection from './CardCollection';
import FilterControls from './Filters';
import { CardSortSelect } from './CardSortSelect';
Expand Down Expand Up @@ -98,7 +99,7 @@ const BulkSelectWrapper = styled(Alert)`
padding: ${theme.gridUnit * 2}px 0;
}
.deselect-all {
.deselect-all, .tag-btn {
color: ${theme.colors.primary.base};
margin-left: ${theme.gridUnit * 4}px;
}
Expand Down Expand Up @@ -207,6 +208,9 @@ export interface ListViewProps<T extends object = any> {
count: number;
pageSize: number;
fetchData: (conf: FetchDataConfig) => any;
refreshData: () => void;
addSuccessToast: (msg: string) => void;
addDangerToast: (msg: string) => void;
loading: boolean;
className?: string;
initialSort?: SortColumn[];
Expand All @@ -227,6 +231,8 @@ export interface ListViewProps<T extends object = any> {
showThumbnails?: boolean;
emptyState?: EmptyStateProps;
columnsForWrapText?: string[];
enableBulkTag?: boolean;
bulkTagResourceName?: string;
}

function ListView<T extends object = any>({
Expand All @@ -235,6 +241,7 @@ function ListView<T extends object = any>({
count,
pageSize: initialPageSize,
fetchData,
refreshData,
loading,
initialSort = [],
className = '',
Expand All @@ -250,6 +257,10 @@ function ListView<T extends object = any>({
highlightRowId,
emptyState,
columnsForWrapText,
enableBulkTag = false,
bulkTagResourceName,
addSuccessToast,
addDangerToast,
}: ListViewProps<T>) {
const {
getTableProps,
Expand Down Expand Up @@ -278,6 +289,7 @@ function ListView<T extends object = any>({
renderCard: Boolean(renderCard),
defaultViewMode,
});
const allowBulkTagActions = bulkTagResourceName && enableBulkTag;
const filterable = Boolean(filters.length);
if (filterable) {
const columnAccessors = columns.reduce(
Expand All @@ -302,6 +314,7 @@ function ListView<T extends object = any>({
}, [query.filters]);

const cardViewEnabled = Boolean(renderCard);
const [showBulkTagModal, setShowBulkTagModal] = useState<boolean>(false);

useEffect(() => {
// discard selections if bulk select is disabled
Expand All @@ -310,6 +323,17 @@ function ListView<T extends object = any>({

return (
<ListViewStyles>
{allowBulkTagActions && (
<BulkTagModal
show={showBulkTagModal}
selected={selectedFlatRows}
refreshData={refreshData}
resourceName={bulkTagResourceName}
addSuccessToast={addSuccessToast}
addDangerToast={addDangerToast}
onHide={() => setShowBulkTagModal(false)}
/>
)}
<div data-test={className} className={`superset-list-view ${className}`}>
<div className="header">
{cardViewEnabled && (
Expand Down Expand Up @@ -375,6 +399,17 @@ function ListView<T extends object = any>({
{action.name}
</Button>
))}
{enableBulkTag && (
<span
data-test="bulk-select-tag-btn"
role="button"
tabIndex={0}
className="tag-btn"
onClick={() => setShowBulkTagModal(true)}
>
{t('Add Tag')}
</span>
)}
</>
)}
</>
Expand Down Expand Up @@ -425,7 +460,6 @@ function ListView<T extends object = any>({
)}
</div>
</div>

{rows.length > 0 && (
<div className="pagination-container">
<Pagination
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ const config = (contentType: ContentType) => {
tooltip: (
<div>
<Info header={t('Created by')} text={contentType.createdBy} />
<Info header={t('Owners')} text={contentType.owners} />
{!!contentType.owners && (
<Info header={t('Owners')} text={contentType.owners} />
)}
<Info header={t('Created on')} text={contentType.createdOn} />
</div>
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export type LastModified = {
export type Owner = {
type: MetadataType.OWNER;
createdBy: string;
owners: string[];
owners?: string[];
createdOn: string;
onClick?: (type: string) => void;
};
Expand Down
40 changes: 22 additions & 18 deletions superset-frontend/src/components/PageHeaderWithActions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export type PageHeaderWithActionsProps = {
showTitlePanelItems: boolean;
certificatiedBadgeProps?: CertifiedBadgeProps;
showFaveStar: boolean;
showMenuDropdown?: boolean;
faveStarProps: FaveStarProps;
titlePanelAdditionalItems: ReactNode;
rightPanelAdditionalItems: ReactNode;
Expand All @@ -129,6 +130,7 @@ export const PageHeaderWithActions = ({
rightPanelAdditionalItems,
additionalActionsMenu,
menuDropdownProps,
showMenuDropdown = true,
tooltipProps,
}: PageHeaderWithActionsProps) => {
const theme = useTheme();
Expand All @@ -149,25 +151,27 @@ export const PageHeaderWithActions = ({
<div className="right-button-panel">
{rightPanelAdditionalItems}
<div css={additionalActionsContainerStyles}>
<AntdDropdown
trigger={['click']}
overlay={additionalActionsMenu}
{...menuDropdownProps}
>
<Button
css={menuTriggerStyles}
buttonStyle="tertiary"
aria-label={t('Menu actions trigger')}
tooltip={tooltipProps?.text}
placement={tooltipProps?.placement}
data-test="actions-trigger"
{showMenuDropdown && (
<AntdDropdown
trigger={['click']}
overlay={additionalActionsMenu}
{...menuDropdownProps}
>
<Icons.MoreHoriz
iconColor={theme.colors.primary.dark2}
iconSize="l"
/>
</Button>
</AntdDropdown>
<Button
css={menuTriggerStyles}
buttonStyle="tertiary"
aria-label={t('Menu actions trigger')}
tooltip={tooltipProps?.text}
placement={tooltipProps?.placement}
data-test="actions-trigger"
>
<Icons.MoreHoriz
iconColor={theme.colors.primary.dark2}
iconSize="l"
/>
</Button>
</AntdDropdown>
)}
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion superset-frontend/src/components/Tags/Tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const Tag = ({
<StyledTag role="link" key={id} onClick={onClick}>
{id ? (
<a
href={`/superset/all_entities/?tags=${name}`}
href={`/superset/all_entities/?id=${id}`}
target="_blank"
rel="noreferrer"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ const createProps = () => ({
maxUndoHistoryToast: jest.fn(),
dashboardInfoChanged: jest.fn(),
dashboardTitleChanged: jest.fn(),
showMenuDropdown: true,
});
const props = createProps();
const editableProps = {
Expand Down
118 changes: 118 additions & 0 deletions superset-frontend/src/features/tags/BulkTagModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import React, { useState, useEffect } from 'react';
import { t, SupersetClient } from '@superset-ui/core';
import { FormLabel } from 'src/components/Form';
import Modal from 'src/components/Modal';
import AsyncSelect from 'src/components/Select/AsyncSelect';
import Button from 'src/components/Button';
import { loadTags } from 'src/components/Tags/utils';
import { TaggableResourceOption } from 'src/features/tags/TagModal';

interface BulkTagModalProps {
onHide: () => void;
refreshData: () => void;
addSuccessToast: (msg: string) => void;
addDangerToast: (msg: string) => void;
show: boolean;
selected: any[];
resourceName: string;
}

const BulkTagModal: React.FC<BulkTagModalProps> = ({
show,
selected = [],
onHide,
refreshData,
resourceName,
addSuccessToast,
addDangerToast,
}) => {
useEffect(() => {}, []);

const onSave = async () => {
await SupersetClient.post({
endpoint: `/api/v1/tag/bulk_create`,
jsonPayload: {
tags: tags.map(tag => tag.value),
objects_to_tag: selected.map(item => [resourceName, +item.original.id]),
},
})
.then(({ json = {} }) => {
addSuccessToast(t('Tagged %s items', selected.length));
})
.catch(err => {
addDangerToast(t('Failed to tag items'));
});

refreshData();
onHide();
setTags([]);
};

const [tags, setTags] = useState<TaggableResourceOption[]>([]);

return (
<Modal
title={t('Bulk tag')}
show={show}
onHide={() => {
setTags([]);
onHide();
}}
footer={
<div>
<Button
data-test="modal-save-dashboard-button"
buttonStyle="secondary"
onClick={onHide}
>
{t('Cancel')}
</Button>
<Button
data-test="modal-save-dashboard-button"
buttonStyle="primary"
onClick={onSave}
>
{t('Save')}
</Button>
</div>
}
>
<>
<>{t('You are adding tags to the %s entities', selected.length)}</>
<br />
<FormLabel>{t('tags')}</FormLabel>
<AsyncSelect
ariaLabel="tags"
// @ts-ignore
value={tags}
options={loadTags}
onHide={onHide}
// @ts-ignore
onChange={tags => setTags(tags)}
placeholder={t('Select Tags')}
mode="multiple"
/>
</>
</Modal>
);
};

export default BulkTagModal;
28 changes: 27 additions & 1 deletion superset-frontend/src/features/tags/TagModal.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
Copy link
Member

Choose a reason for hiding this comment

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

ts-nocheck

import React from 'react';
import { render, screen } from 'spec/helpers/testing-library';
import TagModal from 'src/features/tags/TagModal';
Expand Down Expand Up @@ -36,7 +54,15 @@ test('renders correctly in edit mode', () => {
description: 'A test tag',
type: 'dashboard',
changed_on_delta_humanized: '',
created_by: {},
created_on_delta_humanized: '',
created_by: {
first_name: 'joe',
last_name: 'smith',
},
changed_by: {
first_name: 'tom',
last_name: 'brown',
},
};

render(<TagModal {...mockedProps} editTag={editTag} />);
Expand Down
Loading