tsense 0.2.0-next.6 → 0.2.0-next.7
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.
|
@@ -18,6 +18,7 @@ export declare function removeRow(state: FilterState, index: number): FilterStat
|
|
|
18
18
|
export declare function setRowField(state: FilterState, index: number, field: string): FilterState;
|
|
19
19
|
export declare function setRowCondition(state: FilterState, index: number, condition: string): FilterState;
|
|
20
20
|
export declare function setRowValue(state: FilterState, index: number, value: FilterValue): FilterState;
|
|
21
|
+
export declare function restoreRows(rows: Omit<FilterRow, "id">[]): FilterState;
|
|
21
22
|
export declare function clearState(): FilterState;
|
|
22
23
|
export declare function hasManualRows(state: FilterState): boolean;
|
|
23
24
|
export declare function conditionsFor<T>(descriptor: FilterDescriptor<T>, field: string): FilterDescriptor<T>["columns"][number]["conditions"];
|
|
@@ -56,6 +56,12 @@ export function setRowValue(state, index, value) {
|
|
|
56
56
|
manualRowIds: state.manualRowIds,
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
|
+
export function restoreRows(rows) {
|
|
60
|
+
return {
|
|
61
|
+
rows: rows.map((row) => ({ ...row, id: ++nextRowId })),
|
|
62
|
+
manualRowIds: new Set(),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
59
65
|
export function clearState() {
|
|
60
66
|
return { rows: [], manualRowIds: new Set() };
|
|
61
67
|
}
|
|
@@ -11,6 +11,7 @@ type UseFilterBuilderReturn = {
|
|
|
11
11
|
setCondition: (index: number, condition: string) => void;
|
|
12
12
|
setValue: (index: number, value: FilterValue) => void;
|
|
13
13
|
clear: () => void;
|
|
14
|
+
restore: (rows: Omit<FilterRow, "id">[]) => void;
|
|
14
15
|
conditionsFor: (field: string) => FilterDescriptor["columns"][number]["conditions"];
|
|
15
16
|
columnFor: (field: string) => FilterDescriptor["columns"][number];
|
|
16
17
|
result: Record<string, unknown>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useMemo, useState } from "react";
|
|
2
|
-
import { addRow, addRowWithField, buildResult, clearState, columnFor, conditionsFor, createInitialState, hasManualRows as hasManualRowsState, removeRow, setRowCondition, setRowField, setRowValue, } from "../filters/filter-state.js";
|
|
2
|
+
import { addRow, addRowWithField, buildResult, clearState, columnFor, conditionsFor, createInitialState, hasManualRows as hasManualRowsState, removeRow, restoreRows, setRowCondition, setRowField, setRowValue, } from "../filters/filter-state.js";
|
|
3
3
|
export function useFilterBuilder(descriptor) {
|
|
4
4
|
const [state, setState] = useState(createInitialState);
|
|
5
5
|
const result = useMemo(() => buildResult(state), [state]);
|
|
@@ -14,6 +14,7 @@ export function useFilterBuilder(descriptor) {
|
|
|
14
14
|
setCondition: (index, condition) => setState((s) => setRowCondition(s, index, condition)),
|
|
15
15
|
setValue: (index, value) => setState((s) => setRowValue(s, index, value)),
|
|
16
16
|
clear: () => setState(clearState),
|
|
17
|
+
restore: (rows) => setState(() => restoreRows(rows)),
|
|
17
18
|
conditionsFor: (field) => conditionsFor(descriptor, field),
|
|
18
19
|
columnFor: (field) => columnFor(descriptor, field),
|
|
19
20
|
result,
|