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: card view bulk select #10607

Merged
merged 3 commits into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
32 changes: 25 additions & 7 deletions superset-frontend/src/components/ListView/CardCollection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import React from 'react';
import { TableInstance } from 'react-table';
import styled from '@superset-ui/style';

interface Props {
renderCard?: (row: any) => React.ReactNode;
interface CardCollectionProps {
bulkSelectEnabled?: boolean;
loading: boolean;
prepareRow: TableInstance['prepareRow'];
renderCard?: (row: any) => React.ReactNode;
rows: TableInstance['rows'];
loading: boolean;
}

const CardContainer = styled.div`
Expand All @@ -36,19 +37,36 @@ const CardContainer = styled.div`
${({ theme }) => theme.gridUnit * 4}px;
`;

const CardWrapper = styled.div`
border: 2px solid transparent;
&.card-selected {
border: 2px solid ${({ theme }) => theme.colors.primary.base};
}
`;

export default function CardCollection({
renderCard,
bulkSelectEnabled,
loading,
prepareRow,
renderCard,
rows,
loading,
}: Props) {
}: CardCollectionProps) {
return (
<CardContainer>
{rows.map(row => {
if (!renderCard) return null;
prepareRow(row);
return (
<div key={row.id}>{renderCard({ ...row.original, loading })}</div>
<CardWrapper
className={
row.isSelected && bulkSelectEnabled ? 'card-selected' : ''
}
key={row.id}
onClick={() => row.toggleRowSelected()}
Copy link
Member

Choose a reason for hiding this comment

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

We should probably check to see if bulkSelectEnabled before firing this. Like this, I think it's possible to select cards even if bulkSelect is not enabled.

role="none"
>
{renderCard({ ...row.original, loading })}
</CardWrapper>
);
})}
</CardContainer>
Expand Down
1 change: 1 addition & 0 deletions superset-frontend/src/components/ListView/ListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ const ListView: FunctionComponent<ListViewProps> = ({
)}
{viewingMode === 'card' && (
<CardCollection
bulkSelectEnabled={bulkSelectEnabled}
prepareRow={prepareRow}
renderCard={renderCard}
rows={rows}
Expand Down
4 changes: 3 additions & 1 deletion superset-frontend/src/components/ListViewCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ interface CardProps {
coverLeft?: React.ReactNode;
coverRight?: React.ReactNode;
actions: React.ReactNode;
bulkSelectEnabled?: boolean;
}

function ListViewCard({
Expand All @@ -154,12 +155,13 @@ function ListViewCard({
coverLeft,
coverRight,
actions,
bulkSelectEnabled,
}: CardProps) {
return (
<StyledCard
cover={
<Cover>
<a href={url}>
<a href={bulkSelectEnabled ? undefined : url}>
Copy link
Member

Choose a reason for hiding this comment

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

can we move this logic up into the renderCard functions? We can make url optional and not pass it down when bulkSelect is enabled, that way this component doesn't need to know about bulk select.

Copy link
Member

Choose a reason for hiding this comment

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

Alternatively, we may just be able to do a

e.preventDefault();
e.stopPropagation();

in the CardWrapper's onClick handler, when bulkSelect is enabled, to prevent events from triggering on the children.

<GradientContainer>
<CardCoverImg
src={imgURL}
Expand Down
1 change: 1 addition & 0 deletions superset-frontend/src/views/CRUD/chart/ChartList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ class ChartList extends React.PureComponent<Props, State> {

return (
<ListViewCard
bulkSelectEnabled={this.state.bulkSelectEnabled}
title={props.slice_name}
url={props.url}
imgURL={props.thumbnail_url ?? ''}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ class DashboardList extends React.PureComponent<Props, State> {

return (
<ListViewCard
bulkSelectEnabled={this.state.bulkSelectEnabled}
title={props.dashboard_title}
titleRight={<Label>{props.published ? 'published' : 'draft'}</Label>}
url={props.url}
Expand Down