@sincpro/web-ui 2.0.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -0
- package/dist/components/activity/Activity.d.ts +13 -14
- package/dist/components/activity/Activity.js +1 -1
- package/dist/components/activity/Messages.d.ts +5 -5
- package/dist/components/activity/Messages.js +8 -8
- package/dist/components/attachments/Attachments.d.ts +7 -1
- package/dist/components/attachments/Attachments.js +8 -2
- package/dist/components/board/Board.d.ts +32 -2
- package/dist/components/board/Board.js +27 -4
- package/dist/components/board/index.d.ts +1 -1
- package/dist/components/board/index.js +2 -1
- package/dist/components/form/Form.js +6 -6
- package/dist/components/form/index.js +2 -2
- package/dist/components/frame/FrameView.d.ts +5 -5
- package/dist/components/frame/FrameView.js +4 -4
- package/dist/components/listing/GroupingLevels.d.ts +22 -22
- package/dist/components/listing/GroupingLevels.js +9 -9
- package/dist/components/listing/Listing.d.ts +11 -11
- package/dist/components/listing/Listing.js +11 -11
- package/dist/components/listing/ListingBar.js +11 -11
- package/dist/components/listing/Row.d.ts +19 -19
- package/dist/components/listing/Row.js +27 -27
- package/dist/components/listing/SortMenu.d.ts +36 -36
- package/dist/components/listing/SortMenu.js +6 -6
- package/dist/components/listing/grouping.d.ts +16 -16
- package/dist/components/listing/grouping.js +6 -6
- package/dist/components/listing/index.js +1 -1
- package/dist/components/listing/modelColumns.d.ts +25 -25
- package/dist/components/listing/modelColumns.js +24 -24
- package/dist/components/listing/pages.js +4 -4
- package/dist/components/listing/set.d.ts +18 -18
- package/dist/components/navigation/NavigationTree.js +2 -2
- package/dist/components/navigation/index.js +2 -2
- package/dist/components/record/RecordSkeleton.js +7 -7
- package/dist/components/search/CriteriaBuilder.d.ts +22 -22
- package/dist/components/search/CriteriaBuilder.js +31 -31
- package/dist/components/search/CriteriaChips.d.ts +9 -9
- package/dist/components/search/CriteriaChips.js +12 -12
- package/dist/components/search/FilterBuilder.d.ts +67 -67
- package/dist/components/search/FilterBuilder.js +104 -104
- package/dist/components/search/JoinWord.d.ts +1 -1
- package/dist/components/search/JoinWord.js +14 -14
- package/dist/components/search/JsonEditor.d.ts +8 -8
- package/dist/components/search/JsonEditor.js +16 -16
- package/dist/components/search/SearchBar.d.ts +34 -34
- package/dist/components/search/SearchBar.js +140 -117
- package/dist/components/search/criteria.d.ts +61 -61
- package/dist/components/search/criteria.js +39 -39
- package/dist/components/search/datePeriods.d.ts +47 -48
- package/dist/components/search/datePeriods.js +29 -29
- package/dist/components/search/dateRanges.d.ts +27 -27
- package/dist/components/search/dateRanges.js +16 -16
- package/dist/components/search/index.js +13 -13
- package/dist/components/search/model.d.ts +28 -28
- package/dist/components/search/model.js +21 -21
- package/dist/components/search/query.d.ts +71 -71
- package/dist/components/search/query.js +119 -119
- package/dist/components/shell/AppFrame.d.ts +9 -2
- package/dist/components/shell/AppFrame.js +102 -14
- package/dist/components/shell/Sidebar.d.ts +34 -0
- package/dist/components/shell/Sidebar.js +32 -0
- package/dist/components/shell/TopBar.d.ts +2 -0
- package/dist/components/shell/TopBar.js +13 -9
- package/dist/components/shell/index.d.ts +2 -0
- package/dist/components/shell/index.js +5 -1
- package/dist/components/shell/sidebarDrawer.d.ts +26 -0
- package/dist/components/shell/sidebarDrawer.js +22 -0
- package/dist/foundations/calendar.d.ts +27 -27
- package/dist/foundations/calendar.js +72 -72
- package/dist/foundations/chart.d.ts +57 -57
- package/dist/foundations/chart.js +27 -27
- package/dist/foundations/copy.d.ts +109 -94
- package/dist/foundations/copy.es.js +10 -2
- package/dist/foundations/copy.js +10 -2
- package/dist/foundations/grouping.d.ts +175 -175
- package/dist/foundations/grouping.js +0 -0
- package/dist/foundations/index.d.ts +1 -1
- package/dist/foundations/index.js +21 -21
- package/dist/foundations/pivot.d.ts +133 -131
- package/dist/foundations/pivot.js +54 -54
- package/dist/foundations/pivotSheet.d.ts +36 -36
- package/dist/foundations/pivotSheet.js +0 -0
- package/dist/foundations/slots.d.ts +38 -38
- package/dist/foundations/slots.js +18 -18
- package/dist/foundations/sticky.d.ts +28 -28
- package/dist/foundations/sticky.js +59 -59
- package/dist/foundations/xlsx.d.ts +47 -47
- package/dist/foundations/xlsx.js +0 -0
- package/dist/primitives/block/Line.d.ts +4 -4
- package/dist/primitives/block/Line.js +28 -28
- package/dist/primitives/block/index.js +2 -2
- package/dist/primitives/cell/index.js +2 -2
- package/dist/primitives/choice/index.js +3 -3
- package/dist/primitives/date/Calendar.d.ts +7 -1
- package/dist/primitives/date/Calendar.js +13 -3
- package/dist/primitives/date/DatePicker.d.ts +4 -1
- package/dist/primitives/date/DatePicker.js +2 -2
- package/dist/primitives/date/index.js +3 -3
- package/dist/primitives/disclosure/index.js +1 -1
- package/dist/primitives/field/DropZone.d.ts +22 -3
- package/dist/primitives/field/DropZone.js +33 -12
- package/dist/primitives/menu/Menu.d.ts +10 -6
- package/dist/primitives/menu/Menu.js +4 -3
- package/dist/primitives/notice/Callout.d.ts +30 -30
- package/dist/primitives/notice/Callout.js +6 -6
- package/dist/primitives/overlay/index.js +3 -3
- package/dist/primitives/picker/Picker.d.ts +6 -0
- package/dist/primitives/picker/Picker.js +27 -4
- package/dist/primitives/picker/index.js +2 -2
- package/dist/primitives/table/DataTable.d.ts +32 -32
- package/dist/primitives/table/DataTable.js +24 -24
- package/dist/primitives/table/EditableTable.d.ts +10 -10
- package/dist/primitives/table/EditableTable.js +9 -9
- package/dist/primitives/table/ReportTable.js +7 -7
- package/dist/primitives/table/SheetTable.d.ts +13 -13
- package/dist/primitives/table/SheetTable.js +14 -14
- package/dist/primitives/table/Table.js +8 -8
- package/dist/primitives/tabs/Tabs.d.ts +46 -46
- package/dist/primitives/tabs/Tabs.js +4 -30
- package/dist/primitives/tag/Count.d.ts +23 -0
- package/dist/primitives/tag/Count.js +59 -0
- package/dist/primitives/tag/index.d.ts +1 -0
- package/dist/primitives/tag/index.js +5 -2
- package/dist/primitives/toolbar/index.js +1 -1
- package/dist/primitives/value/Copyable.d.ts +22 -22
- package/dist/primitives/value/Copyable.js +9 -9
- package/dist/primitives/value/Metric.d.ts +7 -2
- package/dist/primitives/value/Metric.js +12 -4
- package/dist/tokens.css +164 -57
- package/dist/views/list/List.d.ts +36 -36
- package/dist/views/list/List.js +19 -19
- package/dist/views/list/ListView.js +74 -74
- package/dist/views/list/columns.d.ts +10 -10
- package/dist/views/list/columns.js +10 -10
- package/dist/views/list/derive.d.ts +30 -30
- package/dist/views/list/derive.js +49 -49
- package/dist/views/list/index.js +2 -2
- package/dist/views/list/presentations.js +3 -3
- package/dist/views/list/types.d.ts +109 -109
- package/dist/views/record/Record.d.ts +14 -14
- package/dist/views/record/Record.js +24 -24
- package/dist/views/record/index.js +1 -1
- package/package.json +1 -1
|
@@ -2,13 +2,13 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { ModelCell } from "./modelCells.js";
|
|
3
3
|
import { fieldLabel, isNumericType, } from "../search/model.js";
|
|
4
4
|
import { formatDuration } from "../../primitives/field/duration.js";
|
|
5
|
-
/**
|
|
5
|
+
/** The fields the declared columns already answer.
|
|
6
6
|
*
|
|
7
7
|
* in [{id:"rows", field:"row_count"}, {id:"name"}]
|
|
8
8
|
* out Set {"row_count", "name"}
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
10
|
+
* The `id` counts as a claim when it matches the field's name: most
|
|
11
|
+
* columns are named after what they show. */
|
|
12
12
|
export function claimedFields(columns) {
|
|
13
13
|
const claimed = new Set();
|
|
14
14
|
for (const column of columns) {
|
|
@@ -18,17 +18,17 @@ export function claimedFields(columns) {
|
|
|
18
18
|
}
|
|
19
19
|
return claimed;
|
|
20
20
|
}
|
|
21
|
-
/**
|
|
21
|
+
/** A record value, into something a cell can sort and draw.
|
|
22
22
|
*
|
|
23
|
-
* in ["edad","sexo"]
|
|
23
|
+
* in ["edad","sexo"] a `text[]`
|
|
24
24
|
* out "edad, sexo"
|
|
25
|
-
* in []
|
|
26
|
-
* out null
|
|
25
|
+
* in [] an empty list is not an empty text
|
|
26
|
+
* out null the table draws «—»
|
|
27
27
|
* in "2026-09-13T04:17:00"
|
|
28
28
|
* out "2026-09-13T04:17:00"
|
|
29
29
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
30
|
+
* Dates are left as they come —ISO— because in ISO alphabetical order IS
|
|
31
|
+
* chronological, and so the column sorts well without parsing anything. */
|
|
32
32
|
export function readModelValue(raw) {
|
|
33
33
|
if (raw === null || raw === undefined)
|
|
34
34
|
return null;
|
|
@@ -71,8 +71,8 @@ export function modelCellKind(type) {
|
|
|
71
71
|
return "number";
|
|
72
72
|
return KIND_OF_TYPE[type.toLowerCase()] ?? "text";
|
|
73
73
|
}
|
|
74
|
-
/**
|
|
75
|
-
*
|
|
74
|
+
/** How much width a field deserves, by its type. A fingerprint is 64 characters and
|
|
75
|
+
* an account is six: giving them the same width ruins both. */
|
|
76
76
|
function widthFor(kind) {
|
|
77
77
|
if (kind === "number" || kind === "duration")
|
|
78
78
|
return 120;
|
|
@@ -83,23 +83,23 @@ function widthFor(kind) {
|
|
|
83
83
|
return 260;
|
|
84
84
|
}
|
|
85
85
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
86
|
+
* The declared columns, plus one for each model field that none
|
|
87
|
+
* answered.
|
|
88
88
|
*
|
|
89
|
-
* in model
|
|
90
|
-
* in declared 6
|
|
91
|
-
* out
|
|
89
|
+
* in model the `model_meta_data` of `account.move` — 12 fields
|
|
90
|
+
* in declared 6 columns written by hand in the view
|
|
91
|
+
* out the 6, and behind them `journal_id`, `currency_id`, `invoice_origin`,
|
|
92
92
|
* `payment_reference`, `fiscal_position_id`, `company_id`,
|
|
93
|
-
* `move_type`,
|
|
93
|
+
* `move_type`, all switched off
|
|
94
94
|
*
|
|
95
|
-
*
|
|
96
|
-
* `translations()`
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
95
|
+
* The label of the added ones comes from `model.translations` in the requested language —the same
|
|
96
|
+
* `translations()` the model publishes for everything else—, with the `default` that same
|
|
97
|
+
* model declared if the language is missing, and the field's name as is only if the model
|
|
98
|
+
* said no word about it. It can never get out of sync with the engine because it comes from the
|
|
99
|
+
* SAME answer that names the field — unlike a dictionary maintained here.
|
|
100
100
|
*
|
|
101
|
-
* `model === null` —
|
|
102
|
-
*
|
|
101
|
+
* `model === null` —the definition has not arrived yet— returns the declared ones
|
|
102
|
+
* untouched, which is exactly what there was before.
|
|
103
103
|
*/
|
|
104
104
|
export function columnsFromModel(declared, model, locale = "default") {
|
|
105
105
|
if (model === null || model === undefined)
|
|
@@ -47,10 +47,10 @@ export function usePagination(items, options = {}) {
|
|
|
47
47
|
setPageSize(clampSize(next));
|
|
48
48
|
setPage(1);
|
|
49
49
|
},
|
|
50
|
-
/*
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
/* It moves from `current` and not from `page`, which may have been left
|
|
51
|
+
too high: if you were on 3 and a filter left two pages, `page` stays
|
|
52
|
+
at 3 while 2 is shown, and `p - 1` went back to 2 — so «previous»
|
|
53
|
+
did nothing until the second click. */
|
|
54
54
|
...(current > 1 ? { onPrev: () => setPage(current - 1) } : {}),
|
|
55
55
|
...(current < pages ? { onNext: () => setPage(current + 1) } : {}),
|
|
56
56
|
},
|
|
@@ -14,26 +14,26 @@ import { type Pages } from "./pages.js";
|
|
|
14
14
|
* reset the page size). Uncontrolled when the screen is the only owner.
|
|
15
15
|
*/
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
17
|
+
* The ways of looking at a set. **It lives here and not in the archetype** because
|
|
18
|
+
* two of them ask the same thing —a list and a frame— and the definition
|
|
19
|
+
* has to be only one.
|
|
20
20
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* idea
|
|
21
|
+
* There were two: `ListPresent` in `archetype/ListView.tsx` and this copy. While the
|
|
22
|
+
* two said `rows | table | board` nobody noticed; adding `sheet` to one left
|
|
23
|
+
* four views not compiling, which is exactly what happens when the same
|
|
24
|
+
* idea is written twice.
|
|
25
25
|
*
|
|
26
|
-
* rows / board no
|
|
27
|
-
* table
|
|
28
|
-
* sheet
|
|
29
|
-
*
|
|
30
|
-
* report
|
|
31
|
-
*
|
|
32
|
-
* pivot
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* chart
|
|
36
|
-
*
|
|
26
|
+
* rows / board no columns: name, cards and meta.
|
|
27
|
+
* table the columns are DECLARED by the code.
|
|
28
|
+
* sheet the columns come from the FILE — there may be forty-one
|
|
29
|
+
* million rows, so it is virtualised.
|
|
30
|
+
* report period columns and rows in a HIERARCHY that ends in
|
|
31
|
+
* totals. It is not sorted: the order IS the report.
|
|
32
|
+
* pivot two AXES at once. A row is a heap and so is a column;
|
|
33
|
+
* what is read is at the crossing. It is not
|
|
34
|
+
* sorted either: the order of each axis is that of its keys.
|
|
35
|
+
* chart the same pivot, drawn: bars, lines or pie. The
|
|
36
|
+
* first grouping is the axis and the second, the series.
|
|
37
37
|
*/
|
|
38
38
|
export type BuiltInPresent = "rows" | "table" | "board" | "sheet" | "report" | "pivot" | "chart" | "calendar" | "gantt" | "timeline";
|
|
39
39
|
/** A presentation of a list: one the package draws, or the `id` of a `List.Present` the
|
|
@@ -3,6 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
3
3
|
import { AriaLocale } from "../../foundations/aria.js";
|
|
4
4
|
import { useUiCopy } from "../../foundations/copy.js";
|
|
5
5
|
import { focusRing, tv } from "../../foundations/variants.js";
|
|
6
|
+
import { Count } from "../../primitives/tag/Count.js";
|
|
6
7
|
import { ChevronRight } from "lucide-react";
|
|
7
8
|
import { useMemo } from "react";
|
|
8
9
|
import { Button as AriaButton, Link, NavigationTree as AriaNavigationTree, NavigationTreeItem as AriaNavigationTreeItem, NavigationTreeItemContent, RouterProvider, } from "react-aria-components";
|
|
@@ -54,7 +55,6 @@ function pathTo(items, id) {
|
|
|
54
55
|
*/
|
|
55
56
|
export function NavigationTree({ items, current, onNavigate, defaultExpanded = [], label, }) {
|
|
56
57
|
const copy = useUiCopy();
|
|
57
|
-
const number = useMemo(() => new Intl.NumberFormat(copy.locale), [copy.locale]);
|
|
58
58
|
const expanded = useMemo(() => [...new Set([...defaultExpanded, ...pathTo(items, current)])],
|
|
59
59
|
// The initial state only: React Aria owns the expansion after the first render.
|
|
60
60
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -73,7 +73,7 @@ export function NavigationTree({ items, current, onNavigate, defaultExpanded = [
|
|
|
73
73
|
: undefined;
|
|
74
74
|
return (_jsxs(AriaNavigationTreeItem, { id: item.id, textValue: item.label, ...(module ? {} : { href: item.id }), className: ({ isCurrent, isFocusVisible }) => row({ isCurrent, isFocusVisible }), children: [_jsx(NavigationTreeItemContent, { children: ({ isCurrent, isCurrentAncestor, isExpanded }) => (_jsxs(_Fragment, { children: [isCurrent ? _jsx("span", { "aria-hidden": true, className: marker }) : null, _jsxs(Link, { className: link({ isModule: module }), style: indent, children: [Icon === undefined ? null : (_jsx(Icon, { className: `size-(--size-icon-md) shrink-0 ${isCurrent || (isCurrentAncestor && !isExpanded)
|
|
75
75
|
? "text-primary"
|
|
76
|
-
: "text-muted"}`, strokeWidth: 2, "aria-hidden": true })), _jsx("span", { className: `min-w-0 flex-1 truncate ${isCurrentAncestor && !isExpanded ? "text-primary" : ""}`, children: item.label }), item.count === undefined
|
|
76
|
+
: "text-muted"}`, strokeWidth: 2, "aria-hidden": true })), _jsx("span", { className: `min-w-0 flex-1 truncate ${isCurrentAncestor && !isExpanded ? "text-primary" : ""}`, children: item.label }), item.count === undefined ? null : (_jsx(Count, { value: item.count, current: isCurrent }))] }), module ? (_jsx(AriaButton, { slot: "chevron", className: ({ isFocusVisible }) => chevronButton({ isFocusVisible }), children: _jsx(ChevronRight, { className: `size-(--size-icon-sm) transition-transform duration-(--duration-quick) ease-(--ease-out) ${isExpanded ? "rotate-90" : ""}`, strokeWidth: 2, "aria-hidden": true }) })) : null] })) }), children.map((child) => render(child, level + 1))] }, item.id));
|
|
77
77
|
};
|
|
78
78
|
return (_jsx(AriaLocale, { children: _jsx(RouterProvider, { navigate: (id) => onNavigate?.(id), useHref: (id) => `#${id}`, children: _jsx(AriaNavigationTree, { "aria-label": label ?? copy.shell.menus, selectedRoute: current ?? null, defaultExpandedKeys: expanded, className: "flex w-full min-w-0 flex-col gap-px p-2 outline-0", children: items.map((item) => render(item, 1)) }) }) }));
|
|
79
79
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/*
|
|
2
|
-
|
|
1
|
+
/* NAVIGATION — an application's side tree. The command palette (⌘K) belongs to the
|
|
2
|
+
workspace (composer), not here. */
|
|
3
3
|
export { NavigationTree, } from "./NavigationTree.js";
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { byDensity, useDensity } from "../../foundations/density.js";
|
|
4
4
|
/* ==================================================================== *
|
|
5
|
-
*
|
|
5
|
+
* THE RECORD'S SHEET, WHILE IT ARRIVES.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
7
|
+
* Invoice and customer answered the wait with `Empty`: «Cargando…» in the
|
|
8
|
+
* middle of the page. That is the phrase for «there is nothing», and the record
|
|
9
|
+
* does exist — it has not arrived yet. The silhouette is the sheet's: the rail, the name,
|
|
10
|
+
* the four facts, the tabs and the body. When the record appears,
|
|
11
|
+
* it lands in the same place.
|
|
12
12
|
*
|
|
13
|
-
*
|
|
13
|
+
* No shimmer. A pulse already means «this state is alive».
|
|
14
14
|
* ==================================================================== */
|
|
15
15
|
const HECHOS = ["w-16", "w-12", "w-20", "w-24"];
|
|
16
16
|
const SOLAPAS = ["w-14", "w-16", "w-20"];
|
|
@@ -4,23 +4,23 @@ export interface BuiltSort {
|
|
|
4
4
|
field: string;
|
|
5
5
|
descending?: boolean;
|
|
6
6
|
}
|
|
7
|
-
/**
|
|
7
|
+
/** A grouping level, like criteria's `Level`: the field and, if it is a date, the grain. */
|
|
8
8
|
export interface BuiltLevel {
|
|
9
9
|
field: string;
|
|
10
10
|
grain?: string | null;
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
* `{ function: "sum", field: "row_count" }`.
|
|
15
|
-
*
|
|
13
|
+
* A number that each heap answers, like criteria's `Measure`:
|
|
14
|
+
* `{ function: "sum", field: "row_count" }`. Named parts and not a pair, just as a
|
|
15
|
+
* condition travels as `{field, operator, value}`.
|
|
16
16
|
*/
|
|
17
17
|
export interface BuiltMeasure {
|
|
18
18
|
function: string;
|
|
19
19
|
field: string;
|
|
20
|
-
/**
|
|
20
|
+
/** What the function needs besides the field. Only `percentile`: the cut's fraction. */
|
|
21
21
|
argument?: number;
|
|
22
22
|
}
|
|
23
|
-
/**
|
|
23
|
+
/** From where a page of heaps starts — the same shape as the rows' pagination. */
|
|
24
24
|
export type BuiltPageStrategy = {
|
|
25
25
|
token: string | null;
|
|
26
26
|
} | {
|
|
@@ -30,23 +30,23 @@ export interface BuiltGroupPagination {
|
|
|
30
30
|
limit?: number;
|
|
31
31
|
strategy?: BuiltPageStrategy;
|
|
32
32
|
}
|
|
33
|
-
/**
|
|
33
|
+
/** The grouping as `@sincpro/criteria` 2.0 declares it, key by key. */
|
|
34
34
|
export interface BuiltGrouping {
|
|
35
|
-
/**
|
|
35
|
+
/** The levels, in order: they are not added, they nest. */
|
|
36
36
|
group_by?: BuiltLevel[];
|
|
37
|
-
/**
|
|
37
|
+
/** The numbers each heap answers, each under a chosen name. */
|
|
38
38
|
measures?: Record<string, BuiltMeasure>;
|
|
39
|
-
/**
|
|
40
|
-
*
|
|
39
|
+
/** A filter on what the heaps measured, not on the rows: `count > 10`. The
|
|
40
|
+
* names it admits are those of `measures`, plus `"count"`. */
|
|
41
41
|
where_measures?: BuiltFilter;
|
|
42
|
-
/**
|
|
43
|
-
* `measures`,
|
|
42
|
+
/** In what order the heaps come back: by the level's own field, by a name from
|
|
43
|
+
* `measures`, or by `count`. */
|
|
44
44
|
order?: BuiltSort[];
|
|
45
|
-
/**
|
|
45
|
+
/** How many heaps of the first level come back, and from where. Absent is all of them. */
|
|
46
46
|
pagination?: BuiltGroupPagination;
|
|
47
47
|
}
|
|
48
|
-
/**
|
|
49
|
-
*
|
|
48
|
+
/** The criteria as the engine declares it. It is what this component builds and returns, and what
|
|
49
|
+
* the code editor shows. */
|
|
50
50
|
export interface BuiltCriteria {
|
|
51
51
|
selection?: BuiltFilter;
|
|
52
52
|
order?: BuiltSort[];
|
|
@@ -55,15 +55,15 @@ export interface BuiltCriteria {
|
|
|
55
55
|
}
|
|
56
56
|
export declare function CriteriaBuilder({ model, initial, focus, onApply, onCancel, }: {
|
|
57
57
|
model: ModelDefinition;
|
|
58
|
-
/**
|
|
58
|
+
/** The criteria that was already set. Reopening has to continue where it was left. */
|
|
59
59
|
initial?: BuiltCriteria;
|
|
60
60
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
61
|
+
* The condition's field to show first: the chip somebody
|
|
62
|
+
* touched in the bar.
|
|
63
63
|
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
64
|
+
* Without this, touching a cut opened the builder on rule one and you had to
|
|
65
|
+
* search among twelve for the one you were looking at — which is the quickest way to
|
|
66
|
+
* edit the wrong one.
|
|
67
67
|
*/
|
|
68
68
|
focus?: string;
|
|
69
69
|
onApply: (criteria: BuiltCriteria | undefined) => void;
|
|
@@ -12,22 +12,22 @@ import { Tags } from "../../primitives/tag/Tags.js";
|
|
|
12
12
|
import { Plus, Trash2 } from "lucide-react";
|
|
13
13
|
import { Fragment, useMemo, useState } from "react";
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
15
|
+
* A date's cuts, from COARSE to fine, with `null` first: with no cut, a
|
|
16
|
+
* date field splits by instant and every row ends up in its own heap.
|
|
17
17
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
18
|
+
* The order is not a preference — a whole day lives inside a single month— and
|
|
19
|
+
* it is the same one `GRAIN_ORDER` publishes for the bar: a single direction for
|
|
20
|
+
* both screens. A level's chip rotates through this list.
|
|
21
21
|
*/
|
|
22
22
|
const GRAINS = [null, ...GRAIN_ORDER];
|
|
23
|
-
/**
|
|
23
|
+
/** Which types admit a grain: cutting a text by month means nothing. */
|
|
24
24
|
const DATE_TYPES = new Set(["date", "datetime"]);
|
|
25
|
-
/**
|
|
26
|
-
* `where_measures`:
|
|
27
|
-
* `is null`
|
|
25
|
+
/** The operators that a measure —always a number— or `count` admit in a
|
|
26
|
+
* `where_measures`: the same ones the model definition publishes for a numeric field,
|
|
27
|
+
* `is null` aside, which means nothing on a number the engine itself computed. */
|
|
28
28
|
const COMPARABLE = ["=", "!=", ">", ">=", "<", "<=", "between"];
|
|
29
|
-
/**
|
|
30
|
-
*
|
|
29
|
+
/** The functions a measure can ask for here, closed on the server side because the
|
|
30
|
+
* name reaches SQL. */
|
|
31
31
|
const MEASURE_FUNCTIONS = ["sum", "avg", "min", "max", "count"];
|
|
32
32
|
function isEmpty(criteria) {
|
|
33
33
|
return (criteria.selection === undefined &&
|
|
@@ -36,8 +36,8 @@ function isEmpty(criteria) {
|
|
|
36
36
|
Object.keys(criteria.grouping?.measures ?? {}).length === 0 &&
|
|
37
37
|
Object.keys(criteria.specification ?? {}).length === 0);
|
|
38
38
|
}
|
|
39
|
-
/**
|
|
40
|
-
*
|
|
39
|
+
/** The `where_measures` editor's tree: what was read, wrapped in a group if it is a single
|
|
40
|
+
* condition, or a blank one over `count` if there is nothing to read. */
|
|
41
41
|
function measuresTreeOf(filter, model) {
|
|
42
42
|
const node = filter === undefined ? null : treeFromFilter(filter);
|
|
43
43
|
if (node === null)
|
|
@@ -45,12 +45,12 @@ function measuresTreeOf(filter, model) {
|
|
|
45
45
|
return node.kind === "group" ? node : { kind: "group", join: "all", children: [node] };
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
|
-
*
|
|
48
|
+
* THE CHIP THAT ADDS: a «+» that opens the list of what can be chosen.
|
|
49
49
|
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
50
|
+
* It is the same as what the hash sign does in the bar, and for the same reason: choosing
|
|
51
|
+
* among twenty fields is choosing from a LIST, not unfolding a `<select>` that already
|
|
52
|
+
* comes with one set and has to be changed. With the `<select>`, adding a
|
|
53
|
+
* level put the model's first field even though nobody had asked for it.
|
|
54
54
|
*/
|
|
55
55
|
function AddTag({ label, options, onPick, }) {
|
|
56
56
|
const [open, setOpen] = useState(false);
|
|
@@ -65,7 +65,7 @@ function AddTag({ label, options, onPick, }) {
|
|
|
65
65
|
},
|
|
66
66
|
})) }) })) : null] }));
|
|
67
67
|
}
|
|
68
|
-
/**
|
|
68
|
+
/** The next cut, and back to the start. */
|
|
69
69
|
function nextGrain(grain) {
|
|
70
70
|
const at = GRAINS.indexOf(grain ?? null);
|
|
71
71
|
return GRAINS[(at + 1) % GRAINS.length] ?? null;
|
|
@@ -73,8 +73,8 @@ function nextGrain(grain) {
|
|
|
73
73
|
export function CriteriaBuilder({ model, initial, focus, onApply, onCancel, }) {
|
|
74
74
|
const surface = useSurface();
|
|
75
75
|
const names = Object.keys(model.fields).sort();
|
|
76
|
-
/*
|
|
77
|
-
(`ops`
|
|
76
|
+
/* Never a relational nor a value-object: neither has a comparison of its own
|
|
77
|
+
(empty `ops`), so neither serves as a target for a filter, an order or a level. */
|
|
78
78
|
const scalarNames = filterableNames(model);
|
|
79
79
|
const sortable = names.filter((name) => model.fields[name]?.sortable === true);
|
|
80
80
|
const decomposed = initial?.selection === undefined ? null : treeFromFilter(initial.selection);
|
|
@@ -90,10 +90,10 @@ export function CriteriaBuilder({ model, initial, focus, onApply, onCancel, }) {
|
|
|
90
90
|
const [measures, setMeasures] = useState(initial?.grouping?.measures ?? {});
|
|
91
91
|
const [groupOrder, setGroupOrder] = useState(initial?.grouping?.order ?? []);
|
|
92
92
|
const [groupLimit, setGroupLimit] = useState(initial?.grouping?.pagination?.limit);
|
|
93
|
-
/* `where_measures`
|
|
94
|
-
|
|
95
|
-
`SelectionTree`
|
|
96
|
-
|
|
93
|
+
/* `where_measures` is a filter like any other, over a synthetic model whose only
|
|
94
|
+
fields are the names it admits: those of `measures`, plus `count`. Reusing
|
|
95
|
+
`SelectionTree` over that model is simpler and more correct than building a separate
|
|
96
|
+
conditions editor. */
|
|
97
97
|
const measuresModel = useMemo(() => ({
|
|
98
98
|
aggregate: "where_measures",
|
|
99
99
|
identity: "count",
|
|
@@ -109,7 +109,7 @@ export function CriteriaBuilder({ model, initial, focus, onApply, onCancel, }) {
|
|
|
109
109
|
const [fields, setFields] = useState(Object.keys(initial?.specification ?? {}));
|
|
110
110
|
const [rawText, setRawText] = useState(() => initial === undefined ? "" : JSON.stringify(initial, null, 2));
|
|
111
111
|
const [rawError, setRawError] = useState(null);
|
|
112
|
-
/**
|
|
112
|
+
/** What the controls say, together: it is what is applied and what the JSON shows. */
|
|
113
113
|
function assemble(next) {
|
|
114
114
|
const selection = next.locked ?? lockedSelection ?? treeToFilter(next.tree ?? tree);
|
|
115
115
|
const sorts = next.order ?? order;
|
|
@@ -119,9 +119,9 @@ export function CriteriaBuilder({ model, initial, focus, onApply, onCancel, }) {
|
|
|
119
119
|
const groupSorts = next.groupOrder ?? groupOrder;
|
|
120
120
|
const limit = "groupLimit" in next ? next.groupLimit : groupLimit;
|
|
121
121
|
const chosen = next.fields ?? fields;
|
|
122
|
-
/*
|
|
123
|
-
|
|
124
|
-
|
|
122
|
+
/* Without levels there is nothing to measure, nothing to filter between heaps, nor in what order or page
|
|
123
|
+
they would come back — a measure, a `where_measures` or a page set and then emptied of
|
|
124
|
+
levels must not survive loose in the criteria that is sent. */
|
|
125
125
|
const grouping = groupBy.length === 0
|
|
126
126
|
? {}
|
|
127
127
|
: {
|
|
@@ -142,7 +142,7 @@ export function CriteriaBuilder({ model, initial, focus, onApply, onCancel, }) {
|
|
|
142
142
|
}),
|
|
143
143
|
};
|
|
144
144
|
}
|
|
145
|
-
/*
|
|
145
|
+
/* Touching any control rewrites the whole JSON: the two views are the same criteria. */
|
|
146
146
|
function push(next) {
|
|
147
147
|
if (next.tree !== undefined)
|
|
148
148
|
setTree(next.tree);
|
|
@@ -166,7 +166,7 @@ export function CriteriaBuilder({ model, initial, focus, onApply, onCancel, }) {
|
|
|
166
166
|
setRawText(isEmpty(built) ? "" : JSON.stringify(built, null, 2));
|
|
167
167
|
setRawError(null);
|
|
168
168
|
}
|
|
169
|
-
/*
|
|
169
|
+
/* Writing the JSON rebuilds the controls, as long as what was written is a criteria. */
|
|
170
170
|
function updateRaw(text) {
|
|
171
171
|
setRawText(text);
|
|
172
172
|
if (text.trim() === "") {
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { type CriteriaJoin, type CriteriaPath, type SearchCriteria } from "./criteria.js";
|
|
2
2
|
import type { Surface } from "../../foundations/types.js";
|
|
3
3
|
export type CriteriaChipsProps = {
|
|
4
|
-
/**
|
|
4
|
+
/** What the bar has set. Groups and filters mixed: here they are separated. */
|
|
5
5
|
criteria: readonly SearchCriteria[];
|
|
6
|
-
/**
|
|
6
|
+
/** Open the builder on an instance. */
|
|
7
7
|
onOpen?: (path: CriteriaPath) => void;
|
|
8
|
-
/**
|
|
8
|
+
/** Change how a node's ones are joined. */
|
|
9
9
|
onJoin?: (path: CriteriaPath, join: CriteriaJoin) => void;
|
|
10
|
-
/**
|
|
10
|
+
/** Remove an instance, or a whole branch. */
|
|
11
11
|
onRemove?: (path: CriteriaPath) => void;
|
|
12
|
-
/**
|
|
12
|
+
/** Remove several at once: the × of the grouping chain drops every level. */
|
|
13
13
|
onRemoveMany?: (paths: readonly CriteriaPath[]) => void;
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* Which node is OPEN: where the next thing written will land.
|
|
16
16
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
17
|
+
* It is marked because otherwise, writing `#and` and then a condition puts it in a
|
|
18
|
+
* place nobody chose by looking: the group exists, the condition goes in, and the
|
|
19
|
+
* only one who knew where it was is the one who wrote it.
|
|
20
20
|
*/
|
|
21
21
|
open?: CriteriaPath;
|
|
22
22
|
/** How many facets show before the rest fold into «+N» (the grouping chain counts as one).
|
|
@@ -12,9 +12,9 @@ export function CriteriaChips({ criteria, onOpen, onJoin, onRemove, onRemoveMany
|
|
|
12
12
|
const [expanded, setExpanded] = useState(false);
|
|
13
13
|
const groups = groupsOf(criteria);
|
|
14
14
|
const filters = filtersOf(criteria);
|
|
15
|
-
/*
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
/* The path is counted over the WHOLE list and not over the drawn half: it is the
|
|
16
|
+
instance's identity, and an identity that changes depending on which side
|
|
17
|
+
you look at it from identifies nothing. */
|
|
18
18
|
const pathOf = (one) => [
|
|
19
19
|
criteria.findIndex((each) => each.id === one.id),
|
|
20
20
|
];
|
|
@@ -81,26 +81,26 @@ function GroupChain({ groups, onOpen, onRemoveMany, surface, }) {
|
|
|
81
81
|
function Node({ node, path, onOpen, onJoin, onRemove, open, surface, }) {
|
|
82
82
|
const copy = useUiCopy();
|
|
83
83
|
if (node.kind !== "join") {
|
|
84
|
-
/*
|
|
85
|
-
|
|
86
|
-
|
|
84
|
+
/* An instance that carries no expression has nothing to edit: the builder
|
|
85
|
+
edits what TRAVELS, and this one is answered by whoever declared it. It is seen and removed
|
|
86
|
+
like any other; what it does not do is promise a door that opens onto nothing. */
|
|
87
87
|
const editable = node.kind === "group" || node.selection !== undefined;
|
|
88
88
|
return (_jsx(Chip, { label: node.label, path: path, ...(onOpen === undefined || !editable ? {} : { onOpen }), ...(onRemove === undefined ? {} : { onRemove }), surface: surface }));
|
|
89
89
|
}
|
|
90
|
-
/*
|
|
91
|
-
|
|
90
|
+
/* The open node is marked: it is where the next thing will land. A ring and not a
|
|
91
|
+
background, because inside there are chips that already have their own. */
|
|
92
92
|
const isOpen = open !== undefined && open.join(".") === path.join(".");
|
|
93
93
|
return (_jsxs("span", { className: `inline-flex min-w-0 flex-wrap items-center gap-1 rounded-control border px-1.5 py-0.5 ${bySurface(surface, "border-line bg-ink/4", "border-chrome-ink/25 bg-chrome-ink/8")} ${isOpen ? "ring-1 ring-primary/60" : ""}`, children: [_jsx(JoinWord, { join: node.join, ...(onJoin === undefined ? {} : { onChange: (next) => onJoin(path, next) }), surface: surface }), node.of.length === 0 ? (
|
|
94
|
-
/*
|
|
95
|
-
|
|
94
|
+
/* A newly opened node has nothing inside, and an empty bracket reads
|
|
95
|
+
as an error. It says it is waiting. */
|
|
96
96
|
_jsx("span", { className: `shrink-0 text-micro italic ${bySurface(surface, "text-muted", "text-chrome-muted")}`, children: copy.search.landsHere })) : null, node.of.map((child, at) => (_jsx(Node, { node: child, path: [...path, at], ...(onOpen === undefined ? {} : { onOpen }), ...(onJoin === undefined ? {} : { onJoin }), ...(onRemove === undefined ? {} : { onRemove }), ...(open === undefined ? {} : { open }), surface: surface }, child.id)))] }));
|
|
97
97
|
}
|
|
98
98
|
function Chip({ label, path, onOpen, onRemove, surface, }) {
|
|
99
99
|
const copy = useUiCopy();
|
|
100
100
|
const shell = `inline-flex min-w-0 max-w-(--container-facet) items-center gap-1 rounded-pill border py-0.5 text-micro ${bySurface(surface, "border-accent/40 bg-accent/18 text-ink", "border-chrome-link/35 bg-chrome-link/18 text-chrome-link")} ${onRemove === undefined ? "px-2" : "pr-0.5 pl-2"}`;
|
|
101
101
|
const remove = onRemove === undefined ? null : (_jsx("button", { type: "button", onClick: (event) => {
|
|
102
|
-
/*
|
|
103
|
-
|
|
102
|
+
/* Without this, removing it also opens it: the click arrives here and then
|
|
103
|
+
bubbles up. */
|
|
104
104
|
event.stopPropagation();
|
|
105
105
|
onRemove(path);
|
|
106
106
|
}, "aria-label": copy.search.removeFilter.replace("{label}", label), className: `inline-flex size-4 shrink-0 items-center justify-center rounded-pill transition-colors duration-(--duration-instant) ${bySurface(surface, "hover:bg-primary/20", "hover:bg-chrome-link/25")}`, children: _jsx(X, { className: "size-3", strokeWidth: 2.5 }) }));
|