@@ -23,6 +23,7 @@ import {
2323 selectRowIds ,
2424 selectRowById ,
2525 rowsSelectors ,
26+ resetTableProperties ,
2627} from "../../slices/tableSlice" ;
2728import {
2829 changeAllSelected ,
@@ -35,12 +36,14 @@ import cn from "classnames";
3536import EditTableViewModal from "../shared/EditTableViewModal" ;
3637
3738import Notifications from "./Notifications" ;
38- import { useAppDispatch , useAppSelector } from "../../store" ;
39+ import { AppThunk , useAppDispatch , useAppSelector } from "../../store" ;
3940import { TableColumn } from "../../configs/tableConfigs/aclsTableConfig" ;
4041import ButtonLikeAnchor from "./ButtonLikeAnchor" ;
4142import { ModalHandle } from "./modals/Modal" ;
4243import { ParseKeys } from "i18next" ;
4344import { LuChevronDown , LuChevronLeft , LuChevronRight , LuChevronUp } from "react-icons/lu" ;
45+ import { AsyncThunk } from "@reduxjs/toolkit" ;
46+ import { useLocation } from "react-router" ;
4447
4548const containerPageSize = React . createRef < HTMLDivElement > ( ) ;
4649
@@ -53,15 +56,49 @@ export type TemplateMap = {
5356 */
5457const Table = ( {
5558 templateMap,
59+ fetchResource,
60+ loadResourceIntoTable,
5661} : {
5762 templateMap : TemplateMap
63+ fetchResource : AsyncThunk < any , void , any > ,
64+ loadResourceIntoTable : ( ) => AppThunk ,
5865} ) => {
5966 const { t } = useTranslation ( ) ;
6067 const dispatch = useAppDispatch ( ) ;
68+ const location = useLocation ( ) ;
6169
6270 const editTableViewModalRef = useRef < ModalHandle > ( null ) ;
6371 const selectAllCheckboxRef = useRef < HTMLInputElement > ( null ) ;
6472
73+ useEffect ( ( ) => {
74+ // State variable for interrupting the load function
75+ let allowLoadIntoTable = true ;
76+
77+ // Clear table of previous data
78+ dispatch ( resetTableProperties ( ) ) ;
79+
80+ // Load resource on mount
81+ const loadResource = async ( ) => {
82+ // Fetching resources from server
83+ await dispatch ( fetchResource ( ) ) ;
84+
85+ // Load resources into table
86+ if ( allowLoadIntoTable ) {
87+ dispatch ( loadResourceIntoTable ( ) ) ;
88+ }
89+ } ;
90+ loadResource ( ) ;
91+
92+ // Fetch resources every minute
93+ const fetchResourceInterval = setInterval ( loadResource , 5000 ) ;
94+
95+ return ( ) => {
96+ allowLoadIntoTable = false ;
97+ clearInterval ( fetchResourceInterval ) ;
98+ } ;
99+ // eslint-disable-next-line react-hooks/exhaustive-deps
100+ } , [ location . hash ] ) ;
101+
65102 const forceDeselectAll = ( ) => {
66103 dispatch ( changeAllSelected ( false ) ) ;
67104 if ( selectAllCheckboxRef . current ?. checked ) {
@@ -187,6 +224,8 @@ const TableHeadRows = ({ forceDeselectAll }: { forceDeselectAll: () => unknown }
187224 let direction : ReverseOptions = "ASC" ;
188225 if ( reverse && reverse === "ASC" ) {
189226 direction = "DESC" ;
227+ } else if ( reverse && reverse === "DESC" ) {
228+ direction = "NONE" ;
190229 }
191230 dispatch ( reverseTable ( direction ) ) ;
192231 dispatch ( updatePages ( ) ) ;
@@ -199,7 +238,7 @@ const TableHeadRows = ({ forceDeselectAll }: { forceDeselectAll: () => unknown }
199238 < th
200239 key = { key }
201240 className = { cn ( {
202- "col-sort" : ! ! sortBy && column . name === sortBy ,
241+ "col-sort" : reverse !== "NONE" && ! ! sortBy && column . name === sortBy ,
203242 sortable : true ,
204243 } ) }
205244 onClick = { ( ) => sortByColumn ( column . name ) }
0 commit comments