From fe354fa8a9f5086f1b59e38d0e36a52dd4c25703 Mon Sep 17 00:00:00 2001
From: Johanna Szepanski <johanna.szepanski@softhouse.se>
Date: Tue, 27 Aug 2024 08:49:44 +0200
Subject: [PATCH] updated list all iocs call with new rtk query

---
 src/views/IOC/IOCListView.js | 69 +++++++++++-------------------------
 1 file changed, 20 insertions(+), 49 deletions(-)

diff --git a/src/views/IOC/IOCListView.js b/src/views/IOC/IOCListView.js
index 4d5a041b..3e5edd19 100644
--- a/src/views/IOC/IOCListView.js
+++ b/src/views/IOC/IOCListView.js
@@ -1,9 +1,9 @@
 import { useState, useEffect, useContext, useCallback } from "react";
+import { useLazyListIocsQuery } from "../../store/deployApi";
 import { Container, Grid, Tabs, Tab } from "@mui/material";
 import {
   GlobalAppBarContext,
   RootPaper,
-  useAPIMethod,
   usePagination
 } from "@ess-ics/ce-ui-common";
 import {
@@ -17,25 +17,12 @@ import {
   deserialize
 } from "../../components/common/URLState/URLState";
 import { useMemo } from "react";
-import { apiContext } from "../../api/DeployApi";
 import IOCTable from "../../components/IOC/IOCTable";
 
 export function IOCListView() {
   const { setTitle } = useContext(GlobalAppBarContext);
   useEffect(() => setTitle(applicationTitle("IOCs")), [setTitle]);
-
-  const client = useContext(apiContext);
-
-  const {
-    value: iocs,
-    wrapper: getIocs,
-    loading,
-    dataReady,
-    abort
-  } = useAPIMethod({
-    fcn: client.apis.IOCs.listIocs,
-    call: false
-  });
+  const [listIocs, { data: iocs, isLoading }] = useLazyListIocsQuery();
 
   const [urlState, setUrlState] = useUrlState(
     {
@@ -121,7 +108,7 @@ export function IOCListView() {
   // Invoked by Table on change to pagination
   const onPage = (params) => {
     setPagination(params);
-    abort();
+    listIocs().abort();
   };
 
   useEffect(() => {
@@ -130,21 +117,9 @@ export function IOCListView() {
       deserialize(urlState.query)
     );
 
-    requestParams.deployment_status = deploymentStatus;
-
-    getIocs(requestParams);
-
-    return () => {
-      abort();
-    };
-  }, [
-    getIocs,
-    urlPagination,
-    deploymentStatus,
-    urlState.query,
-    pagination,
-    abort
-  ]);
+    requestParams.deploymentStatus = deploymentStatus;
+    listIocs(requestParams);
+  }, [listIocs, urlPagination, deploymentStatus, urlState.query, pagination]);
 
   // Callback for searchbar, called whenever user updates search
   const setSearch = useCallback(
@@ -154,23 +129,6 @@ export function IOCListView() {
     [setUrlState]
   );
 
-  let content = (
-    <SearchBar
-      search={setSearch}
-      query={deserialize(urlState.query)}
-      loading={loading}
-      placeholder="Search"
-    >
-      <IOCTable
-        iocs={iocs?.iocList}
-        loading={loading || !dataReady}
-        rowType="explore"
-        pagination={pagination}
-        onPage={onPage}
-      />
-    </SearchBar>
-  );
-
   return (
     <RootPaper>
       <Grid
@@ -201,7 +159,20 @@ export function IOCListView() {
           xs={12}
           md={12}
         >
-          {content}
+          <SearchBar
+            search={setSearch}
+            query={deserialize(urlState.query)}
+            loading={isLoading}
+            placeholder="Search"
+          >
+            <IOCTable
+              iocs={iocs?.iocList}
+              loading={isLoading}
+              rowType="explore"
+              pagination={pagination}
+              onPage={onPage}
+            />
+          </SearchBar>
         </Grid>
       </Grid>
     </RootPaper>
-- 
GitLab