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: add button to sort columns in view table UI #1187

Merged
merged 2 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.DataTableViewColumn {
.DataTableViewSearchBar {
display: flex;
background-color: var(--bg-light);
border-radius: var(--border-radius-sm);

> .SearchBar {
flex: 1
}

> .OrderByButton {
margin-right: 8px;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import { IDataColumn, IDataTable } from 'const/metastore';
import { Nullable } from 'lib/typescript';
import { Loading } from 'ui/Loading/Loading';
import { SearchBar } from 'ui/SearchBar/SearchBar';
import { OrderByButton } from 'ui/OrderByButton/OrderByButton';

import { DataTableColumnCard } from './DataTableColumnCard';
import './DataTableViewColumn.scss';

export interface IDataTableViewColumnProps {
table: IDataTable;
Expand All @@ -29,6 +31,8 @@ export const DataTableViewColumn: React.FunctionComponent<
onEditColumnDescriptionRedirect,
}) => {
const [filterString, setFilterString] = React.useState('');
const [orderColumnsBy, setOrdeColumnsBy] = React.useState(true);
const [orderBoardBy, setOrderBoardBy] = React.useState(false);

const filteredColumns = React.useMemo(() => {
const filteredCols = tableColumns.filter((column) =>
Expand All @@ -39,25 +43,51 @@ export const DataTableViewColumn: React.FunctionComponent<
if (numberOfRows != null) {
filteredCols.splice(numberOfRows);
}
if (orderBoardBy) {
filteredCols.sort(
(a, b) =>
(a.name.toLowerCase() > b.name.toLowerCase() ? 1 : -1) *
(orderColumnsBy ? 1 : -1)
);
}
return filteredCols;
}, [tableColumns, filterString, numberOfRows]);
}, [
tableColumns,
filterString,
numberOfRows,
orderColumnsBy,
orderBoardBy,
]);

if (!table || !tableColumns) {
return <Loading />;
}

const filterDOM = (
<SearchBar
value={filterString}
onSearch={(s) => setFilterString(s)}
isSearching={false}
placeholder={`Find Columns`}
hasIcon
autoFocus
className="mb8"
const sortButton = (
<OrderByButton
asc={orderColumnsBy}
hideAscToggle={!orderBoardBy}
onAscToggle={() => setOrdeColumnsBy((v) => !v)}
orderByField="name"
orderByFieldSymbol={orderBoardBy ? 'Aa' : 'Default'}
onOrderByFieldToggle={() => setOrderBoardBy((v) => !v)}
/>
);

const filterDOM = (
<div className="DataTableViewSearchBar">
<SearchBar
value={filterString}
onSearch={(s) => setFilterString(s)}
isSearching={false}
placeholder={`Find Columns`}
autoFocus
transparent
/>
{sortButton}
</div>
);

const columnDOM = filteredColumns.map((col) => (
<DataTableColumnCard
column={col}
Expand Down
7 changes: 5 additions & 2 deletions querybook/webapp/ui/OrderByButton/OrderByButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React, { useMemo } from 'react';

import NOOP from 'lib/utils/noop';
import { TextToggleButton } from 'ui/Button/TextToggleButton';
import { TooltipDirection } from 'const/tooltip';

import './OrderByButton.scss';

Expand All @@ -23,6 +24,7 @@ export interface ISortButtonProps {
orderByFieldSymbol?: string;
className?: string;
hideAscToggle?: boolean;
toolTipPos?: TooltipDirection;

onOrderByFieldToggle?: () => void;
onAscToggle?: () => void;
Expand All @@ -34,6 +36,7 @@ export const OrderByButton: React.FC<ISortButtonProps> = ({
orderByFieldSymbol,
className,
hideAscToggle,
toolTipPos = 'left',

onOrderByFieldToggle = NOOP,
onAscToggle = NOOP,
Expand All @@ -50,15 +53,15 @@ export const OrderByButton: React.FC<ISortButtonProps> = ({
value={false}
onChange={onAscToggle}
tooltip={asc ? 'Ascending' : 'Descending'}
tooltipPos="left"
tooltipPos={toolTipPos}
text={asc ? '↑' : '↓'}
/>
)}
<TextToggleButton
value={false}
onChange={onOrderByFieldToggle}
tooltip={`Order by ${orderByField}`}
tooltipPos="left"
tooltipPos={toolTipPos}
text={buttonSymbol}
/>
</span>
Expand Down