Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(heureka) : Add components view #263

Merged
merged 8 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 4 additions & 17 deletions heureka/ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions heureka/ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "heureka",
"version": "2.2.2",
"version": "2.3.0",
"author": "UI-Team",
"contributors": [
"Hoda Noori, Arturo Reuschenbach Pucernau"
Expand Down Expand Up @@ -31,7 +31,7 @@
"immer": "^10.0.0",
"jest": "^29.3.1",
"jest-environment-jsdom": "^29.3.1",
"luxon": "^3.0.0",
"luxon": "^3.4.4",
"postcss": "^8.4.21",
"postcss-url": "^10.1.3",
"prop-types": "^15.8.1",
Expand Down
51 changes: 51 additions & 0 deletions heureka/ui/src/components/components/ComponentsList.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Greenhouse contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from "react"
import {
DataGrid,
DataGridRow,
DataGridHeadCell,
DataGridCell,
} from "@cloudoperators/juno-ui-components"
import HintNotFound from "../shared/HintNotFound"
import HintLoading from "../shared/HintLoading"
import ComponentsListItem from "./ComponentsListItem"

const ComponentsList = ({ components, isLoading }) => {
return (
<DataGrid columns={3}>
<DataGridRow>
<DataGridHeadCell>Name</DataGridHeadCell>
<DataGridHeadCell>Type</DataGridHeadCell>
<DataGridHeadCell>Total Number of Versions</DataGridHeadCell>
</DataGridRow>
{isLoading && !components ? (
<HintLoading className="my-4" text="Loading components..." />
) : (
<>
{components?.length > 0 ? (
<>
{components.map((item, index) => (
<ComponentsListItem
key={index}
item={item}
></ComponentsListItem>
))}
</>
) : (
<DataGridRow>
<DataGridCell colSpan={10}>
<HintNotFound text="No components found" />
</DataGridCell>
</DataGridRow>
)}
</>
)}
</DataGrid>
)
}

export default ComponentsList
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Greenhouse contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React, { useMemo, useState } from "react"
import { useQuery } from "@tanstack/react-query"
import {
useQueryClientFnReady,
useQueryOptions,
useActions,
} from "../StoreProvider"
import ComponentsList from "./ComponentsList"
import {
Pagination,
Container,
Stack,
} from "@cloudoperators/juno-ui-components"

const ComponentsListController = () => {
const queryClientFnReady = useQueryClientFnReady()
const queryOptions = useQueryOptions("components")
const { setQueryOptions } = useActions()

const { isLoading, isFetching, isError, data, error } = useQuery({
queryKey: [`components`, queryOptions],
enabled: !!queryClientFnReady,
})

const [currentPage, setCurrentPage] = useState(1) // State for current page

const components = useMemo(() => {
if (!data) return null
return data?.Components?.edges
}, [data])

const pageInfo = useMemo(() => {
if (!data) return null
return data?.Components?.pageInfo
}, [data])

const totalPages = useMemo(() => {
if (!data?.Components?.pageInfo?.pages) return 0
return data?.Components?.pageInfo?.pages.length
}, [data?.Components?.pageInfo])
const onPaginationChanged = (newPage) => {
setCurrentPage(newPage) // Update currentPage
if (!data?.Components?.pageInfo?.pages) return
const pages = data?.Components?.pageInfo?.pages
const currentPageIndex = pages?.findIndex(
(page) => page?.pageNumber === parseInt(newPage)
)
if (currentPageIndex > -1) {
const after = pages[currentPageIndex]?.after
setQueryOptions("components", {
...queryOptions,
after: `${after}`,
})
}
}

const onPressNext = () => {
onPaginationChanged(parseInt(currentPage) + 1)
}
const onPressPrevious = () => {
onPaginationChanged(parseInt(currentPage) - 1)
}
const onKeyPress = (oKey) => {
if (oKey.code === "Enter") {
onPaginationChanged(parseInt(oKey.currentTarget.value))
}
}

return (
<>
<Container py>
<ComponentsList components={components} isLoading={isLoading} />
</Container>
<Stack className="flex justify-end">
<Pagination
currentPage={currentPage}
isFirstPage={currentPage === 1}
isLastPage={currentPage === totalPages}
onPressNext={onPressNext}
onPressPrevious={onPressPrevious}
onKeyPress={onKeyPress}
onSelectChange={onPaginationChanged}
pages={totalPages}
variant="input"
/>
</Stack>
</>
)
}

export default ComponentsListController
19 changes: 19 additions & 0 deletions heureka/ui/src/components/components/ComponentsListItem.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Greenhouse contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from "react"
import { DataGridRow, DataGridCell } from "@cloudoperators/juno-ui-components"

const ComponentsListItem = ({ item }) => {
return (
<DataGridRow>
<DataGridCell>{item?.node?.name}</DataGridCell>
<DataGridCell>{item?.node?.type}</DataGridCell>
<DataGridCell>{item?.node?.componentVersions?.totalCount}</DataGridCell>
</DataGridRow>
)
}

export default ComponentsListItem
19 changes: 19 additions & 0 deletions heureka/ui/src/components/components/ComponentsTab.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Greenhouse contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from "react"
import ComponentsListController from "./ComponentsListController"
import Filters from "../filters/Filters"

const ComponentsTab = () => {
return (
<>
<Filters />
<ComponentsListController />
</>
)
}

export default ComponentsTab
8 changes: 5 additions & 3 deletions heureka/ui/src/components/issues/IssuesList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ import IssuesListItem from "./IssuesListItem"

const IssuesList = ({ issues, isLoading }) => {
return (
<DataGrid columns={9}>
<DataGrid columns={10}>
<DataGridRow>
<DataGridHeadCell>Primary Name</DataGridHeadCell>
<DataGridHeadCell>Secondary Name</DataGridHeadCell>
<DataGridHeadCell>Type</DataGridHeadCell>
{/* <DataGridHeadCell>Secondary Name</DataGridHeadCell> */}
<DataGridHeadCell>Remediation Date</DataGridHeadCell>
<DataGridHeadCell>Status</DataGridHeadCell>
<DataGridHeadCell>Severity</DataGridHeadCell>
<DataGridHeadCell>Component Name</DataGridHeadCell>
Expand All @@ -40,7 +42,7 @@ const IssuesList = ({ issues, isLoading }) => {
</>
) : (
<DataGridRow>
<DataGridCell colSpan={9}>
<DataGridCell colSpan={10}>
<HintNotFound text="No issues found" />
</DataGridCell>
</DataGridRow>
Expand Down
34 changes: 21 additions & 13 deletions heureka/ui/src/components/issues/IssuesListController.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import {
useActions,
} from "../StoreProvider"
import IssuesList from "./IssuesList"
import { Pagination } from "@cloudoperators/juno-ui-components"
import {
Container,
Pagination,
Stack,
} from "@cloudoperators/juno-ui-components"

const IssuesListController = () => {
const queryClientFnReady = useQueryClientFnReady()
Expand Down Expand Up @@ -69,18 +73,22 @@ const IssuesListController = () => {

return (
<>
<IssuesList issues={issues} isLoading={isLoading} />
<Pagination
currentPage={currentPage}
isFirstPage={currentPage === 1}
isLastPage={currentPage === totalPages}
onPressNext={onPressNext}
onPressPrevious={onPressPrevious}
onKeyPress={onKeyPress}
onSelectChange={onPaginationChanged}
pages={totalPages}
variant="input"
/>
<Container py>
<IssuesList issues={issues} isLoading={isLoading} />
</Container>
<Stack className="flex justify-end">
<Pagination
currentPage={currentPage}
isFirstPage={currentPage === 1}
isLastPage={currentPage === totalPages}
onPressNext={onPressNext}
onPressPrevious={onPressPrevious}
onKeyPress={onKeyPress}
onSelectChange={onPaginationChanged}
pages={totalPages}
variant="input"
/>
</Stack>
</>
)
}
Expand Down
15 changes: 10 additions & 5 deletions heureka/ui/src/components/issues/IssuesListItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,24 @@
import React from "react"
import { DataGridRow, DataGridCell } from "@cloudoperators/juno-ui-components"
import { listOfCommaSeparatedObjs } from "../shared/Helper"
import { DateTime } from "luxon"

const IssuesListItem = ({ item }) => {
// Log the item structure
console.log("Item structure:", item)
const formatDate = (dateStr) => {
const dateObj = DateTime.fromISO(dateStr)
return dateObj.toFormat("yyyy.MM.dd.HH:mm:ss")
}
return (
<DataGridRow>
<DataGridCell>{item?.node?.issue?.primaryName}</DataGridCell>
<DataGridCell>
<DataGridCell>{item?.node?.issue?.type}</DataGridCell>
{/* <DataGridCell>
{listOfCommaSeparatedObjs(
item?.node?.effectiveIssueVariants,
"secondaryName"
)}
</DataGridCell>
)}
</DataGridCell> */}
<DataGridCell>{formatDate(item?.node?.remediationDate)}</DataGridCell>
<DataGridCell>{item?.node?.status}</DataGridCell>
<DataGridCell>{item?.node?.severity?.value}</DataGridCell>
<DataGridCell>
Expand Down
Loading
Loading