superset/superset-frontend/src/components/dataViewCommon/TableCollection.tsx

325 lines
7.9 KiB
TypeScript
Raw Normal View History

/**
* 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 from 'react';
import cx from 'classnames';
import { TableInstance } from 'react-table';
import { styled } from '@superset-ui/core';
import Icon from 'src/components/Icon';
interface TableCollectionProps {
getTableProps: (userProps?: any) => any;
getTableBodyProps: (userProps?: any) => any;
prepareRow: TableInstance['prepareRow'];
headerGroups: TableInstance['headerGroups'];
rows: TableInstance['rows'];
columns: TableInstance['column'][];
loading: boolean;
highlightRowId?: number;
}
export const Table = styled.table`
background-color: ${({ theme }) => theme.colors.grayscale.light5};
border-collapse: separate;
border-radius: ${({ theme }) => theme.borderRadius}px;
thead > tr > th {
border: 0;
}
tbody {
tr:first-of-type > td {
border-top: 0;
}
}
th {
background: ${({ theme }) => theme.colors.grayscale.light5};
position: sticky;
top: 0;
&:first-of-type {
padding-left: ${({ theme }) => theme.gridUnit * 4}px;
}
&.xs {
min-width: 25px;
}
&.sm {
min-width: 50px;
}
&.md {
min-width: 75px;
}
&.lg {
min-width: 100px;
}
&.xl {
min-width: 150px;
}
&.xxl {
min-width: 200px;
}
span {
white-space: nowrap;
display: flex;
align-items: center;
line-height: 2;
}
svg {
display: inline-block;
position: relative;
}
}
td {
&.xs {
width: 25px;
}
&.sm {
width: 50px;
}
&.md {
width: 75px;
}
&.lg {
width: 100px;
}
&.xl {
width: 150px;
}
&.xxl {
width: 200px;
}
}
.table-cell-loader {
position: relative;
.loading-bar {
background-color: ${({ theme }) => theme.colors.secondary.light4};
border-radius: 7px;
span {
visibility: hidden;
}
}
&:after {
position: absolute;
transform: translateY(-50%);
top: 50%;
left: 0;
content: '';
display: block;
width: 100%;
height: 48px;
background-image: linear-gradient(
100deg,
rgba(255, 255, 255, 0),
rgba(255, 255, 255, 0.5) 60%,
rgba(255, 255, 255, 0) 80%
);
background-size: 200px 48px;
background-position: -100px 0;
background-repeat: no-repeat;
animation: loading-shimmer 1s infinite;
}
}
.actions {
white-space: nowrap;
min-width: 100px;
svg,
i {
margin-right: 8px;
&:hover {
path {
fill: ${({ theme }) => theme.colors.primary.base};
}
}
}
}
.table-row {
.actions {
opacity: 0;
feat(dashboards): Filter status indicators (#10936) * Initial commit of new filters badge. * refactor applied/rejected filters code * finished filter indicators * filter badge tested * unnecessary imports * formatting and types * fixes * license * code quality tweaks * state management for showing focused filter scope * clean up filter key extraction code * remove unnecessary styles * temp css to demonstrate highlighting * fix focused filter logic * no more color badges * new toys for highlighting dash components (#11144) * tweak style for the filter chart when filter is focused * style: Filters p0 css2 (#11151) * nixing background tweak * src paths * another quick theme color * src paths, adjusting pill icon color, changing icons, showing applied/busted counts * linting stuff * fixing and tweaking tests * show filter indicator when filters are not active * chart title bar cleanup * open the right panel when popover opens * unused import * fix EditableTitle tests * margin on dashboard header * show the chart dropdown menu * fix blur filter breaking dropdowns * style tweak - no pointer events when irrelevant charts are blurred * fix box shadow on filter highlight * it's an array * attempt fixing e2e * style: filters p0 icon churn (#11215) * new filters icon * icon styling * bigger icons in list views * better sizing of table actions and favStars * more icon sizing... * fixing more button size jankiness * linting * Filters performance (#11255) * fixing time filter "ok" button * making unset filter menu collapsible * sort alphabetically * fix highlighting when removing items * try a flex layout (for browser render perf) * more specific transitioning * temp: comment out some code as a test * temp: comment out more code * temp: remove possibly expensive computations from ChartHolder * Revert "temp: comment out some code as a test" This reverts commit 309b880e90f5b1d582ecaec6a866b91abc354094. * Revert "temp: comment out more code" This reverts commit 64c88b2cba7ed995c08bcf258e93a45161b1c0c9. * Revert "temp: remove possibly expensive computations from ChartHolder" This reverts commit 37ce0214f0007386e35f113805a8a9abd291152a. * experiment: upgrade react-select to v3 * Revert "experiment: upgrade react-select to v3" This reverts commit c3972ba486a9e4888ca943ce93d1db47db514140. * fix the damn problem * remove code used for testing purposes * awful hack to avoid adding a class to a container * approaching infinity... and not beyond! * fix ref forwarding * add theme to tests as necessary * fix(extra-filters): add logic for identifying applied extra filters (#11325) * fix: use dashboard id for stable cache key (#11293) * fix: button translations missing (#11187) * button translations missing * blank space before text * feat: update time_compare description and choices (#11294) * feat: update time_compare description and choices * Update sections.jsx * fix(extra-filters): add logic for identifying applied extra filters * lint Co-authored-by: Jesse Yang <jesse.yang@airbnb.com> Co-authored-by: rubenSastre <ruben.sastre@decathlon.com> Co-authored-by: Erik Ritter <erik.ritter@airbnb.com> * address design feedback * slight tweak to panel logic, keep panels open that user has opened * rearrange code to be more graceful * fix: bump superset-ui/core (#11385) * use is_dttm instead of is_temporal * types, names * only show unset filter panel if there are unset filters * fix highlighting the filter control * fix filterbox layout * translations * fix cypress * actually add the test attribute * Update superset-frontend/src/dashboard/components/DashboardBuilder.jsx Co-authored-by: Evan Rusackas <evan@preset.io> * Update superset-frontend/src/dashboard/components/DashboardBuilder.jsx Co-authored-by: Evan Rusackas <evan@preset.io> * formatting * add link comment to hack * Update superset-frontend/src/dashboard/components/gridComponents/ChartHolder.jsx Co-authored-by: Evan Rusackas <evan@preset.io> * stop importing lodash * Update superset-frontend/src/dashboard/components/gridComponents/ChartHolder.jsx Co-authored-by: Evan Rusackas <evan@preset.io> * Update superset-frontend/src/dashboard/components/FiltersBadge/Styles.tsx Co-authored-by: Evan Rusackas <evan@preset.io> * Update superset-frontend/src/dashboard/components/FiltersBadge/Styles.tsx Co-authored-by: Evan Rusackas <evan@preset.io> * Update superset-frontend/src/dashboard/components/FiltersBadge/Styles.tsx Co-authored-by: Evan Rusackas <evan@preset.io> * Update superset-frontend/src/dashboard/components/FiltersBadge/Styles.tsx Co-authored-by: Evan Rusackas <evan@preset.io> * skip broken test * Update superset-frontend/src/dashboard/components/FiltersBadge/Styles.tsx Co-authored-by: Evan Rusackas <evan@preset.io> * Update superset-frontend/src/dashboard/components/FiltersBadge/Styles.tsx Co-authored-by: Evan Rusackas <evan@preset.io> * adjust colors of titles * linting * no indicators when chart is loading * support all time fields * fix lock file Co-authored-by: Natalie Ruhe <natalie@preset.io> Co-authored-by: Evan Rusackas <evan@preset.io> Co-authored-by: Ville Brofeldt <33317356+villebro@users.noreply.github.com> Co-authored-by: Jesse Yang <jesse.yang@airbnb.com> Co-authored-by: rubenSastre <ruben.sastre@decathlon.com> Co-authored-by: Erik Ritter <erik.ritter@airbnb.com> Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com>
2020-10-28 18:46:24 -04:00
font-size: ${({ theme }) => theme.typography.sizes.xl}px;
}
&:hover {
background-color: ${({ theme }) => theme.colors.secondary.light5};
.actions {
opacity: 1;
transition: opacity ease-in ${({ theme }) => theme.transitionTiming}s;
}
}
}
.table-row-selected {
background-color: ${({ theme }) => theme.colors.secondary.light4};
&:hover {
background-color: ${({ theme }) => theme.colors.secondary.light4};
}
}
.table-cell {
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
max-width: 300px;
line-height: 1;
vertical-align: middle;
&:first-of-type {
padding-left: ${({ theme }) => theme.gridUnit * 4}px;
}
}
@keyframes loading-shimmer {
40% {
background-position: 100% 0;
}
100% {
background-position: 100% 0;
}
}
`;
Table.displayName = 'table';
export default React.memo(
({
getTableProps,
getTableBodyProps,
prepareRow,
headerGroups,
columns,
rows,
loading,
highlightRowId,
}: TableCollectionProps) => (
<Table
{...getTableProps()}
className="table table-hover"
data-test="listview-table"
>
<thead>
{headerGroups.map(headerGroup => (
<tr {...headerGroup.getHeaderGroupProps()}>
{headerGroup.headers.map(column => {
let sortIcon = <Icon name="sort" />;
if (column.isSorted && column.isSortedDesc) {
sortIcon = <Icon name="sort-desc" />;
} else if (column.isSorted && !column.isSortedDesc) {
sortIcon = <Icon name="sort-asc" />;
}
return column.hidden ? null : (
<th
{...column.getHeaderProps(
column.canSort ? column.getSortByToggleProps() : {},
)}
data-test="sort-header"
className={cx({
[column.size || '']: column.size,
})}
>
<span>
{column.render('Header')}
{column.canSort && sortIcon}
</span>
</th>
);
})}
</tr>
))}
</thead>
<tbody {...getTableBodyProps()}>
{loading &&
rows.length === 0 &&
[...new Array(25)].map((_, i) => (
<tr key={i}>
{columns.map((column, i2) => {
if (column.hidden) return null;
return (
<td
key={i2}
className={cx('table-cell', {
'table-cell-loader': loading,
[column.size || '']: column.size,
})}
>
2021-03-11 17:08:16 -05:00
<span className="loading-bar" role="progressbar">
<span>LOADING</span>
</span>
</td>
);
})}
</tr>
))}
{rows.length > 0 &&
rows.map(row => {
prepareRow(row);
// @ts-ignore
const rowId = row.original.id;
return (
<tr
data-test="table-row"
{...row.getRowProps()}
className={cx('table-row', {
'table-row-selected':
row.isSelected ||
(typeof rowId !== 'undefined' && rowId === highlightRowId),
})}
>
{row.cells.map(cell => {
if (cell.column.hidden) return null;
const columnCellProps = cell.column.cellProps || {};
return (
<td
data-test="table-row-cell"
className={cx('table-cell', {
'table-cell-loader': loading,
[cell.column.size || '']: cell.column.size,
})}
{...cell.getCellProps()}
{...columnCellProps}
>
2021-03-11 17:08:16 -05:00
<span
className={cx({ 'loading-bar': loading })}
role={loading ? 'progressbar' : undefined}
>
<span data-test="cell-text">{cell.render('Cell')}</span>
</span>
</td>
);
})}
</tr>
);
})}
</tbody>
</Table>
),
);