mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-11-30 12:03:59 +01:00
Sort Yaak Proxy's custom columns, and complete Add Column's field alone
A sort key can now name a header or query parameter column (`field:header.x-cache`). The database sorts it by the value the column shows, read from the stored headers or URL with the name bound as a parameter, and the app's in-memory sort places live flows the same way. Custom column headers sort on click and Option-click and their menus' sort items work; the sort is kept with the columns and removing a column drops it from the sort. The Add Column field completes `@` and the paths a column accepts, with no colon and no values, opens its menu on focus, normalises a pasted term, and says why a path cannot be added. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b5951b36ae
commit
e870604607
11 files changed
+629
-86
No files matched your search
@@ -1,5 +1,33 @@
|
||||
import { describe, expect, test } from "vite-plus/test";
|
||||
import { pathsAt } from "./extension";
|
||||
import type { Completion } from "@yaakapp-internal/query";
|
||||
import { fieldReferences, pathsAt } from "./extension";
|
||||
|
||||
describe("fieldReferences", () => {
|
||||
const item = (insert: string, kind: Completion["kind"] = "field"): Completion => ({
|
||||
label: insert,
|
||||
insert,
|
||||
kind,
|
||||
info: null,
|
||||
example: null,
|
||||
reopen: true,
|
||||
});
|
||||
const refs = (items: Completion[]) => fieldReferences(items).map((i) => [i.insert, i.reopen]);
|
||||
|
||||
test("ends a field or a map's key with no colon, and does not open again", () => {
|
||||
expect(refs([item("@req.header.user-agent:"), item("@host:")])).toEqual([
|
||||
["@req.header.user-agent", false],
|
||||
["@host", false],
|
||||
]);
|
||||
});
|
||||
|
||||
test("opens again after a map, for its key", () => {
|
||||
expect(refs([item("@header.")])).toEqual([["@header.", true]]);
|
||||
});
|
||||
|
||||
test("never offers values", () => {
|
||||
expect(refs([item("Mozilla/5.0", "value"), item("@query.")])).toEqual([["@query.", true]]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("pathsAt", () => {
|
||||
const at = (text: string) => pathsAt(text, text.length);
|
||||
|
||||
@@ -7,7 +7,7 @@ import type { DecorationSet, ViewUpdate } from "@codemirror/view";
|
||||
import { Decoration, EditorView, ViewPlugin } from "@codemirror/view";
|
||||
import type { Tag } from "@lezer/highlight";
|
||||
import { tags as t } from "@lezer/highlight";
|
||||
import type { Schema, TokenKind } from "@yaakapp-internal/query";
|
||||
import type { Completion as QueryCompletion, Schema, TokenKind } from "@yaakapp-internal/query";
|
||||
import { queryCompletions, queryTokens } from "@yaakapp-internal/query";
|
||||
|
||||
/** A term the search cannot run, to underline: `from` and `to` count UTF-16 units */
|
||||
@@ -36,6 +36,11 @@ export interface QueryFilterOptions {
|
||||
moreCompletions?: (typed: string) => Completion[];
|
||||
/** The terms of a query the search cannot run, underlined as typing settles */
|
||||
problems?: (text: string) => Promise<QueryProblem[]>;
|
||||
/**
|
||||
* Completes a reference to a field, `@header.x-request-id`, rather than a term: no colon
|
||||
* after the field and no values, so choosing a field ends it, as a map's key does
|
||||
*/
|
||||
fieldsOnly?: boolean;
|
||||
}
|
||||
|
||||
const tokenTags: Record<TokenKind, Tag | null> = {
|
||||
@@ -116,7 +121,26 @@ function infoOf(info: string | null, example: string | null): Completion["info"]
|
||||
};
|
||||
}
|
||||
|
||||
function completionSource({ schema, values, loadValues, moreCompletions }: QueryFilterOptions) {
|
||||
/**
|
||||
* The engine's completions as references to fields: fields alone, inserted without the colon a
|
||||
* term's value follows, opening again only after a map, for its key
|
||||
*/
|
||||
export function fieldReferences(items: QueryCompletion[]): QueryCompletion[] {
|
||||
return items
|
||||
.filter((item) => item.kind === "field")
|
||||
.map((item) => {
|
||||
const insert = item.insert.replace(/:$/, "");
|
||||
return { ...item, insert, reopen: insert.endsWith(".") };
|
||||
});
|
||||
}
|
||||
|
||||
function completionSource({
|
||||
schema,
|
||||
values,
|
||||
loadValues,
|
||||
moreCompletions,
|
||||
fieldsOnly,
|
||||
}: QueryFilterOptions) {
|
||||
return async (ctx: CompletionContext): Promise<CompletionResult | null> => {
|
||||
const text = ctx.state.doc.toString();
|
||||
let known = values ?? {};
|
||||
@@ -126,8 +150,9 @@ function completionSource({ schema, values, loadValues, moreCompletions }: Query
|
||||
if (ctx.aborted) return null;
|
||||
}
|
||||
const result = queryCompletions(text, ctx.pos, schema, known);
|
||||
const items = fieldsOnly ? fieldReferences(result?.items ?? []) : (result?.items ?? []);
|
||||
|
||||
const options: Completion[] = (result?.items ?? []).map((item) => ({
|
||||
const options: Completion[] = items.map((item) => ({
|
||||
label: item.label,
|
||||
// Not a CodeMirror type: it names the kind for `onlyFields` below, and draws no icon
|
||||
type: item.kind === "field" ? "field" : "value",
|
||||
|
||||
Reference in new issue
Block a user