Skip to content

Commit

Permalink
feat: card view bulk select (apache#10607)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lily Kuang authored and Ofeknielsen committed Oct 5, 2020
1 parent 65ed74d commit 3b0728a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 10 deletions.
40 changes: 33 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,44 @@ 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) {
function handleClick(event: React.FormEvent, onClick: any) {
if (bulkSelectEnabled) {
event.preventDefault();
event.stopPropagation();
onClick();
}
}

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={e => handleClick(e, row.toggleRowSelected())}
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
2 changes: 1 addition & 1 deletion superset-frontend/src/components/ListViewCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ const CoverFooterRight = styled.div`

interface CardProps {
title: React.ReactNode;
url: string;
url: string | undefined;
imgURL: string;
imgFallbackURL: string;
description: string;
Expand Down
2 changes: 1 addition & 1 deletion superset-frontend/src/views/CRUD/chart/ChartList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ class ChartList extends React.PureComponent<Props, State> {
return (
<ListViewCard
title={props.slice_name}
url={props.url}
url={this.state.bulkSelectEnabled ? undefined : props.url}
imgURL={props.thumbnail_url ?? ''}
imgFallbackURL={'/static/assets/images/chart-card-fallback.png'}
description={t('Last modified %s', props.changed_on_delta_humanized)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ class DashboardList extends React.PureComponent<Props, State> {
<ListViewCard
title={props.dashboard_title}
titleRight={<Label>{props.published ? 'published' : 'draft'}</Label>}
url={props.url}
url={this.state.bulkSelectEnabled ? undefined : props.url}
imgURL={props.thumbnail_url}
imgFallbackURL="/static/assets/images/dashboard-card-fallback.png"
description={t('Last modified %s', props.changed_on_delta_humanized)}
Expand Down

0 comments on commit 3b0728a

Please sign in to comment.