revert(data-grid): remove configurable default sorting
This commit is contained in:
1 parent
2e5b439c8a
commit
ed6192842d
24 files changed
+17
-720
No files matched your search
@@ -1,46 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { resolveDataGridHeaderSortAction } from "@/lib/dataGrid/dataGridSort";
|
||||
|
||||
describe("resolveDataGridHeaderSortAction", () => {
|
||||
it("keeps the existing menu action when quick sorting is disabled", () => {
|
||||
expect(
|
||||
resolveDataGridHeaderSortAction({
|
||||
enabled: false,
|
||||
configuredDirection: "desc",
|
||||
configuredMode: "database",
|
||||
currentColumnSorted: false,
|
||||
currentDirection: "asc",
|
||||
currentMode: "local",
|
||||
}),
|
||||
).toEqual({ kind: "menu" });
|
||||
});
|
||||
|
||||
it.each([
|
||||
["local", "asc"],
|
||||
["database", "desc"],
|
||||
] as const)("uses the explicit %s/%s preference for an unsorted column", (configuredMode, configuredDirection) => {
|
||||
expect(
|
||||
resolveDataGridHeaderSortAction({
|
||||
enabled: true,
|
||||
configuredDirection,
|
||||
configuredMode,
|
||||
currentColumnSorted: false,
|
||||
currentDirection: "asc",
|
||||
currentMode: "database",
|
||||
}),
|
||||
).toEqual({ kind: "sort", direction: configuredDirection, mode: configuredMode });
|
||||
});
|
||||
|
||||
it("toggles an existing sort while preserving its scope", () => {
|
||||
expect(
|
||||
resolveDataGridHeaderSortAction({
|
||||
enabled: true,
|
||||
configuredDirection: "asc",
|
||||
configuredMode: "database",
|
||||
currentColumnSorted: true,
|
||||
currentDirection: "asc",
|
||||
currentMode: "local",
|
||||
}),
|
||||
).toEqual({ kind: "sort", direction: "desc", mode: "local" });
|
||||
});
|
||||
});
|
||||
@@ -1,48 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildOpenTableDefaultSort, buildPrimaryKeyOrderBy } from "@/lib/table/tableDefaultSort";
|
||||
|
||||
describe("buildPrimaryKeyOrderBy", () => {
|
||||
it.each([
|
||||
["postgres", '"Tenant" ASC, "Order" ASC'],
|
||||
["mysql", "`Tenant` ASC, `Order` ASC"],
|
||||
["sqlserver", "[Tenant] ASC, [Order] ASC"],
|
||||
["oracle", '"Tenant" ASC, "Order" ASC'],
|
||||
["neo4j", "n.`Tenant` ASC, n.`Order` ASC"],
|
||||
] as const)("quotes composite keys for %s", (databaseType, expected) => {
|
||||
expect(
|
||||
buildPrimaryKeyOrderBy({
|
||||
databaseType,
|
||||
primaryKeys: ["Tenant", "Order"],
|
||||
direction: "asc",
|
||||
}),
|
||||
).toBe(expected);
|
||||
});
|
||||
|
||||
it("quotes every mixed-case or reserved identifier and applies descending to every key", () => {
|
||||
expect(
|
||||
buildPrimaryKeyOrderBy({
|
||||
databaseType: "postgres",
|
||||
primaryKeys: ['Tenant"Id', "select"],
|
||||
direction: "desc",
|
||||
}),
|
||||
).toBe('"Tenant""Id" DESC, "select" DESC');
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildOpenTableDefaultSort", () => {
|
||||
it("keeps metadata order for all primary-key columns while using the first key as the grid indicator", () => {
|
||||
expect(
|
||||
buildOpenTableDefaultSort({
|
||||
mode: "primary-key-desc",
|
||||
databaseType: "postgres",
|
||||
primaryKeys: ["tenant_id", "record_id"],
|
||||
columns: ["record_id", "tenant_id", "value"],
|
||||
}),
|
||||
).toEqual({
|
||||
column: "tenant_id",
|
||||
columnIndex: 1,
|
||||
direction: "desc",
|
||||
orderBy: '"tenant_id" DESC, "record_id" DESC',
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -34,8 +34,6 @@ export interface SavedOpenTab {
|
||||
resultSortDirection?: QueryTab["resultSortDirection"];
|
||||
resultSortMode?: QueryTab["resultSortMode"];
|
||||
orderByInput?: string;
|
||||
openTableDefaultSortApplied?: boolean;
|
||||
openTableDefaultSortOrderBy?: string;
|
||||
resultPageLimit?: number;
|
||||
resultPageOffset?: number;
|
||||
whereInput?: string;
|
||||
@@ -104,8 +102,6 @@ export function serializeOpenTabs(tabs: QueryTab[]): SavedOpenTab[] {
|
||||
...(tab.resultSortDirection !== undefined ? { resultSortDirection: tab.resultSortDirection } : {}),
|
||||
...(tab.resultSortMode !== undefined ? { resultSortMode: tab.resultSortMode } : {}),
|
||||
...(tab.orderByInput !== undefined ? { orderByInput: tab.orderByInput } : {}),
|
||||
...(tab.openTableDefaultSortApplied !== undefined ? { openTableDefaultSortApplied: tab.openTableDefaultSortApplied } : {}),
|
||||
...(tab.openTableDefaultSortOrderBy !== undefined ? { openTableDefaultSortOrderBy: tab.openTableDefaultSortOrderBy } : {}),
|
||||
...(tab.resultPageLimit !== undefined ? { resultPageLimit: tab.resultPageLimit } : {}),
|
||||
...(tab.resultPageOffset !== undefined ? { resultPageOffset: tab.resultPageOffset } : {}),
|
||||
...(tab.whereInput !== undefined ? { whereInput: tab.whereInput } : {}),
|
||||
|
||||
@@ -7,24 +7,6 @@ export interface DataGridSortState {
|
||||
direction: DataGridSortDirection;
|
||||
}
|
||||
|
||||
export type DataGridHeaderSortAction = { kind: "menu" } | { kind: "sort"; direction: DataGridSortDirection; mode: DataGridSortMode };
|
||||
|
||||
export function resolveDataGridHeaderSortAction(options: { enabled: boolean; configuredDirection: DataGridSortDirection; configuredMode: DataGridSortMode; currentDirection: DataGridSortDirection; currentMode: DataGridSortMode; currentColumnSorted: boolean }): DataGridHeaderSortAction {
|
||||
if (!options.enabled) return { kind: "menu" };
|
||||
if (options.currentColumnSorted) {
|
||||
return {
|
||||
kind: "sort",
|
||||
direction: options.currentDirection === "asc" ? "desc" : "asc",
|
||||
mode: options.currentMode,
|
||||
};
|
||||
}
|
||||
return {
|
||||
kind: "sort",
|
||||
direction: options.configuredDirection,
|
||||
mode: options.configuredMode,
|
||||
};
|
||||
}
|
||||
|
||||
export function nextDataGridSortState(current: DataGridSortState, column: string, columnIndex: number): DataGridSortState {
|
||||
if (current.column === column && current.columnIndex === columnIndex) {
|
||||
if (current.direction === "asc") {
|
||||
|
||||
@@ -30,10 +30,6 @@ export const EDITOR_SETTINGS_DRAFT_KEYS = [
|
||||
"compactColumnHeaderActions",
|
||||
"dataGridQuickEntry",
|
||||
"dataGridAutoTransposeSingleRow",
|
||||
"openTableDefaultSortMode",
|
||||
"dataGridQuickSortEnabled",
|
||||
"dataGridQuickSortMode",
|
||||
"dataGridQuickSortDirection",
|
||||
"tableOpenPageSize",
|
||||
"infiniteScroll",
|
||||
"infiniteScrollMaxRows",
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
import type { OpenTableDefaultSortMode } from "@/stores/settingsStore";
|
||||
import type { DatabaseType, QueryTab } from "@/types/database";
|
||||
import { quoteTableDataIdentifier } from "@/lib/table/tableSelectSql";
|
||||
|
||||
export type TableDefaultSortDirection = "asc" | "desc";
|
||||
|
||||
export interface OpenTableDefaultSort {
|
||||
column: string;
|
||||
columnIndex: number;
|
||||
direction: TableDefaultSortDirection;
|
||||
orderBy: string;
|
||||
}
|
||||
|
||||
export function buildPrimaryKeyOrderBy(options: { databaseType?: DatabaseType; identifierQuote?: string; primaryKeys: string[]; direction: TableDefaultSortDirection }): string | undefined {
|
||||
if (options.primaryKeys.length === 0) return undefined;
|
||||
const direction = options.direction.toUpperCase();
|
||||
const prefix = options.databaseType === "neo4j" ? "n." : "";
|
||||
return options.primaryKeys.map((primaryKey) => `${prefix}${quoteTableDataIdentifier(options.databaseType, primaryKey, options.identifierQuote)} ${direction}`).join(", ");
|
||||
}
|
||||
|
||||
export function buildOpenTableDefaultSort(options: { mode: OpenTableDefaultSortMode; databaseType?: DatabaseType; identifierQuote?: string; primaryKeys: string[]; columns: string[] }): OpenTableDefaultSort | undefined {
|
||||
if (options.mode === "none") return undefined;
|
||||
const column = options.primaryKeys[0];
|
||||
if (!column) return undefined;
|
||||
const direction = options.mode === "primary-key-desc" ? "desc" : "asc";
|
||||
const orderBy = buildPrimaryKeyOrderBy({
|
||||
databaseType: options.databaseType,
|
||||
identifierQuote: options.identifierQuote,
|
||||
primaryKeys: options.primaryKeys,
|
||||
direction,
|
||||
});
|
||||
if (!orderBy) return undefined;
|
||||
return {
|
||||
column,
|
||||
columnIndex: options.columns.indexOf(column),
|
||||
direction,
|
||||
orderBy,
|
||||
};
|
||||
}
|
||||
|
||||
export function shouldApplyOpenTableDefaultSort(tab: QueryTab, orderBy?: string): boolean {
|
||||
const trimmedOrderBy = orderBy?.trim();
|
||||
if (tab.openTableDefaultSortApplied) {
|
||||
const defaultOrderBy = tab.openTableDefaultSortOrderBy?.trim();
|
||||
return !trimmedOrderBy || (!!defaultOrderBy && trimmedOrderBy === defaultOrderBy);
|
||||
}
|
||||
return !trimmedOrderBy && !tab.resultSortColumn && !tab.resultSortDirection && !tab.orderByInput?.trim();
|
||||
}
|
||||
|
||||
export function applyOpenTableDefaultSortState(tab: QueryTab, sort: OpenTableDefaultSort | undefined): void {
|
||||
if (!sort) {
|
||||
tab.resultSortColumn = undefined;
|
||||
tab.resultSortColumnIndex = undefined;
|
||||
tab.resultSortDirection = undefined;
|
||||
tab.resultSortMode = undefined;
|
||||
tab.orderByInput = undefined;
|
||||
tab.openTableDefaultSortApplied = undefined;
|
||||
tab.openTableDefaultSortOrderBy = undefined;
|
||||
return;
|
||||
}
|
||||
tab.resultSortColumn = sort.column;
|
||||
tab.resultSortColumnIndex = sort.columnIndex >= 0 ? sort.columnIndex : undefined;
|
||||
tab.resultSortDirection = sort.direction;
|
||||
tab.resultSortMode = "database";
|
||||
tab.orderByInput = sort.orderBy;
|
||||
tab.openTableDefaultSortApplied = true;
|
||||
tab.openTableDefaultSortOrderBy = sort.orderBy;
|
||||
}
|
||||
|
||||
export function clearOpenTableDefaultSortMarker(tab: QueryTab): void {
|
||||
tab.openTableDefaultSortApplied = undefined;
|
||||
tab.openTableDefaultSortOrderBy = undefined;
|
||||
}
|
||||
Reference in new issue
Block a user