@@ -14,7 +14,14 @@ import { ConnectionProvider, TreeView } from "..";
1414import { useShowErrorDialog } from "@/ui/GenericErrorDialog" ;
1515import { useDeepCompareEffect } from "use-deep-compare" ;
1616import deepEqual from "deep-equal" ;
17- import { getColorMap , getStatusMap , getTableItems } from "@/helpers/treeHelper" ;
17+ import {
18+ getColorMap ,
19+ getStatusMap ,
20+ getTableItems ,
21+ getTree ,
22+ getSortedFieldsFromState ,
23+ getOrderFromSortFields ,
24+ } from "@/helpers/treeHelper" ;
1825import { Tree as TreeOoui } from "@gisce/ooui" ;
1926import { getKey } from "@/helpers/tree-columnStorageHelper" ;
2027import { useTreeColumnStorageFetch } from "@/widgets/base/one2many/useTreeColumnStorageFetch" ;
@@ -57,6 +64,8 @@ export const usePaginatedSearch = (props: PaginatedSearchProps) => {
5764 setSelectedRowItems,
5865 setTreeFirstVisibleRow,
5966 treeFirstVisibleRow,
67+ treeFirstVisibleColumn,
68+ setTreeFirstVisibleColumn,
6069 selectedRowItems,
6170 setSearchParams,
6271 searchValues,
@@ -72,12 +81,15 @@ export const usePaginatedSearch = (props: PaginatedSearchProps) => {
7281 setCurrentPage,
7382 pageSize,
7483 setPageSize,
84+ sortState : actionViewSortState ,
85+ setSortState : setActionViewSortState ,
7586 } = useSearchTreeState ( { useLocalState : ! rootTree } ) ;
7687
7788 // Local state
7889 const [ totalRowsLoading , setTotalRowsLoading ] = useState < boolean > ( true ) ;
7990 const [ totalRows , setTotalRows ] = useState < number | null > ( ) ;
8091 const [ results , setResults ] = useState < any [ ] > ( [ ] ) ;
92+ const hasRestoredSortStateForFirstTime = useRef < boolean > ( false ) ;
8193
8294 // Refs
8395 const nameSearch = nameSearchProps || searchTreeNameSearch ;
@@ -173,6 +185,10 @@ export const usePaginatedSearch = (props: PaginatedSearchProps) => {
173185 return treeFirstVisibleRow ;
174186 } , [ treeFirstVisibleRow ] ) ;
175187
188+ const onGetFirstVisibleColumn = useCallback ( ( ) => {
189+ return treeFirstVisibleColumn ;
190+ } , [ treeFirstVisibleColumn ] ) ;
191+
176192 const onRowStyle = useCallback ( ( item : Record < string , any > ) : CSSProperties => {
177193 if ( colorsForResults . current [ item . node ?. data ?. id ] ) {
178194 return { color : colorsForResults . current [ item . node ?. data ?. id ] } ;
@@ -269,6 +285,7 @@ export const usePaginatedSearch = (props: PaginatedSearchProps) => {
269285 mergedParams ,
270286 nameSearch ,
271287 domain ,
288+ actionViewSortState ,
272289 ] ) ;
273290
274291 useEffect ( ( ) => {
@@ -320,6 +337,14 @@ export const usePaginatedSearch = (props: PaginatedSearchProps) => {
320337 attrs . status = treeOoui . status ;
321338 }
322339
340+ let order ;
341+ if ( actionViewSortState ?. length ) {
342+ const sortFields = getSortedFieldsFromState ( {
343+ state : actionViewSortState ,
344+ } ) ;
345+ order = getOrderFromSortFields ( sortFields ) ;
346+ }
347+
323348 const params = nameSearch ? domain : mergedParams ;
324349
325350 const { results, attrsEvaluated } = await searchForTree ( {
@@ -332,6 +357,7 @@ export const usePaginatedSearch = (props: PaginatedSearchProps) => {
332357 : treeView ! . fields ,
333358 context,
334359 attrs,
360+ order,
335361 name_search : nameSearch ,
336362 } ) ;
337363
@@ -401,6 +427,7 @@ export const usePaginatedSearch = (props: PaginatedSearchProps) => {
401427 treeView ,
402428 treeViewFetching ,
403429 updateTotalRows ,
430+ actionViewSortState ,
404431 ] ) ;
405432
406433 const refresh = useCallback ( async ( ) => {
@@ -504,5 +531,10 @@ export const usePaginatedSearch = (props: PaginatedSearchProps) => {
504531 updateColumnState,
505532 currentPage,
506533 pageSize,
534+ sortState : actionViewSortState ,
535+ setSortState : setActionViewSortState ,
536+ treeFirstVisibleColumn,
537+ setTreeFirstVisibleColumn,
538+ onGetFirstVisibleColumn,
507539 } ;
508540} ;
0 commit comments