@easyvision/easyvision-ui 1.4.0 → 1.5.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 +65 -8
- package/dist/index.cjs +37 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +38 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
- [`EasyVisionMultifilter`](#easyvisionmultifilter)
|
|
27
27
|
- [Field types](#field-types)
|
|
28
28
|
- [Pinned, chip, locked](#pinned-chip-locked)
|
|
29
|
-
- [
|
|
29
|
+
- [Perform: live vs manual](#perform-live-vs-manual)
|
|
30
30
|
- [Standalone usage (no table)](#standalone-usage-no-table)
|
|
31
31
|
- [Nesting](#nesting)
|
|
32
32
|
- [Snapshot shape](#snapshot-shape)
|
|
@@ -364,11 +364,45 @@ To make the multifilter fully static (no `+`, no X), set `editable={false}` on t
|
|
|
364
364
|
<EasyVisionMultifilter editable={false} config={...} />
|
|
365
365
|
```
|
|
366
366
|
|
|
367
|
-
###
|
|
367
|
+
### Perform: live vs manual
|
|
368
368
|
|
|
369
|
-
> **Terminology.** "Perform" is the generic name for "user committed the filter" — i.e. the **Buscar / Search** action. It's called `perform` (not `onSearch`) because the multifilter is generic: the same event can drive a list refetch, an export, a recalculation, a navigation.
|
|
369
|
+
> **Terminology.** "Perform" is the generic name for "user committed the filter" — i.e. the **Buscar / Search** action. It's called `perform` (not `onSearch`) because the multifilter is generic: the same event can drive a list refetch, an export, a recalculation, a navigation.
|
|
370
370
|
|
|
371
|
-
|
|
371
|
+
Perform fires through one of four paths:
|
|
372
|
+
|
|
373
|
+
1. The user clicks the **Buscar** button (when `performButton: true`).
|
|
374
|
+
2. The user presses Enter in a prominent text field (when `performButton: true`).
|
|
375
|
+
3. `performOnMount` triggers it once after the multifilter mounts, if there's any non-empty value to re-emit (used to restore persisted state on remount).
|
|
376
|
+
4. The imperative ref handle: `ref.current.perform()`.
|
|
377
|
+
|
|
378
|
+
In addition, **live mode** auto-fires perform on every change to the active values / fields. Use it for in-memory tables where filtering is cheap and per-change UI updates feel natural. Manual mode stays explicit — typically what you want for API-backed tables, where every perform = a network request.
|
|
379
|
+
|
|
380
|
+
```tsx
|
|
381
|
+
<EasyVisionMultifilter
|
|
382
|
+
id="alerts"
|
|
383
|
+
performMode="live" // 'live' | 'manual' | 'auto' (default 'auto')
|
|
384
|
+
performDebounceMs={150} // debounce window for live mode; default 0
|
|
385
|
+
performOnMount // still useful for restoring persisted state
|
|
386
|
+
onPerform={(snap) => api.list(snap.query)}
|
|
387
|
+
config={...}
|
|
388
|
+
/>
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
`performMode: 'auto'` (the default) means **"ask the parent"**. When the multifilter is mounted inside an [`EasyVisionTable`](#binding-a-multifilter) via that table's `multifilter` prop, the table picks `'live'` for `paginationMode: 'local'` and `'manual'` for `paginationMode: 'api'`. Standalone, `'auto'` resolves to `'manual'` — safer for unknown consumers and matches the historical default.
|
|
392
|
+
|
|
393
|
+
The two modes compose with the rest of the perform machinery:
|
|
394
|
+
|
|
395
|
+
| | Manual | Live |
|
|
396
|
+
|---|---|---|
|
|
397
|
+
| Buscar button (`performButton: true`) | Visible if dirty + valid; press commits. | Visible if dirty + valid; press just forces an immediate perform (debounce skipped). |
|
|
398
|
+
| `performOnMount` | Fires once on mount when values are present. | Same. |
|
|
399
|
+
| Imperative `ref.current.perform()` | Always available. | Always available; flushes the debounce timer. |
|
|
400
|
+
| Field add/remove (`+` / `X`) | Stages; no perform until Buscar / ref / unmount. | Counts as a change; debounced perform follows. |
|
|
401
|
+
| Per-keystroke `onChange` | Always fires; perform doesn't follow. | Always fires; perform follows after `performDebounceMs`. |
|
|
402
|
+
|
|
403
|
+
#### Buscar button
|
|
404
|
+
|
|
405
|
+
Set `performButton={true}` to render the button. Its enable state combines:
|
|
372
406
|
|
|
373
407
|
- `editable !== false` — the multifilter must be active.
|
|
374
408
|
- `isValid` — every `mandatory` field has a non-empty value (recursively, including nested multifilters).
|
|
@@ -398,6 +432,8 @@ const ref = useRef<MultifilterHandle>(null);
|
|
|
398
432
|
// ref.current?.getSnapshot();
|
|
399
433
|
```
|
|
400
434
|
|
|
435
|
+
> **Note on `onPerform` timing.** `onPerform` is dispatched on a microtask after the internal snapshot commit, so it's safe to call `setState` on a parent component inside the callback. The microtask deferral prevents React's "Cannot update a component while rendering a different component" warning that would otherwise fire when perform happens inside a commit phase (e.g. via `performOnMount` or live-mode auto-fire).
|
|
436
|
+
|
|
401
437
|
### Standalone usage (no table)
|
|
402
438
|
|
|
403
439
|
Nothing about the multifilter is table-specific — it's a generic, persisted, validated form-snapshot component. Use it on its own to drive a chart, a KPI panel, an export, a URL query, or any other consumer.
|
|
@@ -519,7 +555,9 @@ Override per field with `toCondition: (value) => unknown` (return either a primi
|
|
|
519
555
|
| `performPosition` | `'inline' \| 'belowRow' \| 'externalRef'` | `'inline'` | |
|
|
520
556
|
| `performTargetRef` | `RefObject<HTMLElement>` | — | Required if `performPosition === 'externalRef'` (TODO portal). |
|
|
521
557
|
| `performOnMount` | `boolean` | `false` | Fire `onPerform` once if seeded state has values. |
|
|
522
|
-
| `
|
|
558
|
+
| `performMode` | `'live' \| 'manual' \| 'auto'` | `'auto'` | When perform fires automatically. `'auto'` defers to the bound table's `paginationMode` (local → live, api → manual); standalone, resolves to manual. See [Perform: live vs manual](#perform-live-vs-manual). |
|
|
559
|
+
| `performDebounceMs` | `number` | `0` | Debounce window before a live-mode perform fires after the last change. |
|
|
560
|
+
| `onPerform` | `(snap) => void` | — | Fires when perform commits — from Buscar, `performOnMount`, the imperative `perform()` ref, or (live mode) any value/field change after the debounce. Dispatched on a microtask so calling `setState` inside is safe. |
|
|
523
561
|
| `onChange` | `(snap) => void` | — | Every change (per keystroke / option toggle). |
|
|
524
562
|
| `onStateChange` | `(snap) => void` | — | Same as `onChange`; provided for API symmetry. |
|
|
525
563
|
| `showClearAll` | `boolean` | `editable` | Clears values & active fields. |
|
|
@@ -830,17 +868,24 @@ Highlighted rows get a `bg-muted/50` tint plus `data-highlighted="true"` on the
|
|
|
830
868
|
|
|
831
869
|
### Binding a multifilter
|
|
832
870
|
|
|
833
|
-
Pass a multifilter declaration via the `multifilter` prop. It auto-mounts in the toolbar and inherits the table's namespace.
|
|
871
|
+
Pass a multifilter declaration via the `multifilter` prop. It auto-mounts in the toolbar and inherits the table's namespace. A perform resets `page = 1`, stores the snapshot, and refetches (api) or applies the where-clause client-side (local).
|
|
872
|
+
|
|
873
|
+
**Perform timing is auto-selected.** Unless you pass an explicit `performMode`, the bound multifilter resolves `'auto'` to:
|
|
874
|
+
|
|
875
|
+
- `'live'` when `paginationMode === 'local'` — filters apply as the user picks, no Buscar button needed.
|
|
876
|
+
- `'manual'` when `paginationMode === 'api'` — values stage until the user clicks Buscar (or you call `ref.current.perform()`), so you don't fire one request per keystroke.
|
|
877
|
+
|
|
878
|
+
Override per-table with `multifilter.performMode = 'live' | 'manual'`. Add `multifilter.performDebounceMs` to collapse rapid changes in live mode (useful for `type: 'text'` fields — pair with the input's own `debounceMs` if you want both layers).
|
|
834
879
|
|
|
835
880
|
```tsx
|
|
836
881
|
<EasyVisionTable<Alert>
|
|
837
882
|
id="alerts"
|
|
838
|
-
paginationMode="api" orderingMode="api"
|
|
883
|
+
paginationMode="api" orderingMode="api" // → manual perform by default
|
|
839
884
|
fetchData={fetchAlerts}
|
|
840
885
|
getRowId={(a) => a.id}
|
|
841
886
|
multifilter={{
|
|
842
887
|
id: 'mainFilter',
|
|
843
|
-
performButton: true,
|
|
888
|
+
performButton: true, // explicit Buscar UI for the manual flow
|
|
844
889
|
config: {
|
|
845
890
|
fields: [
|
|
846
891
|
{ id: 'q', type: 'text', field: 'client.name', label: 'Búsqueda', prominent: true, pinned: true },
|
|
@@ -850,6 +895,18 @@ Pass a multifilter declaration via the `multifilter` prop. It auto-mounts in the
|
|
|
850
895
|
}}
|
|
851
896
|
columns={[/* ... */]}
|
|
852
897
|
/>
|
|
898
|
+
|
|
899
|
+
<EasyVisionTable<Bank>
|
|
900
|
+
id="banks"
|
|
901
|
+
paginationMode="local" orderingMode="local" // → live perform by default
|
|
902
|
+
data={banks}
|
|
903
|
+
multifilter={{
|
|
904
|
+
id: 'banksFilter',
|
|
905
|
+
performDebounceMs: 150, // optional; smooths rapid edits
|
|
906
|
+
config: { fields: [/* ... */] },
|
|
907
|
+
}}
|
|
908
|
+
columns={[/* ... */]}
|
|
909
|
+
/>
|
|
853
910
|
```
|
|
854
911
|
|
|
855
912
|
### External filter and manual refetch
|
package/dist/index.cjs
CHANGED
|
@@ -1129,6 +1129,8 @@ var EasyVisionMultifilter = React8.forwardRef(function EasyVisionMultifilter2(pr
|
|
|
1129
1129
|
performPosition = "inline",
|
|
1130
1130
|
performTargetRef,
|
|
1131
1131
|
performOnMount = false,
|
|
1132
|
+
performMode = "auto",
|
|
1133
|
+
performDebounceMs = 0,
|
|
1132
1134
|
onPerform,
|
|
1133
1135
|
onChange,
|
|
1134
1136
|
onStateChange,
|
|
@@ -1138,6 +1140,7 @@ var EasyVisionMultifilter = React8.forwardRef(function EasyVisionMultifilter2(pr
|
|
|
1138
1140
|
persist = false,
|
|
1139
1141
|
clearWhen
|
|
1140
1142
|
} = props;
|
|
1143
|
+
const resolvedPerformMode = performMode === "live" ? "live" : "manual";
|
|
1141
1144
|
const labels = { ...DEFAULT_LABELS, ...labelOverrides };
|
|
1142
1145
|
const showClear = showClearAll ?? editable;
|
|
1143
1146
|
const initialActive = React8.useMemo(() => {
|
|
@@ -1175,17 +1178,17 @@ var EasyVisionMultifilter = React8.forwardRef(function EasyVisionMultifilter2(pr
|
|
|
1175
1178
|
}) : void 0
|
|
1176
1179
|
});
|
|
1177
1180
|
const { activeFields, values, lastConfirmedSnapshotJSON } = slice;
|
|
1178
|
-
const
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1181
|
+
const registryState = React8.useSyncExternalStore(
|
|
1182
|
+
easyVisionRegistry.subscribe,
|
|
1183
|
+
easyVisionRegistry.getState,
|
|
1184
|
+
easyVisionRegistry.getState
|
|
1185
|
+
);
|
|
1183
1186
|
const childSnapshots = React8.useMemo(() => {
|
|
1184
1187
|
const out = {};
|
|
1185
1188
|
for (const f of config.fields) {
|
|
1186
1189
|
if (f.type !== "multifilter") continue;
|
|
1187
1190
|
const childFullId = `${fullId}.${f.id}-multifilter`;
|
|
1188
|
-
const childSlice =
|
|
1191
|
+
const childSlice = registryState.slices[childFullId];
|
|
1189
1192
|
if (childSlice) {
|
|
1190
1193
|
out[f.id] = {
|
|
1191
1194
|
values: childSlice.values,
|
|
@@ -1194,7 +1197,7 @@ var EasyVisionMultifilter = React8.forwardRef(function EasyVisionMultifilter2(pr
|
|
|
1194
1197
|
}
|
|
1195
1198
|
}
|
|
1196
1199
|
return out;
|
|
1197
|
-
}, [fullId, config.fields,
|
|
1200
|
+
}, [fullId, config.fields, registryState]);
|
|
1198
1201
|
const childQueries = React8.useMemo(() => {
|
|
1199
1202
|
const out = {};
|
|
1200
1203
|
for (const f of config.fields) {
|
|
@@ -1266,7 +1269,10 @@ var EasyVisionMultifilter = React8.forwardRef(function EasyVisionMultifilter2(pr
|
|
|
1266
1269
|
const performAction = React8.useCallback(() => {
|
|
1267
1270
|
const key = buildSnapshotKey({ activeFields, values: composedValues });
|
|
1268
1271
|
patch({ lastConfirmedSnapshotJSON: key });
|
|
1269
|
-
onPerform
|
|
1272
|
+
if (onPerform) {
|
|
1273
|
+
const emitted = { ...snapshot, isDirty: false };
|
|
1274
|
+
queueMicrotask(() => onPerform(emitted));
|
|
1275
|
+
}
|
|
1270
1276
|
}, [activeFields, composedValues, patch, onPerform, snapshot]);
|
|
1271
1277
|
const didPerformOnMountRef = React8.useRef(false);
|
|
1272
1278
|
React8.useEffect(() => {
|
|
@@ -1275,6 +1281,28 @@ var EasyVisionMultifilter = React8.forwardRef(function EasyVisionMultifilter2(pr
|
|
|
1275
1281
|
performAction();
|
|
1276
1282
|
}
|
|
1277
1283
|
}, [performOnMount]);
|
|
1284
|
+
const liveTimerRef = React8.useRef(null);
|
|
1285
|
+
const livePrevKeyRef = React8.useRef(null);
|
|
1286
|
+
React8.useEffect(() => {
|
|
1287
|
+
if (resolvedPerformMode !== "live") return;
|
|
1288
|
+
if (livePrevKeyRef.current === null) {
|
|
1289
|
+
livePrevKeyRef.current = snapshotKey;
|
|
1290
|
+
return;
|
|
1291
|
+
}
|
|
1292
|
+
if (livePrevKeyRef.current === snapshotKey) return;
|
|
1293
|
+
livePrevKeyRef.current = snapshotKey;
|
|
1294
|
+
if (liveTimerRef.current !== null) clearTimeout(liveTimerRef.current);
|
|
1295
|
+
liveTimerRef.current = setTimeout(() => {
|
|
1296
|
+
liveTimerRef.current = null;
|
|
1297
|
+
performAction();
|
|
1298
|
+
}, performDebounceMs);
|
|
1299
|
+
return () => {
|
|
1300
|
+
if (liveTimerRef.current !== null) {
|
|
1301
|
+
clearTimeout(liveTimerRef.current);
|
|
1302
|
+
liveTimerRef.current = null;
|
|
1303
|
+
}
|
|
1304
|
+
};
|
|
1305
|
+
}, [snapshotKey, resolvedPerformMode, performDebounceMs, performAction]);
|
|
1278
1306
|
React8.useImperativeHandle(ref, () => ({
|
|
1279
1307
|
perform: performAction,
|
|
1280
1308
|
getSnapshot: () => snapshot
|
|
@@ -2556,6 +2584,7 @@ function EasyVisionTable(props) {
|
|
|
2556
2584
|
EasyVisionMultifilter,
|
|
2557
2585
|
{
|
|
2558
2586
|
...multifilter,
|
|
2587
|
+
performMode: multifilter.performMode === void 0 || multifilter.performMode === "auto" ? isApi ? "manual" : "live" : multifilter.performMode,
|
|
2559
2588
|
ref: setMultifilterRef,
|
|
2560
2589
|
onPerform: handlePerform
|
|
2561
2590
|
}
|