@promoboxx/use-filter 2.0.0 → 2.0.1
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/dist/cjs/_virtual/_rolldown/runtime.js +29 -0
- package/dist/cjs/lib/buildDefaultFilterInfo.d.ts +5 -0
- package/dist/cjs/lib/buildDefaultFilterInfo.js +27 -0
- package/dist/cjs/lib/getOffsetFromPage.d.ts +3 -0
- package/dist/cjs/lib/getOffsetFromPage.js +8 -0
- package/dist/cjs/lib/getPageFromOffset.d.ts +3 -0
- package/dist/cjs/lib/getPageFromOffset.js +8 -0
- package/dist/cjs/lib/shallowEqual.d.ts +3 -0
- package/dist/cjs/lib/shallowEqual.js +24 -0
- package/dist/cjs/store/index.d.ts +14 -0
- package/dist/cjs/store/index.js +18 -0
- package/dist/cjs/store/localStorageStore.d.ts +5 -0
- package/dist/cjs/store/localStorageStore.js +33 -0
- package/dist/cjs/store/memoryStore.d.ts +5 -0
- package/dist/cjs/store/memoryStore.js +25 -0
- package/dist/cjs/store/reduxHelpers/createActions.d.ts +16 -0
- package/dist/cjs/store/reduxHelpers/createActions.js +16 -0
- package/dist/cjs/store/reduxHelpers/createReducer.d.ts +10 -0
- package/dist/cjs/store/reduxHelpers/createReducer.js +25 -0
- package/dist/cjs/store/reduxStore.d.ts +18 -0
- package/dist/cjs/store/reduxStore.js +63 -0
- package/dist/cjs/store/urlParamStore.d.ts +8 -0
- package/dist/cjs/store/urlParamStore.js +68 -0
- package/dist/cjs/useFilter.d.ts +106 -0
- package/dist/cjs/useFilter.js +251 -0
- package/dist/cjs/useSimpleFilter.d.ts +89 -0
- package/dist/cjs/useSimpleFilter.js +198 -0
- package/dist/esm/lib/buildDefaultFilterInfo.d.mts +6 -0
- package/dist/esm/lib/buildDefaultFilterInfo.mjs +27 -0
- package/dist/esm/lib/getOffsetFromPage.d.mts +4 -0
- package/dist/esm/lib/getOffsetFromPage.mjs +7 -0
- package/dist/esm/lib/getPageFromOffset.d.mts +4 -0
- package/dist/esm/lib/getPageFromOffset.mjs +7 -0
- package/dist/esm/lib/shallowEqual.d.mts +4 -0
- package/dist/esm/lib/shallowEqual.mjs +23 -0
- package/dist/esm/store/index.d.mts +14 -0
- package/dist/esm/store/index.mjs +15 -0
- package/dist/esm/store/localStorageStore.d.mts +6 -0
- package/dist/esm/store/localStorageStore.mjs +32 -0
- package/dist/esm/store/memoryStore.d.mts +6 -0
- package/dist/esm/store/memoryStore.mjs +24 -0
- package/dist/esm/store/reduxHelpers/createActions.d.mts +16 -0
- package/dist/esm/store/reduxHelpers/createActions.mjs +15 -0
- package/dist/esm/store/reduxHelpers/createReducer.d.mts +11 -0
- package/dist/esm/store/reduxHelpers/createReducer.mjs +24 -0
- package/dist/esm/store/reduxStore.d.mts +18 -0
- package/dist/esm/store/reduxStore.mjs +61 -0
- package/dist/esm/store/urlParamStore.d.mts +8 -0
- package/dist/esm/store/urlParamStore.mjs +63 -0
- package/dist/esm/useFilter.d.mts +106 -0
- package/dist/esm/useFilter.mjs +251 -0
- package/dist/esm/useSimpleFilter.d.mts +89 -0
- package/dist/esm/useSimpleFilter.mjs +198 -0
- package/package.json +1 -1
- package/.github/workflows/main.yml +0 -38
- package/.vscode/settings.json +0 -3
- package/CHANGELOG.md +0 -185
- package/Makefile +0 -25
- package/eslint.config.js +0 -30
- package/mise.toml +0 -3
- package/prettier.config.js +0 -3
- package/src/lib/buildDefaultFilterInfo.ts +0 -36
- package/src/lib/getOffsetFromPage.ts +0 -5
- package/src/lib/getPageFromOffset.ts +0 -5
- package/src/lib/shallowEqual.test.ts +0 -71
- package/src/lib/shallowEqual.ts +0 -26
- package/src/store/index.ts +0 -30
- package/src/store/localStorageStore.ts +0 -36
- package/src/store/memoryStore.ts +0 -27
- package/src/store/reduxHelpers/createActions.test.ts +0 -32
- package/src/store/reduxHelpers/createActions.ts +0 -56
- package/src/store/reduxHelpers/createReducer.test.ts +0 -65
- package/src/store/reduxHelpers/createReducer.ts +0 -47
- package/src/store/reduxStore.ts +0 -78
- package/src/store/urlParamStore.test.ts +0 -131
- package/src/store/urlParamStore.ts +0 -85
- package/src/useFilter.test.tsx +0 -822
- package/src/useFilter.ts +0 -524
- package/src/useSimpleFilter.test.tsx +0 -676
- package/src/useSimpleFilter.ts +0 -397
- package/src/vitest-env.d.ts +0 -1
- package/tsconfig.json +0 -76
- package/tsdown.config.ts +0 -30
- package/vite.config.ts +0 -9
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { FilterStore } from "./store/index.mjs";
|
|
2
|
+
import { UseFilterUpdateReason } from "./useFilter.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/useSimpleFilter.d.ts
|
|
5
|
+
interface UseSimpleFilterOptions<TFilter> {
|
|
6
|
+
/**
|
|
7
|
+
* Default values for your filter. When calling `.reset` your filter will be
|
|
8
|
+
* set to this.
|
|
9
|
+
* Changing these values does not cause a call to happen.
|
|
10
|
+
*/
|
|
11
|
+
defaultFilterInfo?: Partial<SimpleFilterInfo<TFilter>>;
|
|
12
|
+
/**
|
|
13
|
+
* In case you want to change the default debounce duration.
|
|
14
|
+
*/
|
|
15
|
+
debounceDuration?: number;
|
|
16
|
+
onBeforeSaveFilter?: (filterInfo: SimpleFilterInfo<TFilter>) => SimpleFilterInfo<TFilter>;
|
|
17
|
+
store?: FilterStore;
|
|
18
|
+
}
|
|
19
|
+
interface SimpleFilterApi<TFilter> {
|
|
20
|
+
/**
|
|
21
|
+
* Really more "is debouncing", since simple mode doesn't know when your code
|
|
22
|
+
* is doing anything.
|
|
23
|
+
*/
|
|
24
|
+
isLoading: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Access to the filter and its metadata.
|
|
27
|
+
*/
|
|
28
|
+
filterInfo: SimpleFilterInfo<TFilter>;
|
|
29
|
+
/**
|
|
30
|
+
* Same as the regular `filterInfo`, but updates in a debounced fashion.
|
|
31
|
+
*/
|
|
32
|
+
debouncedFilterInfo: SimpleFilterInfo<TFilter>;
|
|
33
|
+
/**
|
|
34
|
+
* Why the last update happened.
|
|
35
|
+
*/
|
|
36
|
+
updateReason: UseFilterUpdateReason;
|
|
37
|
+
/**
|
|
38
|
+
* Update one or more values in your filter.
|
|
39
|
+
*/
|
|
40
|
+
updateFilter: (filter: Partial<TFilter>, shouldRunImmediately?: boolean) => void;
|
|
41
|
+
/**
|
|
42
|
+
* Does the boring math for you based on your `pageSize` and `totalResults`.
|
|
43
|
+
*/
|
|
44
|
+
pagingInfo: (total: string | number | null | undefined) => {
|
|
45
|
+
totalResults: number;
|
|
46
|
+
totalPages: number;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Resets the filter back to `defaultFilterInfo`.
|
|
50
|
+
*/
|
|
51
|
+
resetFilter: (shouldRunImmediately?: boolean) => void;
|
|
52
|
+
/**
|
|
53
|
+
* Changes the offset. Will update `page`.
|
|
54
|
+
*/
|
|
55
|
+
setOffset: (offset: number | string, shouldRunImmediately?: boolean) => void;
|
|
56
|
+
/**
|
|
57
|
+
* Changes the page. Will update `offset`.
|
|
58
|
+
*/
|
|
59
|
+
setPage: (page: number | string, shouldRunImmediately?: boolean) => void;
|
|
60
|
+
/**
|
|
61
|
+
* Changes the page size.
|
|
62
|
+
*/
|
|
63
|
+
setPageSize: (pageSize: number | string, shouldRunImmediately?: boolean) => void;
|
|
64
|
+
/**
|
|
65
|
+
* Change the sort method.
|
|
66
|
+
*/
|
|
67
|
+
setSort: (sort: string, shouldRunImmediately?: boolean) => void;
|
|
68
|
+
/**
|
|
69
|
+
* Changes the cursor.
|
|
70
|
+
*/
|
|
71
|
+
setCursor: (cursor: string | null | undefined, shouldRunImmediately?: boolean) => void;
|
|
72
|
+
/**
|
|
73
|
+
* Forces a refresh of the filter.
|
|
74
|
+
*/
|
|
75
|
+
forceRefresh: (shouldRunImmediately?: boolean) => void;
|
|
76
|
+
}
|
|
77
|
+
interface SimpleFilterInfo<TFilter> {
|
|
78
|
+
filter: TFilter;
|
|
79
|
+
sort?: string;
|
|
80
|
+
offset: number;
|
|
81
|
+
page: number;
|
|
82
|
+
pageSize: number;
|
|
83
|
+
lastRefreshAt: number;
|
|
84
|
+
cursor?: string | null;
|
|
85
|
+
shouldRunImmediately: boolean;
|
|
86
|
+
}
|
|
87
|
+
declare function useSimpleFilter<TFilter extends Record<string, unknown>>(namespace: string, options: UseSimpleFilterOptions<TFilter>): SimpleFilterApi<TFilter>;
|
|
88
|
+
//#endregion
|
|
89
|
+
export { SimpleFilterApi, SimpleFilterInfo, useSimpleFilter as default };
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import getOffsetFromPage from "./lib/getOffsetFromPage.mjs";
|
|
2
|
+
import getPageFromOffset from "./lib/getPageFromOffset.mjs";
|
|
3
|
+
import shallowEqual from "./lib/shallowEqual.mjs";
|
|
4
|
+
import { getFilterStore } from "./store/index.mjs";
|
|
5
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
6
|
+
|
|
7
|
+
//#region src/useSimpleFilter.ts
|
|
8
|
+
function useSimpleFilter(namespace, options) {
|
|
9
|
+
const ctxRefValue = {
|
|
10
|
+
namespace,
|
|
11
|
+
debounceDuration: options.debounceDuration,
|
|
12
|
+
defaultFilterInfo: options.defaultFilterInfo,
|
|
13
|
+
onBeforeSaveFilter: options.onBeforeSaveFilter,
|
|
14
|
+
store: options.store
|
|
15
|
+
};
|
|
16
|
+
const ctxRef = useRef(ctxRefValue);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
ctxRef.current = ctxRefValue;
|
|
19
|
+
});
|
|
20
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
21
|
+
const [filterInfo, setFilterInfoState] = useState(() => {
|
|
22
|
+
const fromStore = getFilterStore(ctxRef.current.store).getFilter(namespace);
|
|
23
|
+
if (fromStore) {
|
|
24
|
+
const filterInfo = buildDefaultFilterInfo({
|
|
25
|
+
...fromStore,
|
|
26
|
+
shouldRunImmediately: true,
|
|
27
|
+
filter: {
|
|
28
|
+
...options.defaultFilterInfo?.filter,
|
|
29
|
+
...fromStore.filter
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
return filterInfo;
|
|
33
|
+
} else {
|
|
34
|
+
return buildDefaultFilterInfo({
|
|
35
|
+
...options.defaultFilterInfo,
|
|
36
|
+
shouldRunImmediately: true
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
const [debouncedFilterInfo, setDebouncedFilterInfo] = useState(filterInfo);
|
|
41
|
+
const lastRefreshAtRef = useRef(-1);
|
|
42
|
+
const updateReasonRef = useRef("initial");
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
setIsLoading(true);
|
|
45
|
+
if (lastRefreshAtRef.current === filterInfo.lastRefreshAt) {
|
|
46
|
+
setIsLoading(false);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
let timeout = undefined;
|
|
50
|
+
function makeRequest() {
|
|
51
|
+
lastRefreshAtRef.current = filterInfo.lastRefreshAt;
|
|
52
|
+
getFilterStore(ctxRef.current.store).saveFilter(ctxRef.current.namespace, ctxRef.current.onBeforeSaveFilter ? ctxRef.current.onBeforeSaveFilter(filterInfo) : filterInfo);
|
|
53
|
+
setDebouncedFilterInfo(filterInfo);
|
|
54
|
+
setIsLoading(false);
|
|
55
|
+
}
|
|
56
|
+
if (filterInfo.shouldRunImmediately) {
|
|
57
|
+
makeRequest();
|
|
58
|
+
} else {
|
|
59
|
+
timeout = setTimeout(makeRequest, ctxRef.current.debounceDuration ?? 500);
|
|
60
|
+
}
|
|
61
|
+
return () => {
|
|
62
|
+
if (timeout) {
|
|
63
|
+
clearTimeout(timeout);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}, [filterInfo]);
|
|
67
|
+
const previousTotalRef = useRef(0);
|
|
68
|
+
const api = {
|
|
69
|
+
isLoading,
|
|
70
|
+
filterInfo,
|
|
71
|
+
debouncedFilterInfo,
|
|
72
|
+
updateReason: updateReasonRef.current,
|
|
73
|
+
updateFilter: useCallback((filter, shouldRunImmediately = false) => {
|
|
74
|
+
updateReasonRef.current = "filter";
|
|
75
|
+
setFilterInfoState((previous) => {
|
|
76
|
+
const nextFilter = {
|
|
77
|
+
...previous.filter,
|
|
78
|
+
...filter
|
|
79
|
+
};
|
|
80
|
+
if (shallowEqual(previous.filter, nextFilter)) {
|
|
81
|
+
return previous;
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
...previous,
|
|
85
|
+
shouldRunImmediately,
|
|
86
|
+
offset: 0,
|
|
87
|
+
page: 1,
|
|
88
|
+
totalResults: 1,
|
|
89
|
+
totalPages: 1,
|
|
90
|
+
filter: nextFilter,
|
|
91
|
+
cursor: undefined,
|
|
92
|
+
lastRefreshAt: new Date().getTime()
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
}, []),
|
|
96
|
+
pagingInfo: useCallback((total) => {
|
|
97
|
+
const normalized = Number(total == null ? previousTotalRef.current : total);
|
|
98
|
+
previousTotalRef.current = normalized;
|
|
99
|
+
return {
|
|
100
|
+
totalResults: normalized,
|
|
101
|
+
totalPages: Math.ceil(normalized / filterInfo.pageSize)
|
|
102
|
+
};
|
|
103
|
+
}, [filterInfo.pageSize]),
|
|
104
|
+
resetFilter: useCallback((shouldRunImmediately = false) => {
|
|
105
|
+
updateReasonRef.current = "filter";
|
|
106
|
+
setFilterInfoState({
|
|
107
|
+
...buildDefaultFilterInfo(ctxRef.current.defaultFilterInfo),
|
|
108
|
+
shouldRunImmediately
|
|
109
|
+
});
|
|
110
|
+
}, []),
|
|
111
|
+
setOffset: useCallback((offset, shouldRunImmediately = false) => {
|
|
112
|
+
updateReasonRef.current = "pagination";
|
|
113
|
+
const offsetNumber = Number(offset);
|
|
114
|
+
setFilterInfoState((previous) => ({
|
|
115
|
+
...previous,
|
|
116
|
+
offset: offsetNumber,
|
|
117
|
+
page: getPageFromOffset(offsetNumber, previous.pageSize),
|
|
118
|
+
lastRefreshAt: new Date().getTime(),
|
|
119
|
+
shouldRunImmediately
|
|
120
|
+
}));
|
|
121
|
+
}, []),
|
|
122
|
+
setPage: useCallback((page, shouldRunImmediately = false) => {
|
|
123
|
+
updateReasonRef.current = "pagination";
|
|
124
|
+
const pageNumber = Number(page);
|
|
125
|
+
setFilterInfoState((previous) => ({
|
|
126
|
+
...previous,
|
|
127
|
+
offset: getOffsetFromPage(pageNumber, previous.pageSize),
|
|
128
|
+
page: pageNumber,
|
|
129
|
+
lastRefreshAt: new Date().getTime(),
|
|
130
|
+
shouldRunImmediately
|
|
131
|
+
}));
|
|
132
|
+
}, []),
|
|
133
|
+
setPageSize: useCallback((pageSize, shouldRunImmediately = false) => {
|
|
134
|
+
updateReasonRef.current = "pagination";
|
|
135
|
+
setFilterInfoState((previous) => {
|
|
136
|
+
const pageSizeNumber = Number(pageSize);
|
|
137
|
+
const page = getPageFromOffset(previous.offset, pageSizeNumber);
|
|
138
|
+
const offset = getOffsetFromPage(page, pageSizeNumber);
|
|
139
|
+
return {
|
|
140
|
+
...previous,
|
|
141
|
+
pageSize: pageSizeNumber,
|
|
142
|
+
offset,
|
|
143
|
+
page,
|
|
144
|
+
lastRefreshAt: new Date().getTime(),
|
|
145
|
+
shouldRunImmediately
|
|
146
|
+
};
|
|
147
|
+
});
|
|
148
|
+
}, []),
|
|
149
|
+
setSort: useCallback((sort, shouldRunImmediately = false) => {
|
|
150
|
+
updateReasonRef.current = "filter";
|
|
151
|
+
setFilterInfoState((previous) => ({
|
|
152
|
+
...previous,
|
|
153
|
+
sort,
|
|
154
|
+
lastRefreshAt: new Date().getTime(),
|
|
155
|
+
shouldRunImmediately
|
|
156
|
+
}));
|
|
157
|
+
}, []),
|
|
158
|
+
setCursor: useCallback((cursor, shouldRunImmediately = false) => {
|
|
159
|
+
updateReasonRef.current = "pagination";
|
|
160
|
+
setFilterInfoState((previous) => ({
|
|
161
|
+
...previous,
|
|
162
|
+
cursor,
|
|
163
|
+
lastRefreshAt: new Date().getTime(),
|
|
164
|
+
shouldRunImmediately
|
|
165
|
+
}));
|
|
166
|
+
}, []),
|
|
167
|
+
forceRefresh: useCallback((shouldRunImmediately = false) => {
|
|
168
|
+
updateReasonRef.current = "filter";
|
|
169
|
+
setFilterInfoState((previous) => ({
|
|
170
|
+
...previous,
|
|
171
|
+
lastRefreshAt: new Date().getTime(),
|
|
172
|
+
shouldRunImmediately
|
|
173
|
+
}));
|
|
174
|
+
}, [])
|
|
175
|
+
};
|
|
176
|
+
return api;
|
|
177
|
+
}
|
|
178
|
+
function buildDefaultFilterInfo(filterInfo = {}) {
|
|
179
|
+
const merged = {
|
|
180
|
+
filter: {},
|
|
181
|
+
sort: undefined,
|
|
182
|
+
pageSize: 20,
|
|
183
|
+
lastRefreshAt: new Date().getTime(),
|
|
184
|
+
offset: 0,
|
|
185
|
+
page: 1,
|
|
186
|
+
shouldRunImmediately: false,
|
|
187
|
+
...filterInfo
|
|
188
|
+
};
|
|
189
|
+
if (filterInfo.page != null && filterInfo.offset == null) {
|
|
190
|
+
merged.offset = getOffsetFromPage(filterInfo.page, merged.pageSize);
|
|
191
|
+
} else if (filterInfo.page == null && filterInfo.offset != null) {
|
|
192
|
+
merged.page = getPageFromOffset(filterInfo.offset, merged.pageSize);
|
|
193
|
+
}
|
|
194
|
+
return merged;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
//#endregion
|
|
198
|
+
export { useSimpleFilter as default };
|
package/package.json
CHANGED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
name: CI
|
|
2
|
-
on: push
|
|
3
|
-
|
|
4
|
-
jobs:
|
|
5
|
-
ci:
|
|
6
|
-
runs-on: ubuntu-latest
|
|
7
|
-
|
|
8
|
-
steps:
|
|
9
|
-
- uses: actions/checkout@v2
|
|
10
|
-
|
|
11
|
-
- uses: jdx/mise-action@v2
|
|
12
|
-
|
|
13
|
-
- name: Get pnpm store directory
|
|
14
|
-
shell: bash
|
|
15
|
-
run: |
|
|
16
|
-
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
|
|
17
|
-
|
|
18
|
-
- uses: actions/cache@v3
|
|
19
|
-
name: Setup pnpm cache
|
|
20
|
-
with:
|
|
21
|
-
path: ${{ env.STORE_PATH }}
|
|
22
|
-
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
|
|
23
|
-
restore-keys: |
|
|
24
|
-
${{ runner.os }}-pnpm-store-
|
|
25
|
-
|
|
26
|
-
# https://github.community/t/github-actions-bot-email-address/17204/5
|
|
27
|
-
- name: Prep for git push
|
|
28
|
-
run: |
|
|
29
|
-
git config --local user.name "github-actions[bot]"
|
|
30
|
-
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
|
31
|
-
|
|
32
|
-
- name: Prep NPM
|
|
33
|
-
run: npm config set '//registry.npmjs.org/:_authToken' "${{secrets.NPM_TOKEN}}"
|
|
34
|
-
|
|
35
|
-
- run: make prepare-env
|
|
36
|
-
- run: make test
|
|
37
|
-
- run: make build
|
|
38
|
-
- run: make deploy
|
package/.vscode/settings.json
DELETED
package/CHANGELOG.md
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
|
-
|
|
5
|
-
## 2.0.0 (2026-06-07)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
### ⚠ BREAKING CHANGES
|
|
9
|
-
|
|
10
|
-
* ESM + CJS and various upgrades (#23)
|
|
11
|
-
|
|
12
|
-
### Features
|
|
13
|
-
|
|
14
|
-
* ESM + CJS and various upgrades ([#23](https://github.com/promoboxx/use-filter/issues/23)) ([e898ea7](https://github.com/promoboxx/use-filter/commit/e898ea782effbbaa21f3cfe71b44cd007a5c54d2))
|
|
15
|
-
|
|
16
|
-
### 1.11.2 (2023-08-01)
|
|
17
|
-
|
|
18
|
-
### 1.11.1 (2023-06-12)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
### Bug Fixes
|
|
22
|
-
|
|
23
|
-
* Handle partial persisted `FilterInfo` / `TFilter` ([#21](https://github.com/promoboxx/use-filter/issues/21)) ([45e54ae](https://github.com/promoboxx/use-filter/commit/45e54ae960fdc2df2b37f8a9b59c2cc9dc5bc277))
|
|
24
|
-
|
|
25
|
-
## 1.11.0 (2023-05-25)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
### Features
|
|
29
|
-
|
|
30
|
-
* Add `store` to hooks ([#20](https://github.com/promoboxx/use-filter/issues/20)) ([d7232cd](https://github.com/promoboxx/use-filter/commit/d7232cdca3b660020acb8d82a7b2464e3237bd87))
|
|
31
|
-
|
|
32
|
-
## 1.10.0 (2023-05-24)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
### Features
|
|
36
|
-
|
|
37
|
-
* DEV-7161: URL param store ([#19](https://github.com/promoboxx/use-filter/issues/19)) ([ea658f3](https://github.com/promoboxx/use-filter/commit/ea658f3eb6343ddca8bfaa23af5b5cf4335f0428))
|
|
38
|
-
|
|
39
|
-
### 1.9.1 (2023-03-27)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
### Bug Fixes
|
|
43
|
-
|
|
44
|
-
* Better check for totalResults / nextCursor in onChange response ([#18](https://github.com/promoboxx/use-filter/issues/18)) ([3cecc45](https://github.com/promoboxx/use-filter/commit/3cecc45d12f36895498dbb9d38fdb0f1220ca3af))
|
|
45
|
-
|
|
46
|
-
## 1.9.0 (2023-03-16)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
### Features
|
|
50
|
-
|
|
51
|
-
* DEV-6808: Add `onBeforeSaveFilter` ([#17](https://github.com/promoboxx/use-filter/issues/17)) ([f1f6f0b](https://github.com/promoboxx/use-filter/commit/f1f6f0b5e9befcf9fc001223bbf1ddd9d39b1fed))
|
|
52
|
-
|
|
53
|
-
### 1.8.3 (2023-03-16)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
### Bug Fixes
|
|
57
|
-
|
|
58
|
-
* DEV-6994: Reset cursor when filters change ([#16](https://github.com/promoboxx/use-filter/issues/16)) ([9115b92](https://github.com/promoboxx/use-filter/commit/9115b9201d257afb9d1d0dcf7ddd7af23ad1abc9))
|
|
59
|
-
|
|
60
|
-
### 1.8.2 (2022-12-07)
|
|
61
|
-
|
|
62
|
-
### 1.8.1 (2022-12-04)
|
|
63
|
-
|
|
64
|
-
## 1.8.0 (2022-11-25)
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
### Features
|
|
68
|
-
|
|
69
|
-
* Concept of "update reason" ([#14](https://github.com/promoboxx/use-filter/issues/14)) ([0b34cd3](https://github.com/promoboxx/use-filter/commit/0b34cd3854b2d49128998cb5a0fff9c05627ff31))
|
|
70
|
-
|
|
71
|
-
## 1.7.0 (2022-11-25)
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
### Features
|
|
75
|
-
|
|
76
|
-
* Cursor Pagination ([#13](https://github.com/promoboxx/use-filter/issues/13)) ([4df58f6](https://github.com/promoboxx/use-filter/commit/4df58f6a24004a7655f1e5c4d97db4c05e0613d7))
|
|
77
|
-
|
|
78
|
-
## 1.6.0 (2022-06-02)
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
### Features
|
|
82
|
-
|
|
83
|
-
* `setPageSize` helper ([#12](https://github.com/promoboxx/use-filter/issues/12)) ([364b1b8](https://github.com/promoboxx/use-filter/commit/364b1b80acdeef3a6464a2b8fcb1c2bea30ad54a))
|
|
84
|
-
|
|
85
|
-
### 1.5.4 (2022-05-25)
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
### Bug Fixes
|
|
89
|
-
|
|
90
|
-
* When filter exists in useFilter, run immediately on mount ([#11](https://github.com/promoboxx/use-filter/issues/11)) ([50338e9](https://github.com/promoboxx/use-filter/commit/50338e91c0ddeff969e05a63450d90a368a63c08))
|
|
91
|
-
|
|
92
|
-
### 1.5.3 (2022-05-21)
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
### Bug Fixes
|
|
96
|
-
|
|
97
|
-
* Simple mode immediate on mount ([#10](https://github.com/promoboxx/use-filter/issues/10)) ([c5b7023](https://github.com/promoboxx/use-filter/commit/c5b7023ed5e7c80b2948048a32e195ec0f36eacd))
|
|
98
|
-
|
|
99
|
-
### 1.5.2 (2022-05-21)
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
### Bug Fixes
|
|
103
|
-
|
|
104
|
-
* "Advanced" mode is always immediate ([#9](https://github.com/promoboxx/use-filter/issues/9)) ([2a2fdad](https://github.com/promoboxx/use-filter/commit/2a2fdad8d80b9cf98a0729e8f360ed00f71b5e38))
|
|
105
|
-
|
|
106
|
-
### 1.5.1 (2022-05-20)
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
### Bug Fixes
|
|
110
|
-
|
|
111
|
-
* Update package files ([#8](https://github.com/promoboxx/use-filter/issues/8)) ([c06fc1e](https://github.com/promoboxx/use-filter/commit/c06fc1ef8fc9ff6faf177a7535a4a03984c5c750))
|
|
112
|
-
|
|
113
|
-
## 1.5.0 (2022-05-19)
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
### Features
|
|
117
|
-
|
|
118
|
-
* Add useSimpleFilter ([#7](https://github.com/promoboxx/use-filter/issues/7)) ([c103e8e](https://github.com/promoboxx/use-filter/commit/c103e8e675998099f0c990a2b062335e926fd869))
|
|
119
|
-
|
|
120
|
-
## 1.4.0 (2022-05-16)
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
### Features
|
|
124
|
-
|
|
125
|
-
* Add `shouldRunImmediately` and refactor ([#6](https://github.com/promoboxx/use-filter/issues/6)) ([9f6bf0b](https://github.com/promoboxx/use-filter/commit/9f6bf0bc1be7563a1b29920a09a5794c02d506fc))
|
|
126
|
-
|
|
127
|
-
## 1.3.0 (2021-07-18)
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
### Features
|
|
131
|
-
|
|
132
|
-
* Redux store ([#5](https://github.com/promoboxx/use-filter/issues/5)) ([f92bee6](https://github.com/promoboxx/use-filter/commit/f92bee6417f78117ab9ca4936c23b24647aac008))
|
|
133
|
-
|
|
134
|
-
### 1.2.1 (2021-07-17)
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
### Bug Fixes
|
|
138
|
-
|
|
139
|
-
* some git stuff is needed ([2bb0f21](https://github.com/promoboxx/use-filter/commit/2bb0f2117c79fd1ba0b6a309db4234caf162f57b))
|
|
140
|
-
|
|
141
|
-
## 1.2.0 (2021-07-16)
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
### Features
|
|
145
|
-
|
|
146
|
-
* Add localStorageStore ([#4](https://github.com/promoboxx/use-filter/issues/4)) ([a6087e2](https://github.com/promoboxx/use-filter/commit/a6087e2f07a3640799b840e128b96838cd8ef150))
|
|
147
|
-
|
|
148
|
-
## 1.1.0 (2021-07-16)
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
### Features
|
|
152
|
-
|
|
153
|
-
* Add concept of data to useFilter ([#2](https://github.com/promoboxx/use-filter/issues/2)) ([563c5a9](https://github.com/promoboxx/use-filter/commit/563c5a959cdc22a0f8eba9dbb3dde7802df02b46))
|
|
154
|
-
|
|
155
|
-
### 1.0.6 (2021-07-16)
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
### Bug Fixes
|
|
159
|
-
|
|
160
|
-
* dont deploy test files ([500151c](https://github.com/promoboxx/use-filter/commit/500151c04f75139c71baf29b2ad2dccefcd57db7))
|
|
161
|
-
|
|
162
|
-
### 1.0.5 (2021-07-16)
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
### Bug Fixes
|
|
166
|
-
|
|
167
|
-
* declaration files ([4ce29e4](https://github.com/promoboxx/use-filter/commit/4ce29e43469ad4ade2d222c3b09f38ad8f89ca4c))
|
|
168
|
-
|
|
169
|
-
### 1.0.4 (2021-07-16)
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
### Bug Fixes
|
|
173
|
-
|
|
174
|
-
* more release prep ([daf06ac](https://github.com/promoboxx/use-filter/commit/daf06acc94668fdc7f0905c120f5541b4b2d16e9))
|
|
175
|
-
|
|
176
|
-
### 1.0.3 (2021-07-16)
|
|
177
|
-
|
|
178
|
-
### 1.0.2 (2021-07-16)
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
### Bug Fixes
|
|
182
|
-
|
|
183
|
-
* proper secrets syntax ([afc9fe9](https://github.com/promoboxx/use-filter/commit/afc9fe9b177dda2961d82858ef43cc481f762950))
|
|
184
|
-
|
|
185
|
-
### 1.0.1 (2021-07-16)
|
package/Makefile
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
prepare-env:
|
|
2
|
-
pnpm install
|
|
3
|
-
|
|
4
|
-
prepare-when-local:
|
|
5
|
-
ifneq ($(CI),true)
|
|
6
|
-
$(MAKE) prepare-env
|
|
7
|
-
endif
|
|
8
|
-
|
|
9
|
-
start: test
|
|
10
|
-
|
|
11
|
-
build: prepare-when-local
|
|
12
|
-
rm -rf dist/
|
|
13
|
-
./node_modules/.bin/tsc --noEmit
|
|
14
|
-
./node_modules/.bin/eslint --max-warnings 0 --ext js,jsx,ts,tsx,mjs,cjs src/
|
|
15
|
-
./node_modules/.bin/tsdown
|
|
16
|
-
|
|
17
|
-
test: prepare-when-local
|
|
18
|
-
./node_modules/.bin/vitest
|
|
19
|
-
|
|
20
|
-
deploy:
|
|
21
|
-
ifeq ($(GITHUB_REF),refs/heads/main)
|
|
22
|
-
npx standard-version
|
|
23
|
-
git push origin --tags HEAD
|
|
24
|
-
npm publish
|
|
25
|
-
endif
|
package/eslint.config.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import pbxxBase from '@promoboxx/eslint-config'
|
|
2
|
-
import pbxxPrettier from '@promoboxx/eslint-config/prettier'
|
|
3
|
-
import pbxxReact from '@promoboxx/eslint-config/react'
|
|
4
|
-
|
|
5
|
-
/** @type {import('eslint').Linter.Config[]} */
|
|
6
|
-
const config = [
|
|
7
|
-
...pbxxBase,
|
|
8
|
-
...pbxxPrettier,
|
|
9
|
-
...pbxxReact,
|
|
10
|
-
|
|
11
|
-
{
|
|
12
|
-
files: ['**/*.test.{ts,tsx}'],
|
|
13
|
-
rules: {
|
|
14
|
-
'@typescript-eslint/no-non-null-assertion': 'off',
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
|
|
18
|
-
// TODO This project is old, and while it is a library, has way too many
|
|
19
|
-
// `any` and casts. Disabled for now, but should be re-enabled and fixed up
|
|
20
|
-
// over time.
|
|
21
|
-
{
|
|
22
|
-
files: ['**/*.{js,jsx,ts,tsx}'],
|
|
23
|
-
rules: {
|
|
24
|
-
'@typescript-eslint/no-explicit-any': 'off',
|
|
25
|
-
'@typescript-eslint/consistent-type-assertions': 'off',
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
]
|
|
29
|
-
|
|
30
|
-
export default config
|
package/mise.toml
DELETED
package/prettier.config.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { FilterInfo } from '../useFilter'
|
|
2
|
-
|
|
3
|
-
import getOffsetFromPage from './getOffsetFromPage'
|
|
4
|
-
import getPageFromOffset from './getPageFromOffset'
|
|
5
|
-
|
|
6
|
-
function buildDefaultFilterInfo<T extends Record<string, unknown>>(
|
|
7
|
-
filterInfo: Partial<FilterInfo<T>> = {},
|
|
8
|
-
): FilterInfo<T> {
|
|
9
|
-
const merged: FilterInfo<T> = {
|
|
10
|
-
// Cast here to work around "'T' could be instantiated with an arbitrary
|
|
11
|
-
// type which could be unrelated to '{}'"
|
|
12
|
-
filter: {} as T,
|
|
13
|
-
|
|
14
|
-
sort: undefined,
|
|
15
|
-
pageSize: 20,
|
|
16
|
-
lastRefreshAt: new Date().getTime(),
|
|
17
|
-
totalResults: 1,
|
|
18
|
-
totalPages: 1,
|
|
19
|
-
offset: 0,
|
|
20
|
-
page: 1,
|
|
21
|
-
shouldRunImmediately: false,
|
|
22
|
-
...filterInfo,
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// If there's a page but no offset, set the offset.
|
|
26
|
-
if (filterInfo.page != null && filterInfo.offset == null) {
|
|
27
|
-
merged.offset = getOffsetFromPage(filterInfo.page, merged.pageSize)
|
|
28
|
-
// If there's an offset but no page, set the page.
|
|
29
|
-
} else if (filterInfo.page == null && filterInfo.offset != null) {
|
|
30
|
-
merged.page = getPageFromOffset(filterInfo.offset, merged.pageSize)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return merged
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export default buildDefaultFilterInfo
|