diff --git a/src/api/SwaggerApi.js b/src/api/SwaggerApi.js index f01456a9ba6bff7cc5f8f97c2e4e4a06ef67320f..26683fa5f97cb79527b64842da8e09b725532708 100644 --- a/src/api/SwaggerApi.js +++ b/src/api/SwaggerApi.js @@ -693,22 +693,16 @@ export function unpackIocStatus(status) { return { ...status }; } -export function useIocStatus() { +export function useIocStatus(id) { const api = useContext(apiContext); const method = useCallAndUnpack( - (iocId) => api.apis.Monitoring.fetchIocStatus({ ioc_id: iocId }), + api.apis.Monitoring.fetchIocStatus, unpackIocStatus ); - return useAsync({ fcn: method, call: false }); + const boundMethod = useCallback(method.bind(null, { ioc_id: id }), [id]); + return useAsync({ fcn: boundMethod }); } -// export function useIocStatus(id) { -// const api = useContext(apiContext); -// const method = useCallAndUnpack(api.apis.Monitoring.fetchIocStatus, unpackIocStatus); -// const boundMethod = useCallback(method.bind(null, {ioc_id: id}), [id]) -// return useAsync({ fcn: boundMethod}); -// } - export function unpackNaming(naming) { return { ...naming }; } diff --git a/src/components/IOC/IOCAsyncList/IOCAsyncList.js b/src/components/IOC/IOCAsyncList/IOCAsyncList.js index 19276474dbe6e56a9692de129a1afccabe0440d4..be2a276e598c3895edeb67a64f2b807fcff3a86a 100644 --- a/src/components/IOC/IOCAsyncList/IOCAsyncList.js +++ b/src/components/IOC/IOCAsyncList/IOCAsyncList.js @@ -1,6 +1,5 @@ import React from "react"; import { useMediaQuery } from "@mui/material"; -import { IOCDetailFetcher } from "../IOCDetailFetcher"; import { IOCList } from "../IOCList"; import { IOCTable } from "../IOCTable"; @@ -10,8 +9,7 @@ export function IOCAsyncList({ rowType, pagination, onPage, - loading, - asyncDetails = true + loading }) { const smUp = useMediaQuery((theme) => theme.breakpoints.up("sm")); const smDown = useMediaQuery((theme) => theme.breakpoints.down("sm")); @@ -29,15 +27,6 @@ export function IOCAsyncList({ onPage={onPage} /> ) : null} - {asyncDetails && - iocs.map((ioc, index) => ( - <IOCDetailFetcher - key={`ioc-${ioc.id}`} - ioc={ioc} - index={index} - setIocs={setIocs} - /> - ))} </> ); } diff --git a/src/components/IOC/IOCDetailFetcher/IOCDetailFetcher.js b/src/components/IOC/IOCDetailFetcher/IOCDetailFetcher.js deleted file mode 100644 index bffe87faaad96d457100ce7b9e218659182b3115..0000000000000000000000000000000000000000 --- a/src/components/IOC/IOCDetailFetcher/IOCDetailFetcher.js +++ /dev/null @@ -1,42 +0,0 @@ -import { useEffect } from "react"; -import { - useTagsAndCommitIds, - useIocStatus, - useIOC -} from "../../../api/SwaggerApi"; - -function onError(message) { - console.warn(message); -} - -export function IOCDetailFetcher({ ioc, index, setIocs }) { - const [tagOrCommitId, getTagOrCommitId] = useTagsAndCommitIds(onError); - const [iocStatus, getIocStatus] = useIocStatus(); - const [iocDetails, getIocDetails] = useIOC(ioc.id); - - useEffect(() => { - if (ioc.sourceVersion) { - getTagOrCommitId(ioc.gitProjectId, ioc.sourceVersion); - } - - getIocStatus(ioc.id); - getIocDetails(ioc.id); - }, [ioc, getTagOrCommitId, getIocStatus, getIocDetails]); - - useEffect(() => { - setIocs((iocs) => { - iocs[index].sourceVersionShort = - tagOrCommitId?.length === 1 - ? tagOrCommitId[0].shortReference - : iocs[index].sourceVersionShort; - iocs[index].host = iocs[index].activeDeployment?.host; - iocs[index].alertSeverity = iocStatus?.alertSeverity; - iocs[index].alerts = iocStatus?.alerts; - iocs[index].active = iocStatus?.active ?? iocs[index].active; - iocs[index].description = iocDetails?.description; - return [...iocs]; - }); - }, [index, setIocs, tagOrCommitId, iocStatus, iocDetails]); - - return null; -} diff --git a/src/components/IOC/IOCDetailFetcher/index.js b/src/components/IOC/IOCDetailFetcher/index.js deleted file mode 100644 index 65f9c27592610ea9b65ae9e748da49f7a6a929b5..0000000000000000000000000000000000000000 --- a/src/components/IOC/IOCDetailFetcher/index.js +++ /dev/null @@ -1,4 +0,0 @@ -import { IOCDetailFetcher } from "./IOCDetailFetcher"; - -export { IOCDetailFetcher }; -export default IOCDetailFetcher; diff --git a/src/components/IOC/IOCTable/IOCDescription.js b/src/components/IOC/IOCTable/IOCDescription.js new file mode 100644 index 0000000000000000000000000000000000000000..980dd0dc128a7a63b599341b2788c97033e326c4 --- /dev/null +++ b/src/components/IOC/IOCTable/IOCDescription.js @@ -0,0 +1,38 @@ +import React from "react"; +import { useIOC } from "../../../api/SwaggerApi"; +import { Skeleton, Tooltip, Typography } from "@mui/material"; + +function createIocDescription(description) { + return ( + <> + {description ? ( + <Tooltip + title={description} + arrow + enterDelay={400} + > + <Typography + style={{ + overflow: "hidden", + textOverflow: "ellipsis", + whiteSpace: "nowrap" + }} + > + {description} + </Typography> + </Tooltip> + ) : ( + "---" + )} + </> + ); +} + +export const IOCDescription = ({ id }) => { + const [ioc, , , loading] = useIOC(id); + + if (loading) { + return <Skeleton width="100%" />; + } + return createIocDescription(ioc?.description); +}; diff --git a/src/components/IOC/IOCTable/IOCStatus.js b/src/components/IOC/IOCTable/IOCStatus.js new file mode 100644 index 0000000000000000000000000000000000000000..4d0a9bfabbe49367367828612ca3ddcfd749d191 --- /dev/null +++ b/src/components/IOC/IOCTable/IOCStatus.js @@ -0,0 +1,27 @@ +import React from "react"; +import { useIocStatus } from "../../../api/SwaggerApi"; +import { Grid, Skeleton } from "@mui/material"; +import { IOCStatusIcon } from "../IOCIcons"; + +export const IOCStatus = ({ id, activeDeployment }) => { + const [status, , , loading] = useIocStatus(id); + + return ( + <Grid + container + direction="column" + justifyContent="center" + alignItems="center" + > + {loading ? ( + <Skeleton + variant="circular" + height={20} + width={20} + /> + ) : ( + <IOCStatusIcon ioc={{ id, activeDeployment, ...status }} /> + )} + </Grid> + ); +}; diff --git a/src/components/IOC/IOCTable/IOCTable.js b/src/components/IOC/IOCTable/IOCTable.js index c6bda80b4337dafc823db50fc702ee6d3c554ffd..7b747f81d9e94de7cecce162893ff24e32b356d3 100644 --- a/src/components/IOC/IOCTable/IOCTable.js +++ b/src/components/IOC/IOCTable/IOCTable.js @@ -1,7 +1,8 @@ import React from "react"; import { Table } from "@ess-ics/ce-ui-common"; -import { Grid, Tooltip, Typography, Link } from "@mui/material"; -import { IOCStatusIcon } from "../IOCIcons"; +import { Link } from "@mui/material"; +import { IOCDescription } from "./IOCDescription"; +import { IOCStatus } from "./IOCStatus"; import { noWrapText } from "../../common/Helper"; const ownIocsColumns = [ @@ -86,108 +87,61 @@ function createHostLink(host) { return "---"; } -function createIocDescription(description) { - return ( - <> - {description ? ( - <Tooltip - title={description} - arrow - enterDelay={400} - > - <Typography - style={{ - overflow: "hidden", - textOverflow: "ellipsis", - whiteSpace: "nowrap" - }} - > - {description} - </Typography> - </Tooltip> - ) : ( - "---" - )} - </> - ); -} - function createTableRowForHostDetails(ioc) { - const { id, name, namingName, alertSeverity, description } = ioc; + const { id, name, namingName, activeDeployment } = ioc; return { id: id, status: ( - <Grid - container - direction="column" - justifyContent="center" - alignItems="center" - > - <IOCStatusIcon ioc={ioc} /> - </Grid> + <IOCStatus + id={ioc.id} + activeDeployment={activeDeployment} + /> ), namingName: ( <Link href={`/iocs/${id}`}>{noWrapText(namingName ?? name)}</Link> ), - discrepancy: alertSeverity === "WARNING", - inconsistentState: alertSeverity === "ERROR", - description: createIocDescription(description) + description: <IOCDescription id={ioc.id} /> }; } function createTableRowForOwnIocs(ioc) { - const { id, activeDeployment, namingName, alertSeverity, description } = ioc; + const { id, activeDeployment, namingName } = ioc; return { id: id, status: ( - <Grid - container - direction="column" - justifyContent="flex-start" - alignItems="center" - > - <IOCStatusIcon ioc={ioc} /> - </Grid> + <IOCStatus + id={ioc.id} + activeDeployment={ioc.activeDeployment} + /> ), namingName: ( <Link href={`/iocs/${id}`}>{noWrapText(namingName ?? "---")}</Link> ), + description: <IOCDescription id={ioc.id} />, host: createHostLink(activeDeployment?.host), - network: noWrapText(activeDeployment?.host.network || "---"), - discrepancy: alertSeverity === "WARNING", - inconsistentState: alertSeverity === "ERROR", - iocNotDeployed: !ioc.activeDeployment, - description: createIocDescription(description) + network: noWrapText(activeDeployment?.host.network || "---") }; } function createTableRowForExploreIocs(ioc) { - const { id, namingName, createdBy, alertSeverity, host, description } = ioc; + const { id, namingName, activeDeployment } = ioc; return { id: id, status: ( - <Grid - container - direction="column" - justifyContent="center" - alignItems="center" - > - <IOCStatusIcon ioc={ioc} /> - </Grid> + <IOCStatus + id={ioc.id} + activeDeployment={ioc.activeDeployment} + /> ), namingName: ( <Link href={`/iocs/${id}`}>{noWrapText(namingName ?? "---")}</Link> ), - host: createHostLink(host), - network: noWrapText(host?.network || "---"), - createdBy: noWrapText(createdBy || "---"), - discrepancy: alertSeverity === "WARNING", - inconsistentState: alertSeverity === "ERROR", - iocNotDeployed: !ioc.activeDeployment, - description: createIocDescription(description) + description: <IOCDescription id={ioc.id} />, + host: createHostLink(activeDeployment?.host), + network: noWrapText(activeDeployment?.host?.network || "---") }; } diff --git a/src/components/IOC/IOCTable/IOCTable.spec.js b/src/components/IOC/IOCTable/IOCTable.spec.js index 1cbaeefbaca6b3cc8f33e256d7eff7025f170bee..c2606c24e04f4febd24a9ad1bba543bb82332040 100644 --- a/src/components/IOC/IOCTable/IOCTable.spec.js +++ b/src/components/IOC/IOCTable/IOCTable.spec.js @@ -10,8 +10,7 @@ const firstRowData = [ "VacS-RFQ:SC-IOC-130", "Some description", "vacs-accv-vm-ioc", - "ChannelAccess-FEB", - "1.0.0" + "ChannelAccess-FEB" ]; describe("HostTable", () => { @@ -31,7 +30,7 @@ describe("HostTable", () => { cy.findAllByRole("row") .eq(1) // first row is headers, so get next index .find(".MuiTypography-noWrap") - .should("have.length", textColumns.length - 2); + .should("have.length", textColumns.length - 1); }); it("Displays correct content in first row", () => { diff --git a/src/mocks/AppHarness.js b/src/mocks/AppHarness.js index d2de4995433e44b51a8d4b1e92750bc87ddceaf3..cb0ff47983f0658888712e7903a217b82babd416 100644 --- a/src/mocks/AppHarness.js +++ b/src/mocks/AppHarness.js @@ -1,6 +1,6 @@ import React from "react"; import { SnackbarProvider } from "notistack"; -import { Container, StyledEngineProvider } from "@mui/material"; +import { Container, CssBaseline, StyledEngineProvider } from "@mui/material"; import { ThemeProvider } from "@mui/material/styles"; import { theme } from "../style/Theme"; import { APIProvider } from "../api/SwaggerApi"; @@ -17,6 +17,7 @@ export function AppHarness({ children, initialHistory = ["/"] }) { > <StyledEngineProvider injectFirst> <ThemeProvider theme={theme}> + <CssBaseline /> <MemoryRouter initialEntries={initialHistory}> <APIProvider> <UserProvider> @@ -38,7 +39,10 @@ export function RouterHarness({ children, initialHistory = ["/"] }) { return ( <StyledEngineProvider injectFirst> <ThemeProvider theme={theme}> - <MemoryRouter initialEntries={initialHistory}>{children}</MemoryRouter> + <CssBaseline /> + <MemoryRouter initialEntries={initialHistory}> + <APIProvider>{children}</APIProvider> + </MemoryRouter> </ThemeProvider> </StyledEngineProvider> ); diff --git a/src/mocks/fixtures/AsyncCombinedIOCs.json b/src/mocks/fixtures/AsyncCombinedIOCs.json deleted file mode 100644 index 6c52463fbd6920fd6262ede6c6e9e3dd8c3e4c26..0000000000000000000000000000000000000000 --- a/src/mocks/fixtures/AsyncCombinedIOCs.json +++ /dev/null @@ -1,343 +0,0 @@ -[ - { - "id": 346, - "description": "some description", - "namingName": "VacS-RFQ:SC-IOC-130", - "createdBy": "krisztianloki", - "gitProjectId": 5336, - "activeDeployment": { - "host": { - "externalHostId": 3354 - }, - "sourceVersion": "1.0.0", - "sourceVersionShort": "1.0.0" - }, - "host": { - "externalId": 3354, - "fqdn": "vacs-accv-vm-ioc.tn.esss.lu.se", - "hostName": "vacs-accv-vm-ioc", - "network": "ChannelAccess-FEB" - }, - "active": true - }, - { - "id": 345, - "namingName": "VacS-RFQ:SC-IOC-119", - "createdBy": "krisztianloki", - "gitProjectId": 5335, - "activeDeployment": { - "host": { - "externalHostId": 3354 - }, - "sourceVersion": "cc95ff21a09977fd2396ec1999259ec0a5e63147", - "sourceVersionShort": "cc95ff21" - }, - "host": { - "externalId": 3354, - "fqdn": "vacs-accv-vm-ioc.tn.esss.lu.se", - "hostName": "vacs-accv-vm-ioc", - "network": "ChannelAccess-FEB" - }, - "alert": "ERROR", - "alerts": [ - { - "type": "WARNING", - "message": "Example alert without link" - }, - { - "type": "ERROR", - "message": "Example alert with link", - "link": "https://google.com" - } - ], - "active": true - }, - { - "id": 344, - "description": "some description", - "namingName": "VacS-RFQ:SC-IOC-110", - "createdBy": "krisztianloki", - "gitProjectId": 5334, - "activeDeployment": { - "host": { - "externalHostId": 3354 - }, - "sourceVersion": "9a3585a5bea4372f7d964b7e18b83aa3b1afc61f", - "sourceVersionShort": "9a3585a5" - }, - "host": { - "externalId": 3354, - "fqdn": "vacs-accv-vm-ioc.tn.esss.lu.se", - "hostName": "vacs-accv-vm-ioc", - "network": "ChannelAccess-FEB" - }, - "alert": "WARNING", - "alerts": [ - { - "type": "WARNING", - "message": "Example alert warning for VacS-RFQ:SC-IOC-110" - } - ], - "active": true - }, - { - "id": 328, - "namingName": "RFQ-010:SC-IOC-117", - "createdBy": "gabrielfedel", - "gitProjectId": 5953, - "sourceVersion": null, - "activeDeployment": null - }, - { - "id": 251, - "description": "some description", - "namingName": "RFQ-010:SC-IOC-015", - "createdBy": "lucianocarneiro", - "gitProjectId": 5952, - "sourceVersion": null, - "activeDeployment": null - }, - { - "id": 249, - "description": "some description", - "namingName": "RFQ-010:SC-IOC-016", - "createdBy": "gabrielfedel", - "gitProjectId": 5954, - "activeDeployment": { - "host": { - "externalHostId": 4205 - }, - "sourceVersion": "1.0.1", - "sourceVersionShort": "1.0.1" - }, - "host": { - "externalId": 4205, - "fqdn": "rfq-rf-vm-ioc.tn.esss.lu.se", - "hostName": "rfq-rf-vm-ioc", - "network": "ChannelAccess-ACC" - }, - "active": true - }, - { - "id": 166, - "namingName": "RFQ-010:SC-IOC-001", - "createdBy": "gabrielfedel", - "gitProjectId": 4314, - "activeDeployment": { - "host": { - "externalHostId": 2245 - }, - "sourceVersion": "3.0.3", - "sourceVersionShort": "3.0.3" - }, - "host": { - "externalId": 2245, - "fqdn": "rfq-llrf1-mtca-ioc.tn.esss.lu.se", - "hostName": "rfq-llrf1-mtca-ioc", - "network": "ChannelAccess-ACC" - }, - "alert": "ERROR", - "alerts": [ - { - "type": "ERROR", - "message": "Example alert error for RFQ-010:SC-IOC-001" - } - ] - }, - { - "id": 148, - "description": "some description", - "namingName": "RFQ-010:SC-IOC-977", - "createdBy": "krisztianloki", - "gitProjectId": 5429, - "activeDeployment": { - "host": { - "externalHostId": 4178 - }, - "sourceVersion": "0.0.2-usb", - "sourceVersionShort": "0.0.2-usb" - }, - "host": { - "externalId": 4178, - "fqdn": "rfq-ipc-01.tn.esss.lu.se", - "hostName": "rfq-ipc-01", - "network": "ChannelAccess-FEB" - }, - "alert": "WARNING", - "alerts": [ - { - "type": "WARNING", - "message": "Example alert warning for RFQ-010:SC-IOC-977" - } - ], - "active": true - }, - { - "id": 116, - "description": "some description", - "namingName": "RFQ-010:SC-IOC-005", - "createdBy": "joaopaulomartins", - "gitProjectId": 1697, - "activeDeployment": { - "host": { - "externalHostId": 4696 - }, - "sourceVersion": "1.0.0", - "sourceVersionShort": "1.0.0" - }, - "host": { - "externalId": 4696, - "fqdn": "rfq-rflps-vm-ioc01.tn.esss.lu.se", - "hostName": "rfq-rflps-vm-ioc01", - "network": "ChannelAccess-ACC" - }, - "active": true - }, - { - "id": 76, - "description": "some description", - "namingName": "RFQ-010:SC-IOC-004", - "createdBy": "joaopaulomartins", - "gitProjectId": 5257, - "activeDeployment": { - "host": { - "externalHostId": 4205 - }, - "sourceVersion": "1.1.0", - "sourceVersionShort": "1.1.0" - }, - "host": { - "externalId": 4205, - "fqdn": "rfq-rf-vm-ioc.tn.esss.lu.se", - "hostName": "rfq-rf-vm-ioc", - "network": "ChannelAccess-ACC" - }, - "active": true - }, - { - "id": 13, - "description": "some description", - "namingName": "RFQ-010:SC-IOC-056", - "createdBy": "krisztianloki", - "gitProjectId": 5056, - "activeDeployment": { - "host": { - "externalHostId": 4408 - }, - "sourceVersion": "2b8a031d7b698a6944e28408cb17241a7df9ec99", - "sourceVersionShort": "2b8a031d" - }, - "host": { - "externalId": 4408, - "fqdn": "rfq-lob-vm-ioc.tn.esss.lu.se", - "hostName": "rfq-lob-vm-ioc", - "network": "ChannelAccess-FEB" - }, - "alert": "WARNING", - "alerts": [ - { - "type": "WARNING", - "message": "Example alert warning for RFQ-010:SC-IOC-056" - } - ], - "active": true - }, - { - "id": 10, - "description": "some description", - "namingName": "RFQ-010:SC-IOC-011", - "createdBy": "anderslindh", - "gitProjectId": 4929, - "sourceVersion": "961ebd48020add0282688437ae34dd0974b6fa15", - "activeDeployment": null, - "sourceVersionShort": "961ebd48" - }, - { - "id": 9, - "description": "some description", - "namingName": "RFQ-010:SC-IOC-010", - "createdBy": "anderslindh", - "gitProjectId": 4875, - "activeDeployment": { - "host": { - "externalHostId": 4521 - }, - "sourceVersion": "0527d4cfa1c64276634961fefa8f480d00faee26", - "sourceVersionShort": "0527d4cf" - }, - "host": { - "externalId": 4521, - "fqdn": "lab-rf-vm-ioc-02.cslab.esss.lu.se", - "hostName": "lab-rf-vm-ioc-02", - "network": "CSLab-GeneralLab" - }, - "active": true - }, - { - "id": 8, - "description": "some description", - "namingName": "RFQ-010:SC-IOC-009", - "createdBy": "anderslindh", - "gitProjectId": 4947, - "sourceVersion": null, - "activeDeployment": null - }, - { - "id": 6, - "description": "some description", - "namingName": "RFQ-010:SC-IOC-008", - "createdBy": "anderslindh", - "gitProjectId": 2582, - "sourceVersion": null, - "activeDeployment": null - }, - { - "id": 4, - "description": "some description", - "namingName": "RFQ-010:SC-IOC-007", - "createdBy": "anderslindh", - "gitProjectId": 4877, - "activeDeployment": { - "host": { - "externalHostId": 4521 - }, - "sourceVersion": "cb065da1b6e5dcde6da091a93799ac8488e1e818", - "sourceVersionShort": "cb065da1" - }, - "host": { - "externalId": 4521, - "fqdn": "lab-rf-vm-ioc-02.cslab.esss.lu.se", - "hostName": "lab-rf-vm-ioc-02", - "network": "CSLab-GeneralLab" - }, - "active": true - }, - { - "id": 3, - "description": "some description", - "namingName": "RFQ-010:SC-IOC-006", - "createdBy": "anderslindh", - "gitProjectId": 4335, - "activeDeployment": { - "host": { - "externalHostId": 4205 - }, - "sourceVersion": "1.0.0", - "sourceVersionShort": "1.0.0" - }, - "host": { - "externalId": 4205, - "fqdn": "rfq-rf-vm-ioc.tn.esss.lu.se", - "hostName": "rfq-rf-vm-ioc", - "network": "ChannelAccess-ACC" - }, - "alert": "WARNING", - "alerts": [ - { - "type": "WARNING", - "message": "Example alert warning RFQ-010:SC-IOC-006" - } - ], - "active": true - } -] diff --git a/src/mocks/fixtures/IOCStatus.json b/src/mocks/fixtures/IOCStatus.json new file mode 100644 index 0000000000000000000000000000000000000000..58b546dbb8e27c6858b65db855c3972d18b73a1f --- /dev/null +++ b/src/mocks/fixtures/IOCStatus.json @@ -0,0 +1,105 @@ +[ + { + "id": 346, + "active": true + }, + { + "id": 345, + "alerts": [ + { + "type": "WARNING", + "message": "Example alert without link" + }, + { + "type": "ERROR", + "message": "Example alert with link", + "link": "https://google.com" + } + ], + "active": true + }, + { + "id": 344, + "alerts": [ + { + "type": "WARNING", + "message": "Example alert warning for VacS-RFQ:SC-IOC-110" + } + ], + "active": true + }, + { + "id": 328 + }, + { + "id": 251 + }, + { + "id": 249, + "active": true + }, + { + "id": 166, + "alerts": [ + { + "type": "ERROR", + "message": "Example alert error for RFQ-010:SC-IOC-001" + } + ] + }, + { + "id": 148, + "alerts": [ + { + "type": "WARNING", + "message": "Example alert warning for RFQ-010:SC-IOC-977" + } + ], + "active": true + }, + { + "id": 116, + "active": true + }, + { + "id": 76, + "active": true + }, + { + "id": 13, + "alerts": [ + { + "type": "WARNING", + "message": "Example alert warning for RFQ-010:SC-IOC-056" + } + ], + "active": true + }, + { + "id": 10 + }, + { + "id": 9, + "active": true + }, + { + "id": 8 + }, + { + "id": 6 + }, + { + "id": 4, + "active": true + }, + { + "id": 3, + "alerts": [ + { + "type": "WARNING", + "message": "Example alert warning RFQ-010:SC-IOC-006" + } + ], + "active": true + } +] diff --git a/src/mocks/fixtures/PagedIOCResponse.json b/src/mocks/fixtures/PagedIOCResponse.json index 3c715af04a354658fe4d36ade329d64fbd8a59c1..f208a09d94e887652052edbe8379392c0239f885 100644 --- a/src/mocks/fixtures/PagedIOCResponse.json +++ b/src/mocks/fixtures/PagedIOCResponse.json @@ -11,9 +11,13 @@ "gitProjectId": 5336, "activeDeployment": { "host": { - "externalHostId": 3354 + "externalHostId": 3354, + "fqdn": "vacs-accv-vm-ioc.tn.esss.lu.se", + "hostName": "vacs-accv-vm-ioc", + "network": "ChannelAccess-FEB" }, - "sourceVersion": "1.0.0" + "sourceVersion": "1.0.0", + "sourceVersionShort": "1.0.0" } }, { @@ -23,21 +27,30 @@ "gitProjectId": 5335, "activeDeployment": { "host": { - "externalHostId": 3354 + "externalHostId": 3354, + "fqdn": "vacs-accv-vm-ioc.tn.esss.lu.se", + "hostName": "vacs-accv-vm-ioc", + "network": "ChannelAccess-FEB" }, - "sourceVersion": "cc95ff21a09977fd2396ec1999259ec0a5e63147" + "sourceVersion": "cc95ff21a09977fd2396ec1999259ec0a5e63147", + "sourceVersionShort": "cc95ff21" } }, { "id": 344, + "description": "some description", "namingName": "VacS-RFQ:SC-IOC-110", "createdBy": "krisztianloki", "gitProjectId": 5334, "activeDeployment": { "host": { - "externalHostId": 3354 + "externalHostId": 3354, + "fqdn": "vacs-accv-vm-ioc.tn.esss.lu.se", + "hostName": "vacs-accv-vm-ioc", + "network": "ChannelAccess-FEB" }, - "sourceVersion": "9a3585a5bea4372f7d964b7e18b83aa3b1afc61f" + "sourceVersion": "9a3585a5bea4372f7d964b7e18b83aa3b1afc61f", + "sourceVersionShort": "9a3585a5" } }, { @@ -46,26 +59,32 @@ "createdBy": "gabrielfedel", "gitProjectId": 5953, "sourceVersion": null, - "activeDeployment": null + "activeDeployment": {} }, { "id": 251, + "description": "some description", "namingName": "RFQ-010:SC-IOC-015", "createdBy": "lucianocarneiro", "gitProjectId": 5952, "sourceVersion": null, - "activeDeployment": null + "activeDeployment": {} }, { "id": 249, + "description": "some description", "namingName": "RFQ-010:SC-IOC-016", "createdBy": "gabrielfedel", "gitProjectId": 5954, - "sourceVersion": "1.0.1", "activeDeployment": { "host": { - "externalHostId": 4205 - } + "externalHostId": 4205, + "fqdn": "rfq-rf-vm-ioc.tn.esss.lu.se", + "hostName": "rfq-rf-vm-ioc", + "network": "ChannelAccess-ACC" + }, + "sourceVersion": "1.0.1", + "sourceVersionShort": "1.0.1" } }, { @@ -75,117 +94,160 @@ "gitProjectId": 4314, "activeDeployment": { "host": { - "externalHostId": 2245 + "externalHostId": 2245, + "fqdn": "rfq-llrf1-mtca-ioc.tn.esss.lu.se", + "hostName": "rfq-llrf1-mtca-ioc", + "network": "ChannelAccess-ACC" }, - "sourceVersion": "3.0.3" + "sourceVersion": "3.0.3", + "sourceVersionShort": "3.0.3" } }, { "id": 148, + "description": "some description", "namingName": "RFQ-010:SC-IOC-977", "createdBy": "krisztianloki", "gitProjectId": 5429, "activeDeployment": { "host": { - "externalHostId": 4178 + "externalHostId": 4178, + "fqdn": "rfq-ipc-01.tn.esss.lu.se", + "hostName": "rfq-ipc-01", + "network": "ChannelAccess-FEB" }, - "sourceVersion": "0.0.2-usb" + "sourceVersion": "0.0.2-usb", + "sourceVersionShort": "0.0.2-usb" } }, { "id": 116, + "description": "some description", "namingName": "RFQ-010:SC-IOC-005", "createdBy": "joaopaulomartins", "gitProjectId": 1697, "activeDeployment": { "host": { - "externalHostId": 4696 + "externalHostId": 4696, + "fqdn": "rfq-rflps-vm-ioc01.tn.esss.lu.se", + "hostName": "rfq-rflps-vm-ioc01", + "network": "ChannelAccess-ACC" }, - "sourceVersion": "1.0.0" + "sourceVersion": "1.0.0", + "sourceVersionShort": "1.0.0" } }, { "id": 76, + "description": "some description", "namingName": "RFQ-010:SC-IOC-004", "createdBy": "joaopaulomartins", "gitProjectId": 5257, "activeDeployment": { "host": { - "externalHostId": 4205 + "externalHostId": 4205, + "fqdn": "rfq-rf-vm-ioc.tn.esss.lu.se", + "hostName": "rfq-rf-vm-ioc", + "network": "ChannelAccess-ACC" }, - "sourceVersion": "1.1.0" + "sourceVersion": "1.1.0", + "sourceVersionShort": "1.1.0" } }, { "id": 13, + "description": "some description", "namingName": "RFQ-010:SC-IOC-056", "createdBy": "krisztianloki", "gitProjectId": 5056, "activeDeployment": { "host": { - "externalHostId": 4408 + "externalHostId": 4408, + "fqdn": "rfq-lob-vm-ioc.tn.esss.lu.se", + "hostName": "rfq-lob-vm-ioc", + "network": "ChannelAccess-FEB" }, - "sourceVersion": "2b8a031d7b698a6944e28408cb17241a7df9ec99" + "sourceVersion": "2b8a031d7b698a6944e28408cb17241a7df9ec99", + "sourceVersionShort": "2b8a031d" } }, { "id": 10, + "description": "some description", "namingName": "RFQ-010:SC-IOC-011", "createdBy": "anderslindh", "gitProjectId": 4929, "sourceVersion": "961ebd48020add0282688437ae34dd0974b6fa15", - "activeDeployment": null + "activeDeployment": {}, + "sourceVersionShort": "961ebd48" }, { "id": 9, + "description": "some description", "namingName": "RFQ-010:SC-IOC-010", "createdBy": "anderslindh", "gitProjectId": 4875, "activeDeployment": { "host": { - "externalHostId": 4521 + "externalHostId": 4521, + "fqdn": "lab-rf-vm-ioc-02.cslab.esss.lu.se", + "hostName": "lab-rf-vm-ioc-02", + "network": "CSLab-GeneralLab" }, - "sourceVersion": "0527d4cfa1c64276634961fefa8f480d00faee26" + "sourceVersion": "0527d4cfa1c64276634961fefa8f480d00faee26", + "sourceVersionShort": "0527d4cf" } }, { "id": 8, + "description": "some description", "namingName": "RFQ-010:SC-IOC-009", "createdBy": "anderslindh", "gitProjectId": 4947, "sourceVersion": null, - "activeDeployment": null + "activeDeployment": {} }, { "id": 6, + "description": "some description", "namingName": "RFQ-010:SC-IOC-008", "createdBy": "anderslindh", "gitProjectId": 2582, "sourceVersion": null, - "activeDeployment": null + "activeDeployment": {} }, { "id": 4, + "description": "some description", "namingName": "RFQ-010:SC-IOC-007", "createdBy": "anderslindh", "gitProjectId": 4877, "activeDeployment": { "host": { - "externalHostId": 4521 + "externalHostId": 4521, + "fqdn": "lab-rf-vm-ioc-02.cslab.esss.lu.se", + "hostName": "lab-rf-vm-ioc-02", + "network": "CSLab-GeneralLab" }, - "sourceVersion": "cb065da1b6e5dcde6da091a93799ac8488e1e818" + "sourceVersion": "cb065da1b6e5dcde6da091a93799ac8488e1e818", + "sourceVersionShort": "cb065da1" } }, { "id": 3, + "description": "some description", "namingName": "RFQ-010:SC-IOC-006", "createdBy": "anderslindh", "gitProjectId": 4335, - "sourceVersion": "1.0.0", "activeDeployment": { "host": { - "externalHostId": 4205 - } + "externalHostId": 4205, + "fqdn": "rfq-rf-vm-ioc.tn.esss.lu.se", + "hostName": "rfq-rf-vm-ioc", + "network": "ChannelAccess-ACC" + }, + "sourceVersion": "1.0.0", + "sourceVersionShort": "1.0.0" } } ] diff --git a/src/mocks/mockAPI.js b/src/mocks/mockAPI.js index ee47758dcbb6763d0921053c02437279fa454fe3..7eca16ec9749b641cd087e055bb021dabb7efd86 100644 --- a/src/mocks/mockAPI.js +++ b/src/mocks/mockAPI.js @@ -167,6 +167,25 @@ function getProcservLogs(req) { return { body }; } +function fetchIocStatus(req) { + const params = getParameters(req, "/monitoring/status/:id"); + const data = require("./fixtures/IOCStatus.json"); + const { id, alertSeverity, alerts, active } = data.find( + (x) => `${x.id}` === params.id + ); + + const body = { + iocId: id, + alertSeverity, + alerts, + active + }; + console.debug("fetchIocStatus", data, params, body); + const status = body ? 200 : 404; + + return { body, status }; +} + function getStatistics(req) { const body = require("./fixtures/GeneralStatisticsResponse.json"); return { body }; @@ -187,11 +206,6 @@ function activeIocHistory(req) { return { body }; } -function listOwnIocsWithAlarms(req) { - const body = require("./fixtures/AsyncCombinedIOCs.json"); - return { body }; -} - function fetchIOCByName(req) { const body = require("./fixtures/NamingNames.json"); return { body }; @@ -208,9 +222,8 @@ const mockAPI = { }, iocs: { listIOCs, - createIoc, getIOC, - listOwnIocsWithAlarms + createIoc }, deployments: { getDeployment, @@ -227,7 +240,8 @@ const mockAPI = { listProjects }, monitoring: { - getProcservLogs + getProcservLogs, + fetchIocStatus }, statistics: { getStatistics, @@ -280,12 +294,6 @@ export const apiHandlers = [ makeHandler("GET", qRegExp(".*/iocs"), mockAPI.iocs.listIOCs), makeHandler("POST", qRegExp(".*/iocs"), mockAPI.iocs.createIoc), makeHandler("GET", qRegExp(".*/iocs/[0-9]+"), mockAPI.iocs.getIOC), - makeHandler( - "GET", - qRegExp(".*/iocs/my_iocs_with_alarms"), - mockAPI.iocs.listOwnIocsWithAlarms - ), - // git makeHandler( "GET", qRegExp(".*/git_helper/user_info"), @@ -342,6 +350,11 @@ export const apiHandlers = [ mockAPI.monitoring.getProcservLogs, auth ), + makeHandler( + "GET", + qRegExp(".*/monitoring/status/.+"), + mockAPI.monitoring.fetchIocStatus + ), // statistics makeHandler( diff --git a/src/stories/components/common/IOC/IOCTable.stories.js b/src/stories/components/common/IOC/IOCTable.stories.js index de1eb20d83e2414b734d41bd3f91e12d01174fa1..7d3ceb67d5999d95e0c2f27366c5b8d337ecfe75 100644 --- a/src/stories/components/common/IOC/IOCTable.stories.js +++ b/src/stories/components/common/IOC/IOCTable.stories.js @@ -1,10 +1,14 @@ import React from "react"; import { IOCTable } from "../../../../components/IOC/IOCTable"; -import { Container } from "@mui/material"; +import { Box } from "@mui/material"; import iocs from "../../../../mocks/fixtures/PagedIOCResponse.json"; -import asyncCombinedIOCs from "../../../../mocks/fixtures/AsyncCombinedIOCs.json"; +import { rest } from "msw"; +import { handlers } from "../../../../mocks/handlers"; import { RouterHarness } from "../../../../mocks/AppHarness"; -import { disabledTable } from "../../../utils/common-args"; +import { + hideStorybookControls, + paginationNoResults +} from "../../../utils/common-args"; export default { title: "IOC/IOCTable", @@ -13,23 +17,21 @@ export default { options: ["explore", "host"], control: { type: "radio" } }, - iocs: disabledTable, - totalCount: disabledTable, - rowsPerPage: disabledTable, - lazyParams: disabledTable, - columnSort: disabledTable, - setLazyParams: disabledTable, - setColumnSort: disabledTable + iocs: hideStorybookControls, + pagination: hideStorybookControls, + onPage: hideStorybookControls } }; -const Template = (args) => ( - <RouterHarness> - <Container> - <IOCTable {...args} /> - </Container> - </RouterHarness> -); +const Template = (args) => { + return ( + <RouterHarness> + <Box height="90vh"> + <IOCTable {...args} /> + </Box> + </RouterHarness> + ); +}; export const Empty = (args) => <Template {...args} />; @@ -37,13 +39,8 @@ Empty.args = { rowType: "explore", loading: false, iocs: [], - paginator: true, - totalCount: 0, - rowsPerPage: [5, 10, 20, 50, 100], - lazyParams: { rows: 10, page: 0 }, - columnSort: { sortField: null, sortOrder: null }, - setLazyParams: () => {}, - setColumnSort: () => {} + pagination: paginationNoResults, + onPage: () => {} }; export const EmptyLoading = (args) => <Template {...args} />; @@ -57,17 +54,24 @@ export const BeforeAsync = (args) => <Template {...args} />; BeforeAsync.args = { ...Empty.args, - totalCount: iocs.totalCount, + pagination: { ...paginationNoResults, totalCount: iocs.totalCount }, iocs: iocs.iocList }; - BeforeAsync.argTypes = { - loading: disabledTable + loading: hideStorybookControls +}; +BeforeAsync.parameters = { + msw: { + handlers: [ + rest.get("*/iocs/*", (req, res, ctx) => res(ctx.delay("infinite"))), + rest.get("*/monitoring/status/*", (req, res, ctx) => + res(ctx.delay("infinite")) + ), + ...handlers + ] + } }; export const AfterAsync = (args) => <Template {...args} />; - -AfterAsync.args = { - ...BeforeAsync.args, - iocs: asyncCombinedIOCs -}; +AfterAsync.args = { ...BeforeAsync.args }; +AfterAsync.argTypes = { ...BeforeAsync.argTypes }; diff --git a/src/stories/components/common/host/HostTable.stories.js b/src/stories/components/common/host/HostTable.stories.js index 80e1e304828186fe1ad9f760f53820ef7d058e45..b7a59361b95709926b829b2221c623d58036d338 100644 --- a/src/stories/components/common/host/HostTable.stories.js +++ b/src/stories/components/common/host/HostTable.stories.js @@ -3,18 +3,18 @@ import { Container } from "@mui/material"; import hosts from "../../../../mocks/fixtures/PagedCSEntryHostResponse.json"; import { HostTable } from "../../../../components/host/HostTable"; import { RouterHarness } from "../../../../mocks/AppHarness"; -import { disabledTable } from "../../../utils/common-args"; +import { hideStorybookControls } from "../../../utils/common-args"; export default { title: "Host/HostTable", argTypes: { - hosts: disabledTable, - totalCount: disabledTable, - rowsPerPage: disabledTable, - lazyParams: disabledTable, - columnSort: disabledTable, - setLazyParams: disabledTable, - setColumnSort: disabledTable + hosts: hideStorybookControls, + totalCount: hideStorybookControls, + rowsPerPage: hideStorybookControls, + lazyParams: hideStorybookControls, + columnSort: hideStorybookControls, + setLazyParams: hideStorybookControls, + setColumnSort: hideStorybookControls } }; @@ -55,7 +55,7 @@ Populated.args = { }; Populated.argTypes = { - totalCount: disabledTable, - hosts: disabledTable, - loading: disabledTable + totalCount: hideStorybookControls, + hosts: hideStorybookControls, + loading: hideStorybookControls }; diff --git a/src/stories/components/common/job/JobTable.stories.js b/src/stories/components/common/job/JobTable.stories.js index de00a0249fe805c988a6517af1e1d9be13ef4e45..0421e124639b16e16659ea89c2ee0e03abdc2949 100644 --- a/src/stories/components/common/job/JobTable.stories.js +++ b/src/stories/components/common/job/JobTable.stories.js @@ -1,20 +1,20 @@ import React from "react"; import { RouterHarness } from "../../../../mocks/AppHarness"; import { JobTable } from "../../../../components/Job/JobTable"; -import { disabledTable } from "../../../utils/common-args"; +import { hideStorybookControls } from "../../../utils/common-args"; import { Container } from "@mui/material"; import operationList from "../../../../mocks/fixtures/OperationList.json"; export default { title: "Jobs/JobTable", argTypes: { - jobs: disabledTable, - totalCount: disabledTable, - rowsPerPage: disabledTable, - lazyParams: disabledTable, - columnSort: disabledTable, - setLazyParams: disabledTable, - setColumnSort: disabledTable + jobs: hideStorybookControls, + totalCount: hideStorybookControls, + rowsPerPage: hideStorybookControls, + lazyParams: hideStorybookControls, + columnSort: hideStorybookControls, + setLazyParams: hideStorybookControls, + setColumnSort: hideStorybookControls } }; @@ -56,7 +56,7 @@ Populated.args = { }; Populated.argTypes = { - totalCount: disabledTable, - hosts: disabledTable, - loading: disabledTable + totalCount: hideStorybookControls, + hosts: hideStorybookControls, + loading: hideStorybookControls }; diff --git a/src/stories/utils/common-args.js b/src/stories/utils/common-args.js index 1378ebeffaa5a9f8dfc087a04617fed026c421a3..ed66429f96cd717df1356a6c267388143165e686 100644 --- a/src/stories/utils/common-args.js +++ b/src/stories/utils/common-args.js @@ -1,5 +1,13 @@ -export const disabledTable = { +// see https://storybook.js.org/docs/react/essentials/controls#disable-controls-for-specific-properties +export const hideStorybookControls = { table: { disable: true } }; + +export const paginationNoResults = { + totalCount: 0, + rowsPerPageOptions: [5, 10, 20, 50, 100], + rows: 10, + page: 0 +};