mirror of
https://github.com/Elysola/WebHooker.git
synced 2026-11-21 01:23:40 +00:00
feat(filter-editor): integrate searchable condition inputs
Replace chip-only values with context-aware bilingual inputs and a compact condition grid. Preserve drafts across tree changes, block saves and tests until drafts are resolved, and keep keyword filters free of hidden operators.
This commit is contained in:
1 parent
2ebce8495d
commit
d693f70612
10 files changed
+557
-190
No files matched your search
@@ -1,5 +1,47 @@
|
||||
import { describe, it, expect } from "bun:test";
|
||||
import { blankNode, isBlankNode } from "../app/composables/useFilterNode";
|
||||
import {
|
||||
blankNode,
|
||||
formToLeaf,
|
||||
hasPendingDraft,
|
||||
isBlankNode,
|
||||
nodeKey,
|
||||
nodeToForm,
|
||||
scopeEvents,
|
||||
} from "../app/composables/useFilterNode";
|
||||
import type { LeafForm } from "../app/composables/useFilterNode";
|
||||
|
||||
function leaf(overrides: Partial<LeafForm>): LeafForm {
|
||||
return {
|
||||
type: "event",
|
||||
path: "",
|
||||
op: "eq",
|
||||
values: [],
|
||||
exclude: false,
|
||||
draft: "",
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
describe("scopeEvents", () => {
|
||||
it("collects exact event names the route positively filters on", () => {
|
||||
const form = nodeToForm({
|
||||
all: [
|
||||
{ type: "event", match: ["pull_request", "Issues"] },
|
||||
{
|
||||
any: [
|
||||
{ type: "event", match: "release" },
|
||||
{ type: "repo", match: "acme/*" },
|
||||
],
|
||||
},
|
||||
{ type: "event", match: "push", exclude: true },
|
||||
{ not: { type: "event", match: "star" } },
|
||||
{ type: "event", match: "check_*" },
|
||||
{ type: "event", op: "ne", match: "fork" },
|
||||
],
|
||||
});
|
||||
expect(scopeEvents(form).sort()).toEqual(["issues", "pull_request", "release"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("isBlankNode", () => {
|
||||
it("treats untouched conditions and groups as blank", () => {
|
||||
@@ -23,5 +65,56 @@ describe("isBlankNode", () => {
|
||||
exists.children[0]!.leaf.type = "branch";
|
||||
exists.children[0]!.leaf.op = "exists";
|
||||
expect(isBlankNode(exists)).toBe(false);
|
||||
// Typed text not added yet is content as well.
|
||||
const typed = blankNode("not");
|
||||
typed.child!.leaf.draft = "my_event";
|
||||
expect(isBlankNode(typed)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("hasPendingDraft", () => {
|
||||
it("finds unadded text anywhere in the tree", () => {
|
||||
const form = nodeToForm({ all: [{ type: "event", match: "push" }, { not: { type: "repo" } }] });
|
||||
expect(hasPendingDraft(form)).toBe(false);
|
||||
form.children[1]!.child!.leaf.draft = " ";
|
||||
expect(hasPendingDraft(form)).toBe(false);
|
||||
form.children[1]!.child!.leaf.draft = "acme/*";
|
||||
expect(hasPendingDraft(form)).toBe(true);
|
||||
});
|
||||
|
||||
it("follows the leaf when a NOT is unwrapped or the root is wrapped", () => {
|
||||
const not = blankNode("not");
|
||||
not.child!.leaf.draft = "my_event";
|
||||
// What FilterNodeEditor's unwrap and RouteEditor's fragment insert do.
|
||||
const unwrapped = { ...not, kind: not.child!.kind, leaf: not.child!.leaf };
|
||||
expect(hasPendingDraft(unwrapped)).toBe(true);
|
||||
const wrapped = { ...blankNode("all"), children: [unwrapped, blankNode("leaf")] };
|
||||
expect(hasPendingDraft(wrapped)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("formToLeaf", () => {
|
||||
it("never stores an operator on keyword filters", () => {
|
||||
expect(formToLeaf(leaf({ type: "keyword", op: "exists", values: ["hotfix"] }))).toEqual({
|
||||
type: "keyword",
|
||||
match: "hotfix",
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps operators on other filters", () => {
|
||||
expect(formToLeaf(leaf({ type: "field", path: "pull_request.draft", op: "exists" }))).toEqual({
|
||||
type: "field",
|
||||
path: "pull_request.draft",
|
||||
op: "exists",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("nodeKey", () => {
|
||||
it("is stable per node and unique across nodes", () => {
|
||||
const a = blankNode("leaf");
|
||||
const b = blankNode("leaf");
|
||||
expect(nodeKey(a)).toBe(nodeKey(a));
|
||||
expect(nodeKey(a)).not.toBe(nodeKey(b));
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user