Skip to content
Snippets Groups Projects
Commit d7d3d5a9 authored by Alexander Madsen's avatar Alexander Madsen
Browse files

Merge branch 'CE-2064-convert-useIocSearch' into 'develop'

Resolve CE-2064 "Convert useiocsearch"

See merge request !346
parents c5dc1f29 71b6c82e
No related branches found
No related tags found
2 merge requests!407CE-2141: 3.0.0,!346Resolve CE-2064 "Convert useiocsearch"
Pipeline #159943 passed
...@@ -205,13 +205,6 @@ export function unpackIocInfo(ioc) { ...@@ -205,13 +205,6 @@ export function unpackIocInfo(ioc) {
return ioc; return ioc;
} }
const emptyIocListResponse = {
totalCount: 0,
pageNumber: 0,
limit: 0,
iocList: []
};
export function unpackIOCList(iocs) { export function unpackIOCList(iocs) {
let iocArray = iocs.iocList.map((ioc) => unpackIocInfo(ioc)); let iocArray = iocs.iocList.map((ioc) => unpackIocInfo(ioc));
...@@ -225,21 +218,6 @@ export function unpackIOCList(iocs) { ...@@ -225,21 +218,6 @@ export function unpackIOCList(iocs) {
return unpackedIOCList; return unpackedIOCList;
} }
export function useIOCList() {
const api = useContext(apiContext);
const method = useCallAndUnpack(api.apis.IOCs.listIocs, unpackIOCList);
return useAsync({ fcn: method, init: emptyIocListResponse });
}
export function useIOCSearch() {
const api = useContext(apiContext);
const method = useCallAndUnpack(
(params) => api.apis.IOCs.listIocs(params),
unpackIOCList
);
return useAsync({ fcn: method, call: false, init: emptyIocListResponse });
}
export function useCreateIOC(onError) { export function useCreateIOC(onError) {
const api = useContext(apiContext); const api = useContext(apiContext);
const method = useCallAndUnpack( const method = useCallAndUnpack(
......
import React from "react";
import { useMediaQuery } from "@mui/material";
import { IOCList } from "../IOCList";
import { IOCTable } from "../IOCTable";
export function IOCAsyncList({
iocs,
setIocs,
rowType,
pagination,
onPage,
loading
}) {
const smUp = useMediaQuery((theme) => theme.breakpoints.up("sm"));
const smDown = useMediaQuery((theme) => theme.breakpoints.down("sm"));
return (
<>
{smDown ? <IOCList iocs={iocs} /> : null}
{smUp ? (
<IOCTable
iocs={iocs}
setIocs={setIocs}
loading={loading}
rowType={rowType}
pagination={pagination}
onPage={onPage}
/>
) : null}
</>
);
}
import { IOCAsyncList } from "./IOCAsyncList";
export { IOCAsyncList };
export default IOCAsyncList;
import React from "react"; import React from "react";
import { Table } from "@ess-ics/ce-ui-common"; import { Table } from "@ess-ics/ce-ui-common";
import { Link } from "@mui/material"; import { Link, useMediaQuery } from "@mui/material";
import { IOCDescription } from "./IOCDescription"; import { IOCDescription } from "./IOCDescription";
import { IOCStatus } from "./IOCStatus"; import { IOCStatus } from "./IOCStatus";
import { noWrapText } from "../../common/Helper"; import { noWrapText } from "../../common/Helper";
import IOCList from "../IOCList";
const ownIocsColumns = [ const ownIocsColumns = [
{ {
...@@ -146,12 +147,15 @@ function createTableRowForExploreIocs(ioc) { ...@@ -146,12 +147,15 @@ function createTableRowForExploreIocs(ioc) {
} }
export function IOCTable({ export function IOCTable({
iocs, iocs = [],
rowType = "own", rowType = "own",
loading, loading,
pagination, pagination,
onPage onPage
}) { }) {
const smUp = useMediaQuery((theme) => theme.breakpoints.up("sm"));
const smDown = useMediaQuery((theme) => theme.breakpoints.down("sm"));
const tableTypeSpecifics = { const tableTypeSpecifics = {
own: [ownIocsColumns, createTableRowForOwnIocs], own: [ownIocsColumns, createTableRowForOwnIocs],
host: [hostDetailsColumns, createTableRowForHostDetails], host: [hostDetailsColumns, createTableRowForHostDetails],
...@@ -162,12 +166,17 @@ export function IOCTable({ ...@@ -162,12 +166,17 @@ export function IOCTable({
const rows = iocs.map((ioc) => createRow(ioc)); const rows = iocs.map((ioc) => createRow(ioc));
return ( return (
<Table <>
columns={columns} {smDown ? <IOCList iocs={iocs} /> : null}
rows={rows} {smUp ? (
pagination={pagination} <Table
onPage={onPage} columns={columns}
loading={loading} rows={rows}
/> pagination={pagination}
onPage={onPage}
loading={loading}
/>
) : null}
</>
); );
} }
import React from "react"; import React, { useContext } from "react";
import { Card, CardHeader } from "@mui/material"; import { Card, CardHeader } from "@mui/material";
import { useState, useEffect } from "react"; import { useEffect } from "react";
import { useIOCSearch } from "../../../api/SwaggerApi";
import { IOCAsyncList } from "../../IOC/IOCAsyncList";
import { initRequestParams } from "../Helper"; import { initRequestParams } from "../Helper";
import { usePagination } from "../../../hooks/pagination"; import { usePagination } from "../../../hooks/pagination";
import IOCTable from "../../IOC/IOCTable";
import { apiContext } from "../../../api/DeployApi";
import { useAPIMethod } from "@ess-ics/ce-ui-common";
export function UserIocList({ userName }) { export function UserIocList({ userName }) {
const [iocs, getIocs, , loading] = useIOCSearch(); const client = useContext(apiContext);
const [iocList, setIocList] = useState([]);
// Sync manipulatable ioc list copy const {
useEffect(() => { value: iocs,
setIocList(iocs.iocList); wrapper: getIocs,
}, [iocs, setIocList]); loading,
dataReady
} = useAPIMethod({
fcn: client.apis.IOCs.listIocs,
call: false
});
const rowsPerPage = [20, 50]; const rowsPerPage = [20, 50];
const { pagination, setPagination } = usePagination({ const { pagination, setPagination } = usePagination({
...@@ -24,8 +29,8 @@ export function UserIocList({ userName }) { ...@@ -24,8 +29,8 @@ export function UserIocList({ userName }) {
// update pagination whenever search result total pages change // update pagination whenever search result total pages change
useEffect(() => { useEffect(() => {
setPagination({ totalCount: iocs.totalCount ?? 0 }); setPagination({ totalCount: iocs?.totalCount ?? 0 });
}, [setPagination, iocs.totalCount]); }, [setPagination, iocs?.totalCount]);
// Request more results when pagination changes // Request more results when pagination changes
useEffect(() => { useEffect(() => {
...@@ -50,10 +55,9 @@ export function UserIocList({ userName }) { ...@@ -50,10 +55,9 @@ export function UserIocList({ userName }) {
component: "h2" component: "h2"
}} }}
/> />
<IOCAsyncList <IOCTable
iocs={iocList} iocs={iocs?.iocList}
setIocs={setIocList} loading={loading || !dataReady}
loading={loading}
rowType="explore" rowType="explore"
pagination={pagination} pagination={pagination}
onPage={onPage} onPage={onPage}
......
import React, { useState, useEffect, useContext, useCallback } from "react"; import React, { useState, useEffect, useContext, useCallback } from "react";
import { Container, Grid, Typography, Tabs, Tab } from "@mui/material"; import { Container, Grid, Typography, Tabs, Tab } from "@mui/material";
import { GlobalAppBarContext } from "@ess-ics/ce-ui-common"; import {
import { IOCAsyncList } from "../../components/IOC/IOCAsyncList"; GlobalAppBarContext,
import { useIOCSearch } from "../../api/SwaggerApi"; RootPaper,
useAPIMethod
} from "@ess-ics/ce-ui-common";
import { import {
applicationTitle, applicationTitle,
initRequestParams initRequestParams
...@@ -15,19 +17,24 @@ import { ...@@ -15,19 +17,24 @@ import {
} from "../../components/common/URLState/URLState"; } from "../../components/common/URLState/URLState";
import { usePagination } from "../../hooks/pagination"; import { usePagination } from "../../hooks/pagination";
import { useMemo } from "react"; import { useMemo } from "react";
import { RootPaper } from "@ess-ics/ce-ui-common/dist/components/common/container/RootPaper"; import IOCTable from "../../components/IOC/IOCTable";
import { apiContext } from "../../api/DeployApi";
export function IOCListView() { export function IOCListView() {
const { setTitle } = useContext(GlobalAppBarContext); const { setTitle } = useContext(GlobalAppBarContext);
useEffect(() => setTitle(applicationTitle("IOCs")), [setTitle]); useEffect(() => setTitle(applicationTitle("IOCs")), [setTitle]);
const [iocs, getIocs /* reset*/, , loading] = useIOCSearch(); const client = useContext(apiContext);
const [iocList, setIocList] = useState([]);
// Sync manipulatable ioc list copy const {
useEffect(() => { value: iocs,
setIocList(iocs.iocList); wrapper: getIocs,
}, [iocs, setIocList]); loading,
dataReady
} = useAPIMethod({
fcn: client.apis.IOCs.listIocs,
call: false
});
const [urlState, setUrlState] = useUrlState( const [urlState, setUrlState] = useUrlState(
{ {
...@@ -94,8 +101,8 @@ export function IOCListView() { ...@@ -94,8 +101,8 @@ export function IOCListView() {
// update pagination whenever search result total pages change // update pagination whenever search result total pages change
useEffect(() => { useEffect(() => {
setPagination({ totalCount: iocs.totalCount ?? 0 }); setPagination({ totalCount: iocs?.totalCount ?? 0 });
}, [setPagination, iocs.totalCount]); }, [setPagination, iocs?.totalCount]);
// whenever url state changes, update pagination // whenever url state changes, update pagination
useEffect(() => { useEffect(() => {
...@@ -139,10 +146,9 @@ export function IOCListView() { ...@@ -139,10 +146,9 @@ export function IOCListView() {
loading={loading} loading={loading}
placeholder="Search in IOC name" placeholder="Search in IOC name"
> >
<IOCAsyncList <IOCTable
iocs={iocList} iocs={iocs?.iocList}
setIocs={setIocList} loading={loading || !dataReady}
loading={loading}
rowType="explore" rowType="explore"
pagination={pagination} pagination={pagination}
onPage={onPage} onPage={onPage}
......
import React, { import React, { useEffect, useCallback, useContext, useMemo } from "react";
useState,
useEffect,
useCallback,
useContext,
useMemo
} from "react";
import { import {
Link, Link,
Container, Container,
...@@ -19,7 +13,6 @@ import ArrowBackIcon from "@mui/icons-material/ArrowBack"; ...@@ -19,7 +13,6 @@ import ArrowBackIcon from "@mui/icons-material/ArrowBack";
import { useHostIOCList } from "../../api/SwaggerApi"; import { useHostIOCList } from "../../api/SwaggerApi";
import { HostBadge } from "../../components/host/HostBadge"; import { HostBadge } from "../../components/host/HostBadge";
import { SimpleAccordion } from "../../components/common/Accordion/SimpleAccordion"; import { SimpleAccordion } from "../../components/common/Accordion/SimpleAccordion";
import { IOCAsyncList } from "../../components/IOC/IOCAsyncList";
import { KeyValueTable } from "@ess-ics/ce-ui-common/dist/components/common/KeyValueTable"; import { KeyValueTable } from "@ess-ics/ce-ui-common/dist/components/common/KeyValueTable";
import { LokiPanel } from "../../components/common/Loki/LokiPanel"; import { LokiPanel } from "../../components/common/Loki/LokiPanel";
import { useNavigate, Link as ReactRouterLink } from "react-router-dom"; import { useNavigate, Link as ReactRouterLink } from "react-router-dom";
...@@ -38,6 +31,7 @@ import { ...@@ -38,6 +31,7 @@ import {
import { GlobalAppBarContext } from "@ess-ics/ce-ui-common"; import { GlobalAppBarContext } from "@ess-ics/ce-ui-common";
import { usePagination } from "../../hooks/pagination"; import { usePagination } from "../../hooks/pagination";
import { RootPaper } from "@ess-ics/ce-ui-common"; import { RootPaper } from "@ess-ics/ce-ui-common";
import IOCTable from "../../components/IOC/IOCTable";
export function HostDetailsView({ id }) { export function HostDetailsView({ id }) {
const [host] = useHost(id); const [host] = useHost(id);
...@@ -49,11 +43,6 @@ export function HostDetailsView({ id }) { ...@@ -49,11 +43,6 @@ export function HostDetailsView({ id }) {
}, [host, setTitle]); }, [host, setTitle]);
const [iocs, getIocs /* reset*/, , loading] = useHostIOCList(); const [iocs, getIocs /* reset*/, , loading] = useHostIOCList();
const [deployedIocs, setDeployedIocs] = useState([]);
// Sync manipulatable ioc list copy
useEffect(() => {
setDeployedIocs(iocs?.deployedList ?? []);
}, [iocs, setDeployedIocs]);
const [urlState, setUrlState] = useUrlState( const [urlState, setUrlState] = useUrlState(
{ {
...@@ -203,9 +192,8 @@ export function HostDetailsView({ id }) { ...@@ -203,9 +192,8 @@ export function HostDetailsView({ id }) {
setUrlState({ iocs_open: serialize(expanded) }) setUrlState({ iocs_open: serialize(expanded) })
} }
> >
<IOCAsyncList <IOCTable
iocs={deployedIocs} iocs={iocs?.deployedList}
setIocs={setDeployedIocs}
loading={loading} loading={loading}
rowType="host" rowType="host"
pagination={pagination} pagination={pagination}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment