Skip to content
Open
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
38 changes: 31 additions & 7 deletions packages/web-ui/src/components/ui/DataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ import {
DATA_GRID_MIN_COLUMN_WIDTH,
DATA_GRID_MAX_COLUMN_WIDTH,
formatCellValue,
getColumnSortState,
getColumnSortInfo,
calculateSelectionRange,
toggleSetValue,
getResultValueType,
Expand Down Expand Up @@ -293,7 +293,7 @@ interface DataGridProps {
csvDelimiter?: string;
csvIncludeHeaders?: boolean;
sortClause?: string;
onSort?: (colName: string) => void;
onSort?: (colName: string, options: {additive: boolean}) => void;
readonly?: boolean;
/**
* Total rows in the full result set when known (server-side pagination).
Expand Down Expand Up @@ -1868,6 +1868,11 @@ export const DataGrid = React.memo(function DataGrid({

const coreRowModel = useMemo(() => getCoreRowModel(), []);

const sortClauseInfo = useMemo(
() => getColumnSortInfo(columns, sortClause),
[columns, sortClause],
);

const tableColumns = React.useMemo(
() =>
columns.map((colName, index) =>
Expand All @@ -1877,7 +1882,8 @@ export const DataGrid = React.memo(function DataGrid({
// return columns with an empty name, which would otherwise crash the grid.
id: colName !== '' ? colName : `__unnamed_${index}__`,
header: () => {
const sortState = getColumnSortState(colName, sortClause);
const columnSortInfo = sortClauseInfo.byColumn.get(colName);
const sortState = columnSortInfo?.direction ?? null;
const displaySortState: 'none' | 'asc' | 'desc' = sortState ?? 'none';
const sortAction = getSortButtonAction(
displaySortState,
Expand All @@ -1889,6 +1895,14 @@ export const DataGrid = React.memo(function DataGrid({
: sortAction === 'desc'
? t('dataGrid.sortByDesc', {col: colName})
: t('dataGrid.clearSort');
const sortPriority = columnSortInfo?.priority ?? null;
const priorityLabel =
sortPriority !== null && sortClauseInfo.termCount >= 2
? t('dataGrid.sortPriority', {priority: sortPriority})
: null;
const accessibleSortButtonLabel = priorityLabel
? `${sortButtonLabel}, ${priorityLabel}`
: sortButtonLabel;
// Column data type for the DataGrip-style header hover tooltip.
// Only populated when column metadata is present (i.e. table
// browse), not for arbitrary query results.
Expand Down Expand Up @@ -1929,16 +1943,18 @@ export const DataGrid = React.memo(function DataGrid({
<button
type="button"
className="flex shrink-0 flex-col items-center justify-center cursor-pointer"
aria-label={sortButtonLabel}
aria-label={accessibleSortButtonLabel}
title={
// Suppress the native sort-hint title while the type
// tooltip is shown, to avoid two overlapping tooltips.
hasMetadataTooltip ? undefined : sortButtonLabel
hasMetadataTooltip
? undefined
: accessibleSortButtonLabel
}
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
onSort(colName);
onSort(colName, {additive: e.shiftKey});
}}
>
{displaySortState === 'asc' && (
Expand All @@ -1953,6 +1969,14 @@ export const DataGrid = React.memo(function DataGrid({
className="text-secondary/60 opacity-50 group-hover/header:opacity-100 transition-opacity"
/>
)}
{priorityLabel && (
<span
aria-hidden="true"
className="text-xs leading-none text-muted"
>
{sortPriority}
</span>
)}
</button>
)}
{hasMetadataTooltip && (
Expand Down Expand Up @@ -1982,7 +2006,7 @@ export const DataGrid = React.memo(function DataGrid({
columns,
columnHelper,
t,
sortClause,
sortClauseInfo,
defaultSortDirection,
onSort,
columnTypeMap,
Expand Down
1 change: 1 addition & 0 deletions packages/web-ui/src/i18n/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -1779,6 +1779,7 @@
"sortByAsc": "Nach {{col}} ASC sortieren",
"sortByDesc": "Nach {{col}} DESC sortieren",
"clearSort": "Sortierung löschen",
"sortPriority": "Sortierpriorität {{priority}}",
"copyCell": "Zelle kopieren",
"copyRow": "Zeile kopieren",
"selectAll": "Alle auswählen",
Expand Down
1 change: 1 addition & 0 deletions packages/web-ui/src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1852,6 +1852,7 @@
"sortByAsc": "Sort by {{col}} ASC",
"sortByDesc": "Sort by {{col}} DESC",
"clearSort": "Clear sort",
"sortPriority": "Sort priority {{priority}}",
"copyCell": "Copy Cell",
"copyRow": "Copy Row",
"selectAll": "Select All",
Expand Down
1 change: 1 addition & 0 deletions packages/web-ui/src/i18n/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -1810,6 +1810,7 @@
"sortByAsc": "Ordenar por {{col}} ASC",
"sortByDesc": "Ordenar por {{col}} DESC",
"clearSort": "Quitar ordenamiento",
"sortPriority": "Prioridad de orden {{priority}}",
"copyCell": "Copiar Celda",
"copyRow": "Copiar Fila",
"selectAll": "Seleccionar Todo",
Expand Down
1 change: 1 addition & 0 deletions packages/web-ui/src/i18n/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1819,6 +1819,7 @@
"sortByAsc": "Trier par {{col}} ASC",
"sortByDesc": "Trier par {{col}} DESC",
"clearSort": "Effacer le tri",
"sortPriority": "Priorité de tri {{priority}}",
"copyCell": "Copier la cellule",
"copyRow": "Copier la ligne",
"selectAll": "Tout sélectionner",
Expand Down
1 change: 1 addition & 0 deletions packages/web-ui/src/i18n/locales/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -1846,6 +1846,7 @@
"sortByAsc": "Ordina per {{col}} ASC",
"sortByDesc": "Ordina per {{col}} DESC",
"clearSort": "Rimuovi ordinamento",
"sortPriority": "Priorità di ordinamento {{priority}}",
"copyCell": "Copia cella",
"copyRow": "Copia riga",
"selectAll": "Seleziona Tutti",
Expand Down
1 change: 1 addition & 0 deletions packages/web-ui/src/i18n/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -1792,6 +1792,7 @@
"sortByAsc": "{{col}} を昇順で並べ替え",
"sortByDesc": "{{col}} を降順で並べ替え",
"clearSort": "並べ替えを解除",
"sortPriority": "並べ替え優先順位 {{priority}}",
"copyCell": "セルをコピー",
"copyRow": "行をコピー",
"selectAll": "すべて選択",
Expand Down
1 change: 1 addition & 0 deletions packages/web-ui/src/i18n/locales/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -1744,6 +1744,7 @@
"sortByAsc": "{{col}} 오름차순 정렬",
"sortByDesc": "{{col}} 내림차순 정렬",
"clearSort": "정렬 해제",
"sortPriority": "정렬 우선순위 {{priority}}",
"copyCell": "셀 복사",
"copyRow": "행 복사",
"selectAll": "전체 선택",
Expand Down
1 change: 1 addition & 0 deletions packages/web-ui/src/i18n/locales/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -1848,6 +1848,7 @@
"sortByAsc": "Ordenar por {{col}} ASC",
"sortByDesc": "Ordenar por {{col}} DESC",
"clearSort": "Limpar ordenação",
"sortPriority": "Prioridade de ordenação {{priority}}",
"copyCell": "Copiar Célula",
"copyRow": "Copiar Linha",
"selectAll": "Selecionar Tudo",
Expand Down
1 change: 1 addition & 0 deletions packages/web-ui/src/i18n/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -1783,6 +1783,7 @@
"sortByAsc": "Сортировать по {{col}} ASC",
"sortByDesc": "Сортировать по {{col}} DESC",
"clearSort": "Сбросить сортировку",
"sortPriority": "Приоритет сортировки {{priority}}",
"copyCell": "Копировать ячейку",
"copyRow": "Копировать строку",
"selectAll": "Выбрать все",
Expand Down
1 change: 1 addition & 0 deletions packages/web-ui/src/i18n/locales/tl.json
Original file line number Diff line number Diff line change
Expand Up @@ -1811,6 +1811,7 @@
"sortByAsc": "I-sort ang {{col}} ASC",
"sortByDesc": "I-sort ang {{col}} DESC",
"clearSort": "Alisin ang sort",
"sortPriority": "Priyoridad ng pag-uuri {{priority}}",
"copyCell": "Kopyahin ang Cell",
"copyRow": "Kopyahin ang Row",
"selectAll": "Piliin Lahat",
Expand Down
1 change: 1 addition & 0 deletions packages/web-ui/src/i18n/locales/vi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1835,6 +1835,7 @@
"sortByAsc": "Sắp xếp theo {{col}} tăng dần",
"sortByDesc": "Sắp xếp theo {{col}} giảm dần",
"clearSort": "Bỏ sắp xếp",
"sortPriority": "Ưu tiên sắp xếp {{priority}}",
"copyCell": "Sao chép ô",
"copyRow": "Sao chép dòng",
"selectAll": "Chọn tất cả",
Expand Down
1 change: 1 addition & 0 deletions packages/web-ui/src/i18n/locales/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -1857,6 +1857,7 @@
"sortByAsc": "按 {{col}} 升序排序",
"sortByDesc": "按 {{col}} 降序排序",
"clearSort": "清除排序",
"sortPriority": "排序優先級 {{priority}}",
"copyCell": "複製儲存格",
"copyRow": "複製列",
"selectAll": "全選",
Expand Down
1 change: 1 addition & 0 deletions packages/web-ui/src/i18n/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -1750,6 +1750,7 @@
"sortByAsc": "按 {{col}} 升序排序",
"sortByDesc": "按 {{col}} 降序排序",
"clearSort": "清除排序",
"sortPriority": "排序优先级 {{priority}}",
"copyCell": "复制单元格",
"copyRow": "复制行",
"selectAll": "全选",
Expand Down
8 changes: 4 additions & 4 deletions packages/web-ui/src/pages/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
getLoadedRowsExportLimit,
type ResultExportFormat,
} from '@/utils/resultExport';
import {serializePkKey, buildPkMap} from '@/utils/dataGrid';
import {serializePkKey, buildPkMap, updateSortClause} from '@/utils/dataGrid';
import {
createGridHistory,
recordGridEdit,
Expand Down Expand Up @@ -262,7 +262,6 @@ import {
type ColumnStatsSupport,
type PluginColumnStatsFetcher,
} from '@/utils/columnStats';
import {getNextSortClause} from '@/utils/tableToolbar';
import {clampTabGap, getAdjacentTabGap} from '@/utils/tabDnd';
import {getBulkClosedTabIds} from '@/utils/tabPins';
import {
Expand Down Expand Up @@ -3626,14 +3625,15 @@ export const Editor = ({commandScopeId}: EditorProps) => {
);

const handleSort = useCallback(
(colName: string) => {
(colName: string, {additive}: {additive: boolean}) => {
if (!activeTab) return;

const currentSort = activeTab.sortClause || '';
const defaultDir = settings.defaultSortDirection ?? 'asc';
const newSort = getNextSortClause(
const newSort = updateSortClause(
currentSort,
colName,
additive,
defaultDir,
activeCapabilities ?? activeDriver,
);
Expand Down
Loading