Skip to content

Commit

Permalink
Some improvements
Browse files Browse the repository at this point in the history
* Add recommended extensions
* Better filtering
* Added message when there is nothing to show
  • Loading branch information
EhabY committed Aug 25, 2024
1 parent 318cb11 commit bd4abac
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 16 deletions.
4 changes: 4 additions & 0 deletions ui/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode", "SonarSource.sonarlint-vscode"],
"unwantedRecommendations": []
}
20 changes: 18 additions & 2 deletions ui/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SwarmCD UI

This repository contains the code for the Swarm-CD UI, a web-based user interface for checking the deployment status. The UI is built using React and bundled by Vite for fast and efficient development and build processes.
This repository contains the code for the SwarmCD UI, a web-based user interface for checking the deployment status. The UI is built using React and bundled by Vite for fast and efficient development and build processes.

## Installation

Expand All @@ -12,7 +12,7 @@ This repository contains the code for the Swarm-CD UI, a web-based user interfac

## Directory structure

```
```text
swarm-cd-ui/
├── public/ # Static assets
├── src/ # Source files
Expand All @@ -24,3 +24,19 @@ swarm-cd-ui/
├── package.json # Project metadata and scripts
└── vite.config.ts # Vite configuration
```

Recommended `.vscode/settings.json`:

```json
{
"editor.codeActionsOnSave": {
"source.organizeImports": "always",
"source.fixAll.eslint": "always"
},
"editor.tabSize": 2,
"editor.formatOnSave": true,
"eslint.format.enable": true,
"eslint.lintTask.enable": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
```
10 changes: 5 additions & 5 deletions ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ function App(): React.ReactElement {
return (
<>
<Container maxW="container.lg" mt={4}>
<HeaderBar onQueryChange={query => setSearchQuery(query)} />
{error !== null ? (
<Text fontSize="xl" align="center">
<HeaderBar onQueryChange={query => setSearchQuery(query)} error={error !== null} />
{error === null ? (
<StatusCardList statuses={stacks} query={searchQuery} />
) : (
<Text fontSize="xl" align="center" color="red.500">
{error}
</Text>
) : (
<StatusCardList statuses={stacks} query={searchQuery} />
)}
</Container>
</>
Expand Down
9 changes: 8 additions & 1 deletion ui/src/components/HeaderBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import React from "react"
import { FaGithub } from "react-icons/fa"
import ColorToggleButton from "./ColorToggleButton"

function HeaderBar({ onQueryChange }: { onQueryChange: (query: string) => void }): React.ReactElement {
function HeaderBar({
onQueryChange,
error
}: Readonly<{
onQueryChange: (query: string) => void
error: boolean
}>): React.ReactElement {
return (
<Box
as="header"
Expand All @@ -30,6 +36,7 @@ function HeaderBar({ onQueryChange }: { onQueryChange: (query: string) => void }
size="lg"
variant="filled"
bg={useColorModeValue("gray.200", "gray.800")}
disabled={error}
/>
</Box>

Expand Down
6 changes: 2 additions & 4 deletions ui/src/components/StatusCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@ function StatusCard({
repoURL: string
}>): React.ReactElement {
return (
<Box borderWidth="1px" borderRadius="sm" overflow="hidden" p={4} boxShadow="md">
<Box borderWidth="1px" borderRadius="sm" overflow="hidden" p={4} boxShadow="lg">
<Grid templateColumns="auto 1fr" gap={2}>
<Text fontWeight="bold">Name:</Text>
<Text>{name}</Text>

{error !== "" && (
<>
<Text fontWeight="bold" color="red.500">
Error:
</Text>
<Text fontWeight="bold">Error:</Text>
<Text color="red.500">{error}</Text>
</>
)}
Expand Down
17 changes: 13 additions & 4 deletions ui/src/components/StatusCardList.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Text } from "@chakra-ui/react"
import React, { useEffect, useState } from "react"
import { StackStatus } from "../hooks/useFetchStatuses"
import StatusCard from "./StatusCard"
Expand All @@ -6,15 +7,23 @@ function StatusCardList({ statuses, query }: Readonly<{ statuses: StackStatus[];
const [filteredStatuses, setFilteredStatuses] = useState<StackStatus[]>(statuses)

useEffect(() => {
const filtered = statuses.filter(status => Object.values(status).join().toLowerCase().includes(query.toLowerCase()))
const filtered = statuses.filter(status =>
Object.values(status).some(value => value.toString().toLowerCase().includes(query.toLowerCase()))
)
setFilteredStatuses(filtered)
}, [statuses, query])

return (
<>
{filteredStatuses.map((item, index) => (
<StatusCard key={index} name={item.Name} error={item.Error} revision={item.Revision} repoURL={item.RepoURL} />
))}
{filteredStatuses.length === 0 ? (
<Text fontSize="xl" align="center" mt={4}>
No items available
</Text>
) : (
filteredStatuses.map((item, index) => (
<StatusCard key={index} name={item.Name} error={item.Error} revision={item.Revision} repoURL={item.RepoURL} />
))
)}
</>
)
}
Expand Down

0 comments on commit bd4abac

Please sign in to comment.