feat: add badge component to display container state with color coding

This commit is contained in:
faytranevozter
2024-12-27 01:44:46 +07:00
parent f69fb7684b
commit 27252cf58d
3 changed files with 66 additions and 5 deletions

View File

@@ -1,3 +1,4 @@
import { Badge } from "@/components/ui/badge";
import { import {
Card, Card,
CardContent, CardContent,
@@ -30,6 +31,21 @@ export const DockerLogs = dynamic(
}, },
); );
const badgeStateColor = (state: string) => {
switch (state) {
case "running":
return "green";
case "exited":
case "shutdown":
return "red";
case "accepted":
case "created":
return "blue";
default:
return "default";
}
};
interface Props { interface Props {
appName: string; appName: string;
serverId?: string; serverId?: string;
@@ -123,7 +139,9 @@ export const ShowDockerLogs = ({ appName, serverId }: Props) => {
value={container.containerId} value={container.containerId}
> >
{container.name} ({container.containerId}){" "} {container.name} ({container.containerId}){" "}
{container.state} <Badge variant={badgeStateColor(container.state)}>
{container.state}
</Badge>
</SelectItem> </SelectItem>
))} ))}
</div> </div>
@@ -135,7 +153,10 @@ export const ShowDockerLogs = ({ appName, serverId }: Props) => {
value={container.containerId} value={container.containerId}
> >
{container.name} ({container.containerId}@{container.node} {container.name} ({container.containerId}@{container.node}
) {container.state} )
<Badge variant={badgeStateColor(container.state)}>
{container.state}
</Badge>
</SelectItem> </SelectItem>
))} ))}
</> </>

View File

@@ -1,3 +1,4 @@
import { Badge } from "@/components/ui/badge";
import { import {
Card, Card,
CardContent, CardContent,
@@ -35,6 +36,21 @@ interface Props {
serverId?: string; serverId?: string;
} }
const badgeStateColor = (state: string) => {
switch (state) {
case "running":
return "green";
case "exited":
case "shutdown":
return "red";
case "accepted":
case "created":
return "blue";
default:
return "default";
}
};
export const ShowDockerLogsStack = ({ appName, serverId }: Props) => { export const ShowDockerLogsStack = ({ appName, serverId }: Props) => {
const [option, setOption] = useState<"swarm" | "native">("native"); const [option, setOption] = useState<"swarm" | "native">("native");
const [containerId, setContainerId] = useState<string | undefined>(); const [containerId, setContainerId] = useState<string | undefined>();
@@ -123,7 +139,9 @@ export const ShowDockerLogsStack = ({ appName, serverId }: Props) => {
value={container.containerId} value={container.containerId}
> >
{container.name} ({container.containerId}){" "} {container.name} ({container.containerId}){" "}
{container.state} <Badge variant={badgeStateColor(container.state)}>
{container.state}
</Badge>
</SelectItem> </SelectItem>
))} ))}
</div> </div>
@@ -135,7 +153,10 @@ export const ShowDockerLogsStack = ({ appName, serverId }: Props) => {
value={container.containerId} value={container.containerId}
> >
{container.name} ({container.containerId}@{container.node} {container.name} ({container.containerId}@{container.node}
) {container.state} )
<Badge variant={badgeStateColor(container.state)}>
{container.state}
</Badge>
</SelectItem> </SelectItem>
))} ))}
</> </>

View File

@@ -1,3 +1,4 @@
import { Badge } from "@/components/ui/badge";
import { import {
Card, Card,
CardContent, CardContent,
@@ -35,6 +36,21 @@ interface Props {
appType: "stack" | "docker-compose"; appType: "stack" | "docker-compose";
} }
const badgeStateColor = (state: string) => {
switch (state) {
case "running":
return "green";
case "exited":
case "shutdown":
return "red";
case "accepted":
case "created":
return "blue";
default:
return "default";
}
};
export const ShowDockerLogsCompose = ({ export const ShowDockerLogsCompose = ({
appName, appName,
appType, appType,
@@ -87,7 +103,10 @@ export const ShowDockerLogsCompose = ({
key={container.containerId} key={container.containerId}
value={container.containerId} value={container.containerId}
> >
{container.name} ({container.containerId}) {container.state} {container.name} ({container.containerId}){" "}
<Badge variant={badgeStateColor(container.state)}>
{container.state}
</Badge>
</SelectItem> </SelectItem>
))} ))}
<SelectLabel>Containers ({data?.length})</SelectLabel> <SelectLabel>Containers ({data?.length})</SelectLabel>