generated from cloudoperators/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(heureka) : Add components view (#263)
* feat(heureka) : add components view * Automatic application of license header * Install date-fns * feat(heureka): Add the total number of component versions and fix some errors * feat)heureka): Add pagination info to the components query * Using container and stack for styling and some cleanup * add componentInstances to componentVersion in the component query * Change the setting to put pagination on the right side of the page --------- Co-authored-by: License Bot <[email protected]>
- Loading branch information
Showing
14 changed files
with
391 additions
and
32 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,9 +31,13 @@ | |
"immer": "^10.0.0", | ||
"jest": "^29.3.1", | ||
"jest-environment-jsdom": "^29.3.1", | ||
<<<<<<< HEAD | ||
"juno-ui-components": "https://assets.juno.global.cloud.sap/libs/[email protected]/package.tgz", | ||
"luxon": "^3.0.0", | ||
"messages-provider": "https://assets.juno.global.cloud.sap/libs/[email protected]/package.tgz", | ||
======= | ||
"luxon": "^3.4.4", | ||
>>>>>>> 01cf4521 (feat(heureka) : Add components view (#263)) | ||
"postcss": "^8.4.21", | ||
"postcss-url": "^10.1.3", | ||
"prop-types": "^15.8.1", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
96 changes: 96 additions & 0 deletions
96
heureka/ui/src/components/components/ComponentsListController.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
heureka/ui/src/components/components/ComponentsListItem.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.