@webority/web-core 0.125.0 → 0.126.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 +20 -0
- package/dist/index.js +1 -1
- package/dist/query/index.js +1 -1
- package/dist/query/paging.js +1 -1
- package/dist/query/useListQuery.js +1 -0
- package/dist/types/query/index.d.ts +3 -1
- package/dist/types/query/paging.d.ts +10 -12
- package/dist/types/query/useListQuery.d.ts +66 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -225,6 +225,26 @@ strings to the plain names, `ApiError.detail` to `diagnostic` and `detail.signOu
|
|
|
225
225
|
`detail.code`, and lists each removed option (`correlationIdHeader`, `signOutReasonHeader`) and
|
|
226
226
|
constant for a person to delete.
|
|
227
227
|
|
|
228
|
+
## useListQuery
|
|
229
|
+
|
|
230
|
+
`useListQuery` runs a server-paged list from the address bar. The page, sort, filters and search live in the URL, so a reload, a shared link and Back all return to the same view. It reads and writes the URL through react-router's `useSearchParams`, so the list must sit under a router. A new request aborts the one in flight, and a typed search waits 300 ms before it fetches.
|
|
231
|
+
|
|
232
|
+
```tsx
|
|
233
|
+
import { AppDataTable } from "@webority/ui-react";
|
|
234
|
+
import { buildListQuery, useListQuery, userClient } from "@webority/web-core";
|
|
235
|
+
|
|
236
|
+
function LeaveList() {
|
|
237
|
+
const list = useListQuery<Leave>({
|
|
238
|
+
defaults: { sortBy: "start", sortOrder: "desc" },
|
|
239
|
+
fetchPage: (query, { signal }) =>
|
|
240
|
+
userClient.get(`/api/leave?${buildListQuery(query)}`, { signal }).then((r) => r.data),
|
|
241
|
+
});
|
|
242
|
+
return <AppDataTable columns={columns} {...list.tableProps} pagination={list.paginationProps} />;
|
|
243
|
+
}
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
`tableProps` feeds `AppDataTable` and `paginationProps` feeds its pager. The server answers `{ items, page, pageSize, totalCount, totalPages }`, and the hook takes the page size from that answer when the URL names none.
|
|
247
|
+
|
|
228
248
|
## Formatters
|
|
229
249
|
|
|
230
250
|
Called with no options, the house formatters print (zone IST, locale en-IN, empty `-`):
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{DEFAULT_BUILD_CHECK_INTERVAL_MS as e,DEFAULT_LOG_LEVEL as t,DEFAULT_RETRIES as n,DEFAULT_TIMEOUT_MS as r,DEFAULT_VERSION_URL as i,getConfig as a,getConfigValue as o,resetConfig as s,setConfig as c}from"./config/index.js";import{TRACEPARENT_HEADER as l,applyRequestDefaults as u,newTraceparent as d}from"./api/requestDefaults.js";import{Logger as f,configureLogger as p,getDeviceContext as m,setDeviceContext as h,setRemoteLogger as g}from"./logger/logger.js";import{decodeJWT as _,getJWTExpiry as v,isJWTExpired as y}from"./auth/jwt.js";import{ACCESS_TOKEN_KEY as b,LEGACY_REFRESH_TOKEN_LIFETIME_MS as x,REFRESH_TOKEN_KEY as S,SESSION_USER_KEY as C,addSessionEndedListener as w,clearSession as T,getKeepSignedIn as E,getSessionUser as D,getToken as O,hasSession as k,hasSessionEndedInTab as A,removeSessionUser as j,removeToken as M,setKeepSignedIn as N,setLegacyTokenKeys as P,storeSessionUser as F,storeToken as I}from"./auth/authStore.js";import{addNetworkStatusListener as L,getNetworkStatus as R,setNetworkStatusImplementation as z,useNetworkStatus as B}from"./network/networkStatus.js";import{ACCOUNT_ID_HEADER as V,CLIENT_BUILD_HEADER as H,CLIENT_KIND as U,CLIENT_KIND_HEADER as W,getClientBuild as G}from"./api/clientHeaders.js";import{DESIGN_SAMPLE_HEADER as K,DESIGN_SAMPLE_QUERY_KEY as q,DESIGN_SAMPLE_STORAGE_KEY as J,applyDesignSample as Y,readDesignSampleTicket as X}from"./api/designSample.js";import{MIN_APP_VERSION_HEADER as Z,addMinAppVersionListener as Q,getMinAppVersion as $}from"./api/minAppVersion.js";import{WORKSPACE_CHANGED_CODE as ee,WorkspaceChangedError as te,isWorkspaceChangedError as ne}from"./api/workspaceChanged.js";import{IDEMPOTENCY_KEY_HEADER as re,attachRetry as ie,isNeverSentError as ae,isRetryableFailure as oe,isRetryableStatus as se,retryAfterMs as ce}from"./api/retry.js";import{REFRESH_LOCK_NAME as le,withCrossTabRefreshLock as ue}from"./api/crossTabRefreshLock.js";import de from"./api/publicClient.js";import{SESSION_EXPIRED_CODE as fe,SESSION_REVOKED_CODE as pe,injectStore as me,injectUserAuth as he,refreshAccessToken as ge,resetRefreshState as _e}from"./api/tokenRefresh.js";import ve,{RequestOfflineError as ye}from"./api/userClient.js";import{initUserAuth as be}from"./initUserAuth.js";import{CONTRACT_ERROR_CODE as xe,NETWORK_CODE as Se,OFFLINE_CODE as Ce,OFFLINE_MESSAGE as we,REQUEST_CANCELED_CODE as Te,SERVER_FAILURE_MESSAGE as Ee,TIMEOUT_CODE as De,TIMEOUT_MESSAGE as Oe,UNEXPECTED_MESSAGE as ke,UNREACHABLE_MESSAGE as Ae,apiErrorMessage as je,extractApiError as Me,isApiError as Ne,isNoResponse as Pe,toFieldPath as Fe}from"./errors/extractApiError.js";import{configureFormatters as Ie,getFormatterConfig as Le}from"./formatters/formatConfig.js";import{formatCurrency as Re}from"./formatters/currency.js";import{addDays as ze}from"./formatters/dateMath.js";import{formatDate as Be,formatDateTime as Ve,formatMinor as He,formatNumber as Ue,formatPercent as We,formatRelative as Ge,formatTime as Ke}from"./formatters/house.js";import{initWebority as qe}from"./initSDK.js";import{createApiBaseQuery as Je}from"./query/apiBaseQuery.js";import{APP_API_DEFAULTS as Ye,createAppApi as Xe}from"./query/createAppApi.js";import{setupApiListeners as Ze}from"./query/listeners.js";import{
|
|
1
|
+
import{DEFAULT_BUILD_CHECK_INTERVAL_MS as e,DEFAULT_LOG_LEVEL as t,DEFAULT_RETRIES as n,DEFAULT_TIMEOUT_MS as r,DEFAULT_VERSION_URL as i,getConfig as a,getConfigValue as o,resetConfig as s,setConfig as c}from"./config/index.js";import{TRACEPARENT_HEADER as l,applyRequestDefaults as u,newTraceparent as d}from"./api/requestDefaults.js";import{Logger as f,configureLogger as p,getDeviceContext as m,setDeviceContext as h,setRemoteLogger as g}from"./logger/logger.js";import{decodeJWT as _,getJWTExpiry as v,isJWTExpired as y}from"./auth/jwt.js";import{ACCESS_TOKEN_KEY as b,LEGACY_REFRESH_TOKEN_LIFETIME_MS as x,REFRESH_TOKEN_KEY as S,SESSION_USER_KEY as C,addSessionEndedListener as w,clearSession as T,getKeepSignedIn as E,getSessionUser as D,getToken as O,hasSession as k,hasSessionEndedInTab as A,removeSessionUser as j,removeToken as M,setKeepSignedIn as N,setLegacyTokenKeys as P,storeSessionUser as F,storeToken as I}from"./auth/authStore.js";import{addNetworkStatusListener as L,getNetworkStatus as R,setNetworkStatusImplementation as z,useNetworkStatus as B}from"./network/networkStatus.js";import{ACCOUNT_ID_HEADER as V,CLIENT_BUILD_HEADER as H,CLIENT_KIND as U,CLIENT_KIND_HEADER as W,getClientBuild as G}from"./api/clientHeaders.js";import{DESIGN_SAMPLE_HEADER as K,DESIGN_SAMPLE_QUERY_KEY as q,DESIGN_SAMPLE_STORAGE_KEY as J,applyDesignSample as Y,readDesignSampleTicket as X}from"./api/designSample.js";import{MIN_APP_VERSION_HEADER as Z,addMinAppVersionListener as Q,getMinAppVersion as $}from"./api/minAppVersion.js";import{WORKSPACE_CHANGED_CODE as ee,WorkspaceChangedError as te,isWorkspaceChangedError as ne}from"./api/workspaceChanged.js";import{IDEMPOTENCY_KEY_HEADER as re,attachRetry as ie,isNeverSentError as ae,isRetryableFailure as oe,isRetryableStatus as se,retryAfterMs as ce}from"./api/retry.js";import{REFRESH_LOCK_NAME as le,withCrossTabRefreshLock as ue}from"./api/crossTabRefreshLock.js";import de from"./api/publicClient.js";import{SESSION_EXPIRED_CODE as fe,SESSION_REVOKED_CODE as pe,injectStore as me,injectUserAuth as he,refreshAccessToken as ge,resetRefreshState as _e}from"./api/tokenRefresh.js";import ve,{RequestOfflineError as ye}from"./api/userClient.js";import{initUserAuth as be}from"./initUserAuth.js";import{CONTRACT_ERROR_CODE as xe,NETWORK_CODE as Se,OFFLINE_CODE as Ce,OFFLINE_MESSAGE as we,REQUEST_CANCELED_CODE as Te,SERVER_FAILURE_MESSAGE as Ee,TIMEOUT_CODE as De,TIMEOUT_MESSAGE as Oe,UNEXPECTED_MESSAGE as ke,UNREACHABLE_MESSAGE as Ae,apiErrorMessage as je,extractApiError as Me,isApiError as Ne,isNoResponse as Pe,toFieldPath as Fe}from"./errors/extractApiError.js";import{configureFormatters as Ie,getFormatterConfig as Le}from"./formatters/formatConfig.js";import{formatCurrency as Re}from"./formatters/currency.js";import{addDays as ze}from"./formatters/dateMath.js";import{formatDate as Be,formatDateTime as Ve,formatMinor as He,formatNumber as Ue,formatPercent as We,formatRelative as Ge,formatTime as Ke}from"./formatters/house.js";import{initWebority as qe}from"./initSDK.js";import{createApiBaseQuery as Je}from"./query/apiBaseQuery.js";import{APP_API_DEFAULTS as Ye,createAppApi as Xe}from"./query/createAppApi.js";import{setupApiListeners as Ze}from"./query/listeners.js";import{LIST_QUERY_RESERVED as Qe,SEARCH_PARAM as $e,buildListQuery as et,getNextPageParam as tt,getPreviousPageParam as nt,hasNextPage as rt,hasPreviousPage as it,parseListQuery as at}from"./query/paging.js";import{LIST_TAG_ID as ot,itemTag as st,listTag as ct,providesList as lt,providesPagedList as ut}from"./query/tags.js";import{useListQuery as dt}from"./query/useListQuery.js";import{errorToastMiddleware as ft,isSilentRejection as pt}from"./redux/errorToastMiddleware.js";import{createRootReducer as mt,resetState as ht}from"./redux/rootReducer.js";import{SERIALIZABLE_IGNORED_ACTION_PATHS as gt}from"./redux/serializableCheck.js";import{hasRecentlyReloaded as _t,importWithReload as vt,isChunkLoadError as yt,lazyWithReload as bt,markReloaded as xt}from"./router/chunkReload.js";import{classifyRouteError as St,useRouteErrorReport as Ct}from"./router/routeError.js";import{ErrorBoundary as wt}from"./router/ErrorBoundary.js";import{hasPermission as Tt}from"./router/permissions.js";import{RETURN_TO_PARAM as Et,buildLoginPath as Dt,getReturnTo as Ot,toSafeReturnTo as kt}from"./router/returnTo.js";import{PublicOnly as At,RequireAuth as jt,RequirePermission as Mt}from"./router/guards.js";import{publicOnly as Nt,requireAuth as Pt,requirePermission as Ft,withGuards as It}from"./router/loaders.js";import{staticUrl as Lt}from"./static/index.js";import{Storage as Rt,isStorageAvailable as zt,setStorageImplementation as Bt,syncStorage as Vt}from"./storage/index.js";import{isBuildBelowMinimum as Ht,parseBuildNumber as Ut}from"./versionCheck/buildNumber.js";import{addDeployedBuildListener as Wt,getNewerDeployedBuild as Gt,startDeployedBuildCheck as Kt}from"./versionCheck/deployedBuild.js";import{installReloadOnNavigate as qt,isUpdateAvailable as Jt,useVersionCheck as Yt}from"./versionCheck/index.js";export{b as ACCESS_TOKEN_KEY,V as ACCOUNT_ID_HEADER,Ye as APP_API_DEFAULTS,H as CLIENT_BUILD_HEADER,U as CLIENT_KIND,W as CLIENT_KIND_HEADER,xe as CONTRACT_ERROR_CODE,e as DEFAULT_BUILD_CHECK_INTERVAL_MS,t as DEFAULT_LOG_LEVEL,n as DEFAULT_RETRIES,r as DEFAULT_TIMEOUT_MS,i as DEFAULT_VERSION_URL,K as DESIGN_SAMPLE_HEADER,q as DESIGN_SAMPLE_QUERY_KEY,J as DESIGN_SAMPLE_STORAGE_KEY,wt as ErrorBoundary,re as IDEMPOTENCY_KEY_HEADER,x as LEGACY_REFRESH_TOKEN_LIFETIME_MS,Qe as LIST_QUERY_RESERVED,ot as LIST_TAG_ID,f as Logger,Z as MIN_APP_VERSION_HEADER,Se as NETWORK_CODE,Ce as OFFLINE_CODE,we as OFFLINE_MESSAGE,At as PublicOnly,le as REFRESH_LOCK_NAME,S as REFRESH_TOKEN_KEY,Te as REQUEST_CANCELED_CODE,Et as RETURN_TO_PARAM,ye as RequestOfflineError,jt as RequireAuth,Mt as RequirePermission,$e as SEARCH_PARAM,gt as SERIALIZABLE_IGNORED_ACTION_PATHS,Ee as SERVER_FAILURE_MESSAGE,fe as SESSION_EXPIRED_CODE,pe as SESSION_REVOKED_CODE,C as SESSION_USER_KEY,Rt as Storage,De as TIMEOUT_CODE,Oe as TIMEOUT_MESSAGE,l as TRACEPARENT_HEADER,ke as UNEXPECTED_MESSAGE,Ae as UNREACHABLE_MESSAGE,ee as WORKSPACE_CHANGED_CODE,te as WorkspaceChangedError,ze as addDays,Wt as addDeployedBuildListener,Q as addMinAppVersionListener,L as addNetworkStatusListener,w as addSessionEndedListener,je as apiErrorMessage,Y as applyDesignSample,u as applyRequestDefaults,ie as attachRetry,et as buildListQuery,Dt as buildLoginPath,St as classifyRouteError,T as clearSession,Ie as configureFormatters,p as configureLogger,Je as createApiBaseQuery,Xe as createAppApi,mt as createRootReducer,_ as decodeJWT,ft as errorToastMiddleware,Me as extractApiError,Re as formatCurrency,Be as formatDate,Ve as formatDateTime,He as formatMinor,Ue as formatNumber,We as formatPercent,Ge as formatRelative,Ke as formatTime,G as getClientBuild,a as getConfig,o as getConfigValue,m as getDeviceContext,Le as getFormatterConfig,v as getJWTExpiry,E as getKeepSignedIn,$ as getMinAppVersion,R as getNetworkStatus,Gt as getNewerDeployedBuild,tt as getNextPageParam,nt as getPreviousPageParam,Ot as getReturnTo,D as getSessionUser,O as getToken,rt as hasNextPage,Tt as hasPermission,it as hasPreviousPage,_t as hasRecentlyReloaded,k as hasSession,A as hasSessionEndedInTab,vt as importWithReload,be as initUserAuth,qe as initWebority,me as injectStore,he as injectUserAuth,qt as installReloadOnNavigate,Ne as isApiError,Ht as isBuildBelowMinimum,yt as isChunkLoadError,y as isJWTExpired,ae as isNeverSentError,Pe as isNoResponse,oe as isRetryableFailure,se as isRetryableStatus,pt as isSilentRejection,zt as isStorageAvailable,Jt as isUpdateAvailable,ne as isWorkspaceChangedError,st as itemTag,bt as lazyWithReload,ct as listTag,xt as markReloaded,d as newTraceparent,Ut as parseBuildNumber,at as parseListQuery,lt as providesList,ut as providesPagedList,de as publicClient,Nt as publicOnly,X as readDesignSampleTicket,ge as refreshAccessToken,j as removeSessionUser,M as removeToken,Pt as requireAuth,Ft as requirePermission,s as resetConfig,_e as resetRefreshState,ht as resetState,ce as retryAfterMs,c as setConfig,h as setDeviceContext,N as setKeepSignedIn,P as setLegacyTokenKeys,z as setNetworkStatusImplementation,g as setRemoteLogger,Bt as setStorageImplementation,Ze as setupApiListeners,Kt as startDeployedBuildCheck,Lt as staticUrl,F as storeSessionUser,I as storeToken,Vt as syncStorage,Fe as toFieldPath,kt as toSafeReturnTo,dt as useListQuery,B as useNetworkStatus,Ct as useRouteErrorReport,Yt as useVersionCheck,ve as userClient,ue as withCrossTabRefreshLock,It as withGuards};
|
package/dist/query/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createApiBaseQuery as e}from"./apiBaseQuery.js";import{APP_API_DEFAULTS as t,createAppApi as n}from"./createAppApi.js";import{setupApiListeners as r}from"./listeners.js";import{
|
|
1
|
+
import{createApiBaseQuery as e}from"./apiBaseQuery.js";import{APP_API_DEFAULTS as t,createAppApi as n}from"./createAppApi.js";import{setupApiListeners as r}from"./listeners.js";import{LIST_QUERY_RESERVED as i,SEARCH_PARAM as a,buildListQuery as o,getNextPageParam as s,getPreviousPageParam as c,hasNextPage as l,hasPreviousPage as u,parseListQuery as d}from"./paging.js";import{LIST_TAG_ID as f,itemTag as p,listTag as m,providesList as h,providesPagedList as g}from"./tags.js";import{useListQuery as _}from"./useListQuery.js";export{t as APP_API_DEFAULTS,i as LIST_QUERY_RESERVED,f as LIST_TAG_ID,a as SEARCH_PARAM,o as buildListQuery,e as createApiBaseQuery,n as createAppApi,s as getNextPageParam,c as getPreviousPageParam,l as hasNextPage,u as hasPreviousPage,p as itemTag,m as listTag,d as parseListQuery,h as providesList,g as providesPagedList,r as setupApiListeners,_ as useListQuery};
|
package/dist/query/paging.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{LIST_QUERY_RESERVED as e,SEARCH_PARAM as t,buildListQuery as n,parseListQuery as r}from"@webority/ui-elements/listQuery";var i=e=>e.page<e.totalPages,a=e=>e.page>1,o=e=>i(e)?e.page+1:void 0,s=e=>a(e)?e.page-1:void 0;export{e as LIST_QUERY_RESERVED,t as SEARCH_PARAM,n as buildListQuery,o as getNextPageParam,s as getPreviousPageParam,i as hasNextPage,a as hasPreviousPage,r as parseListQuery};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{buildListQuery as e,parseListQuery as t}from"./paging.js";import{useEffect as n,useRef as r,useState as i}from"react";import{isFacetActive as a,listQueryParamNames as o}from"@webority/ui-elements/listQuery";import{useSearchParams as s}from"react-router";var c=300,l=20,u=`No results match these filters.`,d=[];function f(e,n,r){let i=new Set(o(n)),a=[...e.keys()].some(e=>i.has(e)),s=t(e,{facets:n,defaults:{page:r.page,pageSize:r.pageSize,sortBy:r.sortBy,sortOrder:r.sortOrder,filters:r.filters}});return{page:s.page,pageSize:s.pageSize,sortBy:s.sortBy,sortOrder:s.sortOrder,search:a?s.search:r.search??``,filters:s.filters}}function p(t){return e({page:t.page,pageSize:t.pageSize,sortBy:t.sortBy,sortOrder:t.sortOrder,search:t.search,filters:t.filters})}function m(e){let{fetchPage:t,facets:o=[],defaults:m={},debounceMs:h=c}=e,[g,_]=s(),v=f(g,o,m),[y,b]=i(v.search),[x,S]=i(),[C,w]=i(void 0),[T,E]=i(!0),[D,O]=i(0),k={...v,search:y},A=r(k);A.current=k;let j=r(t);j.current=t;let M=`${p(k)}#${D}`,N=r(M);N.current=M,n(()=>{if(v.search===y)return;let e=setTimeout(()=>b(v.search),h);return()=>clearTimeout(e)},[v.search,y,h]),n(()=>{let e=new AbortController,t=()=>e.signal.aborted||N.current!==M;return E(!0),new Promise(t=>{t(j.current(A.current,{signal:e.signal}))}).then(e=>{t()||(S(e),w(void 0),E(!1))},e=>{t()||(w(e),E(!1))}),()=>e.abort()},[M]);let P=(e,t)=>{_(p(e),{replace:!0}),t&&b(e.search)},F=e=>P({...v,page:e},!0),I=e=>P({...v,pageSize:e},!0),L=e=>P({...v,page:1,search:e},!1),R=(e,t)=>P({...v,page:1,filters:{...v.filters,[e]:t}},!0),z=(e,t=`asc`)=>P({...v,page:1,sortBy:e,sortOrder:t},!0),B=e=>z(e,e===v.sortBy&&v.sortOrder===`asc`?`desc`:`asc`),V=()=>{let e=f(new URLSearchParams,o,m);_(new URLSearchParams,{replace:!0}),b(e.search)},H=()=>O(e=>e+1),U=v.search!==``||o.some(e=>a(e,v.filters[e.key])),W=x?.totalCount??0,G=x?.totalPages??0;return{query:v,rows:x?.items??d,loading:T,error:C,totalCount:W,totalPages:G,setFilter:R,setSearch:L,setSort:z,setPage:F,setPageSize:I,reset:V,refetch:H,tableProps:{rows:x?.items??d,sort:v.sortBy?{key:v.sortBy,dir:v.sortOrder}:void 0,onSort:B,loading:T,emptyFiltered:U?u:void 0,sourceCount:U?Math.max(W,1):W},paginationProps:{page:v.page,totalPages:G,pageSize:v.pageSize??x?.pageSize??l,onPageChange:F,onPageSizeChange:I}}}export{m as useListQuery};
|
|
@@ -3,6 +3,8 @@ export { createApiBaseQuery } from "./apiBaseQuery";
|
|
|
3
3
|
export { APP_API_DEFAULTS, createAppApi } from "./createAppApi";
|
|
4
4
|
export { setupApiListeners } from "./listeners";
|
|
5
5
|
export type { ListFilterValue, ListQuery, PagedDataObject, PagedListRequest, SortOrder, } from "./paging";
|
|
6
|
-
export { buildListQuery, getNextPageParam, getPreviousPageParam, hasNextPage, hasPreviousPage, } from "./paging";
|
|
6
|
+
export { buildListQuery, getNextPageParam, getPreviousPageParam, hasNextPage, hasPreviousPage, LIST_QUERY_RESERVED, parseListQuery, SEARCH_PARAM, } from "./paging";
|
|
7
7
|
export type { ApiTag, TagId } from "./tags";
|
|
8
8
|
export { itemTag, LIST_TAG_ID, listTag, providesList, providesPagedList } from "./tags";
|
|
9
|
+
export type { Facet, ListQueryState, UseListQueryOptions, UseListQueryResult } from "./useListQuery";
|
|
10
|
+
export { useListQuery } from "./useListQuery";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The shared list contract, matching Webority.Delivery: the request is
|
|
3
|
-
* `PagedListRequest` (`page` 1-based, `pageSize`, `sortBy`, `sortOrder`)
|
|
4
|
-
* endpoint's filters, and the response is `PagedDataObject<T>`. The
|
|
5
|
-
* defaults a missing page to 1 and a missing size to 20, and cuts a size
|
|
6
|
-
* 100 to 100.
|
|
3
|
+
* `PagedListRequest` (`page` 1-based, `pageSize`, `sortBy`, `sortOrder`, `search`)
|
|
4
|
+
* plus the endpoint's filters, and the response is `PagedDataObject<T>`. The
|
|
5
|
+
* server defaults a missing page to 1 and a missing size to 20, and cuts a size
|
|
6
|
+
* over 100 to 100.
|
|
7
7
|
*/
|
|
8
8
|
export interface PagedDataObject<T> {
|
|
9
9
|
items: T[];
|
|
@@ -18,18 +18,16 @@ export interface PagedListRequest {
|
|
|
18
18
|
pageSize?: number;
|
|
19
19
|
sortBy?: string;
|
|
20
20
|
sortOrder?: SortOrder;
|
|
21
|
+
search?: string;
|
|
21
22
|
}
|
|
22
|
-
export type ListFilterValue = string | number | boolean | null | undefined
|
|
23
|
+
export type ListFilterValue = string | number | boolean | Date | null | undefined | Array<string | number | boolean | Date> | {
|
|
24
|
+
from?: string | Date;
|
|
25
|
+
to?: string | Date;
|
|
26
|
+
};
|
|
23
27
|
export interface ListQuery extends PagedListRequest {
|
|
24
28
|
filters?: Record<string, ListFilterValue>;
|
|
25
29
|
}
|
|
26
|
-
|
|
27
|
-
* The `params` for a list endpoint. Filters sit beside the paging keys, as the
|
|
28
|
-
* API's request type derives from `PagedListRequest`. Unset values and empty
|
|
29
|
-
* strings are dropped, so a cleared filter never sends `?status=`. A filter
|
|
30
|
-
* named like a paging key is refused rather than silently overriding it.
|
|
31
|
-
*/
|
|
32
|
-
export declare const buildListQuery: ({ page, pageSize, sortBy, sortOrder, filters }: ListQuery) => Record<string, string | number | boolean>;
|
|
30
|
+
export { buildListQuery, LIST_QUERY_RESERVED, parseListQuery, SEARCH_PARAM } from "@webority/ui-elements/listQuery";
|
|
33
31
|
export declare const hasNextPage: (page: PagedDataObject<unknown>) => boolean;
|
|
34
32
|
export declare const hasPreviousPage: (page: PagedDataObject<unknown>) => boolean;
|
|
35
33
|
/**
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { type PagedDataObject, type SortOrder } from "./paging";
|
|
2
|
+
export interface ListQueryState {
|
|
3
|
+
page: number;
|
|
4
|
+
pageSize?: number;
|
|
5
|
+
sortBy?: string;
|
|
6
|
+
sortOrder: SortOrder;
|
|
7
|
+
search: string;
|
|
8
|
+
filters: Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
export interface Facet {
|
|
11
|
+
key: string;
|
|
12
|
+
label: string;
|
|
13
|
+
type: "enum" | "multiEnum" | "dateRange" | "text";
|
|
14
|
+
options?: {
|
|
15
|
+
value: string;
|
|
16
|
+
label: string;
|
|
17
|
+
}[];
|
|
18
|
+
}
|
|
19
|
+
export interface UseListQueryOptions<TRow> {
|
|
20
|
+
fetchPage: (query: ListQueryState, options: {
|
|
21
|
+
signal: AbortSignal;
|
|
22
|
+
}) => Promise<PagedDataObject<TRow>>;
|
|
23
|
+
facets?: Facet[];
|
|
24
|
+
defaults?: Partial<ListQueryState>;
|
|
25
|
+
/** Milliseconds a typed search or text filter waits before the list refetches. */
|
|
26
|
+
debounceMs?: number;
|
|
27
|
+
}
|
|
28
|
+
export interface UseListQueryResult<TRow> {
|
|
29
|
+
query: ListQueryState;
|
|
30
|
+
rows: TRow[];
|
|
31
|
+
loading: boolean;
|
|
32
|
+
error: unknown;
|
|
33
|
+
totalCount: number;
|
|
34
|
+
totalPages: number;
|
|
35
|
+
setFilter(key: string, value: unknown): void;
|
|
36
|
+
setSearch(text: string): void;
|
|
37
|
+
setSort(sortBy: string, sortOrder?: SortOrder): void;
|
|
38
|
+
setPage(page: number): void;
|
|
39
|
+
setPageSize(pageSize: number): void;
|
|
40
|
+
reset(): void;
|
|
41
|
+
refetch(): void;
|
|
42
|
+
tableProps: {
|
|
43
|
+
rows: TRow[];
|
|
44
|
+
sort?: {
|
|
45
|
+
key: string;
|
|
46
|
+
dir: SortOrder;
|
|
47
|
+
};
|
|
48
|
+
onSort(key: string): void;
|
|
49
|
+
loading: boolean;
|
|
50
|
+
emptyFiltered?: string;
|
|
51
|
+
sourceCount: number;
|
|
52
|
+
};
|
|
53
|
+
paginationProps: {
|
|
54
|
+
page: number;
|
|
55
|
+
totalPages: number;
|
|
56
|
+
pageSize: number;
|
|
57
|
+
onPageChange(page: number): void;
|
|
58
|
+
onPageSizeChange(size: number): void;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* URL state through the react-router `useSearchParams`, written with replace
|
|
63
|
+
* rather than push. A filter, search or sort change returns to page 1, and a new
|
|
64
|
+
* request aborts the one in flight.
|
|
65
|
+
*/
|
|
66
|
+
export declare function useListQuery<TRow>(options: UseListQueryOptions<TRow>): UseListQueryResult<TRow>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webority/web-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.126.0",
|
|
4
4
|
"description": "Platform layer for Webority React web portals: HTTP clients with single-flight token refresh, auth store, API error extraction, RTK Query base query, logger, formatters, storage, version check and route guards. No UI.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"type": "module",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
},
|
|
83
83
|
"sideEffects": false,
|
|
84
84
|
"dependencies": {
|
|
85
|
-
"@webority/ui-elements": "0.
|
|
85
|
+
"@webority/ui-elements": "0.126.0"
|
|
86
86
|
},
|
|
87
87
|
"peerDependencies": {
|
|
88
88
|
"@reduxjs/toolkit": "^2.12.0",
|