Skip to content

Commit

Permalink
Add table controls.
Browse files Browse the repository at this point in the history
  • Loading branch information
codyml committed Jul 22, 2022
1 parent 852c230 commit 3ca3f87
Show file tree
Hide file tree
Showing 5 changed files with 291 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,30 @@ import { PostProcessingRule } from './PostProcessing';
import { JsonObject } from '../../connection';
import { TimeGranularity } from '../../time-format';

export type QueryObjectFilterClause = {
export type BaseQueryObjectFilterClause = {
col: QueryFormColumn;
grain?: TimeGranularity;
isExtra?: boolean;
} & (
| {
op: BinaryOperator;
val: string | number | boolean;
}
| {
op: SetOperator;
val: (string | number | boolean)[];
}
| {
op: UnaryOperator;
}
);
};

export type BinaryQueryObjectFilterClause = BaseQueryObjectFilterClause & {
op: BinaryOperator;
val: string | number | boolean;
};

export type SetQueryObjectFilterClause = BaseQueryObjectFilterClause & {
op: SetOperator;
val: (string | number | boolean)[];
};

export type UnaryQueryObjectFilterClause = BaseQueryObjectFilterClause & {
op: UnaryOperator;
};

export type QueryObjectFilterClause =
| BinaryQueryObjectFilterClause
| SetQueryObjectFilterClause
| UnaryQueryObjectFilterClause;

export type QueryObjectExtras = Partial<{
/** HAVING condition for Druid */
Expand Down
1 change: 1 addition & 0 deletions superset-frontend/src/components/Icons/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ const IconFileNames = [
'plus_solid',
'queued',
'refresh',
'reload',
'running',
'save',
'sql',
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/**
* 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, { useCallback, useMemo } from 'react';
import { Tag } from 'antd';
import {
BinaryQueryObjectFilterClause,
css,
isAdhocColumn,
t,
useTheme,
} from '@superset-ui/core';
import RowCountLabel from 'src/explore/components/RowCountLabel';
import Icons from 'src/components/Icons';

export default function TableControls({
filters,
setFilters,
totalCount,
onReload,
}: {
filters: BinaryQueryObjectFilterClause[];
setFilters: (filters: BinaryQueryObjectFilterClause[]) => void;
totalCount?: number;
loading?: boolean;
onReload: () => void;
}) {
const theme = useTheme();
const filterMap: Record<string, BinaryQueryObjectFilterClause> = useMemo(
() =>
Object.assign(
{},
...filters.map(filter => ({
[isAdhocColumn(filter.col)
? (filter.col.label as string)
: filter.col]: filter,
})),
),
[filters],
);

const removeFilter = useCallback(
colName => {
const updatedFilterMap = { ...filterMap };
delete updatedFilterMap[colName];
setFilters([...Object.values(updatedFilterMap)]);
},
[filterMap, setFilters],
);

const filterTags = useMemo(
() =>
Object.entries(filterMap)
.map(([colName, { val }]) => ({ colName, val }))
.sort((a, b) => a.colName.localeCompare(b.colName)),
[filterMap],
);

return (
<div
css={css`
display: flex;
justify-content: space-between;
padding: ${theme.gridUnit / 2}px 0;
`}
>
<div
css={css`
display: flex;
flex-wrap: wrap;
margin-bottom: -${theme.gridUnit * 4}px;
`}
>
{filterTags.map(({ colName, val }) => (
<Tag
closable
onClose={removeFilter.bind(null, colName)}
key={colName}
css={css`
height: ${theme.gridUnit * 6}px;
display: flex;
align-items: center;
padding: ${theme.gridUnit / 2}px ${theme.gridUnit * 2}px;
margin-right: ${theme.gridUnit * 4}px;
margin-bottom: ${theme.gridUnit * 4}px;
line-height: 1.2;
`}
>
<span
css={css`
margin-right: ${theme.gridUnit}px;
`}
>
{colName}
</span>
<strong>{val}</strong>
</Tag>
))}
</div>
<div
css={css`
display: flex;
align-items: center;
height: min-content;
`}
>
<RowCountLabel rowcount={totalCount} />
<Icons.ReloadOutlined
iconColor={theme.colors.grayscale.light1}
iconSize="l"
aria-label={t('Reload')}
role="button"
onClick={onReload}
/>
</div>
</div>
);
}

0 comments on commit 3ca3f87

Please sign in to comment.